Skip to content

fix(memory): bind serve-host session identity from the session row (#90) - #91

Merged
abogartz merged 1 commit into
mainfrom
fix/serve-mode-identity
Oct 24, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/serve-mode-identity

Conversation

@abogartz

Copy link
Copy Markdown
Owner

What

Closes #90 — recall silently partitioned every service-hosted (Desktop / serve --service) session.

Data, not guesses

Root cause was confirmed with a probe plugin recording the plugin-side view on both host versions (2.1.4 and 2.0.26):

Signal Standalone (opencode run) Serve (serve --service)
plugin setup vs session creation plugin first session first (lazy plugin load)
session.created delivered? yes — location.directory present never
session.execution.started n/a arrives, carries only {sessionID}
context messages carry location (legacy) no location field at all
session row (session.get) — location.directory present ← the fix's source
stamped row correct (repo=sha1(origin)) module scope = service launch dir

Production corroboration: this session's session_v2.directory is the project, yet its rows carry repo=/Users/Alex/.config/opencode; the host log shows the location service for the project was never booted in the service run.

Why the harness missed it

  1. test/repo-scope-session.test.ts fed the fake event bus and session.context the payload shapes the plugin hopes for — the fake encoded the same wrong assumption as the production code.
  2. e2e/ only ran opencode run --standalone — the mode where the bug cannot exist — and no scenario ever asserted the repo= stamp.

Tests (red first)

  • test/repo-scope-serve-host.test.ts — replays the recorded serve-mode payloads at the plugin boundary. On the pre-fix code (git stash of the src/ change): 2 of 4 fail (identity-from-row, consult-once). Post-fix: 4/4.
  • e2e/stamp.test.ts — service-shaped BDD scenario: plugin via global config, service launched from a directory that is NOT the project, session created in a git repo with a known origin, stamp asserted. Honest classification: green-on-both pins (the HTTP host boots locations on demand, so it self-heals what the Desktop attach path does not) — it is the end-to-end contract guard, not the red proof.

Fix

bindSessionFromApi: resolve location.directory from the host's session get, once per session (bounded LRU, same cap as the scope cache); wired into (a) the identity-event branch when an event carries no directory, and (b) bindSessionIdentity (messages → session row) at every write/read binding site. A host without session.get degrades to today's module-scope fallback (pinned by a test).

Verification

  • bun run gate: typecheck, lint, 356 unit tests, e2e BDD — all green.
  • Degraded path pinned: session.get unavailable → write lands in module scope, never throws.

Follow-up (separate issue): non-git session dirs stamp repo="<raw path>" quoted with spaces — parser-safe but unmatchable by hash; worth normalizing.

On `opencode serve --service` the plugin loads AFTER the session exists, so
session.created (the only location-bearing event) is never delivered,
execution.started carries only {sessionID}, and context messages carry no
location — all three binding paths missed and writes fell back to the module
scope, silently partitioning recall (issue #90, reproduced with recorded
2.1.4/2.0.26 payloads).

- bindSessionFromApi: resolve location.directory from the host's session get,
  once per session (bounded LRU); wired into the identity-event branch and a
  bindSessionIdentity chain (messages -> session row) at every write/read site.
- test/repo-scope-serve-host.test.ts: replays the RECORDED serve-mode payloads
  (execution.started without location, locationless messages); 2 of 4 fail on
  the pre-fix code.
- e2e/stamp.test.ts: service-shaped BDD guard — global-config plugin, service
  launched away from the project, stamp asserted (contract guard: green on
  both pins, HTTP host boots locations on demand).
- test/harness.ts: fake session.get backing the replay.
@abogartz
abogartz merged commit 4f92718 into main Oct 24, 2026
3 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.8.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the fix/serve-mode-identity branch November 19, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant