Repository navigation
fix(runtime): persist attachment bytes so reconstructed context matches what the model saw (F05) - #69
Merged
Merged
Conversation
…es what the model saw (F05) A prompt's `@path` attachments were read into the live request at run start while the durable message row kept the placeholder, so every later request in the session — follow-up, reopen, compaction, and the retry after an automatic compaction — replayed `inspect\[email protected]` where the model's first turn had seen the file bytes. Modifying or deleting the file made the gap permanent. Run start now persists each attachment (path, whole-file SHA-256, line window, content) in the same transaction that marks the run started: store schema 28 -> 29 adds `attachment_blobs`, keyed per session by hash+window so a file attached to several prompts is stored once, and `message_attachments` in prompt order. `load_model_context` joins them and re-renders the `<attached-file>` blocks through the same renderer the live run uses, so the assembled context is byte-identical to the first request. Past a 64 MiB per-session cap the oldest blobs of finished runs lose their bytes and render an explicit `evicted="true"` block, never the bare placeholder. Session delete cascades. `ClaimedRun.resolved_input` carries the first read across the auto-compaction retry instead of re-reading a file that may have changed. `MessageSnapshot.output` still carries the placeholder for display; no protocol change. Assembly cost is one additional indexed query per session. Tests: attach/modify/delete/continue round trip with reopen, dedup counts, reference-assembly oracle and delete cascade; eviction stub rendering; auto-compaction retry keeps the original bytes; schema-29 migration. Closes ENG-788.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: ENG-788. Audit finding F05 (
docs/design/harness-scale-audit-2026-09-16.md), the last open item in work-order 1.Behavior
Before: attach
a.txt(ALPHA_ORIGINAL), complete a run, sendcontinue. Request 1 contains the bytes; request 2 containsinspect\[email protected]. Same after reopen, in the compaction summarizer's input, and — worse — in the retry after an automatic compaction, which re-read the file and could send different bytes than the first attempt.After: every later request reproduces the first request's
<attached-file>blocks byte-for-byte from the store, whatever happened to the file since.MessageSnapshot.output(the transcript row) still shows@a.txtfor display.Design
attachment_blobs(session_id, blob_key, content, content_bytes, created_at_ms, evicted_at_ms)keyed by whole-file SHA-256 (+start-endfor ranges) so a file attached to several prompts is stored once per session.message_attachments(message_id, ordinal, path, digest, blob_key, window_*)in prompt order. Both written in thestart_reserved_runtransaction withRunStarted, so a run is never "started" with attachments that weren't kept. Deleted with the session.load_model_contextadds one indexed query per assembly (empty for sessions without attachments) and re-renders through the samerender_file_attachmentthe live run uses. Prompts that never started, or predate schema 29, keep their placeholder text.MAX_SESSION_ATTACHMENT_BYTES = 64 MiB(mirrors the spill cap). Eviction nulls content on the oldest blobs not referenced by a running/queued prompt; the row stays, and the block renders as<attached-file path=".." evicted="true">with a note to re-read — never the bare placeholder.INSERT OR IGNOREkeeps the first copy so an evicted blob is not resurrected by a later re-attach (which would make an earlier prompt's rendering depend on a later one).ClaimedRun.resolved_input: Option<Arc<ResolvedInput>>holds the first resolution;prepare_executionreuses it instead of re-reading.reload_reserved_messagesunchanged.messages.resolved_output TEXTcolumn. Smaller diff, but duplicates up to 1 MiB per prompt with no dedup and no eviction story; the audit's acceptance asked for both.PROTOCOL_VERSIONchange; no new events.Tests
attached_files_are_reconstructed_as_the_model_first_saw_them: whole file + range, modify one file and delete the other,continue→ request 2 equals request 1's prompt text; re-attach modified file (new blob) then again (dedup) → 3 blobs / 4 references; reopen on a fresh runtime → same;assert_assembly_matches_referenceoracle (updated to look up attachments per message);DeleteSessionempties both tables.evicted_attachments_render_an_explicit_stub_not_the_placeholder.an_over_budget_prompt_keeps_its_first_attachment_bytes_across_auto_compaction: file rewritten while the summary runs; retried prompt and its follow-up still carryALPHA_ORIGINAL.version_twenty_nine_migration_adds_the_attachment_tables_empty.input::testscover the shared renderer round trip and the evicted rendering.cargo fmt --check,cargo clippy --workspace --all-targets --all-features -D warnings,cargo test --workspacegreen.Not in scope
Steering messages with
@pathparts still send placeholders on the live run (pre-existing gap noted inprogress/tool-layer.md).search_historystill searches the placeholder text, not attachment bytes.