fix: read opencode sessions from session_v2/session_message #7
Reference in New Issue
Block a user
Delete Branch "fix/opencode-session-v2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #6.
opencode 2.0.24 migrated its session store on 2026-11-01 21:01:20 UTC.
session,messageandpartstopped being written; sessions now live insession_v2and messages insession_message. The ingest kept querying the abandoned tables, so every sweep after the migration logged0 new— no error, no new sessions indexed.Changes
internal/ingest/opencode_db.gosession_v2(title is nullable there, the existing COALESCE + fallback still apply).$.text, assistant turns from$.content[]filtered totype='text'(reasoning and tool parts are not indexed). Ordered byseq, then part index.session_messageinstead of parts.<system-reminder>text — reminders now arrive assyntheticmessages and would eat the 4000-byte summary budget.opencode-db/v2.internal/watch/watch.go— an entry is no longer skipped oncreated_atalone. Resuming a session appends messages without touching the creation time, so the summary is compared too.internal/ingest/opencode_db_test.go— new test builds the v2 schema in a temp SQLite database and asserts user text and assistant text parts are indexed while reasoning, tool and reminder content is not.Validation
go build ./...,go test ./internal/ingest/ ./internal/db/ ./internal/watch/pass.knox.serviceagainst the live store:Knox OpenCode session adapter compatibility check, observation versionopencode-db/v2), andknox query "knox opencode session adapter compatibility"finds it.Notes
The first commit on this branch is a checkpoint of pre-existing uncommitted work that the adapter fix sits on top of; the fix itself is the second commit (
e07ae8a).e07ae8aa27to6335670ddbRebased onto
main(bb852fa) — conflicts resolved, no merge commit.Why it conflicted
#3(gossip/HLC/watcher/MCP hardening) and#4(gofmt) landed after this branch was cut. Both touched the same files as the checkpoint commit; the fix commit itself merged without a conflict.How each was resolved
internal/cmd/ingest.gointernal/cmd/mcp.gorequiredStringArg/optionalIntArghardening and ported the snippet/code scope onto it. The seven remainingclampIntcall sites (thread_groom, thread_text, snippet_candidates, snippet_search) now useoptionalIntArgand report bad args instead of silently clamping.internal/db/db_test.gotmpDB/record) and this branch's 17 (newTestDB/obs), no symbol collisions.internal/watch/watch.gofileDebouncerand theatomic.Boolrun-guards, re-expressed the 30s log settle as a per-event delay intodebounce.schedule, and re-added the opencode/karakeep/health/snippet tickers (nowCompareAndSwap-guarded) plus their sweep functions.Also added
6335670—gofmt -l .flaggedinternal/watch/gossip_test.go(missed by #4); the tree is now gofmt-clean.Re-validated after the rebase
go build ./...,go vet ./...,go test ./...— all packages pass, including main's newhlc,gossipand concurrency tests.knox.service: first sweep loggedopencode.db: 1 new, 448 unchanged, log debouncing still settles correctly, no errors or panics.git merge-tree origin/main HEADis clean, so the PR merges without conflicts.