Repository navigation
perf(server): thread cost reads only that thread's transcripts - #219
Merged
Merged
Conversation
threadUsage.get (the chat header's cost chip) walked and parsed every transcript modified since the thread started, then rewrote the whole 23 MB usage-scan-cache.json on every call (7.6 s average, 21 s max in prod). It now lists only the thread's own files (Claude <sessionId>.jsonl plus its subagents folder, Codex rollout-*-<sessionId>.jsonl), and a thread read rewrites the scan cache at most every 5 minutes; the service flushes the cache on shutdown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
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.
Problem
threadUsage.getis requested by the chat header's cost chip (ThreadCostControl) whenever a thread is opened. In prod it averaged 7.6 s, with a 21 s max. Two costs, both in the fork block ofUsageService.readThreadUsage:usage-scan-cache.json(23 MB in prod). That happens whenever anything changed, which is always while any session is streaming. TheJSON.stringifyalone blocks the event loop.Fix
Only the thread's own files. New fork module
usage/threadTranscriptFiles.expbkt3.ts. The provider session id is in the file layout, so the walk skips everything else before any stat or parse:<projects>/<slug>/<sessionId>.jsonl, plus everything under<projects>/<slug>/<sessionId>/. Checked on this host: subagent transcripts live in<sessionId>/subagents/agent-*.jsonland carry the parent'ssessionId, so they still count.rollout-<timestamp>-<sessionId>.jsonl. Checked on this host: the filename suffix equals the file'ssession_metaid.fileName: "updates.jsonl"as the summary scan already does.Cache write debounce.
The edits stay inside the existing
T3-CUSTOM(expbkt3)block ofUsageService.ts, plus a marked import. The upstream summary scan is untouched.Evidence
UsageService.expbkt3.test.ts, 2 tests.Listing test:
proj-a/session-1.jsonlandproj-a/session-1/subagents/agent-1.jsonl, not another session's file.rollout-…-thread-b.jsonl.Service test (TestClock):
The whole
src/usage/suite passes (9 files, 93 tests).vp run typecheckinapps/serverand lint are clean, and the fork-marker check passes.After the expbkt3 deploy I will compare
ws.rpc.threadUsage.getspan times on expbkt3.Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.