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.
Interface
No new interfaces are introduced.
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 to understand the codebase structure and locate relevant files. Let me first get an overview.
- Assistant
Let me look at the repository structure more thoroughly, focusing on the WebUI and inbound facade related code.
- Assistant
This appears to be a Rust project (Cargo.toml, Cargo.lock). Let me explore the crates directory and src directory for WebUI related code.
- Assistant
Let me look at the crates more closely, especially those related to WebUI, turns, threads, and product adapters.
- Assistant
Let me search for WebUI related files. The issue mentions "WebUI mutations", "create-thread and send-message", "accepted-message ref/outcome". Let me look at the channels/web directory and the gateway crate.
- Assistant
Let me look at the web directory and gateway crate to understand the WebUI.
- Assistant
Let me read the CLAUDE.md in the web directory to understand the architecture better.
- Assistant
This is a Rust codebase. Let me look more closely at the chat features and the send/thread-new endpoints. I need to understand the idempotency mechanism and the accepted-message ledger.
Let me look at the chat feature files first.
- Assistant
Let me look at the chat feature file to understand the send message and create thread handlers. I'll search for "send" and "thread" related functions.
- Assistant
Let me look at the send handler and the thread new handler to understand the current flow. Let me start with the send handler:
- Assistant
Let me now look at the thread creation handler and the types to understand the current request/response structure.
- Assistant
Now let me look at the types.rs for the request/response types:
- Assistant
Let me look at the SendMessageRequest struct more closely.
- Assistant
Now let me look at the test structure for the web channel. Let me also check if there are any existing idempotency mechanisms:
- Assistant
Let me search for existing idempotency mechanisms:
- Assistant
Let me look at the key files that seem most relevant. The issue is about WebUI idempotency and accepted-message ledger. Let me look at the relevant crates:
- Assistant
Let me look at the webui_inbound.rs file to understand the current implementation.
- Assistant
Now let me look at the ledger.rs file to understand the accepted-message ledger:
- Assistant
Now let me look at the action.rs file to understand the ProductInboundAction structure:cy.rs
- The accepted-message ledger 3.crates/ironclaw_product_workflow/src/action.rs- Actions 4.crates/ironclaw_product_workflow/tests/webui_inbound_contract.rs` - Tests for WebUI inboundLet me look at the webui_inbound.rs file to understand the current implementation.
- Assistant
Now let me look at the workflow.rs file to understand the workflow saga:
- Assistant
Now let me look at the inbound_turn.rs to understand the inbound turn service:
- Assistant
Now let me look at the test files for this crate:
- Assistant
Let me look at the webui_inbound_contract.rs to understand the existing tests:
- Assistant
Let me look at the existing tests in product_workflow_contract.rs and inbound_turn_contract.rs:
- Assistant
Let me look at the reborn_services.rs to see if there is an existing WebUI inbound facade:
- Assistant
Let me continue reading the reborn_services.rs file:
- Assistant
Let me continue reading the rest of the file:
- Assistant
Now let me look at the reborn_services_contract.rs tests to understand what tests already exist:
- Assistant
Let me look at the reborn_services_contract.rs tests to understand what tests already exist:
- Assistant
Now let me look at how
replay_accepted_inbound_messageworks and what types it uses: - Assistant
Let me check the in-memory session thread service to see how it handles duplicate messages:
- Assistant
Let me check the SessionThreadService trait:
- Assistant
Now let me understand what tests are missing. Let me search for duplicate-related tests:
- Assistant
Let me look at the existing duplicate tests in detail:
- Assistant
Let me look at the duplicate submit test:
- Assistant
Let me look at what the existing tests cover and what's missing:
- Assistant
Let me look at all the test names:
- Assistant
Now let me look at the reborn_services types and error files:
- Assistant
Let me also look at the error types:
- Assistant
Let me understand the codebase better by examining the test patterns and the inbound turn contract:
- Assistant
Let me look at the lib.rs to see what's exported:
- Assistant
Let me look at the error.rs for the product workflow:
- Assistant
Let me run the existing tests to understand what they cover and what's missing:
- Assistant
Let me check how to build the project.
- Assistant
I need to install a Rust toolchain first.
- Assistant
Now let me try running the existing tests:
- Assistant
Now I have a good understanding of the codebase. Let me now examine the existing duplicate test patterns more carefully and look for what's specifically missing:
- Assistant
Now I have a thorough understanding of the codebase. Let me plan the changes needed.
Analysis: The existing codebase already has several idempotency mechanisms:
client_action_idis already on WebUI request DTOs and validated intoIdempotencyKeyRebornServices::submit_turnalready usesreplay_accepted_inbound_messagefor same-thread dedupInMemorySessionThreadServicehasInboundIdempotencyKeytracking
What's missing per the acceptance criteria:
- Cross-thread duplicate rejection: Same
client_action_idon a different thread should be rejected. Currently,webui_source_binding_idincludesthread_id, so different threads get different keys and are NOT detected as duplicates. - Concurrent duplicate test: Need to verify at most one message is created under concurrent access.
- Failed validation ghost message test: Validation errors should not create messages.
- Retry after transient state test: Deterministic behavior on retry.
- Assistant
Let me find the exact locations I need to modify:
- Assistant
Let me see the full submit_turn flow:
- Assistant
Now I understand the full flow. Let me implement the changes. First, let me modify
webui_source_binding_idto remove thread_id so cross-thread duplicates are detected: - Assistant
Now let me modify the
webui_source_binding_idfunction to remove thethreadsegment. This way, the sameclient_action_idfrom the same user will be detected as a duplicate regardless of which thread it targets. - Assistant
Now I need to add the cross-thread mismatch check in
submit_turn. Whenreplay_accepted_inbound_messagereturns a match, I need to check if the replayedthread_idmatches the requestedscope.thread_id. Let me find the right location: - Assistant
Now I need to add the cross-thread mismatch check. I'll add it right after the replay is found:
- Assistant
There's a duplicate line! Let me fix it:
- Assistant
There's a duplicate
} else {on line 179-180. Let me fix that: - Assistant
Good, the file looks correct now. Let me verify the full submit_turn method:
- Assistant
Good. Now let me compile the crate to verify there are no syntax errors:
- Assistant
The crate compiles. Now let me add the missing tests. Let me first look at the end of the existing test file to understand where to add:
- Assistant
Now let me add the missing tests. First, let me check the full existing test file structure:
- Assistant
Let me look at the
create_threadmethod: - Assistant
Now I need to add the four missing tests to the contract file. Let me add them before the
facade_source_avoids_forbidden_runtime_dependenciestest: - Assistant
Let me check if
TurnError::unavailableexists: - Assistant
Let me check the TurnError enum:
- Assistant
Let me look at the TurnError enum more carefully:
- Assistant
Good. Now let me also check how
FakeTurnCoordinator::with_submit_errorworks and what theInMemorySessionThreadServicemessage counts would look like: - Assistant
Let me now also check the
submit_turninFakeTurnCoordinatorto understand how errors work: - Assistant
Let me check the
list_thread_historymethod: - Assistant
Now I need to refine the tests. The
create_threaduses deterministic thread_ids, so I need to userequested_thread_idto set "thread-alpha". Let me update the test file: - Assistant
Now let me insert these tests into the test file, right before the
facade_source_avoids_forbidden_runtime_dependenciestest: - Assistant
Let me read the lines around 840-844:
- Assistant
Now let me insert the tests before the
facade_source_avoids_forbidden_runtime_dependenciestest. I'll read the file, insert the tests, and write it back: - Assistant
Now let me verify the file is correct by checking the new test count and running the tests:
- Assistant
Good, we went from 16 to 20
#[tokio::test]tests. Let me now compile and run the tests: - Assistant
All 21 tests pass. Let me now run all the tests in the crate to make sure nothing is broken:
- Assistant
All tests pass across all test files. Let me also run the ironclaw_threads tests since we depend on that crate:
- Assistant
All tests pass. Let me also run the inbound_turn_contract tests:
- Assistant
Let me also run the product_workflow_contract tests:
- Assistant
All tests pass. Let me also check if there are any other crates that might be affected by the
webui_source_binding_idchange: - Assistant
Let me also check if the
inbound_turn.rshas a similarproduct_source_binding_id: - Assistant
Good, the
product_source_binding_idininbound_turn.rsuses adapter-specific identifiers and doesn't include thread_id. This is separate from the WebUI path.Let me also run the broader set of tests in the ironclaw_threads crate that test idempotency:
- Assistant
All idempotency-related tests pass. Let me also verify the specific tests we care about pass:
- Assistant
All 4 duplicate-related tests pass. Let me also run the ghost and retry tests:
- Assistant
All tests pass. Let me now also run a broader check to make sure nothing else is broken:
- Assistant
Let me also check if there are any tests in the main ironclaw crate that might be affected:
- Assistant
No references in the main crate. Let me now verify the complete diff of all changes:
- Assistant
Let me now look at the full diff to verify everything is correct:
- Assistant
The diff looks clean and correct. Let me now run all the tests one final time to make sure everything passes:
- Assistant
All tests pass. Let me also run the other test files:
- Assistant
All tests pass. Let me also run the ironclaw_threads tests one more time to be thorough:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.