Fix Cursor agentKv timestamp attribution#345
Conversation
a3f0498 to
c1c96bb
Compare
|
I rechecked this after rebasing and am not going to push the rebased branch as-is. The blocker is the prior maintainer validation on #262: a live Cursor database with ~15k agentKv rows reportedly had no parseable timestamp fields, and the mtime fallback was kept intentionally for that path. Requiring Recommendation: close or rescope this PR. The cache-only stale-result issue should stay separate from changing agentKv timestamp semantics. |
|
Closing this one. Validated against real Cursor state.vscdb data: All three fields are NULL across 5,048 agentKv rows. Cursor does not store internal timestamps in agentKv JSON, so this PR would silently drop all agentKv session data rather than fixing the timestamp attribution. The mtime fallback is imperfect but at least reports the data. A fix here would need a different approach (e.g. deriving timestamps from row ordering + bubble cross-reference, or accepting mtime as a bounded estimate). |
Summary
Fixes #325 by removing the remaining Cursor timestamp fallback that could attribute historical usage to the SQLite database modification time.
This is separate from the undated
bubbleId:%path fixed onmain: bubble rows already requirecreatedAt. The remaining risk wasagentKv, where CodeBurn still dated every parsed agentKv session withstatSync(state.vscdb).mtimeMsand fell back tonew Date()if the stat failed.Root Cause
Cursor can modify
state.vscdbfor background maintenance, migrations, or unrelated writes. Using the database filemtimeas the usage timestamp means an old agentKv conversation can be reported as new usage whenever the DB file changes.Concrete example covered by the tests:
agentKvsession contains old user/assistant content.2099-01-01.What Changed
createdAt,timestamp, ortime.state.vscdbmtime or parse time.CODEBURN_CACHE_DIRsupport to the Cursor result cache so tests can isolate cache state from the user's real cache.Relation To #337
#337 invalidates cached results after the undated bubble-row fix. This PR includes the same cache-version/cache-dir hunk because agentKv timestamp semantics also change and v3 caches can contain mtime-bucketed agentKv calls.
If #337 merges first, this PR can be rebased to keep the agentKv parser/tests and drop the duplicate cache hunk if needed.
Validation
npx vitest run tests/providers/cursor-agentkv-timestamp.test.ts tests/providers/cursor.test.ts tests/providers/cursor-bubble-dedup.test.ts tests/providers/cursor-workspace-breakdown.test.ts- 24/24 tests passed.npx tsc --noEmit --pretty false- passed.npm run build- passed.git diff --check- passed.Notes
I did not validate with real local Cursor history and did not include any local project names, prompts, paths, session IDs, usage values, screenshots, or private product details. The proof uses synthetic SQLite fixtures specifically constructed to reproduce the timestamp-attribution failure mode.
The intentional tradeoff is that legacy agentKv rows without any internal timestamp are skipped. That is safer than reporting historical usage under the wrong day.