Skip to content

[bug(opencode)] Resuming an opencode session never re-registers on 2.2.1 -> all writes fail #1543

Description

@Julpach65

[bug(opencode)] Resuming an opencode session never re-registers on 2.2.1 -> all writes fail

Summary

On engram 2.2.1, any opencode conversation that is resumed (reopened) after its session was ended is permanently unable to write observations/prompts from that opencode process. Every attributed write aborts with:

gentle-engram could not confirm Engram session registration for <tool>

Environment

  • engram 2.2.1 (latest release, 2026-09-25)
  • opencode (Node) 1.18.33, Windows 11, plugin regenerated via engram setup opencode
  • Write path: plugin -> serve POST /sessions (ensureSession) then observation write

Repro

  1. Start opencode on a conversation (id ses_xxx). Writes work.
  2. End that session with POST /sessions/{id}/end (plugin dispose/close hook or mem_session_end).
  3. Resume the SAME conversation (opencode keeps a stable session id across restarts).
  4. Ask the agent to save a memory. Write fails.

Root cause

  • The opencode host adapter resolves the session's stable id (data.sessionID) on every attributed write and calls POST /sessions via ensureSession(sessionID, renew=true).
  • For an id whose row has ended_at set, the serve replies 409 {"code":"session_already_ended"} and the session is never re-registered/re-opened. There is no reopen/restart endpoint (checked /restart, /reopen, DELETE /sessions) and engram delete session refuses sessions that have observations.
  • Reads still work (MCP path is separate), which makes the failure confusing: mem_context/doctor fine, all writes blocked.
  • Workaround on our side: clear ended_at directly in SQLite, then POST /sessions returns 201. Confirmed end-to-end.

Suggested fix

When a host re-registers an id that exists with ended_at set, treat it as an intentional reactivation (reopen) instead of returning 409 — or provide an explicit reopen endpoint. This is the same family as the pi --continue bug (#1376/#1387), now also reachable from the opencode host. The claude and codex adapters got a registration confirmation at resume (#1478, #1513); the opencode adapter is the remaining gap (#1485 draft).

Related: #1376, #1387, #1396, #1478, #1485, #1513.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions