Skip to content

bug(opencode): leftover root session from previous day still fail-closes mem_save on 2.0.0-rc.12 #1242

Description

@lbatmad

📝 Bug Description

On Engram 2.0.0-rc.12 with a single OpenCode session, omitted-session mem_save still fails closed:

multiple active runtime sessions match the current project and directory; provide session_id or end other active matching sessions before retrying

This was treated as resolved by #1101/#1102 (7-day activity window) and #1131/#1159 (OpenCode sub-agent / misregistered-session close). The remaining case is a leftover root session from the previous day: ended_at stays NULL, both rows fall inside the 7-day window, and there is no live-process check. One OpenCode window is enough to get two Engram candidates.

engram doctor --check ambiguous_active_runtime_sessions reports the pair. Closing the stale row with mem_session_end unblocks writes. The MCP mem_doctor call in the same session did not include that check.

🔄 Steps to Reproduce

  1. Run Engram MCP 2.0.0-rc.12 with OpenCode in a project directory.
  2. Use one OpenCode session, then leave it (do not archive or delete it). Start a new OpenCode session in the same directory the next day. Only one OpenCode session is live.
  3. Call mem_save without session_id.
  4. Run engram doctor --project <project-name> --check ambiguous_active_runtime_sessions.

✅ Expected Behavior

A leftover root session with no live OpenCode process should not count as a concurrent runtime candidate. mem_save without session_id should resolve to the current session.

Fail-closed should apply only when two sessions are genuinely live.

OpenCode root-session end should set ended_at, not only session.deleted, plugin dispose, or archive (#1192).

❌ Actual Behavior

Two ownership_mode=shared rows for the same project+directory stayed ended_at IS NULL:

mem_save without session_id failed closed until the leftover id was ended. Doctor CLI warned; MCP mem_doctor in that session did not surface ambiguous_active_runtime_sessions.

Operating System

macOS

Engram Version

2.0.0-rc.12

Agent / Client

OpenCode

📋 Relevant Logs

engram 2.0.0-rc.12
PATH binary: ~/.local/bin/engram (shadows Homebrew 1.20.0)

mem_save:
Failed to save: multiple active runtime sessions match the current project and directory; provide session_id or end other active matching sessions before retrying

engram doctor --check ambiguous_active_runtime_sessions:
status=warning
reason_code=ambiguous_active_runtime_sessions
message=Project "<project-name>" has 2 active runtime session candidates across 1 directory or directories.
evidence.active_candidate_count=2
directories=["<project-dir>"]
session_ids=["ses_<current>", "ses_<stale>"]

sessions table (redacted):
ses_<current>|<project-dir>|<today>|NULL|shared
ses_<stale>|<project-dir>|<yesterday>|NULL|shared

After mem_session_end(ses_<stale>):
doctor check result=ok
mem_save succeeded

💡 Additional Context

Activity

  1. LCubero commented on Sep 18, 2026

    @LCubero

    Reproduced on Windows with OpenCode 1.18.31 and Engram 2.0.0-rc.12.0.20260917164859-2cdda9041c1b.

    User-observed runtime state: one OpenCode window open.

    Observed behavior:

    • mem_save without session_id failed with multiple active runtime sessions match the current project and directory.
    • mem_session_summary without session_id failed with the same ambiguity.
    • engram doctor --project <project> --check ambiguous_active_runtime_sessions --json reported 7 active candidates across 1 directory.
    • No candidate was selected, ended, or modified.

    Comparative evidence: a prior Pi session in the same project successfully wrote both the local continuity backup and the Engram session summary with the same explicit session ID.

    Version check: the installed Engram commit is 6 commits behind current main, but plugin/opencode/engram.ts has the same Git blob at the installed commit and at current main, so the current upstream plugin still contains no relevant change for this occurrence.

    Expected: the current OpenCode root session should be bound unambiguously, or non-live leftover roots should not make omitted-session writes ambiguous.

    Actual: both memory writes fail closed despite only one OpenCode window being reported as open.

  2. LCubero commented on Sep 18, 2026

    @LCubero

    I traced this issue to an outdated locally installed OpenCode plugin rather than Engram’s core session-selection logic.

    After running engram setup opencode, the installed engram.ts was refreshed. I then verified that mem_save and mem_session_summary both bound to the correct root OpenCode session, and that a normal OpenCode exit persisted the session’s ended_at value.

    The current installed plugin now structurally matches the source on main (99b7df243fd933ce3c4e1714e8b27c9273e1d755), apart from the expected installer-generated ENGRAM_BIN path.

    This resolves the reported behavior locally. However, the incident suggests a remaining upgrade/documentation gap: updating the Engram binary does not clearly warn that an installed OpenCode plugin may be stale or that engram setup opencode should be rerun. It may be worth tracking plugin drift detection or documenting the required refresh step separately.

  3. dnlrsls commented on Sep 18, 2026

    @dnlrsls
    Member

    Resolved by #1267, merged as 6ad49f17b558004b0fa1f70d161cb9f2fba62aae.

    The merged owner-liveness contract persists and renews a local runtime lease, prefers a genuinely live leased owner over stale legacy rows in the same directory, and still fails closed when multiple runtimes are actually live. Its regression coverage includes the next-day stale OpenCode root-session scenario reported here, and the final PR head passed the full required CI suite.

    Closing as completed. If the same scenario reproduces on a build containing that merge commit, please reopen with the new session rows and ambiguous_active_runtime_sessions output.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions