Untitled conversation
- User
[Reborn WebUI Beta] Add WebUI idempotency and accepted-message ledger Parent tracker: #3607 Module: M2 — Native Product Workflow / Inbound Facade Priority: P0
Goal
Make WebUI mutations idempotent so duplicate browser submits do not create duplicate turns/messages.
Scope
- Use client action id / idempotency key for create-thread and send-message.
- Preserve accepted-message ref/outcome for duplicate requests.
- Handle concurrent duplicate submissions safely.
Acceptance criteria
- Duplicate send returns the same accepted ref/outcome.
- Concurrent duplicate send creates at most one accepted message/turn.
- Failed validation does not create a ghost turn/message.
- Retry after transient unavailable state has deterministic behavior.
- Tests cover same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior.
Interface
No new interfaces are introduced.
- Assistant
Now let me examine the DB-backed thread service to understand the durable ledger keying:
- Assistant
Now I'll implement. First, the facade changes in
reborn_services.rs: - Assistant
Now the binding id helpers:
- Assistant
Now the idempotent
mark_message_submittedin both thread-service backends: - Assistant
The durable wrapper is transactional, so that's safe. Now document the contract on the trait:
- Assistant
Now build to check compilation before writing tests:
- Assistant
Now the tests. First check whether
IdempotencyKeyderivesHash: - Assistant
Now update the contract tests. First the
FakeTurnCoordinatorto model the real coordinator's scoped submit idempotency: - Assistant
Now strengthen the duplicate test and add the new coverage:
- Assistant
Now add the thread-service level test for the idempotent
mark_message_submitted: - Assistant
ironclaw_conversationsalso implements the trait — check whether itsmark_message_submittedneeds the same replay semantics: - Assistant
ironclaw_conversationsdefines its own separate trait — not affected. Now check the dependent crates compile and their tests pass: - Assistant
All dependents pass. Update the crate spec to document the idempotency contract:
- Assistant
All checks pass. The work is complete — here's a summary of the implementation:
Changes
WebUI idempotency facade —
crates/ironclaw_product_workflow/src/reborn_services.rs- Thread-independent ledger key:
webui_source_binding_idnow identifies the submitting caller (surface, tenant, agent, project, actor) and deliberately excludes the thread. Since the accepted-message ledger dedupes on(source_binding_id, client_action_id), a reusedclient_action_idis now detected across threads, not just within one. - Cross-thread duplicate rejection:
submit_turn's replay branch rejects with 409 Conflict when the ledger record's thread (or scope) doesn't match the request, instead of silently accepting a second copy or replaying another thread's outcome. The concurrent-race variant of the same case is caught by the thread store'sIdempotentReplayThreadMismatch(also → 409). - New
webui_reply_binding_id: reply routing stays thread-scoped (source binding + thread segment), so dedupe identity and reply-target identity are no longer conflated.
Accepted-message ledger convergence —
crates/ironclaw_threadsmark_message_submittedis now an idempotent replay when the message is alreadySubmittedwith the sameturn_id/turn_run_id(bothin_memory.rsand the durabledb.rsbackend). This is what makes concurrent duplicates converge: both racers resolve the same message from the ledger and the same run from the coordinator's scoped submit idempotency, so the second mark must return the record rather than an invalid-transition 409. Mismatched turn/run still fails. Contract documented on the trait (service.rs).
Tests
session_thread_contract.rs: same-turn re-mark replays; mismatched turn/run rejected; single transcript row preserved.reborn_services_contract.rs(drives the facade, per the test-through-the-caller rule):FakeTurnCoordinatornow models the real coordinator's(scope, idempotency_key)submit idempotency.- Duplicate send returns the same accepted ref/run (strengthened existing test).
- Cross-thread duplicate → 409, no second submission, no ghost thread.
- Concurrent duplicates (multi-thread runtime,
tokio::spawn) → both succeed with identical refs, exactly one submission and one transcript message (stable across 8 runs). - Failed validation → 400 with no thread/message/turn created.
- Retry after transient
Unavailable→ replays the ledger's accepted message (one transcript row) and submits exactly one turn, with matchingmsg:ref.
Verified:
cargo testonironclaw_threads(incl.--features libsql),ironclaw_product_workflow, and the dependentsironclaw_loop_support,ironclaw_reborn_composition,ironclaw_reborn— all green;cargo clippy --all-features --testsclean;cargo fmt --checkclean. Spec updated incrates/ironclaw_product_workflow/CLAUDE.md. - Thread-independent ledger key:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →