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
Let me start by understanding the repository structure and the issue at hand. The issue is about adding WebUI idempotency to prevent duplicate browser submits from creating duplicate turns/messages. Let me explore the repository first.
Assistant
This is a Rust project (ironclaw). Let me explore the structure more, particularly the
srcdirectory andcratesdirectory, to understand the codebase. The issue mentions "WebUI", "create-thread", "send-message", "idempotency", and "accepted-message ledger". Let me look for relevant files.Let me first search for relevant terms like "idempotency", "idempotent", "send_message", "create_thread", "WebUI" etc.
Assistant
Let me search for relevant terms:
Assistant
Let me look at the channels/web directory more closely since the issue is about WebUI.
Assistant
Let me look at the chat module and the types to understand the current WebUI API:
Assistant
Let me look at the types and the thread creation handler:
Assistant
Let me find the
chat_new_thread_handlerand understand the current flow betterAssistant
Let me look at both handlers more
Assistant
Let me look at the
GatewayStateto understand available storage and the overall architecture:Assistant
Now let me look at the Database trait to understand what storage is available:
Assistant
Let me look at the Database trait to understand what methods are available for storing data.
Assistant
Let me look at the
IncomingMessagetype and try to understand the flowAssistant
Let me look at the IncomingMessage structure.
Assistant
Let me look at the existing tests and helpers for chat_send_handler to understand the patterns.
Assistant
Let me check the test helper to understand how GatewayState is created:
Assistant
Let me look at the test_helpers file
Assistant
Let me check what dependencies are available:
Assistant
Now I have a comprehensive understanding. Let me implement the solution step by step.
First, let me check if there are any existing idempotency-related patterns:
Assistant
Let me look at the existing WebUI inbound facade and product workflow infrastructure
Assistant
Let me look at the reborn_services.rs to understand how these are wired
Assistant
Now I have a comprehensive understanding. Let me look at the
chat_new_thread_handlerto see what request type it uses:Assistant
Let me look at how the routes are registered:
Assistant
Now let me implement the solution. Let me start by checking the module declarations
Assistant
Let me implement the solution step by step. First, I'll add
client_action_idto the typesAssistant
Let me look at the SendMessageRequest and SendMessageResponse.
Assistant
Now let me add
client_action_idtoSendMessageRequestandSendMessageResponseAssistant
Let me use replace for the types first
Assistant
Now let me edit the specific lines.
Assistant
Let me use the heredoc syntax for multi-line editing
Assistant
Let me use
sedfor the changes insteadAssistant
Let me verify the change
Assistant
I need to fix some issues. Let me restore and redo cleanly.
Assistant
Let me use Python to make the changes properly
Assistant
Let me verify the
Assistant
Good, the types are updated. Now let me create the idempotency store module
Assistant
Let me create the file using bash
Assistant
Now let me add the module declaration to mod.rs
Assistant
Now let me add
idempotency_storeto GatewayAssistant
Let me add the idempotency_store field to GatewayState after frontend_html_cache:
Assistant
Let me use sed for this insertion
Assistant
Let me add the field
Assistant
Let me verify the addition
Assistant
The insertion broke the comment. Let me fix it
Assistant
Let me use a temp Python script with precise string replacement
Assistant
Let me verify
Assistant
Now update test_helpers.rs to include
idempotency_storein all buildersAssistant
Now let me update the chat_send_handler to use the idempotency store. Let me first look at the full current handler:
Assistant
Now let me update the chat_send_handler with idempotency support:
Assistant
Let me search for all places where SendMessageResponse is constructed to update them with the new field
Assistant
Let me check the chat/mod.rs for SendMessageResponse constructions
Assistant
Let me check the file for issues
Assistant
The file got corrupted. Let me restore and try a different approach
Assistant
Let me write the update as a Python script file to avoid encoding issues
Assistant
Let me verify the file is still valid
Assistant
Let me check more closely
Assistant
Let me restore and take a different approach, making smaller edits
Assistant
Let me use smaller targeted edits. First, let me update the tracing and add the idempotency guard right after the function signature:
Assistant
Let me use replace with multi-line syntax
Assistant
Let me try a different approach - use sed with line numbers
Assistant
Let me make smaller, targeted edits using edit command with small line ranges
Assistant
Let me take a completely different approach - write a temp Python script that reads the file line by line
Assistant
Let me verify the file is
Assistant
Let me verify the handler was
Assistant
Now let me check if the existing tests compile with the new field. The
client_action_idfield has#[serde(default)]so deserialization works. But test code constructs the struct directly, so I need to update those tooAssistant
Let me find all places where SendMessageRequest is constructed in tests and fix them
Assistant
Let me look at each test construction and update them
Assistant
Let me add
client_action_id: None,to all SendMessageRequest constructions in testsAssistant
Let me verify
Assistant
The third one seems to have an indentation issue. Let me check and fix it
Assistant
Let me fix the indentation
Assistant
Let me check the indentation
Assistant
Let me check the test struct constructions
Assistant
Let me check the context around line 2061
Assistant
Let me check for other SendMessageRequest
Assistant
Let me check for other SendMessageResponse
Assistant
Let me check lines 309 and 375
Assistant
I need to update these two other places too. Let me fix
Assistant
Let me
Assistant
Let me fix the first one directly
Assistant
OK, so line 309 is the one to fix. Let me use sed:
Assistant
Let me
Assistant
Now let me also propagate the
client_action_idinto the IncomingMessage metadata. Let me find where the msg is created in the newAssistant
Let me look at the context around the message creation to add client_action_id propagation
Assistant
Let me add the client_action_id to the message metadata:
Assistant
Let me check if there are other references to SendMessageRequest in the codebase
Assistant
Let me also check if responses_api.rs uses SendMessageResponse
Assistant
Now let me add tests for the idempotency feature. Let me find the test section
Assistant
Let me find the end of the test module
Assistant
Let me add idempotency tests at the end of the test module
Assistant
Let me verify the file is valid
Assistant
Let me fix the test code - there's an issue with the first test. Let me rewrite the tests clean
Assistant
Let me verify the file validity
Assistant
I realize there's a concurrency issue with the idempotency store. The per-key lock is dropped when
acquirereturns, so two concurrent requests could both getOk(None). Let me fix this by makingacquirereturn a guard that holds the lock untilsettleorreleaseis called.Assistant
Let me rewrite the idempotency store with a cleaner API
Assistant
Now let me update the chat handler to use the new
AcquireResultAPIAssistant
Let me use a script file
Assistant
Now let me update the tests to match the new API as well
Assistant
Let me check the test code
Assistant
Let me look at the test code that directly uses idem_store.acquire
Assistant
Let me update the test code to use the new API
Assistant
Let me rewrite the idempotency store to avoid unsafe transmute - using owned guards:
Assistant
Now let me do a final review of all the changes
Assistant
Let me check all changes are correct
Assistant
Let me look at the key parts of the diff to verify
Assistant
Let me check the rest of the diff
Assistant
Let me verify the idempotency.rs file is correct
Assistant
Let me verify the approval handler responses
Assistant
Let me check if there are any other places constructing SendMessageResponse that I missed
Assistant
Let me check if there are other references to SendMessageResponse in tests or elsewhere
Assistant
Let me also check the chat_new_thread_handler more
Assistant
Let me find the chat_new_thread_handler in the updated
Assistant
Let me look at the current chat_new_thread_handler
Assistant
Let me look at the test for chat_new_thread_handler
Assistant
Let me do a final verification of the complete implementation by reviewing all modified
Assistant
Let me verify the code quality by checking for obvious issues
Assistant
I'm satisfied with the implementation. Let me do one final review of the complete changes before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.