Skip to content

Skip unchanged cost snapshot conversions - #2832

Closed
kiranmagic7 wants to merge 1 commit into
steipete:mainfrom
kiranmagic7:kiran/skip-stable-cost-snapshot-conversion-20260810
Closed

Skip unchanged cost snapshot conversions#2832
kiranmagic7 wants to merge 1 commit into
steipete:mainfrom
kiranmagic7:kiran/skip-stable-cost-snapshot-conversion-20260810

Conversation

@kiranmagic7

@kiranmagic7 kiranmagic7 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Refs #2824.

persistFile converted every retained Codex token timestamp and JSON-encoded every usage row before deciding whether the SQLite cursor was unchanged. During bounded catch-up, that repeated the hottest ISO-8601 work across the full historical prefix even when the stable-cursor branch wrote no rows.

This moves conversion and encoding behind the persistence decision. Stable files do none of that work, append-safe files convert only the new suffix, and replacement behavior stays the same. The database schema, metadata, aggregates, event indexes, and row indexes are unchanged.

Tests:

  • CI=1 CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --disable-keychain --disable-netrc --filter 'CostUsageStore|CostUsagePerformanceGateTests' (103 tests passed)
  • CI=1 CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 make check (passed)
  • CI=1 CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 make test does not complete locally because two unrelated AdaptiveRefreshTimerTests time out with CancellationError(). The exact clean base, 1ba79680364dddbc611d710fbf59dddf76062627, reproduces both failures at lines 39 and 78.

Real-corpus proof (redacted):

I ran the exact pre-fix base and this head against the same completed 125.8 MB local Codex session-day subset, using a fresh isolated cache for each run. The base carried only the same counter hook around token-snapshot conversion; it did not change persistence decisions.

pre-fix base  files=62 snapshots=1866 cold_conversions=1866 stable_conversions=1866 cold_seconds=4.801 stable_seconds=0.234
patched head  files=62 snapshots=1866 cold_conversions=1866 stable_conversions=0    cold_seconds=4.802 stable_seconds=0.118

The patched run asserted that stable conversions were zero and passed. The near-identical cold times are a useful comparability check; the conversion counts are the deterministic signal. No filenames, paths, session contents, report output, project names, or account/model/cost data were captured.

This is a narrow reduction in the repeated store work reported in #2824, not the broader delta-persistence redesign. Compatibility risk should be low because the write branches and schema are unchanged. Review focus: the append-only suffix indexes and the stable-cursor no-conversion invariant.

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 3:05 AM ET / 07:05 UTC.

ClawSweeper review

What this changes

The PR postpones Codex token-snapshot conversion and usage-row encoding until the SQLite cost-usage cache must append or replace rows, avoiding repeated work for unchanged files.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal merge review: the patch is a focused repair for the reported cost-store hot path, includes a targeted regression test, and now provides credible after-fix real-corpus proof. No blocking patch defect was found.

Priority: P1
Reviewed head: f0e0508e8fdcb6ec6e789f681cd6271595ff8604

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation, targeted regression coverage, green reported checks, and credible real-corpus after-fix output support normal merge review.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies a redacted before/after run against the same 125.8 MB local corpus, showing stable conversions fall from 1,866 to zero while cold-run timing remains comparable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies a redacted before/after run against the same 125.8 MB local corpus, showing stable conversions fall from 1,866 to zero while cold-run timing remains comparable.
Evidence reviewed 5 items Current-main behavior: Current main eagerly converts every token snapshot and JSON-encodes every usage row before evaluating the stable-cursor checks, so the reported repeated-work path remains present.
Narrow branch repair: The branch retains the existing append/replace decisions but converts only the required suffix or full replacement; the unchanged branch performs neither conversion nor encoding.
Regression coverage: The focused cutover test verifies one conversion for an appended row, zero conversions at stable EOF, and unchanged report output.
Findings None None.
Security None None.

How this fits together

CodexBar scans local Codex session files and persists usage data in a SQLite cost-usage cache. On each refresh, the store decides whether existing cached rows can be reused, appended to, or replaced before reports consume that cache.

flowchart LR
A[Codex session files] --> B[Usage scanner]
B --> C[Cost usage cache store]
C --> D{Cursor comparison}
D -->|unchanged| E[Reuse stored rows]
D -->|append or replace| F[Convert needed rows]
F --> G[SQLite cache]
G --> H[Usage reports]
Loading

Before merge

  • Complete next step (P2) - No repair dispatch is needed because the submitted patch has no actionable review finding and has adequate real-behavior proof.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +53/-16; tests +32/-4 The small implementation change is accompanied by focused coverage of both append and unchanged-cursor behavior.

Technical review

Best possible solution:

Land the narrow lazy-conversion change with its stable-cursor regression coverage, preserving the existing append and replacement semantics.

Do we have a high-confidence way to reproduce the issue?

Yes at high confidence from source: current main performs conversion before the stable-cursor decision, and the focused test exercises append then unchanged-EOF refreshes. The PR also supplies redacted real-corpus output showing stable conversions drop from 1,866 to zero.

Is this the best way to solve the issue?

Yes. Deferring conversion until the existing persistence decision is reached is the narrowest maintainable repair because it preserves the schema and all existing write branches.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 930b1c4d0d43.

Labels

Label justifications:

  • P1: The linked report identifies sustained full-core usage in the live cost-usage workflow, and this PR directly removes one measured hot path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies a redacted before/after run against the same 125.8 MB local corpus, showing stable conversions fall from 1,866 to zero while cold-run timing remains comparable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies a redacted before/after run against the same 125.8 MB local corpus, showing stable conversions fall from 1,866 to zero while cold-run timing remains comparable.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current cost-store save-cycle implementation and is the historical owner of the touched persistence boundary. (role: introduced the current persistence path; confidence: high; commits: 8051ce40e4b8; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageStore+CodexCache.swift, Tests/CodexBarTests/CostUsageStoreCutoverTests.swift)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-10T06:27:01.168Z sha f0e0508 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 10, 2026
@steipete

Copy link
Copy Markdown
Owner

Thanks for the careful diagnosis and real-corpus proof. This independently found the same eager-conversion hot path that was merged shortly afterward in #2834 / 17afef7b84eba42ad27563f5b5e02f9ec141eb09, so I’m closing this as superseded rather than asking you to resolve the current conflicts.

I compared the implementations against current main:

  • both choose stable reuse, suffix-only append, and full replacement under the same cursor/count conditions;
  • both perform zero snapshot conversion and row encoding for stable collections and materialize only absolute-indexed suffixes for safe appends;
  • the merged CostUsagePersistencePlanner centralizes that decision for both collection types and has broader coverage for stable transforms, append indexes, SQLite round-trips, and replacement after file-identity changes;
  • the process-global conversion observer unique to this PR is no longer needed for regression coverage.

Your 125.8 MB before/after run remains useful corroboration of the root cause, and the unchanged cold-run timing is a good comparability check. No criticism of the patch itself—this was simply a parallel fix race. Thanks again for the strong evidence.

@steipete steipete closed this Aug 10, 2026
@kiranmagic7

Copy link
Copy Markdown
Contributor Author

That makes sense, thanks for checking the overlap. I agree #2834 covers the stable, append, and replacement cases, and the planner shape is the better place for the shared decision logic. I will leave this closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants