fix: report tool accounting — attribute tool-results to their tool - #203
Conversation
…386 follow-up) - collectVisible: resolve tool-result -> calling tool's name via toolCallId map (previously toolName ?? "text" dumped every result into the text bucket; the tool bucket showed ~0.6% of real volume) - pct(): drop the Math.max(1, ...) floor so tiny buckets show 0% and the three percentages no longer sum past 100 - renderUncompressedRanges: merged ranges now label the true dominant tool by token weight instead of the first message's label - recommend.ts isToolMessage exported and reused (single tool definition) - panel.ts docstrings: stop claiming chars/4 — numbers use the core's countTokens (kernel default = CJK-aware defaultCountTokens) - tests/report-tool-accounting.test.ts: 5 regression tests
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)In your adapter project: npm install acp-kernel@pr-203Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf acp-kernel-pr203.tgz
npm install ./packageThis comment is automatically updated on each push. |
[bot] 🏷 Review of PR #203 — approved with conditions I independently re-ran the full verification and audited the diff against the old code and the wire layer. Details below. What I verifiedAll 5 reported defects are real, and the root cause is at the wire-codec level (not a symptom):
Preflight (re-run by me, not taken on faith):
The 5 new regression tests are meaningful (exact arithmetic via ASCII padding, no float fragility): volume lands in the tool bucket, results resolve to the calling tool's name in both Top-tools and drilldown, orphans stay out of text, tiny buckets render 0% with sum ≤100, merged ranges labeled with the dominant tool.
|
| #203 | #177 | |
|---|---|---|
| Range mislabel (defect #4) | ✅ fixed | ❌ not touched |
| Structure | exports isToolMessage from recommend.ts |
new leaf module src/message-kind.ts |
compress.ts breakdown dedup |
no (inline copy remains) | ✅ unified onto shared predicate |
Public export / isTool flag |
no | ✅ both |
| State vs master | mergeable, green | conflicts (stale base) |
| Agent reviews so far | this one | one LGTM already on file |
Recommendation (single path, no fork): ship via #203, then close #177 as superseded and open a small follow-up that ports #177's structural wins (leaf module, compress.ts dedup, isTool flag replacing the "text" sentinels at src/report.ts:161/164, plus its cross-surface agreement + CJK-scale tests). Rationale: #203 covers a strict superset of user-visible defects (it fixes the range labeling #177 misses), is already green and mergeable against current master, while #177's remaining value is non-behavioral refactoring + extra tests — ideal for a low-risk follow-up after the fix lands.
⚠️ Process flag before merge
The PR branch contains the release v0.0.53 commits (0dc35b2 version bump + its merge commit), which are not on origin/master — and PR #202 (release v0.0.53) shows as closed without merge even though tag v0.0.53 exists. Merging #203 as-is would land the version bump into master through this fix PR, breaking the release-commit convention. Please:
- Rebase/recreate the branch onto current master so only the fix commit rides the PR, and
- Clarify the state of release v0.0.53 #202 / the v0.0.53 publish (was it closed by mistake?).
Nits (non-blocking)
renderOverviewstill buckets totals via the string sentinels (m.tool !== "text"/=== "text") — correct under the new classification, but magic-string coupled; would miscount a tool literally namedtext. TheisToolflag from the planned follow-up resolves this.- Exporting
isToolMessagefromrecommend.tscouples report→recommend; the leaf-module layout is cleaner (again, covered by the follow-up). - Plain
Math.roundcan still sum >100% in pathological cases (e.g. 33.5%/33.5%/33% → 34+34+33=101). The floor defect is fixed; this is cosmetic and vanishingly rare — not worth blocking on.
Verdict
Approve with conditions: (a) rebase off the release commits, (b) one more independent agent review per AGENTS.md §6 (this counts as one of the required two). After that it's ready for human merge; then close #177 as superseded and file the structural follow-up.
Re: "
|
[bot] 🏷 Correction: process flag retracted — you're right, no rebase needed. I re-verified against live GitHub API state (not my local clone, which was serving stale refs):
So condition (a) from my review verdict is withdrawn. Two things went wrong on my side, for the record: (1) my local clone's Remaining condition before human merge: exactly one — a second independent agent review per AGENTS.md §6 (my review above counts as one of the required two; the thread currently has no other review). Everything else from the audit stands: all five defects verified real at root cause, preflight green (typecheck / 580-580 vs 575 baseline / build), nits tracked for the follow-up. #177 path: agreed as stated — once #203 merges, close #177 as superseded and open the small follow-up carrying its structural wins ( m00026 |
Follow-up on the acp_status accounting defects reported in billion-context#386 (kernel side).
What was wrong
report.tsclassified messages withtoolName ?? "text". Wire adapters settoolNameonly on tool-CALLS, never on tool-RESULTS, so every tool result (the bulk of context) landed in the text bucket — the tool bucket showed ~0.6% of the real tool volume.report.tskeyed ontoolName,recommend.tshad the semantically correctisToolMessage(contentType-based) — private.Math.max(1, ...)forced every non-empty bucket to render ≥1%, so three buckets could sum >100%.renderUncompressedRangeslabeled a merged range with the first message's tool despite the comment claiming "dominant tool".countTokens(kernel default = CJK-awaredefaultCountTokens).Changes
src/report.tscollectVisiblebuilds atoolCallId -> toolNamemap from tool-calls and resolves each tool-result back to its calling tool; unresolvable results fall into a generictoolbucket instead oftext.pct()returns plainMath.round((n/total)*100)— no floor.src/recommend.ts—isToolMessageis nowexported;report.tsreuses it (single definition, no cycle).src/panel/panel.ts— docstrings corrected to "estimated, kernel countTokens scale".tests/report-tool-accounting.test.ts— 5 regression tests: tool-result volume lands in tool bucket (12.5K/99%); results resolve to calling tool's name (Top tools + per-tool drilldown); orphan results stay out of text; 0% for tiny buckets with sum ≤100; ranges labeled with dominant tool.Verification
Downstream (billion-context side, separate PR after this ships)
bili's 3
buildStatusReportcall sites passestimateTokensFast(chars/4) while the nudge side uses the kernel default CJK-aware estimator — mixing scales 4x-underestimates CJK. They will be switched todefaultCountTokens+ acp-kernel pin bump, tracked in billion-context#386.