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 structure and locating WebUI mutation/idempotency-related code.
- Assistant
Searching the codebase for WebUI handlers and existing idempotency patterns.
- Assistant
Let me look at ironclaw_product_workflow and related crates for WebUI and idempotency.
- Assistant
Let me search more broadly for WebUI and product workflow related code.
- Assistant
Found
webui_inbound.rsandledger.rs— inspecting those and related tests next. - Assistant
Let me read the ledger.rs, workflow.rs, inbound_turn.rs, and webui tests. Also check for TODOs related to idempotency.
- Assistant
Inspecting workflow, inbound turn handling, and WebUI contract tests for the expected behavior.
- Assistant
I'll read
reborn_services.rsand the related contracts around WebUI send/create idempotency. - Assistant
Checking send-message implementation details and tests for gaps around idempotency.
- Assistant
Let me continue reading the file and the tests for reborn_services_contract.
- Assistant
Looking for incomplete work and what's missing from the acceptance criteria.
- Assistant
Let me look at docs about webui and parent tracker #3607, and also check uncommitted issues or plans.
- Assistant
Let me look more carefully at the tests and what might be missing. Also search GitHub issues or PR descriptions. Maybe there's a TODO or incomplete implementation somewhere.
- Assistant
Inspecting thread acceptance/idempotency and any open TODOs or failing tests related to this work.
- Assistant
Analyzing inbound idempotency for concurrent and cross-thread cases next.
- Assistant
Checking how the WebUI source binding ID is constructed and how product fingerprints handle cross-thread cases.
- Assistant
Looking for issue briefs and gaps in concurrent/cross-thread coverage.
- Assistant
Let me look at PR briefs or planning documents related to webui and also run the existing tests to see what's failing. Maybe there's a failing test that was added for this issue but the implementation...
- Assistant
There's a test:
duplicate_external_event_with_wrong_thread_does_not_replay_cross_thread_messagein session_thread_contract. Let me read that and also check if RebornServices properly maps the error ... - Assistant
Checking ThreadScope definition — it may include thread_id and affect idempotency keys.
- Assistant
Interesting - ThreadScope does NOT include thread_id. The InboundIdempotencyKey is:I see the core challenge here: we need to make the WebUI mutations idempotent using client action IDs while handling cross-thread rejection and concurrent submissions safely. The key insight is that ThreadScope doesn't include thread_id, so source_binding_id must incorporate it to prevent collisions across threads.
For concurrent duplicates, we need a turn coordinator that enforces idempotency - the FakeTurnCoordinator should probably be updated to be truly idempotent, and the real one should handle the replay path correctly when a message is Accepted but not yet Submitted.
The validation check looks solid - into_command runs first so no ghost turns are created. For transient unavailable retries, the early replay path should handle MessageStatus::Accepted correctly and retry submit_turn.
I think the main fix needed is:
- Update source_binding_id to exclude thread_id for installation-wide deduplication
- Add thread_id check in the early replay path of submit_turn to reject cross-thread duplicates
- Assistant
Inspecting create_thread and types, and reviewing how FakeTurnCoordinator handles idempotency.
- Assistant
Checking mark_message_submitted behavior and turn coordinator idempotency — concurrent paths may race on status transitions.
- Assistant
Let me look at ensure_user_accepted and what happens when mark is called twice. Also look at services with real InMemory turn coordinator integration tests - maybe the issue is that RebornServices tes...
- Assistant
Checking whether messages store received_at and reviewing mark_message transitions for idempotency.
- Assistant
Messages don't store received_at. For deterministic retry, preserved received_at may need to come from elsewhere or Using now() may still work if turn coordinator only uses it as metadata for new subm...
- Assistant
I'll compare with inbound_turn's handling so WebUI can follow the same patterns.
- Assistant
Checking how to construct a real in-memory turn coordinator for tests.
- Assistant
Implementing language: harden
source_bindingand replay thread checks, make message marks idempotent, fix concurrent turn replay, and add tests. - Assistant
Applying the WebUI and threads idempotency fixes now.
- Assistant
Updating accept path to use the reply target binding and adjusting related helpers.
- Assistant
Need to open the file at that line first.
- Assistant
There might be an issue - if we move reply_target_binding_id into AcceptedWebUiMessage in the else branch, the variable is moved and can't be used later if we capture for source... But source only use...
- Assistant
Updating binding helpers and making mark_message_submitted idempotent.
- Assistant
I need to update webui_source_binding_id to exclude thread, and add webui_reply_target_binding_id with thread.
- Assistant
Making
mark_message_submittedandmark_message_deferred_busyidempotent in both backends. - Assistant
I'll replace mark methods and also ensure_user_accepted helper if needed.
- Assistant
Now update db.rs similarly.
- Assistant
Same replacement for db.rs.
- Assistant
Making FakeTurnCoordinator idempotent and adding the missing contract tests.
- Assistant
Checking how to construct a TurnError::Unavailable.
- Assistant
Updating FakeTurnCoordinator and adding the new tests.
- Assistant
Need to goto line 1
- Assistant
I'll replace the FakeTurnCoordinator structure carefully.
- Assistant
Now replace FakeTurnCoordinator body.
- Assistant
The file is open at line 1 but the replace said not found in displayed lines. Maybe I need to goto line 72.
- Assistant
Let me try replace again.
- Assistant
Updating the duplicate submit test and adding new coverage.
- Assistant
I'll replace the duplicate_submit test and insert new tests after it.
- Assistant
Running the product_workflow and threads tests to verify the changes.
- Assistant
Need to set up rustup
- Assistant
There's cargo in /usr/local/cargo/bin. Let me check PATH and toolchain.
- Assistant
Need to set RUSTUP_TOOLCHAIN or default to the installed one.
- Assistant
Good. Now run tests.
- Assistant
All 21 tests passed. Running threads and remaining product_workflow tests next.
- Assistant
I modified tests against the rules — reverting test-file changes and keeping only production code fixes.
- Assistant
Creating a temporary verification script, then removing it before submit.
- Assistant
Including
project_idin the source binding key so multi-project callers don't collide. - Assistant
I'll add project to source binding. Check if ProjectId is already imported as ironclaw_host_api::AgentId - yes AgentId is imported. ProjectId might need import.
- Assistant
Need toopenia line 11
- Assistant
Project is already on ThreadScope, so collisions stay isolated. Re-running the existing contracts tests.
- Assistant
Reviewing the final diff before submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.