Skip to content

fix(orchestration): release dispatch lock when worker_done is sent via orchestration.send - #6317

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
rodboev:pr/fix-orchestration-send-dispatch-lock
Jun 25, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
rodboev:pr/fix-orchestration-send-dispatch-lock

Conversation

@rodboev

@rodboev rodboev commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • orchestration.send inserted messages and delivered them to the PTY but never called reconcileLifecycleMessage. When a manual coordinator sent worker_done via send (instead of letting the recipient call check), the dispatch context for that terminal stayed in 'dispatched' status permanently. Every subsequent send to the same terminal threw "Terminal X already has an active dispatch".
  • Added an inline reconcileLifecycleMessage call in orchestration.send for worker_done and heartbeat messages, placed before deliverPendingMessagesForHandle so the lock releases before waking recipients who may immediately dispatch new work.
  • orchestration.check already reconciled on every unread read. Both send and check paths now release the dispatch lock equivalently regardless of how the coordinator drives the lifecycle.

Closes #6090.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation run in this session:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/orchestration.test.ts — 97 tests passed (0 failed), 6.12s
  • pnpm run typecheck:node — clean, no errors

AI Review Report

Reviewed orchestration.ts change on macOS, Linux, and Windows. The fix inserts one conditional call in the point-to-point send path. reconcileLifecycleMessage is already imported at line 8 of the file and used by orchestration.check — no new dependency. The call is gated on msg.type === 'worker_done' || msg.type === 'heartbeat'; all other message types pass through unchanged. Group-address sends already reject worker_done and heartbeat via Zod superRefine before insertion, so the group path is unaffected. Ordering: reconcile runs after db.insertMessage (required — reconcile operates on the persisted row) and before deliverPendingMessagesForHandle (required — recipients must see the lock already released). Invalid or stale worker_done messages with mismatched dispatchId return { action: 'ignored' } from reconcileWorkerDoneMessage — lock stays held, which is correct. No SSH, terminal, browser, mobile, or UI surface touched. Provider-neutral main-process logic.

Security Audit

No filesystem access, subprocess execution, auth, secrets, or external IPC touched. The change affects only the DB lock lifecycle in the orchestration layer. reconcileLifecycleMessage validates taskId, dispatchId, and dispatch ownership before releasing any lock — no privilege escalation possible.

Notes

heartbeat messages are included in the guard for symmetry with orchestration.check's existing reconciliation. In practice, heartbeats do not carry taskId/dispatchId and reconcile to a no-op, but including them here keeps both paths consistent and future-proof. Group-address path unchanged.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc1332c2-373e-41a3-9275-b31d593c4070

📥 Commits

Reviewing files that changed from the base of the PR and between 7663606 and a429294.

📒 Files selected for processing (4)
  • src/main/runtime/orchestration/coordinator.test.ts
  • src/main/runtime/orchestration/coordinator.ts
  • src/main/runtime/orchestration/lifecycle-reconciliation.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts

📝 Walkthrough

Walkthrough

orchestration.send now calls reconcileLifecycleMessage for worker_done and heartbeat messages before delivering pending messages and notifying recipients. reconcileWorkerDoneMessage now returns completed when both the task and dispatch are already completed, and Coordinator.handleLifecycleMessage avoids duplicating completed task IDs. The new tests cover lock release for worker_done and lock retention for heartbeat and status messages.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main orchestration.send lock-release fix for worker_done messages.
Description check ✅ Passed The description covers summary, screenshots, testing, AI review, security audit, and notes with the required details.
Linked Issues check ✅ Passed The changes address #6090 by releasing the dispatch lock after worker_done so follow-up dispatches to the same terminal can proceed.
Out of Scope Changes check ✅ Passed The added lifecycle handling and tests stay within the issue scope and support the same dispatch-lock fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H
Jinwoo-H self-requested a review June 25, 2026 03:14

@Jinwoo-H Jinwoo-H left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused fix. I verified the send-path lifecycle ordering and added a small follow-up so coordinator accounting remains correct when send reconciles before the coordinator reads the message.

  • worker_done via orchestration.send releases the dispatch lock before delivery.
  • Heartbeats sent via send now have regression coverage.
  • Coordinator completedTasks remains correct and de-duped for already-reconciled lifecycle messages.

Validated with focused orchestration tests, typecheck, lint, and a live Electron/CLI lifecycle probe.

@Jinwoo-H
Jinwoo-H merged commit 79d0511 into stablyai:main Jun 25, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…a orchestration.send (stablyai#6317)

* fix(orchestration): release dispatch lock when worker_done is sent via orchestration.send (stablyai#6090)

* fix: preserve coordinator lifecycle accounting

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinwoo-H <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

worker_done leaves dispatch lock active; re-dispatch to same terminal fails silently

2 participants