Skip to content

opencode-claimant(claimant.py): zero-message gate calls /api/session/<id>/messages — a 404 empty body reads as "zero messages" (fail-open before DELETE + binding clear) #7760

Closed

Description

@dezren39

Summary

The zero-message verification in pm-stack/opencode-claimant/claimant.py (prompt.md step 1a, the #4758 / design #4912 recovery rule) calls an endpoint the v2 server does not have:

claimant.py:253  GET http://127.0.0.1:13420/api/session/<id>/messages

The live server serves the singular /message (returning {"data": [...], "cursor": ...}). /messages is a 404 with an empty body — verified on http://127.0.0.1:13420 on 2026-11-08:

GET /api/session/ses_e5e441ca753ffdMse0Sd5IZ977/message   -> 200  data[50], cursor
GET /api/session/ses_e5e441ca753ffdMse0Sd5IZ977/messages  -> 404  (empty body)

poll.py and the fire probe already use the singular form (fire-probe.py session_messages()); only claimant.py — and the stub in test/test_claimant.py:75, which pins the wrong path — use /messages.

Why this is fail-open, not merely inert

The block at claimant.py:250-265 is:

messages_response = subprocess.run(["curl", "-s", "-m", "5",
    f"http://127.0.0.1:13420/api/session/{session_id}/messages"], ...)
if messages_response.returncode == 0:
    message_count = len(json.loads(messages_response.stdout or "[]"))
    if message_count == 0:
        recovery_candidates.append(...)

curl -s exits 0 on a 404, and the 404 body is empty, so:

  1. returncode == 0 → true,
  2. stdout or "[]" → "[]" (the or was written for a timeout producing empty output),
  3. message_count == 0 → every stuck-bound row passes the zero-message gate.

The session GET immediately above it has the same shape (claimant.py:217-231): an unauthenticated curl -s returns a 401 {"_tag": ...} body, which is parsed and has no id, so the session is treated as gone. Chained together in live mode, the step-1 path is:

session GET → 401 body, no id → "gone" → attempts remain → messages read → 404 empty body → "0 messages" → recovery candidate → DELETE (401, returncode == 0, recorded as success — #7367) → bind --launched-by opencode-claimant-recovery:zero-message-deleted clears both bindings.

That is precisely the ordering the packet's step 1b forbids: an un-deleted session holding messages, with its binding cleared, leaving the task launchable for a second session while the first may still be alive. Today the only thing preventing it is that supervision_step's candidate list comes from repo-queue list parsed as JSON, which fails (#7325), so the list is empty. The safety is incidental, not structural.

Not covered by the open issues

Fix direction

  1. One transport helper (per opencode-claimant(claimant.py): every OpenCode server call is unauthenticated — session create always 401s, and the delete gate trusts curl's exit status #7367) with a path constant, using GET /api/session/<id>/message and reading data from the envelope.
  2. Treat an empty body, a non-2xx status, or a body that is not a message list as unknown, never as zero: the step-1a rule already says "if the message read is unavailable/incomplete, treat the state as unknown … leave it bound and stop". The current stdout or "[]" inverts that.
  3. test/test_claimant.py:75 must stub the singular path, and the fail-closed test should assert that a 404/empty messages read emits no bind argv and leaves the binding intact (it currently stubs an empty-body-free "[]", so it cannot fail).

Acceptance

  • With the stub transport returning 404 + empty body for the messages read (and a live session object for the per-id GET), no recovery bind is emitted and no DELETE is issued.
  • With the stub returning {"data": [ ... 50 messages ... ]}, no recovery candidate is produced.
  • With the stub returning {"data": []} and every other stuck-bound fact true, the DELETE and atomic recovery bind are emitted, in that order.
  • grep -rn '/messages' pm-stack/opencode-claimant/ returns nothing outside the retired implementation docs (README.md:96, IMPLEMENTATION_CHECKLIST.md:206 also name the wrong path).

Found by the laptop opencode-lane claimant fire 2026-11-08 (shadow, #3026 slice 1). Shadow report: ~/.local/state/opencode-claimant/shadow-fire-20261108T161653Z.json.

Acceptance criteria

  • The zero-message gate in pm-stack/opencode-claimant/claimant.py queries the endpoint the v2 server actually serves (singular /message), matching poll.py and fire-probe.py.
  • An HTTP error status (404/401) or an empty/unparseable body can never be read as 'zero messages': the gate fails closed and the session is not added to recovery candidates.
  • The session-exists check above it has the same fail-closed property: an error body without an id is not treated as 'session gone'.
  • The stub in test/test_claimant.py pins the correct path, and a regression test feeds a 404-empty-body response and asserts no recovery candidate (and no DELETE / binding clear) results.

Activity

  1. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 8, 2026
  2. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  3. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/highImportant and time-sensitive
    effort/sSmall: expected under 2 hours of work
    source/humanFiled directly by a human
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    on Nov 8, 2026
  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    Intake review

    Related: #7367 (unauthenticated claimant calls — the DELETE-401 half of the chain in this issue's evidence); #4758 / design #4912 (the recovery rule this gate implements); sibling claimant defects filed today: #7732 (cap_room log), #7706 (yield-field mismatch, enriched last run).
    Live check: the filer's live probe (2026-11-08) shows /messages returning 404-empty while /message returns 200 on the same session; no merged PR in this run's search fixes the claimant path.
    Notes / risks: this is fail-open on a destructive path — DELETE plus binding clear on a session that may hold messages is exactly the ordering the packet's step 1b forbids. Fix the endpoint AND the error handling; fixing only the path leaves the 401 variant armed.
    Suggested approach: switch to the singular endpoint, treat non-200 and empty bodies as gate failures (skip recovery, log the status), and add the 404 regression case to the claimant tests.

    — fleet monitor (repo-fleet-monitor), 2026-11-08 10:12 CST run: acceptance criteria appended to the body, labels normalized, meta/enriched applied.

  5. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · design-architect pass 74 — adopted as a phase of design #7770

  6. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    Live confirmation from the 2026-11-09 12:27-12:30Z claimant fires (primary clone, mode=live, standing server 127.0.0.1:13420):

    • GET /api/session/<id>/messages → HTTP 404, empty body (today, on a real bound session).
    • GET /api/session/<id>/message → the message list for that same session.

    claimant.py supervision reads the plural endpoint with curl -s (no -f), then json.loads(body or "[]") → [] → len == 0, so every read that 404s is classified as zero messages and proceeds to DELETE + atomic bind-clear. Because that check only runs for sessions that carry a terminal marker (time.idle / outcome), the practical case is: a bound session that finished a turn is deleted and its task reclaimed regardless of how many messages it holds — the fail-open path into duplicate execution this issue names.

    Fix appears to be commit 1797b0c19b ("read session messages from /message and fail closed on unknown") plus the delete-gate hardening in e423ba3b72 (origin/queue/14229-7367-claimant-delete-gate); neither is an ancestor of origin/main, so the deployed claimant still has the bug.

  7. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 10, 2026
  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    • Agent: triage-step
    • State: triaged
    • Work kind: task/small-fix
    • Priority: priority/high — Brief line 1: keep the fleet itself able to work. The claimant's fail-open zero-message gate can clear a live session's binding and launch a duplicate, a fleet-stalling failure mode; the issue already carried priority/high and it stands.
    • Effort: effort/s (already on the issue)
    • First step: In pm-stack/opencode-claimant/claimant.py, point the zero-message gate at the singular /api/session//message endpoint and treat any non-200, empty-body, or wrong-shape read as UNKNOWN — never zero, never gone — and correct the stub in test/test_claimant.py:75 to the writer's shapes. This is Phase 2 of design Act only on a verified read — one seam contract for the opencode-claimant #7770; do not re-scope or split it.
    • Acceptance check: A 200 from the singular /message path whose data list is empty is the only read that counts as zero messages; 404/401/empty/wrong-shape reads block recovery instead of triggering DELETE + bind-clear, pinned by tests using the corrected stub.
    • Packet: No new fix packet enqueued: the design-architect note on this issue (2026-11-08) records it as Phase 2 of design Act only on a verified read — one seam contract for the opencode-claimant #7770 with its existing queue lifecycle unchanged and no new packet to be filed.
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · Phase 4 evidence (design #7770 closing audit, issue #7772, task 14782)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)meta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/highImportant and time-sensitivesource/design-architectFiled by the repo design architect jobsource/humanFiled directly by a humanstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions