Repository navigation
fix(rpc): keep the omp child on every command timeout - #436
RoyaLemonade wants to merge 5 commits into
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
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. |
Code Review Roast 🔥Verdict: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
📊 Overall: Like a seatbelt that fastens but then unfastens itself in a crash — the fence logic is the right idea, but it's checking the wrong sensor. Files Reviewed (19 files)
Previous Review Summary (commit a2dbac9)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit a2dbac9)Verdict: 3 Issues Found | Recommendation: Address before merge
Issue Details (click to expand)
🏆 Best part: The timeout contract is genuinely well thought through — a busy child stays alive instead of getting recycled mid-run, and a 💀 Worst part: Dismissed notices rising from the dead in 📊 Overall: Like a second pancake — the batter finally cooked through, but one side is still stuck to the pan. Files Reviewed (17 files)
Reviewed by free · Input: 2.2M · Output: 146.9K · Cached: 4M |
A command omp answered late used to recycle the child, ending a run that was merely busy and losing the prompt's outcome. Control and passthrough commands now share one bounded path: at most 32 may wait (else `session_busy`), and an expired wait answers `session_slow` with `maybeStarted` or `abortUnconfirmed` instead of hanging or destroying the child. Only a child that has produced no frame and answered nothing for five minutes is disposed, and its session reports that as an exited run with `detail: "stalled"`. `alive` is now reported separately from `running`, so a freshly spawned idle child is not mistaken for a dead one, and `silentForMs` says how long the child has been quiet. A stray unhandled promise rejection is journaled and rate-limited instead of taking the whole server down; an uncaught exception still exits 2.
Review follow-ups for the command-timeout contract. - hooks/useAgentSession.ts: the 503 busy branch read `stateRes.json()` a second time after the request had already parsed it, so the read threw and a busy chat became an HTTP 503 load failure. The code now comes from the parsed body. Covered by opening a chat through the hook against a real Response (a second read throws there). - lib/message-outbox.ts: `refused` now honours the wrapper's explicit `maybeStarted` evidence, so a `session_slow` ack timeout (HTTP 400) fails as possibly-sent instead of "Not sent" with a resend offer. - lib/rpc-manager.ts: `destroyIfStalled` stops the child with `stopShared` instead of only dropping this web app's membership, so the "was stopped" claim is true for a daemon-owned child. - lib/rpc-manager.ts: a timed-out new_session/switch_session fences commands until a state read reconciles the identity, instead of leaving a stale wrapper identity that a later command could act through. - Routes answer the dead state (not `503 alive:true`) when the watchdog disposed the child, and the sessions-state route includes its stalled exit record. - Hook Slow-mode consumers read `alive` (with `running` as the fallback for older servers), so an idle live child keeps its session-scoped support instead of falling back to the catalog. - Dropped unrelated payloads: goal types/passthrough, the notification-answer helpers, the ownership helper, the unhandled-rejection policy change, reminder i18n strings, the `?systemPrompt=0` option, and the `RunAgentCommandOptions` refactor. - Tests: the duplicated block is gone and the source-string assertion is replaced by a transport-boundary one (the deadline `sendCommand` receives). New cases cover the stall watchdog's `stopShared`, the identity fence, the outbox `maybeStarted` classification and the busy chat hydration.
…the tool bridge
A switch that is acked but whose follow-up get_state times out left the wrapper on the old session id with no fence: the next command acted on the wrong conversation and the raw timeout escaped as an unlabelled 500. The identity read now fences and answers session_slow like a timed-out switch does.
The stall watchdog measured silence since the last frame, but an idle omp sends no frames at all: any session left open longer than five minutes was disposed by its first timed-out command. It now measures an unanswered streak, cleared by any frame or any command answer, so a single timeout can never reach the threshold.
set_host_tools/set_host_uri_schemes were bounded at 5 s, but their onReply only records the names when omp answers, and a late reply after a timeout is dropped: one slow registration left the bridge rejecting every host_tool_call for the rest of the child's life. Both registrations are unbounded again, as on main.
The identity fence ran before the liveness check, so a child that exited while fenced answered session_slow ('the session keeps running') and clients retried a dead session forever. Liveness is checked first, and a reconcile that loses the child reports it gone.
A 503 session_slow on load marked a run this tab never dispatched, and the reconcile poll then reported 'the agent stopped without returning a response' even when the child was blocked on non-run work. runUnclaimedRef suppresses that classification while still clearing the spinner.
Also: lib/session-routes.test.mjs expected the pre-alive body (CI-red), and scripts/link-hol-probe.ts still keyed on session_state_timeout, so a timed-out get_state was read as a successful one.
The comments claimed the code came from 0.6.0, which this tree no longer ships. It is reachable only from a wrapper that outlived a bun --hot reload and kept its previous module instance; the branch is kept for that, and the changelog now says so instead of leaving the compat window unexplained.
a2dbac9 to
2676912
Compare
The two client branches that answer a command timeout had no hook test:
deleting them left the suite green (283 pass either way).
- a prompt POST answered 400 {code:session_slow, maybeStarted:true} keeps
the optimistic turn, keeps sending locked (a second send is rejected and
posts nothing) and shows the maybeStarted hint instead of rolling back.
- an abort_and_restore_queue answered 400 {abortUnconfirmed:true} warns
exactly once, is not retried, sends no fallback abort and rewrites no
draft; the per-entry fallback abort's unconfirmed ack warns the same way.
Each was verified by deleting its branch in hooks/useAgentSession.ts: the
test fails (rejected instead of accepted; 2 attempts instead of 1; no
warning), then the branch was restored byte-identically.
|
Follow-up at 3ceadab. Rebased onto current main with a semantic merge in
|
| // Link lost: the child runs on there and the reconcile on reconnect | ||
| // settles it. Every other timeout site answers `host_offline`; a raw | ||
| // timeout here would surface as a bare 500 with no code. | ||
| if (this.linkLostDuring(error)) throw this.hostOfflineError("unknown"); |
| // Link lost: the child runs on there and the reconcile on reconnect | ||
| // settles it. Every other timeout site answers `host_offline`; a raw | ||
| // timeout here would surface as a bare 500 with no code. | ||
| if (this.linkLostDuring(error)) throw this.hostOfflineError("unknown"); |
There was a problem hiding this comment.
🔥 The Roast: You finally added a fence for the timed-out identity read — good. But the timeout branch still answers host_offline based on linkLostDuring, which checks lastUplinkAt. That's the same host-link check used to excuse every timeout elsewhere, and it has nothing to do with whether the session switched. A linked host that sent a heartbeat after the command went down gets "the run continues there" while the wrapper is actually holding a stale _sessionId — the exact wrong-conversation hazard this whole function exists to prevent. The fence should fire on the switch outcome being unknown, not on the host link.
🩹 The Fix: On a timeout here, set this.identityStale = true and throw slowSessionError(), and reserve host_offline for when the link genuinely dropped. The child runs on either way; the only question is whether the identity is settled.
📏 Severity: warning
|
Hi @RoyaLemonade, thank you for your contribution, and apologies for the long wait on this PR. We really appreciate the time and effort you have put into it. We are working through a major refactor of ompweb, including switching to our own build of omp. We are close to finishing that work; once the refactor is complete, we will turn our attention back to the pending PRs, including this one. Thank you for your patience and for helping improve ompweb! |
|
Hi, thanks for this PR. It currently conflicts with main and can't be merged as-is — please rebase it onto current main and resolve the conflicts. Once it's rebased I'll re-run the checks. After the rebase this still needs a first maintainer review — it's a core-path change (+434/−61 in |
Bun port of #325, supersedes #325. Rebased onto current
origin/main(shared-daemon lifecycle).What
session_busy), and an expired wait answerssession_slowinstead of hanging the request.maybeStarted(the frame is already in omp's stdin, so the message may still run) orabortUnconfirmed(Stop may have landed) — the client stops rolling back and resending, and the outbox marks such an entry as possibly-sent instead of "Not sent".destroyAndWait(..., stopShared=true)so a daemon-owned child is really stopped, recorded asexited.detail: "stalled".GET /api/agent/{id}andGET /api/sessions/{id}/stateanswer{ running, alive, state?, silentForMs? }and503 session_slowwhile busy;aliveis separate fromrunningso a freshly spawned idle child is not read as dead, and a child the watchdog disposed answers the dead state (with its stalled exit record) instead of a busy 503.new_session/switch_sessionfences commands until a state read reconciles which conversation the child serves, so a later command cannot act through a stale wrapper identity.Why
A busy omp blocks its event loop for tens of seconds on large sessions. Recycling it ended a live run and lost the prompt outcome; the client also needs
alive/session_slowto tell "busy" from "gone".Review follow-ups (this push)
hooks/useAgentSession.tsre-readstateRes.json()after the request had already parsed it; the second read threw and a busy chat became an HTTP 503 load failure. The code now comes from the parsed body.refusedhonours the wrapper's explicitmaybeStarted, so asession_slowack timeout (HTTP 400) fails as possibly-sent.destroyIfStalledstops the child withstopShared; it no longer only detaches membership while claiming the child was stopped.get_statereconciles the identity.running:false, alive:falsewhen the watchdog disposed the child; the sessions-state route includes thedetail:"stalled"exit record.runningmigration: hook Slow-mode consumers readalive(falling back torunningfor servers that do not send it), so an idle live child keeps its session-scoped support.?systemPrompt=0option (that is feat(sessions): navigation-only reads, context ETag and a prompt-less state #415) and theRunAgentCommandOptionsrefactor.Tests
bun test --timeout 30000 lib/rpc-manager.test.mjs— 166 pass.bun test --timeout 30000 lib/message-outbox.test.mjs lib/agent-command.test.mjs— 68 pass.bun test --timeout 30000 hooks/useAgentSession.rpc.test.mjs— 253 pass.bun test --timeout 30000 server/routes.test.ts— 5 pass.npm run typecheckclean;npm run lintclean on every changed file.stopShared→falsefails the watchdog test; removing the identity fence fails the switch test; droppingmaybeStartedfrom the outbox classification fails the uncertain-delivery test; re-reading the state body fails the busy-chat hydration test.Response(a second read throws there), outboxsession_slowwith/withoutmaybeStarted, the watchdog'sstopShared+ stalled exit record, the identity fence, and a transport-boundary deadline assertion replacing the previous source-string check.lib/rpc-manager.test.mjs+lib/message-outbox.test.mjsin one process show 4–5 failures in host-tool/adoption tests. The same files on unmodifiedorigin/mainfail identically (verified), so it is pre-existing cross-file fixture interference, not this change. Each file passes alone.Reopened as a new PR: #408 was closed automatically when its branch ref was briefly recreated during the review update (GitHub does not allow reopening it). Review history and the follow-up reply are on #408.