Skip to content

fix(morph): emit queued: "adapter", carries on drain, and map non-400 stopTask errors - #1249

Open
m3lonxd wants to merge 2 commits into
botiverse:mainfrom
m3lonxd:fix/morph-queue-and-stoptask-1069
Open

m3lonxd wants to merge 2 commits into
botiverse:mainfrom
m3lonxd:fix/morph-queue-and-stoptask-1069

Conversation

@m3lonxd

@m3lonxd m3lonxd commented Nov 28, 2026

Copy link
Copy Markdown

Closes #1069

Summary

  • 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 toRuntime prompt 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)

@stamp-build

stamp-build Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

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

  1. 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:

    delete next.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.
  2. 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.

  3. 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 →

@m3lonxd

m3lonxd commented Nov 28, 2026

Copy link
Copy Markdown
Author

Addressed all 3 review findings in commit 38082e46:

  1. 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.
  2. 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.
  3. 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).

@stamp-build

stamp-build Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

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)
  • OAR_COMMUNITY_TESTS=1 vitest run: passed (599 passed | 3 skipped (602) files, 5915 passed | 114 skipped (6029) tests; tests/community/morph/morph-session.test.ts 22/22)
  • 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 →

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.

community(morph): adapter-held queue omits queued:'adapter' and carries, and stopTask maps 5xx to runtime_refused

1 participant