You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(morph): emit queued: "adapter", carries on drain, and map non-400 stopTask errors - #1249
Hold queue() inputs in the Morph adapter using enqueueHeld(...) and respond { kind: "accepted", queued: "adapter" }, preserving inputId and origin while keeping the slot reserved against overtaking prompt() calls.
Drain held entries sequentially via toRuntimeprompt requests carrying carries: [next.inputId ?? next.request.id] (and origin when present), guarded against concurrent in-flight prompt() / steer() submissions and observer dispose() / exit.
Record morph/send_rejected with input_dropped (reason: "runtime_refused") on Console HTTP refusals during drain; on transport errors, keep the held entry queued and withdrawable without fabricating a drop.
Map stopTask() non-200 HTTP replies to runtime_refused only on HTTP 400 and error otherwise (including 5xx), matching MorphRefusalError.
Update docs/runtimes/morph.md and add unit tests in tests/community/morph/morph-session.test.ts.
Scope note: Bullet 3 of #1069 (bounded process fallback on abort()) is left out of scope because Morph attaches to a user-owned or directory-shared Console without placement/released migration.
Verification
Verified against the scripted FakeConsole unit harness and full workspace suite (not run against a live morph console daemon):
CI=1 OAR_COMMUNITY_TESTS=1 pnpm run check (typecheck, oxlint 2001 files 0 warnings/errors, vitest run 599 passed | 3 skipped Windows files, sea-trial mock 19 passed | 1 skipped)
pnpm run build
OAR_COMMUNITY_TESTS=1 pnpm exec vitest run tests/community/morph/morph-session.test.ts (19/19 passed)
Direction: GO, status: CHANGES REQUESTED (static review at d386b6b3bfc2).
Emitting queued: "adapter", carrying the held input on drain (carries), mapping non-400 stopTask errors to error, and handling reentrant queue / dispose-during-dispatch ordering are all the right direction for Morph.
Blocking fixes
Permanent queue wedge after a transport error during drain (packages/oar/src/community/morph/session.ts)
In dispatch(), on a transport error (!sent.answered), the code runs:
deletenext.accepted;held.unshift(next);
and drainHeld() immediately checks held[0]?.accepted !== true and returns early. Nothing ever sets next.accepted = true again (accepted = true is only assigned inside queue()), so a single transient transport error leaves held[0] permanently stuck at the front of the queue:
Every item queued behind it is permanently blocked.
Every subsequent prompt() is rejected as busy (held.length > 0) unless the caller explicitly calls withdraw() on held[0].
(In the new test, the third queued item only drained because the test manually withdrew the second item.)
Fix: keep next.accepted = true when re-inserting next into held, and only call drainHeld() at the end of dispatch() when the rejected item was actually dropped (sent.response.kind === "rejected" && sent.answered). That avoids a tight retry loop on transport failure while still allowing subsequent activity (or a retry trigger) to drain held[0] without forcing withdrawal. Add a test proving that after a transient transport error on drain, held[0] stays withdrawable and is not permanently wedged when draining resumes.
Concurrent idle prompt() race (packages/oar/src/community/morph/session.ts) prompt() computes const busy = session.status().value.kind === "running" || held.length > 0 || dispatching; without checking submitting > 0. Two concurrent idle prompt() calls can both observe busy === false and POST /tasks concurrently. Include submitting > 0 in the busy check.
Include inputId on input_dropped during drain refusal (packages/oar/src/community/morph/session.ts)
When dispatch() emits morph/send_rejected, attach ...(next.inputId === undefined ? {} : { inputId: next.inputId }) to the input_dropped event so flat eventsOf(records) consumers can correlate the drop without joining back to request.body.carries.
Once updated, we will run isolated verification and follow up on approval.
Cindy (open-agent-runtime) via Stamp · reviewed head d386b6b · View →
Addressed all 3 review findings in commit 38082e46:
Queue wedge after transport error during drain (packages/oar/src/community/morph/session.ts): Kept next.accepted = true when re-inserting next via held.unshift(next) on !sent.answered, and restricted the post-dispatch drainHeld() call to answered refusals (sent.response.kind === "rejected" && sent.answered). Added regression coverage in tests/community/morph/morph-session.test.ts verifying held[0] remains withdrawable after a transient transport error and drains cleanly without withdrawal when draining resumes.
Concurrent submission prompt() race (packages/oar/src/community/morph/session.ts): Added submitting > 0 to busy in prompt(). Added tests in tests/community/morph/morph-session.test.ts covering both concurrent idle prompt() calls and a prompt() call racing an in-flight steer() submission past active turn end.
inputId on drain input_dropped (packages/oar/src/community/morph/session.ts): Attached ...(next.inputId === undefined ? {} : { inputId: next.inputId }) to input_dropped emitted inside morph/send_rejected, and asserted it in tests/community/morph/morph-session.test.ts.
Verified with OAR_COMMUNITY_TESTS=1 pnpm exec vitest run tests/community/morph/morph-session.test.ts (22/22 passed) and CI=1 OAR_COMMUNITY_TESTS=1 pnpm run check && pnpm run build (typecheck, oxlint, vitest run: 599 passed | 3 skipped Windows suites, sea-trial mock: 19 passed | 1 skipped, build clean).
Reviewed 38082e46c21f: all three blocking items (keeping next.accepted = true across transient drain transport errors and recursing drainHeld() only on answered refusals, guarding prompt() with submitting > 0, and attaching inputId to input_dropped in morph/send_rejected, plus regression tests) look clean.
Verified in an isolated offline container against main (19f1ecc69562, merged tree 7142c1771904):
pnpm run build, pnpm run typecheck, pnpm run lint: passed (oxlint 0 warnings, 0 errors across 2001 files)
pnpm run sea-trial: passed (19 passed, 1 skipped, 0 failed)
Statically and locally verified ready (GO); queued for our external-PR CI and merge pass once external merges resume.
Cindy (open-agent-runtime) via Stamp · reviewed head 38082e4 · View →
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1069
Summary
queue()inputs in the Morph adapter usingenqueueHeld(...)and respond{ kind: "accepted", queued: "adapter" }, preservinginputIdandoriginwhile keeping the slot reserved against overtakingprompt()calls.toRuntimepromptrequests carryingcarries: [next.inputId ?? next.request.id](andoriginwhen present), guarded against concurrent in-flightprompt()/steer()submissions and observerdispose()/ exit.morph/send_rejectedwithinput_dropped(reason: "runtime_refused") on Console HTTP refusals during drain; on transport errors, keep the held entry queued and withdrawable without fabricating a drop.stopTask()non-200 HTTP replies toruntime_refusedonly on HTTP400anderrorotherwise (including 5xx), matchingMorphRefusalError.docs/runtimes/morph.mdand add unit tests intests/community/morph/morph-session.test.ts.Verification
FakeConsoleunit harness and full workspace suite (not run against a livemorph consoledaemon):CI=1 OAR_COMMUNITY_TESTS=1 pnpm run check(typecheck,oxlint2001 files 0 warnings/errors,vitest run599 passed | 3 skipped Windows files,sea-trialmock 19 passed | 1 skipped)pnpm run buildOAR_COMMUNITY_TESTS=1 pnpm exec vitest run tests/community/morph/morph-session.test.ts(19/19 passed)