Give the agenda planner a token budget that survives thinking - #243
Merged
Conversation
The same defect fixed in `lib/ai/review.ts` in #221. `max_tokens` is one ceiling over reasoning and visible text together, and `claude-sonnet-5` reasons by default when the request omits `thinking`. The call passed 4096 — sized for the placements alone — so a long think could spend the budget and leave the JSON cut off. A programme is exactly the answer that earns a long think, and the body grows with the queue, so both halves are large here. Raise it to 16,000, matching the reviewer. Downstream this failed more quietly than the reviewer did. `extractJson` returns no placements from a fragment, exactly as it does from prose, and the organizer was shown an empty proposal with `status: "ok"` — the planner appearing to have nothing to suggest, when it had plenty and ran out of room saying it. Add `proposalText`, which reads `stop_reason` and withholds a cut-off draft so the caller can name the real cause. Suggest a shorter queue, since that is the half of the budget the organizer controls. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Finishes what #221 started. The AI reviewer and the agenda planner had the same defect; #221 fixed the reviewer, this fixes the planner.
The bug
max_tokensis a single ceiling over reasoning and visible text.claude-sonnet-5reasons by default when the request omitsthinking.lib/ai/agenda.tspassedmax_tokens: 4096— sized for the placements alone — so a long thinking pass could spend the budget and leave the JSON cut off.This one is more exposed than the reviewer was. A programme is exactly the kind of answer that earns a long think, and the response body grows with the queue, so both halves are large.
It failed more quietly than the reviewer did
The reviewer at least said something was wrong. Here,
extractJsonreturns no placements from a fragment — exactly as it does from prose — and the caller then returnsstatus: 'ok'with an empty proposal. The organizer sees a planner that apparently had nothing to suggest, when in fact it had plenty and ran out of room saying it. No error, no log line, nothing to investigate.The fix
proposalTextreadsstop_reasonand withholds a cut-off draft, so the caller returnsstatus: 'error'naming the real cause rather than an empty board. The message suggests a shorter queue, which is the half of the budget the organizer actually controls.The two alternatives stay rejected for the same reasons as in #221:
budget_tokensis rejected outright by this model, and turning thinking off is documented to let reasoning prose leak into the text block — which is the stringextractJsonreads.Nothing about the trust boundary changed. Every placement still goes through
validateProposaland the samedetectConflictsthe board uses.Tests
New
lib/ai/agenda.test.ts(6 cases) — the file had none. Covers text blocks joined, non-text blocks ignored,stop_reason: "max_tokens"withholding the draft, and the point of the guard: that truncation is not detectable from the text, since a budget can run out on the token after a syntactically complete object.bun run test(1758 passed / 163 files),bun run lint,bun run typecheckall clean.Note for #173
#173 also touches
lib/ai/agenda.ts. This change is confined to the constant, one new exported function, and the block that reads the response — but whichever merges second should checkMAX_OUTPUT_TOKENSsurvived, andlib/ai/agenda-optimizer.tsdeserves the same look before it ships.🤖 Generated with Claude Code