Create activity for existing assets in record_run
When asset already exists, check if activity exists too. If no activity, create one for the existing asset. This fixes the case where an asset was registered but the activity creation failed or was skipped. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
29
server.py
29
server.py
@@ -2197,7 +2197,34 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
|
||||
existing = await db.get_asset_by_name_tx(conn, output_hash)
|
||||
if existing:
|
||||
logger.info(f"record_run: Output {output_hash[:16]}... already exists")
|
||||
return {"asset": existing, "activity": None, "existing": True}
|
||||
# Check if activity already exists for this run
|
||||
existing_activity = await db.get_activity(provenance["run_id"])
|
||||
if existing_activity:
|
||||
logger.info(f"record_run: Activity {provenance['run_id'][:16]}... also exists")
|
||||
return {"asset": existing, "activity": existing_activity, "existing": True}
|
||||
# Asset exists but no activity - create one
|
||||
logger.info(f"record_run: Creating activity for existing asset")
|
||||
object_data = {
|
||||
"type": existing.get("asset_type", "image").capitalize(),
|
||||
"name": output_hash,
|
||||
"id": f"https://{DOMAIN}/objects/{output_hash}",
|
||||
"contentHash": {
|
||||
"algorithm": "sha3-256",
|
||||
"value": output_hash
|
||||
},
|
||||
"attributedTo": f"https://{DOMAIN}/users/{user.username}",
|
||||
"provenance": provenance
|
||||
}
|
||||
activity = {
|
||||
"activity_id": provenance["run_id"],
|
||||
"activity_type": "Create",
|
||||
"actor_id": f"https://{DOMAIN}/users/{user.username}",
|
||||
"object_data": object_data,
|
||||
"published": now
|
||||
}
|
||||
activity = sign_activity(activity, user.username)
|
||||
created_activity = await db.create_activity_tx(conn, activity)
|
||||
return {"asset": existing, "activity": created_activity, "existing": True}
|
||||
|
||||
# Create output asset with provenance - named by content_hash
|
||||
output_asset = {
|
||||
|
||||
Reference in New Issue
Block a user