Skip to content

[CI] Ordering gate blocked 4x: coordinator writes planner completion under session_id='unknown' but hook reads actual CLAUDE_SESSION_ID #738

@akaszubski

Description

@akaszubski

Problem

The ordering gate (agent_ordering_gate.py via unified_pre_tool.py Layer 4) blocked the implementer 4 consecutive times in the Issue #737 pipeline run despite planner having legitimately completed. The coordinator then had to manually diagnose and patch the state by calling `record_agent_completion` with the real session ID.

Root cause: The coordinator writes planner completion to pipeline state under `session_id='unknown'` (because the pipeline state file initialized without `CLAUDE_SESSION_ID` being set at that point). The hook reads state from a file keyed by `hashlib.sha256(CLAUDE_SESSION_ID)` where `CLAUDE_SESSION_ID` is the real env variable. These two hashes differ, so the hook finds an empty completion set and blocks the implementer.

Repo: autonomous-dev
Session: 93d0ad3b-935c-461f-823e-9e8bd40bbb71
Issue: #737 pipeline run (2026-04-09)

Evidence

From activity log 2026-04-09.jsonl:

12:48:05 — planner agent allowed, runs successfully
12:50:42 — SubagentStop (planner completes)
12:51:28 — implementer DENIED: "ORDERING VIOLATION: 'implementer' requires [planner]"
12:51:45 — implementer DENIED (2nd attempt)
12:52:15 — implementer DENIED (3rd attempt)
12:52:36 — implementer DENIED (4th attempt)
12:53:01 — coordinator checks state file: sid='unknown' → hash path shows stale/empty state
12:53:10 — coordinator reads env CLAUDE_SESSION_ID=93d0ad3b-...
12:53:32 — coordinator manually calls record_agent_completion(sid='93d0ad3b-...')
12:53:48 — implementer ALLOWED (5th attempt, now passes)

The coordinator spent ~2 minutes diagnosing and manually patching the state. Four implementer invocations were wasted.

Related Issues

Suggested Fix

In pipeline_completion_state.py and the coordinator flow: when recording agent completion, resolve the session ID eagerly at pipeline init time from `os.environ.get('CLAUDE_SESSION_ID')`. If it's not available at init, re-resolve it at each `record_agent_completion` call rather than falling back to the literal string `'unknown'`. The fallback should only be used when the hook itself can't read the env variable, not for the coordinator writes.

Plugin Version: PLUGIN_VERSION_PLACEHOLDER


Filed automatically by continuous-improvement-analyst

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-improvementContinuous improvement analyst findings

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions