refactor(realism): enforce synthetic_files 64KB cap at the repo

The orchestrator worker clipped last_body at write time, but the repo
didn't enforce. A future caller that forgot the clip would write the
full body. Move the clip to record_synthetic_file and
update_synthetic_file via SYNTHETIC_FILE_BODY_LIMIT in
decnet/web/db/models/realism.py. Worker now passes the full body and
trusts the repo. Tests retargeted to assert repo enforcement.
This commit is contained in:
2026-04-27 17:37:36 -04:00
parent b86129e35e
commit 7e9bc6d49a
4 changed files with 33 additions and 39 deletions

View File

@@ -385,7 +385,7 @@ async def _bump_synthetic_file_after_edit(repo, action, result) -> None:
patch["content_hash"] = hashlib.sha256(
new_body.encode("utf-8"),
).hexdigest()
patch["last_body"] = new_body[:65536]
patch["last_body"] = new_body
await repo.update_synthetic_file(action.synthetic_file_uuid, patch)
@@ -411,10 +411,7 @@ async def _record_synthetic_file(repo, action) -> None:
"last_modified": now,
"edit_count": 0,
"content_hash": content_hash,
# Cap the persisted body — large blobs (DOCX/PDF/canary
# artifacts in stage 7) are wasted disk on this side; the
# decky filesystem holds the canonical bytes.
"last_body": body[:65536],
"last_body": body,
}
try:
await repo.record_synthetic_file(row)
@@ -432,7 +429,7 @@ async def _record_synthetic_file(repo, action) -> None:
{
"last_modified": now,
"content_hash": content_hash,
"last_body": body[:65536],
"last_body": body,
"edit_count": int(match.get("edit_count", 0)) + 1,
},
)