Skip to content

fix: revive the tp-* response-budget watchdog (0.49.0) - #60

Merged
Shahinyanm merged 1 commit into
masterfrom
feat/revive-budget-watchdog
Jul 26, 2026
Merged

fix: revive the tp-* response-budget watchdog (0.49.0)#60
Shahinyanm merged 1 commit into
masterfrom
feat/revive-budget-watchdog

Conversation

@Shahinyanm

Copy link
Copy Markdown
Member

What

Revives the tp-* response-budget watchdog, which has been dead for months, and cuts 0.49.0.

Why

Every tp-* agent declares a Response budget: ~N tokens, and a watchdog was supposed to flag replies that overran it. It never ran once.

The check lived in PostToolUse:Task, which does not fire for the dispatch tool on current Claude Code. This repo already knew that — installer.ts has said so since v0.39.3 — but nobody connected it to the budget path. The evidence was quiet and total: .token-pilot/over-budget.log did not exist on any machine, and every recorded task event carried a null budget.

It surfaced while chasing a suspected undercount in token accounting. There was no undercount, but this was sitting next to it.

How

  • Moved the check to SubagentStop, where subagent completions actually arrive.
  • Corrected what it measures. It now sizes the agent's final reply rather than everything the agent emitted along the way. That distinction decides whether the feature is usable at all: summing all output gives ~55k against a 600-token budget, so every agent would be flagged forever.
  • The source is the transcript, not the payload's last_assistant_message. That field is present in the 2.1.220 bundle, but nothing in this codebase has ever read it, so there is no evidence it gets populated. The transcript is a path we already depend on and verified against real data.
  • Reuses the existing loadAgentBody / parseAgentBudget / decideBudgetAdvice / appendOverBudgetLog helpers rather than reimplementing them.
  • over-budget.log is written unconditionally. Surfacing the warning in the transcript rides the existing TOKEN_PILOT_SUBAGENT_FEEDBACK gate, because additionalContext on SubagentStop needs CC 2.1.163+.

Risk

Low. checkSubagentBudget returns null on every negative path — non-tp agent, no budget declared, agent file missing, transcript unreadable — and is wrapped so it cannot throw. A watchdog must not be able to break subagent completion.

Verified end to end on a built dist: an overrun writes agent=tp-debugger budget=100 actual=2000 over=19.00, and a reply within budget writes nothing while still recording its task event. 11 new tests, full suite 1438 green.

Notes for reviewer

The measurement axis is the judgement call worth checking. "Response budget" reads as the size of the answer handed back, so that is what this measures. If the intent was the agent's total output instead, the threshold in every agent file is wrong by two orders of magnitude and the fix belongs there rather than here.

Every tp-* agent declares a "Response budget: ~N tokens" and a watchdog
was supposed to flag replies that overran it. It never ran once.

The check lived in PostToolUse:Task, which does not fire for the dispatch
tool on current Claude Code. This repo already knew that — installer.ts
has said so since v0.39.3 — but nobody connected it to the budget path.
The evidence was quiet and total: .token-pilot/over-budget.log did not
exist, and every recorded task event carried a null budget.

Moved the check to SubagentStop, where completions actually arrive, and
corrected what it measures. It now sizes the agent's FINAL reply instead
of everything the agent emitted along the way. That distinction matters:
a response budget is about the answer handed back, and summing all output
would have flagged essentially every agent (55k of output against a 600
token budget).

The source is the transcript, not the payload's last_assistant_message.
That field is present in the 2.1.220 bundle, but nothing here has ever
read it, so there is no evidence it is populated — while the transcript
is a path we already depend on and verified against real data.

over-budget.log is written unconditionally. Surfacing the warning in the
transcript rides the existing TOKEN_PILOT_SUBAGENT_FEEDBACK gate, since
additionalContext on SubagentStop needs CC 2.1.163+.

Verified end to end on a built dist: an overrun writes
agent=tp-debugger budget=100 actual=2000, and a reply within budget
writes nothing while still recording its task event.
@Shahinyanm
Shahinyanm merged commit ebef5a1 into master Jul 26, 2026
3 checks passed
@Shahinyanm
Shahinyanm deleted the feat/revive-budget-watchdog branch July 26, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant