Skip to content

bug(claude): PreToolUse write gate denial gives no release-skew guidance for a stale unmanaged server #2401

Closed

Description

@SebasCouto

Existing Issue Search

  • I searched existing issues and will add evidence to a canonical tracker when applicable.

Related: #2242 (canonical stale-server report, closed by #2311), #1708 (Codex equivalent, closed with upgrade guidance), #2362 (listener PID on Unix), #1357 (Homebrew managed service).

📝 Observed Consequence

After an in-place binary upgrade, a manually started engram serve from an old release kept listening on 127.0.0.1:7437. From then on, every Claude Code write tool (mem_save, mem_update, mem_judge, …) was denied by the plugin's PreToolUse gate:

PreToolUse:mcp__engram__mem_save hook error: Claude managed local server identity unconfirmed: expected current data directory instance

Read tools (mem_search, mem_context) kept working, because the gate only matches write tools and engram mcp opens the store directly. So memory looked healthy while nothing could be saved. Nothing on the local-only install pointed at the cause:

  • the denial reports neither the observed server release nor what to do;
  • engram ps reports unmanaged Engram listener on port 7437 (owning PID unavailable) with no versions;
  • engram cloud status prints not configured and never reaches the local daemon;
  • engram doctor (10 checks) inspects only the store.

The skew report added by #2311 is therefore unreachable in this setup: it covers only pidfile-managed daemons (ps) and cloud-configured installs (cloud status).

The stale process had been running about two months. The gate denied writes correctly; the gap is the missing diagnosis.

sequenceDiagram
    autonumber
    participant CC as Claude Code
    participant Hook as PreToolUse gate<br/>(engram 3.7.2)
    participant Srv as engram serve on :7437<br/>(stale 0.1.0, no supervisor)
    participant MCP as engram mcp (3.7.2)
    participant DB as Store (data dir)

    Note over CC,MCP: Read path: not gated
    CC->>MCP: mem_search
    MCP->>DB: open store directly
    DB-->>CC: results OK

    Note over CC,Srv: Write path: gated
    CC->>Hook: mem_save
    Hook->>DB: EnsureInstanceID(data dir) gives expected id
    Hook->>Srv: GET /health
    Srv-->>Hook: {"status":"ok","service":"engram","version":"0.1.0"} (no instance_id)
    Hook-->>CC: deny: "identity unconfirmed" (version 0.1.0 is discarded)
    Note over Hook: Proposed: report server 0.1.0 vs CLI 3.7.2<br/>and restart guidance, as the Codex guard does (#1708)
Loading

🔄 Steps to Reproduce

  1. Start engram serve manually, with no supervisor (no launchd, systemd or engram run -d), from a release whose /health has no instance_id. Observed with 0.1.0.
  2. Upgrade the binary in place, same path (Homebrew), to 3.7.2. Do not stop the running server.
  3. Install the Claude Code plugin 0.1.23 and register the MCP (engram setup claude-code).
  4. In a Claude Code session, call mem_search: it succeeds.
  5. Call mem_save: it is denied with the message above.
  6. Run engram ps, engram cloud status (no cloud configured) and engram doctor: none of them reports the release skew.

✅ Expected Behavior

Writes stay blocked, which is correct, but the operator gets an actionable diagnosis:

  1. Claude Code denial with skew guidance. When /health answers status: ok, service: engram but its instance_id is missing or mismatched, the denial includes the observed server version and the installed CLI version, plus the restart guidance. That parity already exists for the Codex guard since bug(codex): stale Engram core denies all memory writes; guard fails closed without capability negotiation or upgrade guidance #1708. Example: stale Engram server on :7437 (server 0.1.0, CLI 3.7.2): restart it through its supervisor, or stop it and run engram run -d.
  2. engram ps versions for unmanaged listeners. Following fix(cli): report running server release skew and pending restart #2311, an unmanaged listener's /health version is shown as diagnostic-only metadata, with no signaling and no adoption, e.g. unmanaged listener on 7437, server 0.1.0; installed CLI 3.7.2; restart pending.
  3. Optional doctor check. Compares the reachable configured listener's release with the CLI. It can stay diagnostic-only, like the other checks.

❌ Actual Behavior

  • Writes are denied with managed local server identity unconfirmed: expected current data directory instance. No version and no guidance.
  • /health from the stale server: {"service":"engram","status":"ok","version":"0.1.0"}.
  • engram ps: unmanaged Engram listener on port 7437 (owning PID unavailable); not managed by this pidfile; not signaling or adopting it; verify the owner locally and stop it manually if appropriate.
  • engram cloud status: Cloud status: not configured (no effective server URL).
  • engram doctor: no finding related to the running server.

Operating System

macOS

Release Version (Report Context)

engram 3.7.2 (Homebrew); Claude Code plugin 0.1.23; stale server 0.1.0

Agent / Client

Claude Code

📋 Relevant Logs

Before (stale server):

$ engram version
engram 3.7.2
$ ps -o ppid,command -p <pid>
1  engram serve
$ curl -s http://127.0.0.1:7437/health
{"service":"engram","status":"ok","version":"0.1.0"}

Mitigation: kill <pid>, then engram run -d.

After:

$ curl -s http://127.0.0.1:7437/health
{"capabilities":{...},"daemon_token":"<redacted>","instance_id":"<redacted>","service":"engram","status":"ok","version":"3.7.2"}
$ engram ps
running (pid <pid>) on port 7437
Versions: server 3.7.2; installed CLI 3.7.2

The mem_save that had been denied was retried and accepted.

💡 Additional Context

  • The denial is raised in cmd/engram/hook_local_server.go (confirmHookLocalIdentity and hookLocalHealthMatches). The health body is already parsed there, so the observed version is available without an extra request.
  • Fail-closed behavior and "hooks never restart the server" (README, DOCS) are correct and should stay. This report asks only for diagnosis.
  • Workaround for others: curl -s 127.0.0.1:7437/health, compare version with engram version, and run the server under a supervisor or engram run -d so ps and restart can manage it.
  • I'm reporting this. I'm not volunteering to implement it, but I'm happy to test a fix.

Activity

  1. added
    status:needs-review
    type:bug
    on Nov 20, 2026
  2. dnlrsls commented on Nov 21, 2026

    @dnlrsls
    Member

    Maintainer triage

    Reproduced on canonical main ef8f2978d5d1f09b13ab5b4d93329d805e187349 with a Windows CLI built from that commit and a disposable data directory. A loopback fixture returned the reported /health shape with status ok, service engram, version 0.1.0, and no instance ID. The real engram hook claude-pre-tool-use denied the write with the exact generic message. The listener saw only a single GET /health.

    The shared local health reader currently discards the version during identity checking. First delivery: add diagnostic-only release guidance to that denial when the bounded, complete health response identifies Engram and reports a comparable version different from the installed CLI. Keep the independent instance check before session or directory traffic, the generic fallback for invalid/unknown versions, the current redirect and recovery rules, and the explicit URL behavior. Version metadata cannot confer identity or authority over a process. Test missing/mismatched identity, matching identity, same-version and malformed metadata, and a listener that never receives any request beyond health on denial.

    Use Refs #2401. The unmanaged engram ps view and any doctor check remain outside this delivery.

  3. added
    status:approved
    and removed
    status:needs-review
    on Nov 21, 2026
  4. self-assigned this
    on Nov 21, 2026
  5. dnlrsls commented on Nov 21, 2026

    @dnlrsls
    Member

    Unmanaged ps follow-up

    On current canonical main 80291ed42ea3673c88e9f147b442ec0f5c8a9bec, a Windows CLI built with release version 3.7.2 issued one GET /health to a disposable loopback listener reporting Engram 0.1.0. With no pidfile, engram ps exited 1 and correctly reported occupied/unmanaged. The version already returned by the bounded daemon probe was discarded from this diagnostic.

    Approved next scope: reuse the existing probe for the unmanaged listener reported by engram ps and display bounded validated release information. Keep the exit status, pidfile policy, token authority and stop/restart/start behavior. Test missing/stale/mismatched pidfile states, an unrelated service, unknown releases and one health request per status check. Keep the optional doctor check outside this follow-up.

  6. dnlrsls commented on Nov 21, 2026

    @dnlrsls
    Member

    Closing as completed in main. #2417 reports both versions when a stale localhost server blocks the Claude hook. #2418 gives the same version information in engram ps for the unmanaged listener. Both paths were verified with the native Windows CLI against an isolated loopback fixture. The latest release, v3.7.2, predates these changes. Verification on the original macOS/Homebrew setup is welcome once the changes ship.

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

Metadata

Metadata

Assignees

Labels

status:approvedtype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions