Persist the codex priority-turns memo across launches#1421
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep open for maintainer review: the persistence change has strong live proof, but the current branch still changes the global Codex parser hash and can invalidate existing session-cost caches; merged work in #1430 also means maintainers should explicitly decide whether this stateful persistence path is still wanted. Canonical path: Close this PR as superseded by #1430. So I’m closing this here and keeping the remaining discussion on #1430. Review detailsBest possible solution: Close this PR as superseded by #1430. Do we have a high-confidence way to reproduce the issue? Yes for the merge blocker: source inspection shows Codex session cache keys are derived from CodexParserHash.value, and the PR changes that value without adding the current main key to the compatible set. The performance benefit itself is also supported by the PR body's two-process live output. Is this the best way to solve the issue? No as-is. Persisting the priority-turn memo is plausible, but the merge path should first preserve session-cache compatibility and get a maintainer decision on whether the merged file-stat approach already supersedes this stateful cache. Security review: Security review cleared: The diff adds local metadata cache serialization and tests, with no dependency, workflow, credential, permission, or downloaded-code changes. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against dd8cf8b06ebb. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: pickaxe <54486432+ProspectOre@users.noreply.github.com>
The rowid-cursor memo keeps live refreshes incremental, but it is process-local: every app launch and every CLI invocation pays one full trace-database scan before incremental refreshes resume. Persist the memo to a versioned cost-usage artifact (parser-hash producer key, atomic replace-on-write) and seed it once per process through the monotonic store, so the first refresh after launch resumes from the persisted cursor.
e7f3e20 to
0874aba
Compare
|
Rebased onto the reviewed #1404 stack and force-updated with an exact lease. Maintainer fixups:
Proof:
|
|
Linux CI failure on |
|
Superseded by the smaller measured fix in #1430, landed as dd8cf8b. Exact-head profiling on the same 60,607-file real archive showed the priority SQLite scan was about 4% of the expired-refresh cost; repeated Foundation metadata/resource-identifier reads and cached-path validation were dominant. The landed replacement removes that cost with +124/-24 lines, no persisted cursor/memo state, and measured a 6.74s warm expired refresh versus 20.22-37.43s across the stacked candidates. Thanks @ProspectOre for the investigation, implementation work, and benchmark evidence. Contributor credit is retained in the landed commit and changelog. |
Problem
The priority-turns memo introduced in #1404 makes live refreshes incremental, but it is process-local. Every app launch and every CLI invocation pays one full
logs_2.sqlitescan (tens of seconds on large trace databases) before incremental refreshes resume — the disclosed P1 limitation from #1404's review.Change
Persist the memo to disk following the existing cost-usage cache conventions:
cost-usage/codex-priority-turns-v1.jsonwith aproducerKeyembedding the parser hash (codex:pt:p<hash>), so a parser change falls back to one full rescan — same invalidation contract as the codex cost cache.replaceItemAtwrites; corrupted or version-mismatched artifacts are ignored.codexPriorityTurnscall site in the codex scan, which runs on theCostUsageScanExecutorserial queue (Run cost-usage corpus scans off the Swift cooperative thread pool #1402), so the synchronous file IO stays off the cooperative pool and the main actor.Runtime Proof (real database, redacted)
Two separate
swift testprocesses against the live trace database — a true relaunch boundary. Cold first, then warm from the persisted artifact:Validation
swift test --filter CostUsageScannerCodexPriority— 16 tests pass (13 from Resolve codex priority turns incrementally per refresh #1404 + 3 new: relaunch roundtrip with cursor continuity, producer-key/version mismatch discard, corrupted artifact ignored).make check— 0 violations in 1043 files.Scripts/regenerate-codex-parser-hash.sh check— hash committed (the new source file participates in the hash, so this release triggers the usual one-time rescan).No CHANGELOG edit per current review guidance (release-owned).