Repository navigation
Conversation
The agent loop read only text deltas, tool calls, errors and aborts out of the stream, so the provider's own finish reason was discarded before anything could look at it. A turn a provider stopped at an output limit therefore reached the loop looking exactly like a turn the model chose to end. takeTurn now keeps the finishReason the SDK maps off the provider's field, read from both finish-step and finish, and null on the abort path where no finish part is ever emitted. Refs libredb#2291.
…shorter move A turn the endpoint stopped at its output limit was treated as a turn the model had finished. Nothing from it is trustworthy: its text is a truncated sentence and a call it carried may be truncated too, so the branch sits before the prompted readers and before dispatch, drops the calls, and clears the run's own text so no partial answer is filed as its closing statement. An agent run is told once, in a sentence that names the length limit and asks for less writing rather than less waiting, and a second cut ends the run as failed/output-limit instead of model-stopped. Planning runs are not told: the sentence names compose_report, which they do not hold, and their prose is what the plan verifier already judges. Measured against Ollama 0.40.15 with a num_predict cap: the final frame of a cut text turn is finish_reason length. The shape a cut inside tool arguments takes there is tool_calls with unparsable arguments, which reaches the loop as an unreadable tool call and is answered by that path. Refs libredb#2291.
docs/AGENT.md states the new bound beside the per-call ceiling, with the measured finish reasons and the shape a cut inside tool arguments takes on the endpoint it was measured on. docs/AGENT_GUIDE.md states it where the rails' ceilings are described, because the reader's next question is why an answer stopped mid-sentence and the two limits are repaired in opposite ways. Refs libredb#2291.
The comment on ModelTurn.finishReason said the values other than length are "the model's own decisions", which is false for content-filter and error, and it cited Anthropic's max_tokens although this build has no anthropic provider kind. It now states what each value is and that the two unhandled ones are follow-ups. The notice asked for "one tool call, with its arguments and nothing else", which reads as an instruction to write bare arguments on the prompted protocol. It now says what its sibling says, and the docblock records why the shape of a call is left to the protocol reminder. The stop reason is renamed model-output-limit so it reads beside model-timeout rather than turn-limit: one bounds turns, the other one answer. Two tests pin the surface a real run reaches, because a run ended here also carries a no-report verdict and the timeline prefers the shortfall. One more takes the arm that withholds the notice when the run is inside its report reserve, and the finishReason assignment is guarded against an adapter that omits the field. Refs libredb#2291.
Evidence and measurements for #2291Posted as the first comment so the description stays short. Everything here was run on this branch. 1. The provider states the cutOllama 0.40.15,
2. The shape the issue did not predictSame endpoint,
A cut that lands inside tool arguments is therefore not a 3. Live end to end
Both live records carry 4. Tests and gates
5. Size197 added source lines, of which 74 are comments, 11 blank and 112 code. The published library bundle 6. Not claimed
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
The agent loop discarded the model's finish reason, so a turn the server stopped at its output limit
looked like a turn the model chose to end. That cut turn then reached the prompted readers and
dispatch, and an agent run holding no report ended
model-stopped.This reads the finish reason and treats a cut turn as cut: nothing from it is kept, an agent run is
asked once for a shorter move, and a second cut ends the run with its own reason.
Type of Change
Related Issue
Closes #2291
Changes Made
1.
fix(agent): read the finish reason of every model turnModelTurncarriesfinishReason: FinishReason | null, read fromfinish-stepandfinish, andnullon the abort path, where no finish part ever arrives.compiler question.
2.
fix(agent): end a cut answer with its own reason, and ask once for a shorter movemodel-output-limit, a guidance id of the same name, a notice, andAGENT_MODEL_OUTPUT_LIMIT_ASKS = 1counted off the ledger.from the cut turn is kept: the text is cleared, the calls are not run, and no assistant message is
pushed.
failed/model-output-limit.compose_report, which that mode does not hold.rail a headline for the notice. No layout or interaction changes.
3.
docs(agent): say which limit stopped a cut answerdocs/AGENT.mdstates the bound beside the per-call ceiling;docs/AGENT_GUIDE.mdstates it wherethe ceilings are described.
Alternatives considered
short answer.
cut are indistinguishable from the client, and the one place a truncated call must never land is a
statement.
the same length that was already refused.
max_tokens. Rejected on the ground agent: read each turn's token usage, bound the run by it, and show the figure #2290 was closed on: it changes everyrequest, which invalidates the cells measured on the default shape, and it cuts reasoning turns.
plan cells.
Evidence
a cut text turn ends
finish_reason: "length"and nothing else in the body says the answer wasstopped.
max_tokensso the application's own request is unchanged:the notice reached the model verbatim on the next call, the transcript grew by exactly one message,
and a run cut twice ended
failed/model-output-limit.main, the same capped scenario filed a truncated envelope as the run'sclosing-statementandnever named the limit.
answered as an unreadable call; it is out of scope here, and both the code and
docs/AGENT.mdsayso.
Full token counts, the second wire shape, the suite figures and the coverage check are in the first
comment.
What this does not do
max_tokens.model-timeoutpath, which can still file a partial turn's text.Testing
Tests cover the cut shape on each of the three wires, and the negative cases: a turn that ended by
itself is still
model-stopped, a planning run is not told, both notice gates end the run instead,and the surface that shows the sentence is pinned for a run that also carries a
no-reportverdict.Test Environment
6fd6d4c0astatus line, covered by component tests
postgresthrough a stub provider on the ledger side, so the tool pipeline isreal to the point of execution and no statement leaves the process; the model is a real Ollama
0.40.15 over the
customprovider kindChecklist
bun run test:coverageandbun run coverage:checkran here on this branch, 211355/211355 lines (100.00%)src/lib/db/providers/changeAdditional Notes
Re-ask transcript shape validation
The re-ask transcript format was validated against a live Ollama endpoint. When a turn is cut off,
the partial assistant message is omitted and the notice is appended directly after the previous
message, which may result in consecutive user messages. A follow-up completion request succeeded
with this transcript structure.
Why the text is cleared in the branch rather than in
conclude()conclude()is shared across every terminal path, and moving the reset into it would also changewhat a
model-timeoutrun records. The reset is applied only where the turn is explicitly discarded.