Repository navigation
perf(status): tj status ran 12 analyzers inline for its footer line - #694
Merged
Merged
Conversation
`tj status` took about a minute of CPU on a real corpus (measured 55-59s, ~95% CPU, 300+ agents). The cause was the one-line recoverable-savings footer: `_recoverable_teaser` called `build_report` live on every plain run, dispatching the whole cost analyzer set over the entire corpus, including the deliberately unbounded relearn scan. `core/optimize/report_store.py` exists precisely to end this failure mode on the HTTP side, where the same inline scan hung the dashboard's recoverable-waste panel for minutes: "no request path runs an analyzer". A status command a user types to read a table is the same kind of path; the CLI caller had simply never adopted the store. The teaser now reads `report_store.stored_report`, scoping to COST_ANALYZERS on the read since the store holds every analyzer's finding. Analyzer runs stay where they belong: daemon boot, the daemon's schedule, a user rescan, or an explicit `tj optimize`. A cold store renders no figure at all. Not zero, not $0.00, not "nothing to recover" - a scan that never ran cannot support an absence claim - just a line naming the command that would produce one. Same measurement after the change: 1.6s wall. The teaser no longer takes a `db` argument, so the test that pinned its silence in API-shim mode is inverted rather than dropped: with no local DB handle the stored figure now renders, which is exactly the mode where the store is warm. Added a regression pin that the status module cannot reach `build_report` at all, plus coverage for the cold store and the COST_ANALYZERS scoping. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_status.py | Replaces inline report generation with a fail-soft stored-report read while preserving cost scoping and largest-estimate rendering. |
| tests/unit/test_cmd_status_teaser.py | Updates teaser tests for stored reports and adds cold-store, API-shim, analyzer-scoping, and no-inline-analysis regression coverage. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Scan["Daemon scan / tj optimize"] --> Store["Persisted optimize report"]
Status["tj status"] --> Read["Read stored report"]
Store --> Read
Read -->|Warm| Filter["Filter cost analyzers"]
Filter --> Teaser["Render largest estimate"]
Read -->|Cold| Cold["Suggest tj optimize without a figure"]
Reviews (1): Last reviewed commit: "perf(status): read the stored analyzer r..." | Re-trigger Greptile
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.
tj statusspent about a minute running analyzersOn a real corpus (304 agents),
tj statustook 55-59 seconds at ~95% CPU. Compute-bound, not IO-wait.The status table itself is cheap. The cost was the one-line recoverable-savings footer at the bottom of the screen:
_recoverable_teaserintokenjam/cli/cmd_status.pycalledbuild_report(findings=list(COST_ANALYZERS))live, uncached, on every plaintj status. That dispatches the whole cost analyzer set over the entire corpus, including the deliberately unboundedrelearnscan, so the user waits a minute for a table that was ready in a second.This is a failure mode the codebase already documented
tokenjam/core/optimize/report_store.pywas written to end exactly this, after the same inline scan on an HTTP request thread hung the dashboard's recoverable-waste panel and the Budget-at-risk card for minutes. Its module docstring states the rule outright:A status command a user types to read a table is the same kind of path. The CLI caller had simply never adopted the store.
The fix
_recoverable_teasernow readsreport_store.stored_report(config). Nothing else about the figure changed: it is still the largest single analyzer estimate rather than a sum (the analyzers price overlapping angles on the same spans, so summing would print an inflated non-additive headline), still gated at $1, still shown regardless of billing mode. TheCOST_ANALYZERSscoping the teaser has always claimed is now applied on the read, since the store holds every analyzer's finding rather than just the cost rail's.Analyzer runs stay where they belong: daemon boot, the daemon's schedule, a user rescan, or an explicit
tj optimize.A cold store renders no figure at all. Not zero, not
$0.00, not "nothing to recover". A scan that never ran cannot support an absence claim, and$0.00 recoverablereads as reassurance. The cold line names the command that would produce a figure and states no quantity:The teaser no longer needs a
dbargument, which also fixes a smaller bug: it used to go silent whenever the daemon held the write lock (API-shim mode, no.conn), because it had no connection to scan with. That is precisely the mode where the store is warm, so the figure now renders there.Measured
Same machine, same corpus, same command:
Both footer states, rendered from the real CLI against the same corpus:
Tests
tests/unit/test_cmd_status_teaser.pyrewritten against the store rather than a monkeypatchedbuild_report.COST_ANALYZERSscoping cannot be bypassed by a finding stored under another name.build_report, asserted both statically against the source and dynamically withbuild_reporttrapped to raise.pytest tests/unit -k "status or optimize or report_store"-> 402 passed.tests/unit/test_advertised_commands_are_invocable.py-> 12 passed (the footer still advertisestj optimize, which resolves).Sweep
Every other
build_report/COST_ANALYZERS/ direct-analyzer call site intokenjam/cli/is a command whose entire purpose is the analysis the user asked for, so none is the same defect:cmd_optimize.py- the analyzer command itselfcmd_report.py-tj report --trim/--reuse, single scoped analyzer per invocationcmd_route.py-tj route,findings=["downsize"]cmd_quickstart.py- the zero-install demo whose output is the figuredata_access.py/cmd_quota_audit.py-audit_opus_quota, reached only fromtj quota-audittj statuswas the only plain command path running an analyzer as a side effect.🤖 Generated with Claude Code