Skip to content

guard --session <uuid> fails with 'Could not detect current session' on every invocation #73

@bdwelle

Description

@bdwelle

Bug

When cozempic guard --daemon is invoked with an explicit --session <uuid> flag (as the SessionStart hook does via ${SESSION_ID:+--session $SESSION_ID}), the daemon starts, immediately prints ERROR: Could not detect current session, and exits — leaving a stale PID file behind and providing zero protection.

Note: I had Claude write this issue for me. I don't really understand enough about what's going on to file it myself, just that I got caught again this morning with the "Extra usage is required for long context requests" warning and asked omp/Claude to diagnose and fix it.

Environment

  • cozempic 1.6.18
  • macOS 26.1 Tahoe (Mac Mini M4)
  • Oh My Pi coding harness (omp/14.1.0) — hooks fire correctly but guard always dies

Reproduction

The cozempic init-generated SessionStart hook runs:

cozempic guard --daemon --session <uuid> --cwd /path/to/project

This fails every time. Log output:

--- Guard daemon started at 2026-04-11T08:48:28 ---
CWD: /Users/bdwelle/lib/foilfinder
CMD: python3 -m cozempic.cli guard --cwd /Users/bdwelle/lib/foilfinder --threshold 50.0 --interval 30 -rx standard --session <uuid>

  ERROR: Could not detect current session.

Contrast: working invocation

Running without --session from the same directory succeeds — the daemon auto-detects the correct session ID and starts the 4-tier guard:

cozempic guard --daemon --threshold 50 -rx standard --interval 30
4-tier guard protecting context (200K window):
  Soft  (25%): gentle prune, no reload
  Hard1 (55%): standard prune + reload
  Hard2 (80%): aggressive prune + reload
  Hard3 (90%): manual aggressive

Impact

The SessionStart hook is the entire auto-protection mechanism. When --session breaks the daemon, every session silently goes unguarded. In our case: 66 consecutive guard processes spawned across multiple days, all dead on arrival, all leaving stale PID files in /tmp.

Workaround

Remove the explicit --session injection from the hook — replace:

cozempic guard --daemon ${SESSION_ID:+--session $SESSION_ID}

with:

cozempic guard --daemon

Guard auto-detects the session correctly when left to its own devices.

Suggested fix

Either:

  1. Fix guard --session <uuid> to resolve the session file path the same way auto-detection does, or
  2. Have cozempic init not inject --session into the hook (auto-detection already works)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcriticalCritical severityguard

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions