Skip to content

fix: prevent orphaned opencode processes from duplicate requestStart#559

Closed
conradkoh wants to merge 1 commit into
release/v1.46.1from
fix/opencode-orphan-request-start
Closed

fix: prevent orphaned opencode processes from duplicate requestStart#559
conradkoh wants to merge 1 commit into
release/v1.46.1from
fix/opencode-orphan-request-start

Conversation

@conradkoh
Copy link
Copy Markdown
Owner

Summary

  • Backlog: ps7bvnx0gsyar8ceb4vpm41hrd87epn6 — Multiple agent.requestStart events leave orphaned opencode serve processes
  • Root cause: getCommandEvents returns every non-expired agent.requestStart for a machine (e.g. double-click / start-all). The daemon dedupes by event ID only, so each distinct event can trigger another opencode serve spawn while older serves remain running.
  • Fix: Dedupe agent.requestStart to the latest event per chatroomId+role in getCommandEvents, and stop/remove any tracked opencode-sdk session for that role before spawning.

Assumptions

  • Duplicate starts for the same role within the 2-minute deadline window represent the same user intent; keeping only the latest is correct.
  • agent.requestStop events are unchanged and still processed in timestamp order alongside the deduped starts (restart = stop then start still works).

Risks

  • Low: If two intentional starts for the same role with different workingDir/model were issued within the deadline, only the latest is delivered. Unlikely in normal UI flows.
  • Daemon + backend: Requires backend deploy for dedupe; CLI deploy for spawn-time cleanup. No schema migration.

Test plan

  • pnpm typecheck
  • pnpm test (cli + backend)
  • New unit test: dedupeRequestStartEvents
  • New integration test: getCommandEvents dedupes duplicate starts
  • opencode-sdk: clears stale session metadata before spawn
  • Manual: double-click Start agent → single opencode serve process (ps aux | grep opencode)
  • Manual: Restart agent → old process stopped, new one running

Made with Cursor

…tart events

Dedupe agent.requestStart per chatroom+role in getCommandEvents and clean up
tracked opencode-sdk sessions before respawn so duplicate starts do not leave
orphaned serve processes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chatroom Ready Ready Preview, Comment May 26, 2026 11:16pm

@conradkoh
Copy link
Copy Markdown
Owner Author

Closing as superseded by #584 (squash-merged to release/v1.49.2).

This PR implemented backend dedupeRequestStartEvents in getCommandEvents plus opencode-sdk session cleanup before spawn. #584 deliberately removed backend dedupe and moved orphan prevention to the daemon (AgentProcessManager kill-then-spawn on requestStart replacement + consolidated harness stop()).

Merging both approaches would be contradictory. The current release branch no longer contains dedupeRequestStartEvents.ts.

If further opencode-sdk-specific hardening is needed, it should be a fresh PR on top of release/v1.49.2 aligned with the per-harness audit plan.

@conradkoh conradkoh closed this May 29, 2026
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