Cache Pi session parsers
Summary
- cache the Pi session filename regex instead of recompiling it for each filename
- reuse a locked pair of ISO8601DateFormatter instances for Pi session start parsing
- keep the change private to PiSessionCostScanner and preserve the same filename format and parse order
Why
Pi session refreshes walk session directories and parse every candidate filename before deciding whether it falls inside the requested scan window. The previous path rebuilt the regular expression and ISO formatters for each filename, which adds avoidable overhead on larger session directories.
Proof
Local validation, June 16, 2026 PT:
.build/lint-tools/bin/swiftformat Sources Tests --lint0/1139 files require formatting
.build/lint-tools/bin/swiftlint --strictFound 0 violations, 0 serious in 1138 files
swift test --filter PiSessionCostScannerTests10 tests in 1 suite passed after 0.066 seconds
swift build --build-testsBuild complete! (1.08 sec)
git diff --check- passed with no output
Benchmark harness was temporary and is not committed. Both runs used the same public PiSessionCostScanner.loadDailyReport path over 2,500 synthetic session filenames, with swift test --skip-build --filter PiSessionParserBenchmarkTests for the timed pass.
| Metric | Before | After | Change |
|---|---|---|---|
| fastest scanner pass | 0.678561s | 0.323273s | 2.1x faster |
| command real time | 6.99s | 3.10s | 2.3x faster |
| user CPU | 2.94s | 1.68s | 1.8x lower |
| max RSS | 177,963,008 bytes | 121,094,144 bytes | 32.0% lower |
| peak memory footprint | 29,098,680 bytes | 28,672,696 bytes | 1.5% lower |
| checksum | 2500 | 2500 | unchanged |
Risk
Low. NSRegularExpression is immutable after construction, and the shared ISO8601DateFormatter pair is protected by an NSLock, matching the existing scanner timestamp-parser pattern elsewhere in the codebase.
Codex review: needs maintainer review before merge. Reviewed June 16, 2026, 4:29 AM ET / 08:29 UTC.
Summary
The branch caches Pi session filename and ISO8601 parsers inside PiSessionCostScanner to reduce refresh parsing overhead without changing the filename format or parse order.
Reproducibility: not applicable. this is a performance cleanup PR rather than a bug report. The PR body supplies validation and benchmark evidence for the changed scanner path.
Review metrics: 2 noteworthy metrics.
- Diff Surface: 1 file modified, +23/-10. The change is tightly scoped to the private Pi session scanner parser path.
- Benchmark Proof: 2.1x fastest scanner pass over 2,500 synthetic filenames. The reported measurement directly targets the parser overhead this PR changes.
Merge readiness Overall: 🦞 diamond lobster Proof: 🦞 diamond lobster Patch quality: 🦞 diamond lobster Result: ready for maintainer review.
Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.
Risk before merge
- [P1] Final merge should wait until the draft is marked ready and the remaining CI job completes; no code-level blocker was found in the diff.
Maintainer options:
- Decide the mitigation before merge
Land the narrow private cache once the draft is ready and CI is green, preserving the existing parser behavior and focused scanner tests. - Pause or close
Do not merge this PR until maintainers decide whether the risk is worth taking.
Next step before merge
- No automated repair is needed; human handling is limited to normal draft readiness, CI completion, and final review.
Security Cleared: The diff only changes private parser caching in Swift source and does not alter dependencies, secrets, scripts, CI, or external execution paths.
Review details
Best possible solution:
Land the narrow private cache once the draft is ready and CI is green, preserving the existing parser behavior and focused scanner tests.
Do we have a high-confidence way to reproduce the issue?
Not applicable: this is a performance cleanup PR rather than a bug report. The PR body supplies validation and benchmark evidence for the changed scanner path.
Is this the best way to solve the issue?
Yes: keeping the cache private to PiSessionCostScanner and matching the existing locked ISO8601 formatter pattern is the narrowest maintainable solution.
AGENTS.md: found and applied where relevant.
Codex review notes: model internal, reasoning high; reviewed against ac01d73625ee.
Label changes
Label changes:
- add
P3: This is a low-risk private performance cleanup with no reported user-facing regression. - add
proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied local validation output and a before/after benchmark over the public scanner path, which is sufficient for this non-visual performance change. - add
rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. - add
status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied local validation output and a before/after benchmark over the public scanner path, which is sufficient for this non-visual performance change.
Label justifications:
P3: This is a low-risk private performance cleanup with no reported user-facing regression.rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied local validation output and a before/after benchmark over the public scanner path, which is sufficient for this non-visual performance change.proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied local validation output and a before/after benchmark over the public scanner path, which is sufficient for this non-visual performance change.
Evidence reviewed
What I checked:
- Repository policy read: Read the full target
AGENTS.md; its guidance favored focused parser tests, avoiding live/keychain validation, and keeping changes small. (AGENTS.md:1) - Current main behavior: Current main recompiles the Pi session filename regex and creates ISO8601DateFormatter instances inside the per-filename parsing path. (
Sources/CodexBarCore/PiSessionCostScanner.swift:821, ac01d73625ee) - Patch implementation: The PR adds a private formatter box, a cached filename regex, and lock-guarded reuse for the fractional/plain ISO8601 formatters. (
Sources/CodexBarCore/PiSessionCostScanner.swift:3, 0b84056ecbae) - Existing pattern: The repository already uses an
@unchecked Sendableformatter box with anNSLockfor shared ISO8601 parsing in the vendored cost usage timestamp parser. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Timestamp.swift:3, ac01d73625ee) - PR proof and state: The PR body reports focused formatting/lint/build/test commands plus a before/after benchmark over the public scanner path; GitHub reports the PR as draft, mergeable, with one CI check still in progress at review time. (0b84056ecbae)
Likely related people:
- steipete: Recent commits touched
PiSessionCostScannerand its tests, including Claude usage pricing and review-feedback fixes in this area. (role: recent area contributor; confidence: high; commits: 20004f3d2e81, 6c0adfce42f8; files:Sources/CodexBarCore/PiSessionCostScanner.swift,Tests/CodexBarTests/PiSessionCostScannerTests.swift) - ngutman: The Pi session cost scanner and its initial focused tests appear to have been introduced in the cost history integration commit. (role: introduced behavior; confidence: high; commits: c23edb9dc048; files:
Sources/CodexBarCore/PiSessionCostScanner.swift,Tests/CodexBarTests/PiSessionCostScannerTests.swift)
What the crustacean ranks mean
- 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
- 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
- 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
- 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
- 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
- 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
- 🌊 off-meta tidepool: rating does not apply to this item.
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.
How this review workflow works
- 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-reviewcomments, 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-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto 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 explainto ask for more context, or@clawsweeper stopto stop active automation.
Maintainer proof for rebased head eecfe892:
- Rebased cleanly onto current
main(70f37afc). swift test --filter PiSessionCostScannerTests: 10 tests passed.make check: passed (SwiftFormat, strict SwiftLint, locale and repository checks).- Structured Codex autoreview: clean; no accepted/actionable findings (confidence 0.86).
- Diff remains limited to the private Pi parser cache plus maintainer changelog credit.
- Public model identifier gate: not applicable; no model identifiers changed.
The contributor's scanner-path benchmark remains the relevant performance proof: 2,500 synthetic session filenames, unchanged checksum, with the cached implementation reporting a 2.1x faster scanner pass. This maintainer pass verified correctness and integration on the rebased candidate rather than presenting a second incomparable benchmark environment.