Skip to content

Session repo identity never binds on host 2.1.4 — recall silently partitions writes under the server cwd #90

Closed

Description

@abogartz

Symptom

memory_recall (and injection) silently misses rows that are present and correctly stamped in the daily logfmt, for sessions hosted by the Desktop app / opencode-cli serve (host 2.1.4). Writes from such sessions are stamped with the wrong repo identity, so they are visible only to their own session; rows written in the real repo are invisible to them.

Root cause

Per-session repo identity (src/repokey.ts, src/index.ts) is learned from:

  1. ctx.session.context() message payloads — reading m.location.directory / m.info.location.directory
  2. session events (created / execution.started / moved)

On host 2.1.4 neither source carries the directory:

  • The host stores it on the session row (opencode.db → session_v2.directory); message payloads (session_message.data, all types: user/assistant/system/…) contain no location field.
  • The event path did not bind either (observed with event table empty; subscription likely never sees a directory-bearing payload).

Binding therefore fails silently and every write falls back to the module scope — the server process cwd. Observed: a session whose session_v2.directory is the project repo wrote rows stamped repo=/Users/Alex/.config/opencode repoPath=/Users/Alex/.config/opencode.

Secondary defect

A session in a non-git directory stamps repo with the raw path, quoted, spaces included: repo="/Users/Alex/Documents/Default Project". This breaks naive field parsing and makes the row unmatchable by hash-based identity forever.

Evidence

  • ~/.local/share/opencode/opencode.db: session_v2.directory = correct project path; message payloads have no location.
  • ~/.config/opencode/memory/2026-10-24.logfmt: same repo, same day — rows stamped 5699fad3a258 (bound TUI session) vs repo=/Users/Alex/.config/opencode (unbound Desktop session); recall in the Desktop session sees only its own.
  • Repro: Desktop session in this repo → memory_remember → inspect the appended row's repo=; then memory_recall from a TUI session in the same repo does not see it.

Expected

Session identity resolves from the host's session location (whatever API actually carries it in V2 — session info, not message payloads), and an unbindable session must NOT silently write repo-partitioned rows under a fallback scope — it should stay unscoped (global-visible) or bind lazily and re-stamp.

Notes

  • Found while dogfooding 0.8.x; the same code path exists in 0.6.5 and current main (bindSessionFromMessages reads location?.directory).
  • Related: opencode plugin update only refreshes the cache snapshot; the running service keeps the old code until the service itself restarts.

Activity

  1. added
    bug
    on Oct 24, 2026
  2. abogartz commented on Oct 24, 2026

    @abogartz
    OwnerAuthor

    Root cause confirmed with recorded host payloads (opencode 2.1.4, probe plugin capturing the plugin-side view):

    Standalone (opencode run) — works. The plugin loads before the session exists, so it receives session.created, whose payload carries location.directory:

    {"type":"session.created","location":{"directory":"<proj>"},"data":{"sessionID":"ses_…","location":{"directory":"<proj>"},…}}

    The stamped row is byte-correct: repo=38315f5bf4a6 (sha1 of the probe origin) repoPath=<proj toplevel>.

    Serve (opencode serve --service, production) — broken. The plugin loads lazily on the first prompt for a location, i.e. AFTER POST /api/session created the session → session.created is never delivered. The only identity event that arrives per turn is:

    {"type":"session.execution.started","durable":{"aggregateID":"ses_…"},"data":{"sessionID":"ses_…"}}

    — no location anywhere. The message-payload fallback also cannot work: GET /api/session/{id}/context returns messages with no location field (all message types checked); the directory lives only on the session row (GET /api/session/{id} → location.directory). All three binding paths miss → writes fall back to the module scope (server cwd) → silent recall partitioning.

    Why the harness missed it (two structural gaps):

    1. test/repo-scope-session.test.ts feeds the fake event bus and fake session.context the payload shapes the plugin hopes for (location on events, location on messages). The unit fakes encode the same wrong assumption as the production code — fakes must be recorded from the real host, not imagined.
    2. e2e/ runs only opencode run --standalone — the mode where the bug does not exist — and no scenario ever asserts the repo= stamp on the written row.

    Fix direction: on identity events lacking a directory, resolve it from the session API (ctx.session.get → location.directory, verified present in serve mode) before any store write; and add a serve-mode e2e scenario that asserts the stamp, plus a unit replay using the recorded real payload shapes (execution.started without location, context messages without location).

  3. added a commit that references this issue on Oct 24, 2026
  4. abogartz-opencode-self-improvement commented on Oct 24, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.8.12 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions