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 inspect the repository to locate the WebUI inbound facade, mutation handlers, and existing tests. Then I’ll trace current create-thread/send-message behavior, implement a durable/concurrency-safe idempotency ledger consistent with the project’s storage patterns, and run focused tests plus the broader relevant suite.
- Assistant
The repository already has durable inbound-message idempotency and atomic acceptance in both in-memory and database-backed thread services, plus turn-level idempotency. The gap is that the WebUI’s idempotency key is currently combined with a source binding containing the thread ID, so the same browser action can be accepted again on another thread. I’ll make the WebUI source identity stable across threads (while retaining tenant/agent/project/user isolation), and explicitly reject a replay whose recorded thread differs from the requested thread before attempting to read or submit its run. This preserves the existing atomic ledger behavior for concurrent requests and makes cross-thread reuse deterministic.
- Assistant
The patch now preserves caller isolation by including tenant, agent, project, and actor in the stable source binding while intentionally excluding thread. Thus same-thread retries replay the ledger entry, concurrent requests serialize through the existing atomic acceptance path, and cross-thread reuse returns HTTP 409 without creating a message. I’ll inspect the final diff and available toolchain; the environment currently has no configured Rust toolchain, so verification may be limited to static checks.
- Assistant
A deeper race is present: the durable ledger key also contains
ThreadScope, so merely changing the facade lookup would not protect two concurrent cross-thread submissions—the two atomic inserts would still use different keys. I’ll tighten inbound acceptance itself to treat(source_binding_id, external_event_id)as the idempotency identity, while retaining the stored scope for ownership and returning the existing thread-mismatch error. This makes the invariant hold even when both requests pass the initial replay probe concurrently. - Assistant
The atomic acceptance path is now corrected in both thread backends: it searches the ledger by stable source/event identity while holding the backend’s mutation lock/transaction, and rejects a different requested thread before insertion. This closes the concurrent cross-thread race, not just the sequential facade case. I’ll perform final whitespace/diff validation and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.