Skip to content

Recover from replies cut off at the output limit - #2299

Draft
fazxes wants to merge 5 commits into
mainfrom
fazxes/recover-cut-off-replies
Draft

fazxes wants to merge 5 commits into
mainfrom
fazxes/recover-cut-off-replies

Conversation

@fazxes

@fazxes fazxes commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A reply cut off at its output limit no longer ends the turn. fx tells the model in the same turn what was cut and lets it continue, at most twice in a row. The third cut in a row ends the turn with a notice that says why.
  • Tool calls that finished before the cut run. A call the limit cut off never runs.
  • A reply cut while writing text keeps that text, and the model continues from where it stopped. The final answer, the saved turn, and a subagent's report hold the whole answer.
  • A reply cut before any text or tool call asks the model to take a smaller step, at low effort for one step when the model offers it. This replaces the one-time silent resend.
  • When fx picked the output limit itself, the first cut raises it for the rest of the turn, up to 65536 tokens and never past the model's context window or advertised limit.
  • A cut reply never ends a turn as completed. Before, a cut answer or an empty cut reply could end as a success with no work done.
  • A subagent whose turn ends this way reports output_limit to its parent instead of agent_turn_failed, and /trace lists each cut as an output_limit problem.
  • The write_file and edit_file descriptions ask the model to keep each call small.
  • The libfx wasm size budgets go up by the size of the new code: fx-core.wasm from 2,475,000 to 2,490,000 bytes and fx-term.wasm from 4,276,000 to 4,292,000. Both files grew about 15 to 17 KB over main.
  • Tests and TLA+ rules that pinned the old behavior now pin the new one. In the custom connection model, ResendDiffers and NoResendOfResend give way to AtMostTwoNotesInARow and NeverLowTwiceInARow, each with a planted bug that must break it.
  • A new model, tests/tla/agent_runtime/OutputLimit.tla, describes the recovery, with planted bugs that its rules must catch. Its driver, tests/tla/drivers/agent_runtime/output_limit.ts, runs the built fx along it, and a new CI step runs that driver.

Before and after

Before:

flowchart TD
  R[Reply stops at the output limit] --> T{Tool calls in it?}
  T -- yes --> F[Turn fails, calls dropped: send your message again]
  T -- no --> E{Any text?}
  E -- yes --> C[Turn ends as completed with the cut text]
  E -- no --> S{Can fx change the request?}
  S -- yes --> RS[Resend once, silently, with a higher limit or low effort]
  S -- no --> C2[Turn ends as completed: ran out of output tokens before any text]
Loading

After:

flowchart TD
  R[Reply stops at the output limit] --> N{Third cut in a row, or no step left?}
  N -- yes --> F[Turn fails with output_limit and a notice]
  N -- no --> K{What did the reply have?}
  K -- whole tool calls --> RC[Run them, then a note after their results]
  K -- only cut calls --> SS[Note: do it in smaller steps]
  K -- text --> CT[Keep the text, note: continue where it stopped]
  K -- nothing --> AN[Note: think less, take a small step]
  RC --> NX[Next request, with a limit fx chose raised once]
  SS --> NX
  CT --> NX
  AN --> NX
  CT -.-> J[The reply that finishes the answer joins every part]
Loading

The AI SDK finishes a tool call only when its arguments are whole, so fx records the order in which calls started. A call counts as whole only when a later call started after it, so the call that started last never runs.

A cut reply is a successful response on the network, so /trace would not list it. A small ring of the last 16 cuts, with counts and names only, lets /trace show each one and what fx did.

Docs: vercel-labs/fx-web#367

A reply that stops at its output limit no longer ends the turn. fx tells
the model in the same turn what was cut and lets it continue, at most
twice in a row; the third cut in a row ends the turn with a clear notice.
Tool calls that finished before the cut run, and a call the limit cut off
never runs. A reply cut while writing text keeps its text and the model
picks up where it stopped. A reply cut before any text asks the model to
take a smaller step.
@fazxes fazxes added the type: improvement Improves existing user-facing behavior label Nov 25, 2026
When the last cut reply of a turn streamed no text, the end of the turn
showed the earlier parts of the answer again. It now shows only that
reply's text and keeps the whole answer for the saved turn. Also log when
tool activity ends an answer fx was joining, and drop an unused total of
output-limit stops.
fx holds the first letters of a reply until it can check the reply's
language, and only a finished reply gets that check. A part cut off
before the check never showed, so the screen and the JSON output lost
it while the saved answer kept it. A cut reply now shows that text
before fx asks the model to go on.
main raised the wasm budgets for provider compaction. With the cut reply
recovery on top, fx-core.wasm is 2,508,068 bytes and fx-term.wasm is
4,310,326 bytes after wasm-opt, so both budgets now sit just above those.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: improvement Improves existing user-facing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant