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. Let me first list the top-level directories.
- Assistant
Let me get a better overview of the repository structure.
- Assistant
Let me explore the crates directory and understand the project better. This seems like a Rust project with a Cargo workspace. Let me also check if there's any WebUI related code.
- Assistant
This is a Rust project. Let me look for WebUI related code and understand the structure. I'll search for "webui" or "web_ui" in the codebase.
- Assistant
Good, I found some relevant files. Let me examine the key files to understand the structure.
- Assistant
Let me now look at the reborn_services.rs file since that's likely where the actual mutation logic lives, and the webui_inbound_contract.rs tests.
- Assistant
Let me see the full reborn_services.rs file by scrolling down.
- Assistant
Let me read the full file in chunks.
- Assistant
Let me look at the test files to understand the existing patterns and see what's expected.
- Assistant
Now let me look at the reborn_services_contract.rs test file to understand the existing test patterns.
- Assistant
Let me see the full test file by scrolling down.
- Assistant
Let me see the full test file in chunks.
- Assistant
Let me look at the full test file to understand what tests already exist.
- Assistant
Let me understand the thread service and the idempotency mechanism.
- Assistant
Let me look at the thread service implementation to understand the replay_accepted_inbound_message mechanism and how idempotency works.
- Assistant
Let me look at the
in_memory.rsfile to understand the in-memory implementation of idempotency. - Assistant
Let me first run the existing tests to see which ones are passing and which are failing.
- Assistant
Let me check what Rust toolchain is available.
- Assistant
Need to set up Rust toolchain first.
- Assistant
Good, Rust toolchain is set up. Now let me run the existing tests to understand the baseline.
- Assistant
Let me check the
AcceptedInboundMessageReplaystructure and theMessageStatusenum to understand the data model. - Assistant
Let me search more broadly.
- Assistant
Let me look at the types and understand the structure.
- Assistant
Let me look at the db.rs to understand the types.
- Assistant
Let me search for the definition of AcceptedInboundMessageReplay.
- Assistant
Let me read the contract.rs file to understand the AcceptedInboundMessageReplay structure and MessageStatus enum.
- Assistant
Now let me look at the existing thread service contract test to understand the idempotency test patterns:
- Assistant
Let me look at the error types and the types module in the reborn_services directory to understand the full structure.
- Assistant
Let me look at the types file now and the RebornSubmitTurnResponse to understand the response shapes.
- Assistant
Let me also look at the
inbound_turn.rsfile to understand what it covers. - Assistant
Now let me look at the full
reborn_services.rssubmit_turn section more carefully, and also understand what changes are needed for idempotency. Let me also check theReplayAcceptedInboundMessageRequeststruct: - Assistant
Let me look at the TurnCoordinator trait to understand its idempotency:
- Assistant
Let me look at the coordinator.rs file more carefully.
- Assistant
Let me look at the TurnStateStore trait to understand if there's idempotency at the store level:
- Assistant
Let me look at the store.rs for more context on the idempotency mechanism:
- Assistant
Now let me look at the idempotency record structures:
- Assistant
Let me look at the InMemoryTurnStateStore to understand its idempotency behavior:
- Assistant
Let me look at the submit_turn implementation in the memory store:
- Assistant
Let me continue reading the memory store to understand the full flow.
- Assistant
Let me look at the full submit_turn function flow to understand the complete implementation.
- Assistant
Now I have a good understanding of the codebase. Let me look at the full list of tests that exist for the product_workflow crate:
- Assistant
Let me check the lib.rs to understand what's exported:
- Assistant
Now I have a thorough understanding of the codebase. Let me analyze what needs to be done:
Analysis
Current state:
- The
reborn_services.rsfacade already handlesreplay_accepted_inbound_messagefor duplicate detection (when the message was already created) - The
InMemorySessionThreadServicehandles idempotency at the thread/message level
- The
- Assistant
Now let me make the key changes to the
submit_turnmethod. First, let me modify theelsebranch to handle concurrent idempotent replays: - Assistant
Let me look at the exact line numbers I need to modify. I need to:
- Modify lines around 192-197 (the
elsebranch'sAcceptedWebUiMessageconstruction) to checkidempotent_replay - Modify lines around 226-235 (the
mark_message_submittedcall) to handleInvalidMessageTransition - Modify lines around 249-258 (the
mark_message_deferred_busycall) to handleInvalidMessageTransition
Let me see the exact lines first.
- Modify lines around 192-197 (the
- Assistant
Now I have a clear picture. Let me implement the changes step by step. First, I'll modify the
elsebranch ofsubmit_turnto handle concurrent idempotent replays: - Assistant
Now let me edit the
elsebranch to handle concurrent idempotent replays: - Assistant
Let me use the edit command to modify the file. I need to replace lines 180-197 with the new code that handles concurrent idempotent replays.
- Assistant
Now let me modify the
mark_message_submittedcall to handleInvalidMessageTransitionerrors gracefully: - Assistant
Now let me modify the
mark_message_deferred_busycall similarly: - Assistant
Now let me verify the file compiles correctly. First, let me check if
SessionThreadErroris already imported: - Assistant
Good,
SessionThreadErroris already imported. Let me now compile to check for errors: - Assistant
The issue is that
accepted_message_reflocal variable shadows the function. Let me fix this by inlining the function call: - Assistant
Let me also check if
AcceptedMessageRefis already imported: - Assistant
Good,
AcceptedMessageRefis already imported. Let me also check thatRebornServicesErrorCodeis imported: - Assistant
Now let me compile and check:
- Assistant
The
scopeis moved intoSubmitTurnRequestbefore the error handling blocks. Let me look at wherescopeis moved: - Assistant
The
scopeis moved into theSubmitTurnRequest. I need to clone it before the move for use in the error handling. Let me fix this: - Assistant
Now let me compile again:
- Assistant
The code compiles. Now let me run the existing tests to make sure they still pass:
- Assistant
All existing tests pass. Now I need to add the new tests required by the acceptance criteria. Let me add them:
- Assistant
Now let me add the new tests at the end of the file:
- Assistant
Now let me add the new tests to the contract file. I need to add the
TurnErrorimport as well since we use it in the tests: - Assistant
Let me check the rest of the imports and the beginning of the test file.
- Assistant
Good,
TurnErroris already imported. Now let me add the new tests. I'll append them to the test file: - Assistant
Now let me run all the tests including the new ones:
- Assistant
All 21 tests pass, including the 4 new ones. Let me also run the other related tests to make sure nothing is broken:
- Assistant
Let me also run the session_thread_contract tests:
- Assistant
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 now run the broader test suite to make sure nothing is broken:
- Assistant
All tests pass. Let me now review the final state of the code changes:
- Assistant
Let me review the full diff:
- Assistant
Let me also run the broader ironclaw_threads tests to make sure nothing is broken:
- Assistant
Let me also run the ironclaw_turns tests:
- Assistant
All tests pass. Let me now do a comprehensive review and verify the checklist:
- Assistant
Let me verify the full test suite passes by running a broader set of tests:
- Assistant
All tests pass. Let me now verify the final state of the modified files:
- Assistant
Let me also verify that the facade source file doesn't contain any forbidden dependencies:
- Assistant
Good - no forbidden dependencies found. Let me run the complete test suite one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.