The wrong OpenCode session
One SQLite store holds every OpenCode session, and anything can leave one behind. When the bridge had to find its own session again, it took the newest. Usually that was someone else's.
Yesterday's fix was about having nowhere to write.
Today's is the opposite problem.
Too many places.
And the bridge kept choosing the wrong one.
Every agent except OpenCode keeps its sessions as files.
One conversation, one file, in a directory only that agent writes to.
OpenCode keeps all of them in a single SQLite store.
That's a better design in most ways.
It also means the directory isn't yours.
Any opencode run from a project folder leaves a session filed under it.
An app that makes its own model calls in your working directory will quietly fill it with two-message remnants.
Most of the time this never surfaces.
The bridge links a session once and keeps using it.
But sometimes it has to find that session again.
After an unlink.
After a seed.
When doctor relinks a project.
The rule it used was simple.
Take the newest session in this directory.
In a clean project, the newest session is your conversation.
In a busy one, the newest session is whatever ran last.
Usually a remnant.
--adopt bound to it, and the bridge went on carrying handoffs into a two-message shell while the real conversation sat untouched a few rows away.
Recency was standing in for ownership.
It's a reasonable proxy right up until something else shares the namespace.
The fix is to stop guessing and start recognising.
The bridge already leaves marks.
A handoff it delivers writes a message with a msg_bridge_* id.
A session it fabricates gets a ses_bridge* id.
Both were already there. Neither was being read.
Discovery now looks for them.
Exactly one marked session in the directory is provably the right one, and it is adopted silently.
Several narrow to the newest of those, behind --adopt.
None keeps the old newest-wins guess, which is correct for a genuine first adoption.
The extra store read only happens when a directory is actually ambiguous. One candidate, or none, never pays for it.
The verification is the part I like.
A real directory. Twenty-seven OpenCode sessions.
The newest was a two-message remnant.
The bridge's own session was a ninety-message conversation.
Before: the two-message remnant.
After: the ninety-message conversation.
343 tests. The litter case is bite-proven — the old rule was put back, and the test failed.
Worth knowing where this bites hardest.
It has nothing to do with git.
It's worst in directories that aren't git repositories, because OpenCode files all of those together under one global project.
Upgrading
npm i -g @serdardb/context-bridge
Only OpenCode is affected, and only when a directory holds more than one of its sessions.
If yours holds one, nothing changed for you.