Skip to content

refactor: move replay dedup from ACP protocol handler to MessageWriter#563

Draft
matt2e wants to merge 5 commits intomainfrom
read-in-messages-from-acp
Draft

refactor: move replay dedup from ACP protocol handler to MessageWriter#563
matt2e wants to merge 5 commits intomainfrom
read-in-messages-from-acp

Conversation

@matt2e
Copy link
Copy Markdown
Contributor

@matt2e matt2e commented Mar 31, 2026

Summary

  • Moves replay message deduplication logic from the ACP notification handler's complex phase-based state machine into the simpler MessageWriter, which checks incoming messages against previously persisted DB roles
  • Makes the prompt parameter optional in AgentDriver::run(), allowing session setup/resume without sending a prompt
  • Removes get_session_messages from the Store trait (no longer needed at the protocol layer)
  • Significantly simplifies the ACP notification handler by removing ~350 lines of replay-sync machinery (HandlerPhase, ReplayBuffer, idle-timeout polling)

Test plan

  • Verify new session creation works (no replay roles loaded)
  • Verify session resumption correctly skips replayed messages via MessageWriter
  • Verify existing MessageWriter unit tests pass
  • Run full CI (clippy, tests, fmt)

🤖 Generated with Claude Code

matt2e and others added 5 commits April 1, 2026 12:45
Change `prompt: &str` to `prompt: Option<&str>` in the `AgentDriver::run()`
trait method, both driver implementations (`AcpDriver` and `SimpleDriverWrapper`),
and the internal `run_acp_protocol()` helper. When `None`, the driver sets up
or resumes the session but skips sending a prompt. All existing callers now
pass `Some(prompt)` to preserve current behaviour.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ocol handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When resuming an ACP session, the server replays all previous messages.
MessageWriter now loads existing message roles from the DB on resume and
skips writing duplicates by tracking a replay cursor, preventing
duplicate messages from being inserted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Filter out User messages when building replay_roles (User messages are
  inserted by session_runner before the driver runs, but never forwarded
  by AcpNotificationHandler, so they would block the cursor)
- Add skipping_assistant flag to prevent double-advancing the replay
  cursor when flush_text is called multiple times for the same block
- Combine replay_messages and replay_cursor into single Mutex<ReplayState>
- Use .as_ref() instead of .to_string() for tool_call_id in driver to
  avoid unnecessary allocation
- Add test for resume dedup behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt2e matt2e force-pushed the read-in-messages-from-acp branch from 11d8249 to 2a47771 Compare April 1, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant