ISSUE DESCRIPTION [Reborn WebUI Beta] Add WebUI idempotency and accepted-message ledger…
- User
ISSUE DESCRIPTION
[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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Assistant
I'll start by exploring the repository structure to understand the codebase and then implement the idempotency feature for WebUI mutations.
Assistant
This is a Rust project (Cargo.toml, Cargo.lock). Let me explore the source structure to understand the WebUI and inbound facade modules.
Assistant
Let me understand the codebase better. I need to look at:
- The WebUI channel implementation
- How messages are sent/threads created
- Where idempotency should be implemented
Let me search for WebUI-related files and the existing message handling infrastructure.
Assistant
Let me explore the WebUI inbound module and related files.
Assistant
Now let me look at the existing test files and the crate structure to understand the full picture:
Assistant
Now let me look at the key types and interfaces to understand what I need to implement:
Assistant
Let me look at the crate structure and lib.rs to understand what's exported:
Assistant
Let me look at the ledger module and action module to understand the existing idempotency infrastructure:
Assistant
Now let me understand what's needed. Looking at the issue, I need to:
- Make WebUI mutations idempotent using client action id / idempotency key
- Preserve accepted-message ref/outcome for duplicate requests
- Handle concurrent duplicate submissions safely
The
submit_turnmethod inRebornServicesalready uses theclient_action_idasexternal_event_idand usesreplay_accepted_inbound_messagefor dedup. But I need to check what else needs to be added forcreate_thread, and I need to check the accepted-message ledger concept.Let me look at the threads crate to understand the thread service:
Assistant
Let me look at the contract file to understand the thread service's accepted-message replay mechanism:
Assistant
Now let me look at the in-memory implementation to understand how the replay mechanism works:
Assistant
Now I have a good understanding of the codebase. Let me look at the Cargo.toml for the product workflow crate and examine the full test file:
Assistant
Now I have a comprehensive understanding. Let me review what's already implemented and what's missing:
Current state of
submit_turninRebornServices:- ✅ Uses
client_action_idasexternal_event_idin the message - ✅ Uses
replay_accepted_inbound_messageto detect duplicates - ✅ Returns
AlreadySubmittedfor duplicates that were already processed - ✅ Uses
idempotency_keyonSubmitTurnRequest
What's missing based on the issue:
- Need
create_threadto be idempotent (using client_action_id) - Need an accepted-message ledger that tracks the accepted-message ref/outcome
- Need tests for same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior
Let me check what
create_threadcurrently looks like:- ✅ Uses
Assistant
Let me now check if
create_threadis exposed in theRebornServicesApitrait:Assistant
I see. The
create_threadmethod exists onRebornServicesbut is NOT part of theRebornServicesApitrait. Now let me run the existing tests to understand the current state:Assistant
Good, all existing tests pass. Let me also run the reborn_services_contract tests:
Assistant
All tests pass. Now let me understand the current state better. Let me see the full test file for more context:
Assistant
Now let me check the duplicate submit test and see what's expected:
Assistant
Now I have a comprehensive understanding of the codebase. Let me analyze what needs to be done:
Current state:
submit_turnalready has idempotency viareplay_accepted_inbound_messageand returnsAlreadySubmittedfor duplicatescreate_threadalready generates deterministic thread IDs fromclient_action_id, making duplicates return the same thread- Both use
client_action_idas the idempotency key
What's needed per the issue:
- Add the
accepted_message_refto the idempotency tracking (the "accepted-message ledger" concept) - Add idempotency for
create_threadto theRebornServicesApitrait - Add an
AcceptedMessageLedgertype to track accepted messages - Add tests for: same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior
Let me look more closely at what the issue requires. The key items are:
- "accepted-message ref/outcome for duplicate requests" - meaning we need to track and return the accepted_message_ref
Assistant
Now let me plan my implementation:
Plan:
- Add
AcceptedMessageLedgertype and trait for tracking accepted messages (the "accepted-message ledger") - Add
create_threadto theRebornServicesApitrait - Update
RebornServices::submit_turnto record accepted messages in the ledger - Add tests for:
- Same-thread duplicate (already exists as
duplicate_submit_replays_prior_handoff_without_second_submission) - Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Same-thread duplicate (already exists as
- Make sure validation failures don't create ghost turns/messages
Let me start implementing:
- Add
Assistant
Now I have a complete understanding of the codebase. Let me implement the changes:
- First, I'll create an
accepted_message_ledgermodule for tracking accepted messages - Add
create_threadto theRebornServicesApitrait - Add tests for cross-thread duplicate rejection and concurrent duplicate behavior
- First, I'll create an
Assistant
Let me look at the full
reborn_services.rsto understand the structure better before making changes:Assistant
Now I understand the full picture. Let me implement the changes:
- Add
AcceptedMessageLedgermodule for accepted-message tracking - Add
create_threadto theRebornServicesApitrait - Update
RebornServicesto use the ledger - Add comprehensive tests
Let me start by creating the
accepted_message_ledger.rsmodule:- Add
Assistant
Now update
reborn_services.rsto include the new module and addcreate_threadto the trait:Assistant
Now I need to add the pub use for the accepted_message_ledger module:
Assistant
Let me verify the changes:
Assistant
Good. Now I need to add
create_threadto theRebornServicesApitrait. Let me find where the trait is defined:Assistant
I need to add
create_threadto theRebornServicesApitrait. Let me find the exact location:Assistant
Now I'll add
create_threadto the trait. I'll insert it aftersubmit_turn:Assistant
Now I need to implement
create_threadin theimpl RebornServicesApi for RebornServicesblock. Let me find where the impl block starts:Assistant
I need to add the
create_threadimplementation to theimpl RebornServicesApi for RebornServicesblock. Currentlycreate_threadis a standalone method onRebornServicesthat is NOT part of the trait. I need to make the trait implementation use the same logic. Let me find the standalonecreate_threadmethod:Assistant
I see. The
create_threadmethod is already defined in a separateimpl RebornServicesblock. I need to add the trait implementation that delegates to it. Let me add thecreate_threadmethod to theimpl RebornServicesApi for RebornServicesblock:Assistant
Good. Now I also need to update the
lib.rsto export the new types:Assistant
I need to update the lib.rs to export the accepted message ledger types:
Assistant
Now let me try to compile to check for any issues:
Assistant
Good, it compiles! Let me fix the warning:
Assistant
Now let me run the existing tests to make sure nothing is broken:
Assistant
The sed command replaced too many instances. Let me fix the file properly:
Assistant
I need to fix the
recordmethod - it needsmut:Assistant
All tests pass. Now let me add the comprehensive tests required by the issue:
- Same-thread duplicate (already exists as
duplicate_submit_replays_prior_handoff_without_second_submission) - Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Accepted-message ledger tests
Let me also add tests for the
AcceptedMessageLedgeritself. I'll add them to the existing test files:- Same-thread duplicate (already exists as
Assistant
Now I need to add the necessary imports to the test file:
Assistant
I need to add the imports for
AcceptedMessageLedgerand related types:Assistant
I need to fix the import conflict and the ref patterns. The issue is that I added imports at the crate level but some are also imported locally inside the test functions. Let me fix this:
Assistant
The issue is that my test functions have
use ironclaw_product_workflow::{...}inside them which conflicts with the top-level import. Let me fix the tests:Assistant
The inner
usestatements conflict with the top-level import. Let me remove the inner imports since we now have the types at the top level:Assistant
I see the issue - the
sedcommand created duplicate imports. Let me fix the test file by removing the duplicate inner imports and fixing the ref patterns:Assistant
The
cross_thread_duplicate_returns_conflicttest is failing because the current idempotency mechanism is based onsource_binding_id+external_event_id, and when the thread changes, thesource_binding_idalso changes (it includes the thread). So the duplicate isn't detected.This is actually the expected behavior of the current implementation — it's designed to detect duplicates within the same thread/source, not across threads. The
InboundIdempotencyKeyinin_memory.rsincludes thescopewhich contains the thread scope.Looking at the issue requirements more carefully:
- "Tests cover same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior"
The cross-thread duplicate rejection test should verify that a duplicate
client_action_idfor a different thread is rejected rather than creating another message. Let me check what the current behavior is in the thread service:Assistant
The
IdempotentReplayThreadMismatcherror exists. This is the error the in-memory service returns when the same idempotency key is used for a different thread. However, the issue is that thesource_binding_idincludes the thread ID, so it won't match across threads.Let me look at how the
source_binding_idis constructed:Assistant
The
source_binding_idincludes the thread ID. This means the current deduplication is scoped per-thread. For cross-thread duplicate detection, we need a different approach.Looking at the issue requirements more carefully: the "cross-thread duplicate rejection" test should verify that a client_action_id that was already used for one thread cannot be used for a different thread. This is where the
AcceptedMessageLedgercomes in — it provides a global (cross-thread) idempotency check.The current implementation only deduplicates within the same thread (via
replay_accepted_inbound_message). For cross-thread dedup, we need to use theAcceptedMessageLedgerin thesubmit_turnflow.Let me update the
submit_turnmethod inRebornServicesto use the ledger for cross-thread dedup. But first, let me understand the current design better:Assistant
Actually, looking at the architecture more carefully, the
AcceptedMessageLedgeris a separate port/abstraction that can be used independently. The cross-thread duplicate detection is a feature that can be implemented at theRebornServiceslevel using the ledger, but it's optional.For now, let me adjust my test to match the actual behavior: the current idempotency is scoped per-thread (via source_binding_id), and cross-thread duplicates should create a new message in a different thread. This is actually valid behavior — the same action_id could be retried on a different thread intentionally.
However, the issue specifically says "cross-thread duplicate rejection" should be tested. This means we need to add cross-thread idempotency through the ledger. Let me update
RebornServicesto optionally use the ledger:Assistant
Let me update
RebornServicesto include an optional accepted message ledger for cross-thread deduplication:Assistant
Now I need to update the
submit_turnmethod to use the ledger for cross-thread dedup. Let me find wheresubmit_turndoes the actual acceptance:Assistant
Now I need to add the cross-thread dedup check. I'll add it at the beginning of the
submit_turnmethod, right after validation:Assistant
Now I need to record the accepted message in the ledger after a successful submission. Let me find where the submission succeeds and add the ledger recording:
Assistant
I need to record the ledger entry after a successful submission. Let me update the code to record to the ledger:
Assistant
Now let me also update the test to use the ledger:
Assistant
The
client_action_idis moved intoSubmitTurnRequest. I need to clone it before the move. Let me fix this:Assistant
I need to save the
client_action_idstring before it's moved. Let me fix this properly:Assistant
All 24 tests pass. Let me also run all the tests in the package:
Assistant
All 41 tests pass (24 reborn_services_contract + 17 webui_inbound_contract). Let me verify there are no compiler warnings:
Assistant
Clean build with no warnings. Let me also verify by checking for any clippy warnings:
Assistant
Let me fix the clippy warning about the collapsible if:
Assistant
All tests pass. Let me verify clippy is also clean:
Assistant
archive
Assistant
Clean clippy with no warnings. Now let me review the complete changes I've made and verify everything is in order:
Assistant
Wait, I also created a new file. Let me check:
Assistant
Good. Let me verify the full content of each modified/new file:
Assistant
Now let me verify the lib.rs changes:
Assistant
Let me now verify the key parts of the reborn_services.rs changes:
Assistant
Let me see the rest of the diff:
Assistant
Let me run all the tests one more time to confirm everything is working:
Assistant
All 74 tests pass (4 unit + 13 inbound_turn + 1 planned_agent + 15 product_workflow + 24 reborn_services + 17 webui_inbound).
Now let me verify the changes satisfy all the acceptance criteria from the issue:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.