2.6 KiB
2.6 KiB
T10.3 — Idempotent run admission
| Field | Value |
|---|---|
| Phase | P10 — Orchestration |
| Size | S — under 1 day |
| Status | Not started |
| Flags | — |
| Spec | inlined below |
| Blocks | T10.4, T10.7 |
Goal
dispatch_key on spawn requests: a redelivered spawn request (from Kafka
at-least-once delivery, T10.7) becomes a no-op insert instead of a duplicate
run.
Facts (inlined — no spec read needed)
- Same principle as the outbox's
(BranchKey, Lsn)fold-key idempotency (T7.4) — exactly-once is achieved at the admission boundary, not in transport. dispatch_keyis caller-supplied, opaque, unique per intended spawn — e.g. aReconcilerdecision id.- Admission with no
dispatch_keybehaves exactly as today. This is additive, not a required field.
Steps
- Add optional
dispatch_key: Option<String>to spawn-run input. - Add a unique index on
(TenantId, dispatch_key)wheredispatch_keyis set. - On spawn: if
dispatch_keyis set and already seen, return the existingRunIdinstead of creating a new run — no error, no duplicate. - Test redelivery: same
dispatch_keysubmitted twice, concurrently and sequentially.
Acceptance
- Two spawn calls with the same
dispatch_keyproduce exactly one run; the second call returns the first run'sRunId. - Spawn calls with no
dispatch_keyare unaffected.
Verify
Harness: spawn endpoint (T10.4) or direct kernel call, two concurrent callers.
Integration test — tests/it_idempotent_admission.rs:
- Spawn with
dispatch_key=K; assert one run created,RunId=R. - Spawn again with
dispatch_key=K; assert no new run created, returnedRunId == R. - Fire 20 concurrent spawn calls with the same
dispatch_key; assert exactly one run exists after all resolve. - Spawn with no
dispatch_keytwice; assert two distinct runs (unaffected baseline).
Command: cargo test -p kernel idempotent_admission -- --test-threads=1
False pass:
- Testing only sequential redelivery. Concurrent redelivery is the actual failure mode under Kafka rebalance/retry and needs the unique-index race caught, not a check-then-insert race.
Traps
- Making
dispatch_keyrequired. Breaks every direct/manual spawn call that isn't part of a goal chain. - Deduping by a hash of
(workflow_ref, input)instead of the caller-supplied key. Two legitimately identical requests would then silently collapse into one run.
Background (not required to do this task): rust-agentic-sys.md §8.3, §9.3 · T7.4-outbox-relay.md · T3.6-version-pinning-at-spawn.md