This repository was archived by the owner on Sep 30, 2026. It is now read-only.
Repository navigation
fix(server): dedup re-sent user submissions via a stable submission nonce - #14
Merged
Merged
Conversation
…once On a busy shared server a client that sends a queued follow-up while a turn is still running is rejected with 'Already processing a message'. The client's anti-loss recovery (issue 1jehuang#391) re-queues the same content and re-adopts a running-turn state, so a transient busy race turns one logical submission into several accepted, appended user turns - the ~16 duplicate user turns observed in rewind history. Add server-side idempotency, mirroring the existing swarm-spawn request_nonce dedup pattern: - Protocol: Request::Message gains an optional submission_nonce (backward-compatible default None; older clients keep prior behavior). - Server: each connection keeps a bounded per-connection MessageNonceTracker. A duplicate nonce is acknowledged with Done and never appended or run a second time; the nonce is recorded only once a submission passes the reload and busy gates and is actually accepted. - Client (TUI): begin_remote_send resolves a stable nonce for each logical submission and preserves it across every busy/disconnect re-send of the same content (in-flight pending message, the busy-recovery re-queue stash, and the reload save/restore path), so retries reuse the original nonce. Genuinely new content mints a fresh nonce; an empty reminder poke carries none. - ACP bridge: stamps each single-shot prompt with a fresh nonce. Tests: MessageNonceTracker unit tests (absent nonce never dedups, record/ detect, idempotent record, FIFO eviction), a server regression test proving a duplicate-nonce re-send appends exactly one user turn, and extended wire roundtrip tests covering the new field. cargo build + clippy clean for jcode-protocol, jcode-app-core, jcode-tui, and the jcode binary.
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a busy shared server, a single user message can be injected many times (the ~16 duplicate user turns seen in rewind history). Root cause: no inbound-message idempotency plus the client busy-requeue loop. When a queued follow-up races a still-running turn, the server rejects it with
Already processing a message; the client's anti-loss recovery (issue 1jehuang#391) re-queues the same content and re-adopts a running-turn state, so each accepted re-dispatch appends another identical user turn. Full diagnosis: server rejects before append, so the amplification is client re-sends with no idempotency key, not a server double-append.Fix
Server-side idempotency, mirroring the existing swarm-spawn
request_noncededup pattern (wire.rs/handle_comm_spawn):crates/jcode-protocol/src/wire.rs):Request::Messagegains an optionalsubmission_nonce(backward-compatibledefault None; older clients keep prior behavior,skip_serializing_if).crates/jcode-app-core/src/server/message_nonce_dedup.rs+client_lifecycle.rs): each connection owns a bounded FIFOMessageNonceTracker. A duplicate nonce is acknowledged withDoneand never appended or run again. The nonce is recorded only once a submission passes the reload and busy gates and is actually accepted, so a busy-rejected send (which appends nothing) does not poison the set. The duplicate check sits at the top of the message arm, short-circuiting the busy-recovery amplifier itself.crates/jcode-tui):begin_remote_sendresolves a stable nonce per logical submission and preserves it across every busy/disconnect re-send of the same content - the in-flight pending message, the busy-recovery re-queue stash (queue_recovery.rs), and the reload save/restore path (state_ui.rs). Genuinely new content mints a fresh nonce; an empty reminder poke carries none.src/cli/acp.rs): stamps each single-shot prompt with a fresh nonce.Tests
MessageNonceTrackerunit tests: absent nonce never dedups, record/detect, idempotent double-record, FIFO eviction beyond capacity.duplicate_submission_nonce_appends_exactly_one_user_turn: an accepted submission appends its user turn, and a same-nonce re-send is detected as a duplicate and appends nothing.Validation
cargo build+cargo clippyclean forjcode-protocol,jcode-app-core,jcode-tui, and thejcodebinary.cargo test: nonce-tracker + regression tests pass; 56 protocol roundtrip tests pass.MVP is the server nonce guard; the client nonce-preservation makes the guard actually engage across the retry storm. Not the money/model hot path.