Skip to content

bug(j5): spawn_agent silently replays the first spawn when a client_request_id is reused with different arguments #181

Closed

Description

@Jacksondr5

What happens

spawn_agent derives the child thread id, every command id, and the brief's message id from providerSessionId plus client_request_id alone (apps/server/src/j5/a2a/mcp/handlers.ts, stableInput, now in spawnIds.ts on the crews branches). The orchestrator's dispatch path looks up an existing receipt by command id and, when it was accepted, replays it without comparing the payload (apps/server/src/orchestration-v2/Orchestrator.ts around L7054-7080: "A receipt only proves this exact command was handled", then canReplayCommandReceipt checks only the thread id).

So a second call that reuses a client_request_id with a different brief, provider, model, reasoning, or (since #147) agent:

  1. thread.create replays the first thread and returns its receipt.
  2. recordFacts is idempotent and returns the first home and placement.
  3. message.dispatch replays the first brief by message id.
  4. The handler returns success, naming the first spawn's participant, with none of the new arguments applied.

The caller gets a success response for a spawn that did not happen. Nothing logs the mismatch.

Repro

Two spawn_agent calls from one session with the same client_request_id:

spawn_agent { brief: "Review the auth flow", agent: "scout", provider: "codex", model: "gpt-5.6-terra", reasoning: "high", client_request_id: "k1" }
spawn_agent { brief: "Fix the CI failures",  agent: "builder", provider: "codex", model: "gpt-5.6-sol", reasoning: "high", client_request_id: "k1" }

The second call returns the Scout's participant id and the Scout keeps running on the first brief. No Builder exists.

Expected

A reused id with a different payload is refused with a state error naming the original request ("client_request_id k1 already spawned with a different brief/agent; use a fresh id"), the same way a previously rejected id is refused today. Same id, same payload keeps replaying safely.

Notes

  • The tool description says "Reuse client_request_id to retry the same spawn safely", so a model that reuses an id for a different spawn is misusing it, which is why this is low priority. The cost when it happens is a silent wrong result, which is the worst kind.
  • Every J5 lifecycle verb that takes client_request_id (stop_agent, archive_agent, join_squadron, propose_crew, request_crew_member, stop_crew, archive_crew) derives ids the same way; check whether the same fix applies before implementing it only for spawn.
  • Smallest fix: fold a digest of the stable payload into the id derivation is wrong (it would defeat retries after a partial failure). Instead, store the request digest with the first accepted command and compare on replay, or compare the request against the created thread's stored title, model selection, and persona assignment before returning.

Found during the Crews stack review (#147); pre-existing on j5/main.

Activity

  1. self-assigned this
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions