Repository navigation
Description
Existing Issue Search
- I searched existing issues. Related, not the same: bug(claude): failed resume registration is silent; writes then fail with "Claude host session … already ended" #2305 and bug(claude): resuming an ended Claude Code session permanently denies memory writes (session_already_ended) #1624 (a resume after the app quit), feat(doctor): warn when an ended session keeps receiving activity without an open continuation #1821 (doctor warning). In this case the Claude Code process never stopped: the Engram session was ended while its conversation was still running.
📝 Observed Consequence
In a running Claude Code CLI conversation, Engram marked the session ended about 19 minutes in. From then on every write was denied by the PreToolUse gate with Claude host session "<id>" already ended. That lasted 32 minutes, until the next SessionStart:resume created <id>:resume:2. Nothing in the conversation could recover it: mem_save and mem_update both failed, and the agent could not restart its own session.
🔄 What happened (one conversation, all times UTC, from the Engram DB and the Claude transcript)
| Time | Event |
|---|---|
| 01:27:17 | Root <id> registered (project_owned). |
| 01:34:43 | mem_save succeeds. |
| 01:45:55 | An unrelated session bff874a5-… is registered; it ends at 01:45:58, leaves no transcript. |
| 01:45:59 | The conversation's own transcript records hook_success for SessionStart:resume. The CLI process (same PID) was mid-turn, running a Bash tool call; nobody resumed it by hand. |
| 01:46:05 | sessions.ended_at is set for <id>. POST /sessions/{id}/end is the only writer of ended_at, so something sent a SessionEnd carrying this conversation's ID. |
| 01:47–02:17 | Every mem_save / mem_update is denied: PreToolUse:mcp__engram__mem_update hook error: Claude host session "<id>" already ended. |
| 02:17:59 | The next SessionStart:resume creates <id>:resume:2; writes work again. |
I could not identify what fired the SessionStart:resume and SessionEnd at 01:45:59–01:46:05. My best guess is a second, short-lived Claude process that resumed the same session ID and then exited. A terminal multiplexer plugin that relaunches panes with claude --resume <id>, or a background helper, would do that. Either way, Claude Code can deliver SessionEnd(<id>) while another process still owns <id>, and Engram ends the session for both.
✅ Expected Behavior
A live conversation should not lose memory writes because some other process ended its session ID. Either of these would cover it:
- Self-heal in the gate: when the
PreToolUsegate finds the root ended but this host process is still the registered owner (thehost-sessions/<pid>.jsonbinding), register or renew a<id>:resume:Ncontinuation, asSessionStart:resumealready does, instead of denying the write. - Ignore an end from a non-owner:
session-end.sh(or the server) skipsPOST /sessions/{id}/endwhen theSessionEndcomes from a process other than the registered host for that ID.
At minimum, engram doctor (#1821) could flag "ended while its host PID is alive".
🧩 Environment
- Linux x86_64, Claude Code CLI 2.1.327, terminal multiplexer with several Claude panes in the same repository.
- engram 3.6.0, Claude Code plugin from the marketplace at
7cf4ed2(2026-10-30). I have not retested on 3.7.2. From the changelog, fix(claude): preserve resume ownership and report registration failures #2310 reports registration failures and preserves resume ownership, but it does not seem to cover an end that arrives while the conversation is still running.
Activity
dnlrsls commentedon Nov 21, 2026
Maintainer triage
Reproduced on canonical main
380d513841f0cc96f87088b837156d758bd1ee4cusing real Windows Claude Code lifecycle callbacks, a loopback provider and a disposable Engram instance. The sole-host control closed normally. With a live peer, exiting the second host ended both a live root and a live continuation, and the next guard call denied the surviving host. Simultaneous exit submitted two end operations. The exact trigger of the original Linux incident remains unconfirmed.The runtime end endpoint resolves the current live continuation from the root. A delayed request can therefore end a successor that the caller never confirmed. First delivery: add an optional expected effective ID to the runtime end endpoint and compare it inside the existing transaction before updating the session. Advertise support in health. Preserve omitted-field behavior and the manual exact-ID end route. Test successful end, delayed/repeated requests, scope conflict, malformed or duplicate expectations, and absence of new writes or sync mutations on rejection.
Host attachment, last-host coordination across callbacks, mixed-version admission and ambiguous acknowledgements remain follow-up work. The issue stays open after the first PR. The delivery needs independent contract review before merge.
fix(doctor): report ended sessions for verified live hosts (Gentleman…
dnlrsls commentedon Nov 24, 2026
Maintainer-approved private Core follow-up
On exact canonical
f8fa1b460084dd5988c7e05cc72dec03a730f90f, the actual Claude Code 2.1.330 installer and marketplace plugin 0.1.28 ran in two disposable WSL2 profiles. Both real processes attached to the same Claude session. The first process stayed alive after its peer exited, but the persisted session was already ended and its installed MCP deniedmem_save. The managed prototypeed5e922on the same canonical revision recovered a replaced owner, saved from the surviving instance under the original effective identity, and finalized on last exit.The previous expected-effective-ID fence cannot distinguish multiple hosts within one effective session. The approved increment gives a private session-owned Core a transactional host roster, admission and retirement, a generation fence, and a terminal receipt. An open managed generation rejects ordinary scoped close. A stale generation, a retained live host, or an unresolved write keeps managed closure pending. Public exact-ID maintenance and existing ordinary sessions retain their current behavior.
This increment covers the private Core and its optional local Store catalog. It excludes launcher activation, mixed-version compatibility, use of a shared Store by stock and managed instances, and closing #2395 at merge. Direct managed participation requires the private owner token and a verified host identity. The follow-up will use Refs #2395. Owner @dnlrsls.
Exact local candidate
f0f9dd39d1e8adccb47f6ce06d9cf1c129c082bdpassed focused Linux Store, Server and host namespace checks, and focused native Windows race checks. Independent review covered the owner-only transport, the scope fence in the same transaction, optional catalog copying, unchanged ordinary callers, and on-disk receipts. Acceptance also requires the other affected packages and hosted checks.The maintainer approves a size exception for this 1,382-line review unit. The host roster, write intent, generation and terminal receipt are reviewed together because the safety invariant depends on their transaction boundaries. Launcher and supervisor activation stay outside this change.
dnlrsls commentedon Nov 24, 2026
Approved follow-up for managed save recovery
On canonical main
5f17b40d116700de4dfd737b036d18cfad75c515, the owned Core accepts opaque write intents. When the originating host disappears before dispatch, that intent contains no payload to recover, so it can leave terminal close pending. The private API regression on the same SHA rejects a write intent carrying the proposed observation with HTTP 400.The next increment has two review units. First, allow the existing private owner route to admit a save with its validated, redacted observation, pin the prepared bytes to the managed scope and operation ID, and clear the staged payload atomically with the observation and its receipt. Preserve opaque intents and the existing optional Store catalog. Second, recover already-admitted writes from the current generation in admission order and keep older opaque intents pending until their explicit retry. Recovery will load one observation at a time and expose the resulting save receipt through the existing lookup.
This scope excludes the supervisor, launchers, ordinary CLI and hook behavior, shared stores, and closing #2395 on merge. Owner @dnlrsls. Use
Refs #2395and deliver against canonical main in order. Each unit requires independent review and current checks. Acceptance covers the original-main rejection, exact-payload conflicts and replay, schema compatibility, on-disk reopen, forced rollback, and batching with concurrent recovery. Independent local review ofbb147ecd94b1ed74464dcd0f1854a6eae7a88336andebcc6a92657b25c43c9dd7e7ae52c1b5c6cfb821found no remaining blockers in these scopes.