Stage B: decouple large file bodies from the plan JSON#4
Closed
Anmolnoor wants to merge 1 commit into
Closed
Conversation
The crash root cause: file.write actions inlined the entire file body in the schema-constrained plan JSON, so a large write overflowed the structured-output budget and truncated mid-string, killing the turn. Separate the control plane (the plan) from the data plane (file bytes): - foundation.file.write now accepts EITHER content (literal, for tiny files) OR content_brief (a short description). New FileWriteBriefRequest model; planner validation enforces the content-xor-content_brief convention. - The orchestrator materializes deferred writes before execution: for each write carrying content_brief, it makes a separate ProviderResponseFormat.TEXT call (unconstrained, honoring max_output_tokens) to generate the body, then swaps content_brief -> content. The plan JSON stays tiny. - If body generation fails, the brief is left in place so the write degrades to a normal failed action (the executor rejects the unknown field) rather than killing the turn. - Planner prompt + schema outline instruct the model to use content_brief for anything beyond a few short lines. Tests: brief materialized via a TEXT call and written verbatim while the plan call never carries the body; generation failure degrades to a failed action with no file written. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 27, 2026
Owner
Author
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.
Context
The actual fix for the truncation crash. Root cause:
file.writeactions inlined the entire file body in the schema-constrained plan JSON, so a large write overflowed the structured-output budget and truncated mid-string, killing the turn.This separates the control plane (the plan) from the data plane (file bytes) — the pattern production agents use.
What changed
foundation.file.writeacceptscontentXORcontent_brief.content(literal) for tiny files;content_brief(a short description) for anything longer. NewFileWriteBriefRequestmodel; planner validation enforces exactly-one.content_brief, it makes a separateProviderResponseFormat.TEXTcall (unconstrained, honoringmax_output_tokensfrom Stage A) to generate the body, then swapscontent_brief → content. The plan JSON stays tiny, so grammar-constrained decoding never has to emit a huge string.content_brieffor anything beyond a few short lines.Tests
2 new (387 total, ruff clean): brief materialized via a TEXT call and written verbatim while the plan call never carries the body; generation failure degrades to a failed action with no file written.
Sequencing
Stage B of A→B→C→D. A+B together fix the crash. C (user questions) and D (out-of-scope escalation) are the questioning feature, still to come.
🤖 Generated with Claude Code