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 required idempotency features for WebUI mutations.
Assistant
Let me explore the repository structure more systematically to understand the codebase.
Assistant
This is a Rust project (Cargo.toml, Cargo.lock, crates directory). Let me explore the source structure to find the WebUI-related code.
Assistant
Let me search more broadly for WebUI-related code:
Assistant
Now I can see the WebUI-related code is in
/ironclaw/src/channels/web/. Let me explore this directory structure.Assistant
Let me look at the chat feature directory since the issue mentions create-thread and send-message:
Assistant
Let me explore the main chat module to understand the create-thread and send-message functionality:
Assistant
Let me search more broadly for idempotency-related code in the project:
Assistant
So there's no existing idempotency key mechanism for the WebUI chat endpoints. Let me look at the types to understand the current request/response structure.
Assistant
Now let me look at the new thread handler and understand the thread creation flow:
Assistant
Now let me look at the crates directory for any existing idempotency-related structures:
Assistant
Let me look at the
ironclaw_product_workflowcrate since the issue mentions "Module: M2 — Native Product Workflow / Inbound Facade":Assistant
This is the right crate. Let me examine the
webui_inbound.rs,ledger.rs, andinbound_turn.rsfiles, which seem most relevant to the idempotency feature:Assistant
This is very informative. The
webui_inbound.rsfile already defines theclient_action_idfield in the request DTOs, and it validates them. Now let me look at theinbound_turn.rsand the existing tests to understand the current implementation:Assistant
Now let me look at the existing tests for the webui inbound contract:
Assistant
Now let me look at the workflow orchestrator and see how it processes the WebUI commands:
Assistant
Now let me look at the
ironclaw_turnscrate to understand theIdempotencyKeytype and the TurnCoordinator:Assistant
Now let me look at the fakes to understand the test infrastructure:
Assistant
Now I have a good understanding of the codebase. Let me look at what tests already exist for the product workflow:
Assistant
Now let me check what's currently in the inbound turn contract tests:
Assistant
Now I have a thorough understanding of the codebase. Let me check the existing tests and error module:
Assistant
Now let me understand the full picture. The issue asks for:
- Client action id / idempotency key for create-thread and send-message
- Preserve accepted-message ref/outcome for duplicate requests
- Handle concurrent duplicate submissions safely
- Tests for same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior
The
webui_inbound.rsalready hasclient_action_idin the request DTOs. Now I need to implement the WebUI-specific idempotency handling. Let me look at how the WebUI chat handler currently works and check if there's a WebUI idempotency layer:Assistant
So the WebUI routes are not yet integrated with the
ironclaw_product_workflowcrate. The WebUI has its own handler insrc/channels/web/features/chat/mod.rs. Thewebui_inbound.rsmodule defines the canonical DTOs and commands but they're not wired up to the actual handlers yet.Let me check the Cargo.toml to understand the crate dependencies:
Assistant
Let me check what's needed. Based on my analysis, the issue is about implementing WebUI idempotency. The
webui_inbound.rsmodule already defines the request DTOs withclient_action_id, and there's already anIdempotencyLedgertrait andDefaultProductWorkflow. What's missing is the WebUI-specific idempotency handling that:- Accepts
client_action_idin the WebUI handlers - Maintains an accepted-message ledger for replaying duplicates
- Handles concurrent duplicates safely
Let me look more at the existing tests and understand what specific tests are expected:
- Accepts
Assistant
The tests don't exist yet. Let me run the existing tests to confirm they pass:
Assistant
All 65 tests pass. Now I understand the task better. Looking at the issue requirements and the existing codebase:
- The
webui_inbound.rsmodule already defines the request DTOs withclient_action_idfields - The
IdempotencyLedgertrait exists for durable deduplication - The
DefaultProductWorkflowexists and uses the ledger for deduplication - The Reborn services API exists (
reborn_services.rs)
What's missing is the WebUI-specific idempotency layer that:
- Handles the WebUI
client_action_idfor idempotent create-thread and send-message - Maintains an accepted-message ledger specifically for WebUI requests
- Handles concurrent duplicate submissions safely
- Tests for same-thread duplicate, cross-thread duplicate rejection, and concurrent duplicate behavior
Let me look at the reborn services to understand how they use idempotency:
- The
Assistant
Let me examine the existing reborn services tests more closely to understand what's already covered:
Assistant
Let me examine the existing duplicate tests more closely:
Assistant
Let me look at the full reborn_services_contract.rs test file and check what's missing:
Assistant
Let me examine what tests are needed by looking at the acceptance criteria more carefully and the current test coverage:
Assistant
I apologize for the malformed message. Let me continue investigating what tests are missing based on the acceptance criteria.
Assistant
Based on the acceptance criteria, I need to add tests for:
- Cross-thread duplicate rejection - same client_action_id used with different threads
- Concurrent duplicate behavior - concurrent submissions with same client_action_id
- Failed validation does not create ghost turn/message - validation errors shouldn't create state
- Retry after transient unavailable state - deterministic retry behavior
Let me examine the reborn services implementation to understand what's needed:
Assistant
Let me look at what the
RebornServicesApitrait is missing. The issue mentions "create-thread and send-message" need idempotency, but the trait only hassubmit_turnand notcreate_thread. Let me check ifcreate_threadexists in the trait.Assistant
Now I have a good understanding of the codebase. Let me summarize what exists and what needs to be added:
Already exists:
client_action_idinWebUiCreateThreadRequestandWebUiSendMessageRequest- Idempotency for duplicate sends (same
client_action_idreplays) - Idempotency for duplicate thread creation
Missing based on acceptance criteria:
- Cross-thread duplicate rejection - Same
client_action_idused with differentthread_idshould be rejected - Concurrent duplicate behavior - Concurrent submissions should create at most one message
- Failed validation does not create ghost turn/message - Validation errors shouldn't create state
- Retry after transient unavailable - Deterministic retry behavior
Let me add the missing tests to the reborn services contract test file:
Assistant
Let me examine the test infrastructure to understand how to write the new tests:
Assistant
I need to understand the full test infrastructure to add the missing tests. Let me look at the FakeTurnCoordinator implementation to understand what I can do with it, and then add the missing test cases for:
- Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Failed validation does not create ghost turn/message
- Retry after transient unavailable state
Let me first examine the FakeTurnCoordinator to understand how to configure it.
Assistant
The output seems to have been cut off. Let me continue to examine the FakeTurnCoordinator to understand how it handles concurrent submissions, then I can write the missing tests for the acceptance criteria.
Let me see what else I need to understand about the test infrastructure before adding the new tests.
Assistant
Let me understand how the replay mechanism works to write proper tests:
Assistant
Now I have a clear picture of the codebase. Let me understand what tests need to be added:
- Cross-thread duplicate rejection - Same
client_action_idwith differentthread_idshould be rejected - Concurrent duplicate behavior - Concurrent submissions create at most one message
- Failed validation does not create ghost turn/message - Validation errors don't create state
- Retry after transient unavailable - Deterministic retry behavior
Let me now implement the missing tests. I'll add them to the reborn_services_contract.rs file.
- Cross-thread duplicate rejection - Same
Assistant
Let me understand the full picture now:
-
The issue requires adding WebUI idempotency tests for:
- Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Failed validation doesn't create ghost turn/message
- Retry after transient unavailable has deterministic behavior
-
The existing tests already cover basic duplicate replay. I need to add more comprehensive tests.
-
I also need to potentially add the
create_threadmethod to theRebornServicesApitrait since the existing implementation has it as a direct method onRebornServicesbut not in the trait.
Let me look at what needs to be added:
- The
RebornServicesApitrait doesn't havecreate_thread- it should - Tests for cross-thread duplicate rejection
- Tests for concurrent duplicate behavior
- Tests for validation not creating ghost state
- Tests for retry after transient unavailable
Let me start by modifying the code to add missing trait methods and then add the tests.
-
Assistant
<tool_call> <function=bash_terminal> <parameter=command> grep -n "external_event_id" /ironclaw/crates/ironclaw_threads/src/in_memory.rs | head -30 </tool_call>
Assistant
I need to properly invoke the bash command to search for external_event_id in the in_memory.rs file.
Assistant
Now I understand the replay mechanism. Let me implement the missing features and tests. I'll:
- Add
create_threadto theRebornServicesApitrait - Add comprehensive tests for the acceptance criteria
- Add
Assistant
Now I understand the structure. Let me implement the required changes:
- Add
create_threadto theRebornServicesApitrait - Add the missing tests for acceptance criteria
- Add
Assistant
Let me continue examining the codebase to understand the full picture of what needs to be implemented. I need to:
- Check that my trait patch was applied correctly
- Add the missing tests for the acceptance criteria:
- Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Failed validation does not create ghost turn/message
- Retry after transient unavailable has deterministic behavior
- Run the tests to verify everything works
Assistant
Let me check the current state of the implementation to fix the recursive call issue.
Assistant
I see the issue - there's a recursive call. The trait implementation is calling itself. I need to fix this by properly delegating to the inherent method. Let me examine the full structure first.
Assistant
I see the issue - the trait implementation calls
self.create_thread()which creates infinite recursion because it calls the trait method instead of the inherent method. I need to restructure this properly. Let me fix the code by:- Renaming the inherent method to something like
create_thread_impl - Having both the trait impl and inherent method call it
- Renaming the inherent method to something like
Assistant
Continuing my work on the WebUI idempotency implementation. I need to:
- Verify the recursive call fix was applied correctly
- Check if the code compiles
- Add the missing tests for acceptance criteria:
- Cross-thread duplicate rejection
- Concurrent duplicate behavior
- Failed validation does not create ghost turn/message
- Retry after transient unavailable has deterministic behavior
Let me check the current state of the file and fix any issues.
Assistant
I apologize for the empty message. Let me check the current state of the file and verify the changes are correct.
Assistant
Good, the trait implementation is correct now. Let me verify the inherent impl block was cleaned up properly and that there's no duplicate method causing conflicts:
Assistant
I see there's a syntax issue with the comment block. The
{{and}}are escape sequences from Python that got rendered literally. Let me fix this and verify the code compiles:Assistant
I need to fix the comment in the file and then verify the code compiles. Let me use sed to fix the double braces issue.
Assistant
The user seems to have received an error message but no actual command was executed. Let me continue with my work. I need to:
- Verify the code compiles
- Add the missing tests for acceptance criteria
- Run all tests to confirm everything works
Let me continue by checking if the code compiles and then add the missing tests.
Assistant
The code compiles successfully. Now I need to add the missing tests for the acceptance criteria. Let me add them to the reborn_services_contract.rs file.
Assistant
Let me run the tests to verify the changes work correctly:
Assistant
One test failed:
cross_thread_duplicate_rejected_with_conflict. The current implementation replays the accepted message even when thethread_iddiffers. I need to add a cross-thread check in thesubmit_turnimplementation.Let me examine the current
submit_turncode:Assistant
Looking at the test failure, the cross-thread duplicate rejection isn't working because
source_binding_idincludes the thread ID, so different threads don't trigger the replay logic. I need to add a method to check if a message with the sameexternal_event_idexists on a different thread and reject it.Let me implement this by adding a new lookup method to
SessionThreadService:Assistant
I see that the cross-thread duplicate rejection is failing because the current implementation uses
source_binding_id(which includes the thread ID) as part of the lookup key. This means different threads have differentsource_binding_ids, so the replay logic doesn't catch cross-thread duplicates.Looking at the code flow:
- First request to
thread-alphawithclient_action_id: "cross-thread-dup"→ creates message withexternal_event_id: "cross-thread-dup" - Second request to
thread-betawithclient_action_id: "cross-thread-dup"→ looks up replay with a DIFFERENTsource_binding_id(because thread ID differs), so no replay found → creates a new message
I need to add cross-thread duplicate detection. The key insight is that
external_event_id(theclient_action_id) should be unique globally, not per-thread. I need to add a method to check if a message with the sameexternal_event_idexists on ANY thread.Let me look at how the in-memory service stores messages to see if I can add a cross-thread lookup:
- First request to
Assistant
I need to add cross-thread duplicate detection. The current implementation uses
source_binding_idwhich includes the thread ID, so duplicates across different threads aren't detected. I need to add a lookup method that can find messages byexternal_event_idglobally.Let me first check what methods exist on
SessionThreadService:Assistant
I need to add cross-thread duplicate detection. The solution is to add a new method to
SessionThreadServicethat can look up messages byexternal_event_idalone, regardless of thread. Let me implement this:Assistant
I need to add a new method to the
SessionThreadServicetrait that can find messages byexternal_event_idglobally across all threads, to enable cross-thread duplicate detection.Assistant
I'll continue by adding the trait method for cross-thread lookup, implementing it in the in-memory service, and using it in
RebornServicesto reject cross-thread duplicates.Assistant
The user wants me to continue. I need to:
- Export the new types from the threads crate
- Implement the new method in InMemorySessionThreadService
- Update RebornServices to use the new method for cross-thread duplicate detection
- Run tests to verify everything works
Let me continue with implementing the method in the in-memory service.
Assistant
I need to:
- Export the new types from the threads crate's lib.rs
- Implement the method in InMemorySessionThreadService
- Update RebornServices to use cross-thread duplicate detection
- Run tests
Let me start by exporting the new types.
Assistant
Now I need to implement the method in
InMemorySessionThreadServiceand updateRebornServicesto use it for cross-thread duplicate detection.Assistant
I need to implement the
find_accepted_message_by_event_idmethod inInMemorySessionThreadService. Let me find where the impl block ends and add the method:Assistant
Now I need to update the
RebornServices::submit_turnto use this new cross-thread lookup. Let me modify the code:Assistant
I need to modify
submit_turnto check for cross-thread duplicates. Let me add the cross-thread check before the existing replay logic:Assistant
<anth: My previous command may have timed out. Let me verify the state of the file and continue with the implementation. I need to check if the cross-thread check was properly added to
reborn_services.rsand then run the tests.Assistant
The cross-thread check was added successfully. Now let me run the tests to verify everything works.
Assistant
I need to fix the field reference in the in-memory implementation. Let me check the
StoredThreadstruct.Assistant
Assistant
Assistant
Assistant
I need to continue fixing the code. The previous sed command worked - I can see line 409 now has the correct field reference. Let me run the tests again to see if the compilation error is fixed.
Assistant
I need to add the missing trait method implementation to the
ScopeMismatchThreadStubin the test file.Assistant
<tool_call> <function=bash_terminal> <parameter=command> sed -n '204,310p' /ironclaw/crates/ironclaw_product_workflow/tests/reborn_services_contract.rs </tool_call>
Assistant
I need to properly invoke the bash terminal command to view the ScopeMismatchThreadStub implementation.
Assistant
I need to add the missing
find_accepted_message_by_event_idmethod to theScopeMismatchThreadStubimplementation in the test file.Assistant
The stub method was added. Let me run the tests again to see if there are any other missing implementations.
Assistant
All 70 tests pass. Let me verify the broader codebase still compiles and run a few more related tests to ensure nothing is broken.
Assistant
All tests pass. Let me now:
- Run tests for the threads crate to make sure the new method works correctly
- Verify the broader workspace compiles
- Review my changes against the acceptance criteria
- Prepare to submit
Let me run the threads crate tests first.
Assistant
All tests pass. Let me now review the changes I made and verify they meet the acceptance criteria before submitting.
Let me check the git diff to see all changes.
Assistant
Let me verify all tests pass and then submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.