Skip to content

fix(orchestration): treat ask as a long-poll so it survives the 30s socket idle wall - #9351

Merged
nwparker merged 1 commit into
stablyai:mainfrom
averydev:fix/orchestration-ask-long-poll-keepalive
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
averydev:fix/orchestration-ask-long-poll-keepalive

Conversation

@averydev

@averydev averydev commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

fix(orchestration): treat ask as a long-poll so it survives the 30s socket idle wall

Summary

Fixes orchestration.ask calls dying at 30 seconds with a misleading runtime_unavailable error regardless of the requested timeout.

ELI5

When one agent asked another a question and waited for the answer, the connection was silently killed after 30 seconds even if you asked it to wait longer. This keeps the line open until a real reply arrives.

Root cause & fix

orchestration.ask blocks server-side until a reply lands or its deadline (default 600s) passes, holding the RPC socket open exactly like check --wait. But isLongPollRequest() only classified terminal.wait and check --wait as long-polls, so ask fell through. That meant keepalive frames were never armed (the 30s socket idle timer then destroyed the connection) and the abort signal was never wired (so a client disconnect never released the waiter). The fix adds orchestration.ask to isLongPollRequest(), arming the existing keepalive machinery and abort wiring — no new --wait-style param gate is needed since ask blocks unconditionally.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Clean rebase onto origin/main (base 7ab601487c, head 1cd244d304); changed files: runtime-rpc.ts (fix), runtime-rpc.test.ts (test).
  • Test on branch: orchestration.ask blocks → 1 passed (55 skipped).
  • Reverting the fix only makes the test fail, proving it captures the bug:
AssertionError: expected 0 to be greater than or equal to 3
  at runtime-rpc.test.ts:3950  expect(keepalives.length).toBeGreaterThanOrEqual(3)
=> With the fix reverted, no keepalive frames are emitted while ask blocks.
  • Lint clean: oxlint src/main/runtime/runtime-rpc.ts → exit 0.

Trade-offs

None — pure fix.

Regression risk

Zero-regression: the change is purely additive to the long-poll classifier. Short RPCs and non-ask paths are byte-identical and unaffected. orchestration.ask genuinely holds the socket, so keepalive/abort wiring is the correct treatment, proven by the passing test that fails when reverted.


Credit to original author @averydev. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The RPC runtime now classifies orchestration.ask requests as long-poll operations, enabling existing admission, abort, and keepalive handling. A new integration test opens a framed orchestration.ask session, verifies a timed-out terminal response and multiple keepalive frames, and cleans up the orchestration database and RPC server.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix well, but it misses required template sections like Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections, including screenshots/no visual change, testing checklist, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: treating orchestration.ask as a long-poll to avoid socket idle timeouts.

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/main/runtime/runtime-rpc.test.ts (1)

3566-3569: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reorder shutdown sequence and clean up the temporary directory.

It is safer to stop the server before closing the database to ensure that no in-flight requests or shutdown routines attempt to access a closed database connection, which could throw unhandled exceptions. Additionally, consider removing the temporary userDataPath directory to avoid resource leaks across test runs.

♻️ Proposed refactor
       } finally {
-        db.close()
         await server.stop()
+        db.close()
+        rmSync(userDataPath, { recursive: true, force: true })
       }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9184c62e-38c0-46b4-a212-5c5766e82e8f

📥 Commits

Reviewing files that changed from the base of the PR and between d8629c4 and c85816822a08ea8d6628791ca7b90fce177fae5e.

📒 Files selected for processing (3)
  • src/cli/runtime/client.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts

@averydev
averydev force-pushed the fix/orchestration-ask-long-poll-keepalive branch from c858168 to 1cd244d Compare July 18, 2026 16:15
@AmethystLiang AmethystLiang self-assigned this Jul 18, 2026
@AmethystLiang
AmethystLiang self-requested a review July 18, 2026 16:46
…ocket idle wall

orchestration.ask blocks server-side until a reply lands or its timeout
(default 600s) elapses, holding the RPC open — but isLongPollRequest never
classified it as a long-poll. So the keepalive that resets the 30s
RUNTIME_RPC_SOCKET_IDLE_TIMEOUT_MS was never armed, and any ask left
unanswered for 30s died with a misleading runtime_unavailable ("The Orca
runtime closed the connection"), regardless of --timeout-ms. The same
omission left the handler's abort signal unwired (it is only passed for
long-polls), so the client-disconnect release path guarded by
signal?.aborted was dead code.

Add orchestration.ask to isLongPollRequest so it gets the keepalive, the
abort signal, and long-poll admission. The client already extends its
per-call socket timeout for ask (handlers/orchestration.ts passes
timeoutMs + 5s at the call site), so only the server-side classification
was missing.
@nwparker
nwparker force-pushed the fix/orchestration-ask-long-poll-keepalive branch from 1cd244d to 2f0c964 Compare July 23, 2026 11:48
@nwparker
nwparker merged commit cd28da1 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @averydev — treat ask as a long-poll so it survives the 30s socket idle wall. Verified (fail-on-main/pass-on-branch), rebased on latest main, reviewed, and merged. Really appreciate it! 🙏

@averydev

Copy link
Copy Markdown
Contributor Author

My pleasure @nwparker I've been using the orca cli primitives for some really fun stuff that is a bit off the beaten path so I think I'm exercising a slightly unusual combinations of tools. I'll keep em coming! great work!

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ocket idle wall (stablyai#9351)

orchestration.ask blocks server-side until a reply lands or its timeout
(default 600s) elapses, holding the RPC open — but isLongPollRequest never
classified it as a long-poll. So the keepalive that resets the 30s
RUNTIME_RPC_SOCKET_IDLE_TIMEOUT_MS was never armed, and any ask left
unanswered for 30s died with a misleading runtime_unavailable ("The Orca
runtime closed the connection"), regardless of --timeout-ms. The same
omission left the handler's abort signal unwired (it is only passed for
long-polls), so the client-disconnect release path guarded by
signal?.aborted was dead code.

Add orchestration.ask to isLongPollRequest so it gets the keepalive, the
abort signal, and long-poll admission. The client already extends its
per-call socket timeout for ask (handlers/orchestration.ts passes
timeoutMs + 5s at the call site), so only the server-side classification
was missing.
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.

3 participants