Skip to content

test(claude): give claude time to see the --once stdio server exit before restarting it - #374

Merged
xxchan merged 1 commit into
mainfrom
lookout/claude-mcp-config-restart-latency
Oct 12, 2026
Merged

xxchan merged 1 commit into
mainfrom
lookout/claude-mcp-config-restart-latency

Conversation

@xxchan

@xxchan xxchan commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Test-only. No release needed.

Problem

sea-trial/vendor/claude-mcp-config.vendor.test.ts failed twice on macOS on 2026-10-12, with the same missing echo both times:

-   "echo:restarted-stdio via=stdio token=…",

The other three echoes arrived.

Cause

The stdio echo server runs with --once: it exits right after answering its first call. The third step calls it again, so claude has to restart it. If claude sends that call before it has noticed the exit, the call goes to the exiting process. claude answers the tool call with "Connection closed" (is_error: true) and does not restart the server for it. On Linux claude notices the exit before the next call; on macOS it sometimes does not.

Change

EchoStep gets an optional delayMs: how long the model waits before replying with that step's call. It is implemented as aimock's streamingProfile.ttft, which adds a one-time delay. aimock's latency would apply the delay to every streamed chunk.

The restarted-stdio step uses delayMs: 1500. The test still proves what it is for: claude restarts the server and the restarted server gets its credential.

Other users of echoFixtures are unchanged. The field is optional.

Evidence (Linux, real claude 2.1.296, aimock, no account)

To mimic a runtime that notices the exit late, I used a local, uncommitted patch to tests/fixtures/echo-mcp-server.mjs. With it, the server exits 300 ms or 1000 ms after its answer instead of right away.

Server exits Without this change With this change
right away (fixture as committed) passes (6 of 6 runs) passes (about 4.2 s vs 3.0 s)
300 ms late fails in 11 of 12 runs: the third call gets "Connection closed" and restarted-stdio is missing, as on macOS CI passes in 8 of 8 runs
1000 ms late fails in 5 of 5 runs passes in 5 of 5 runs

Lint (oxlint --type-aware --deny-warnings on both files), pnpm run typecheck, and the whole vendor file with OAR_TEST=claude-aimock (2 of 2) pass.

🤖 Generated with Claude Code

…fore restarting it

The claude --mcp-config vendor test failed twice on macOS (main 8e4c5e4,
and a #355 branch run) without "echo:restarted-stdio". The --once stdio
echo server exits right after its first answer. When claude sends the
next call to it before noticing that exit, the call gets "Connection
closed" (is_error) and claude does not restart the server for it.

The model's reply that makes the restart call now waits 1.5 s (aimock
time to first token), so the test still proves that claude restarts the
server and hands it its credentials.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xxchan
xxchan merged commit 8a45045 into main Oct 12, 2026
17 checks passed
@xxchan
xxchan deleted the lookout/claude-mcp-config-restart-latency branch October 12, 2026 11:02
stamp-build Bot added a commit that referenced this pull request Nov 20, 2026
…or, DSH, Factory, and Pi Durable (#1070)

<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/ZXll.svg"
width="16" height="16" align="absmiddle" alt=""> <b>Lookout</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_2f47dc7fecca6e2c6e48943e85683c53"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

## Summary

Fix the runtime-specific `steer` and `abort()` issues assigned in
`#core:#375` (from the `#agy-soak:046f9f1b` audit, re-verified against
`main` `94e43d10`), plus the corresponding Decisions 2, 3, 4, and 5
requirements on those runtimes.

Community Morph was not modified; filed low-priority issue #1069
instead.

## Per-Item Verification & Changes

- **B.3 Pi RPC (`packages/oar/src/runtimes/pi/rpc/session.ts`):**
- Disarm the 10 s `fallback` timer when `{ type: "abort" }` returns `{
success: false }` (`pi/abort_rejected`), instead of discarding the
disarm handle and killing the live process 10 s later.
- Track `exitSettled` from `rpc.child.onExit` and await it in
`kernel.dispose` (both active release and `afterExit`) so a `dispose()`
racing with process exit never leaves a dangling `dispose` request.
  - Regression test: `tests/pi/pi-rpc-abort-dispose.test.ts`.
- **B.6 Factory manual compaction `abort()` (already fixed on `main`
`94e43d10`):**
- Verified `packages/oar/src/runtimes/factory/session.ts:256` already
rejects `busy` when `compaction.busy()` is true. No change needed.
- **B.7 Factory abort refusal rollback
(`packages/oar/src/runtimes/factory/session.ts`):**
- Roll back `abortingTurn = false` in `factory/session.ts` when
`droid.interrupt_session` fails/refuses (Decision 4), so a subsequent
retry still reaches `droid`.
- Regression test: `tests/factory/factory-session.test.ts`
(`refuse-interrupt` mode in `tests/fixtures/fake-droid.mjs`).
- Note: per review, the shared `observe/` status/busy rule for
`queued_message_handed_back` (a late end or drop for a non-current turn
must not move `status()`) moves to `#core:#374`.
- **B.8 Cursor `abort()` (`packages/oar/src/runtimes/cursor/session.ts`,
`packages/oar/src/runtimes/cursor/run.ts`, `docs/runtimes/cursor.md`):**
- **B.8a + Decision 4:** Extracted `cancelActiveRun` in `cursor/run.ts`
to catch `run.cancel()` rejections (classifying a late-cancel race after
run end as `no_active_turn` and a live native refusal as
`runtime_refused` instead of `error`), bound `abort()` at 10 s
(`abortTimeoutMs`), arm a 10 s subprocess `createAbortFallback` that
stops the subprocess if the run ignores cancel, and bound `run.cancel()`
in `dispose()` under `DISPOSE_SETTLE_MS`.
- Documented the in-process 10 s timeout limitation in
`docs/runtimes/cursor.md`.
- **B.8b (verified intentional by spec):**
`docs/spec/manual-compaction.md:154-155` and
`tests/cursor/cursor-manual-compaction.test.ts:115-130` explicitly
specify that Cursor accepts an early cancellation before `summarize()`
supplies the run and applies it when the run arrives. Left unchanged.
  - Regression tests: `tests/cursor/cursor-abort-edge-cases.test.ts`.
- **B.9 Pi SDK `abort()` in `agent_end` to `agent_settled`
(`packages/oar/src/runtimes/pi/session.ts`):**
- Verified against installed `@earendil-works/pi-coding-agent`
(`AgentSession.abort()` calls `abortRetry()`, `abortCompaction()`,
`abortBranchSummary()`, and sets `_abortDuringBeforeSettle` while
`isStreaming` is `false`).
- Changed the active-run check from `piAgentSession.isStreaming ||
compaction.busy()` to `nativeActive || piAgentSession.isStreaming ||
compaction.busy()`, matching `pi/rpc/session.ts:207`.
- Updated `tests/pi/pi-turn-preflight.test.ts` to assert `abort()` calls
native `abort()` once during `agent_end -> agent_settled` without
leaking onto the next run.
- **B.10 Codex `abort()` refusal
(`packages/oar/src/runtimes/codex/session.ts`, `refusal.ts`):**
- Routed `abortPlan.onError` through `codexControlRefusal(message,
native)` so `turn/interrupt` preserves `session_not_found` (`-32600
thread not found`), `failure` (for example `-32001` `overloaded`), and
`native`.
- Regression test: `tests/codex/codex-abort-refusal.test.ts` (and
updated `tests/codex/codex-session-stream.test.ts` to expect `native`).
- **B.11 DSH RPC exit and fallback ordering
(`packages/oar/src/runtimes/dsh/control.ts`, `session.ts`):**
- Tagged exit rejections in `dshControl` (`isDshExitedError`) and mapped
them to `code: "runtime_exited"` (not `"error"`) in `dsh/session.ts`.
- Moved `fallback.clear()` before `kernel.frame(...)` on root
`turn_ended` so a synchronous observer's new turn abort fallback is
never cleared by the prior turn's end.
- Checked `!active() && !prompting` before `withInputImages` in `steer`
so idle `steer` with images answers `no_active_turn` before
`unsupported` (Decision 3).
  - Regression tests: `tests/dsh/abort-and-exit.test.ts`.
- **B.12 Pi Durable (`packages/oar/src/runtimes/pi-durable/session.ts`,
`projection.ts`, `docs/runtimes/pi-durable.md`):**
- Check live running state (`await flush()` + `liveOf(state.view).run ??
liveOf(observation.value).run`) before image validation (Decision 3) and
before duplicate-`inputId` idempotency on `steer` (B.12a), and await
`admissions` + `flush()` in `abort()` so immediate post-`prompt()`
`steer`/`abort` agree with `status() === "running"` (Decision 2 /
B.12b).
- Pass `whenIdle: "reject"` on `steer` and map native `ConversationIdle`
to `no_active_turn` (preserving `ConversationBusy` as `runtime_refused`
when locally idle per `pi-durable-watch.vendor.test.ts`).
- Separate `conversation.submit()` from `submission.status()` error
handling so a status-read failure after a durable commit records
`pi-durable/submissions_error` and still returns `accepted` (B.12c).
- Bound `abort()` at 10 s (Decision 4) and document the in-process
timeout behavior in `docs/runtimes/pi-durable.md`.
- Observe unplaced `pi.inbox` removals whose native receipts settle
`unanswered` with `reason: "aborted"` (excluding explicit `withdraw()`)
and emit `input_dropped` with `reason: "turn_interrupted"` (Decision 5).
- Updated `docs/runtimes/pi-durable.md` and added
`tests/pi-durable/controls.test.ts`.

## Call-Site Audit

- **`codexControlRefusal`
(`packages/oar/src/runtimes/codex/session.ts`):** Checked all 4 control
plans (`promptPlan`, `steerPlan`, `queuePlan`, `abortPlan`); all 4 now
route through `codexControlRefusal(message, native)`.
- **`createAbortFallback`:** Checked all 6 call sites across
`packages/oar/src/`:
- Changed: `pi/rpc/session.ts` (capture and call `disarm()` on refusal),
`cursor/session.ts` (added subprocess fallback + bounded cancel),
`dsh/session.ts` (clear before `kernel.frame`), `factory/session.ts`
(roll back `abortingTurn` on refusal).
- Unchanged (owned by Otter `#core:#374`): `shared/abort-fallback.ts`,
`shared/stream-json/session.ts`, `shared/acp/turns.ts`, and `onFallback`
requirement on Factory/DSH `arm()`.
- **Community runtimes:** Untouched; Morph tracked in #1069.

## Verification

- Local `CI=1 pnpm run check`: typecheck, oxlint (0 warnings), vitest
(`583` files / `5,510` tests passed), and mock sea-trial (`19` passed,
`1` skipped, `0` failed), plus `OAR_TEST=pi-durable-aimock`
`sea-trial/vendor/pi-durable-watch.vendor.test.ts` (`9` passed).

---------

Co-authored-by: Lookout <[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.

1 participant