Skip to content

Fix OpenCode session cache source paths#348

Open
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:codex/opencode-db-cache-source
Open

Fix OpenCode session cache source paths#348
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:codex/opencode-db-cache-source

Conversation

@ozymandiashh
Copy link
Copy Markdown
Contributor

Summary

Fixes OpenCode session-cache keying by discovering one source per real opencode*.db file instead of one synthetic <dbPath>:<sessionId> source per root session.

The parser now opens the database source, iterates unarchived root sessions inside it, and keeps the recursive child-session parsing added in #343.

Root cause

OpenCode discovery used paths like:

/path/to/opencode.db:root-session-id

The shared session cache fingerprints source paths with stat(). That synthetic path is not a real file, so OpenCode cache entries could be treated as changed or stale on every run.

What changed

  • OpenCode discovery now emits path: dbPath for each opencode*.db.
  • The parser iterates unarchived root sessions from the DB source.
  • Root parsing still walks unarchived child/grandchild session subtrees.
  • Legacy compound <dbPath>:<sessionId> source paths are still accepted.
  • Old synthetic cache keys are pruned on the next parse because discovery now reports only the real DB path.
  • Docs and changelog describe the new cache behavior.

Validation

  • Differential synthetic repro against origin/main vs this branch.
  • npx vitest run tests/providers/opencode-cache.test.ts tests/providers/opencode.test.ts tests/provider-registry.test.ts - 54/54 tests passed.
  • npx tsc --noEmit --pretty false - passed.
  • npx vitest run - 876/876 tests passed.
  • npm run build - passed.
  • git diff --check origin/main...HEAD - passed.
  • Argus-style strict review - PASS.
  • Claude Opus 4.7 effort max review - PASS.
  • Gemini 3.1 Pro Preview review - PASS.
Cache proof

Synthetic OpenCode DB fixture:

root-a
└─ child-a
root-b

Same fixture parsed on origin/main and this branch.

origin/main cache keys:

/tmp/.../opencode.db:root-a
/tmp/.../opencode.db:root-b

This branch cache keys:

/tmp/.../opencode.db

Behavior stayed equivalent:

calls: 3
root sessions: 2
projects:
  tmp-project-a: 2 calls, 1 session
  tmp-project-b: 1 call, 1 session
child dedup key preserved:
  opencode:child-a:msg-child-a-assistant
warm unchanged run rewrote cache: false
legacy <dbPath>:<sessionId> keys pruned: true

Scope and privacy notes

Validation uses synthetic SQLite fixtures only. No real local OpenCode history, prompts, paths, session IDs, usage values, or private project data are included.

@ozymandiashh ozymandiashh marked this pull request as ready for review May 18, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant