Skip to content

fix(server): make the upstream harnesses deterministic and require them in check - #311

Merged
opficdev merged 7 commits into
mainfrom
fix/harness-flakes
Dec 5, 2026
Merged

opficdev merged 7 commits into
mainfrom
fix/harness-flakes

Conversation

@opficdev

@opficdev opficdev commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Makes every upstream differential harness (crates/server/tests/own_*.rs) deterministic and moves the harnesses job into check. Follows up the flakes listed in #308.

Each flake, its cause and its fix

Harness Cause Fix
own_forks, own_imports, own_switch, own_rollback Once the provider took the prompt, the start records the context-handoff.updated it delivered while the session stream ingests the turn's first events. Either lands first, in upstream as in own mode. The table dump puts such a handoff ahead of the ingested events it landed among (harness::order_delivered_handoffs). Every other event keeps its place.
own_requests The "accept again" receipt was sent 300 ms after the accept, so its result sequence depended on timing. Pending requests were read before their card was written. The second answer goes after the next pending request. pending() waits for the request together with its waiting card.
own_agent_threads, own_fresh, own_recovery An approval could land between the runtime request's write and its card's, which left upstream's card waiting. The harnesses wait for the card.
own_limit_stop, own_steering They relied on the Replay agent's 250 ms between frames to Stop or steer mid-turn. fixtures/hold-replay-agent.mjs proxies the Replay agent, and its turns hold at their plan (HOLD_AFTER_PLAN) or before their first frame (HOLD_FROM_START) until the client cancels. own_steering now runs.
own_turns, own_background_work, own_subagents, own_requests A thread watcher's snapshot raced the first message, and the watcher stopped after a fixed sleep. harness::watch_thread waits for the snapshot and stops once it saw the thread's last stored event.
own_background_work The fake Claude CLI reported a tool_use and ran its MCP tool at the same time. The fake runs the tool first, then reports the call.
own_workspace::terminals (Linux) Each stream chunk has to be acked before the server sends the next. The harness wrote to the terminal with a plain call on the socket that carried the terminal's stream. When bash's first prompt landed during that write, the call dropped the chunk without acking it, and the stream stopped. harness::call_beside reads and acks the stream while the call waits. The test now takes 5 s instead of timing out at 30 s.
own_commands A real own-mode regression from #284: /compact on a session without thread.compact publishes a failed terminal for a turn that never started. Run routing then dropped that terminal, because it was not the root provider turn, so the run never ended. See below. The harness runs again.
own_manual_continuation, own_mcp_sessions Each failed once (usage at Stop; one run not settling). Neither failed again in about 20 CI runs or 10 local passes. No change. Without retries, another failure shows in check.

/compact in own mode

As in upstream, a run whose turn could not start now ends with its failedProviderTurnId. That is the attempt's provider turn, or one named for the failed attempt (ids::failed_provider_turn). Run routing accepts that turn's terminal as the end of the root turn.

CI

  • harnesses is in check's needs.
  • It runs on 10 Linux runners. The macOS shard is removed.
  • Each runner builds only its share's test targets, in the background while upstream restores.
  • Each runner runs its share longest first, two at a time, split by the measured times.
  • pnpm sets up only when upstream is not cached.
  • There are no retries, and no harness is skipped.
  • A change to tern-server now waits about 150 s for check: the harness jobs took 137 to 172 s on the final head's three runs. Before, the harnesses alone took 200 to 270 s per Linux shard and 360 to 511 s on macOS. The floor comes from:
    • the longest harnesses, about 75 s each;
    • upstream's cache restore, about 35 s.
  • docs/ci.md describes the required jobs, what keeps the harnesses still, and what stays manual.

Verification

  • 10 local passes of the harnesses above, with a scratch HOME, TERN_KEYCHAIN=off and Node 26.13.1, all passed. The last passes include own_workspace::terminals.
  • cargo fmt --all, cargo clippy --workspace --all-targets --locked -- -D warnings and cargo test --workspace --locked (1,460 tests) all pass.
  • check passed three runs in a row on the final head.

🤖 Generated with Claude Code

opficdev and others added 5 commits December 6, 2026 02:46
`/compact` after a turn never ended in own mode since #284: the Replay
agent's session has no `thread.compact`, so the start publishes a failed
`turn.terminal` on the session's stream, and the routing #284 ported
takes a terminal only for the run's root provider turn, which no turn
reported yet. The run waited for a terminal it had dropped.

Upstream settles such a run with that terminal directly
(`makeFailedTerminalEvent`), without routing it. The run now takes the
terminal that names its failed provider turn, which is the attempt's own
or one named for the failed attempt (`failedProviderTurnId`), as the
start now names it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The differential harnesses compared states that depended on which of
two concurrent writes came first, or on how long a busy runner took:

- A turn's start records the context handoffs it delivered once the
  provider took the prompt, while the session's stream ingests the
  turn's first events; either lands first, in upstream as in own mode.
  Table dumps now put such a handoff ahead of the ingested events it
  landed among (own_forks, own_imports, own_switch, own_rollback).
- A runtime request's node, the request and its card are written one
  by one; a harness answered once the request was there, sometimes
  before its card. It now waits for the card (own_agent_threads,
  own_requests, own_fresh, own_recovery), and answers a request again
  once the next one waits, not 300 ms after the first answer.
- Steering and Stop into a Replay turn counted on the agent's next
  frame coming 250 ms after the plan. fixtures/hold-replay-agent.mjs
  puts upstream's Replay agent behind a proxy whose turns hold at their
  plan, or before their first frame, until the client cancels them
  (own_steering, own_limit_stop).
- A `subscribeThread` watcher returned before its snapshot was taken,
  so the snapshot held what the next message wrote or not, and stopped
  500 ms after the last turn. It now waits for the snapshot, and stops
  once the stream carried the thread's last event (own_turns,
  own_requests, own_subagents, own_background_work).
- The fake Claude CLI reported its MCP tool call before running it, so
  the link the tool writes and the call's items raced. It now runs the
  tool first (own_background_work).

own_workspace's tests log the bridge, which hosts the terminals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The harnesses no longer depend on the runner's timing, so `check` needs
them. A harness that fails fails the run, with no second try, and the
ones skipped for being broken run again: own_commands, own_steering,
and own_workspace::terminals on Linux.

Each shard now reads its tests from the sources and builds only their
targets, in the background while it restores upstream, so it does not
build all forty test binaries after the restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to it

A stream sends its next chunk only once the client acknowledged the last.
The terminals harness wrote to a terminal with a plain call on the socket
that carried the terminal's stream, so when the shell's first prompt landed
during the write, the call dropped it unacknowledged and the stream stopped:
on Linux, where bash prints its prompt later than zsh, the echo never came.
call_beside reads and acknowledges the stream while it waits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
opficdev and others added 2 commits December 6, 2026 03:26
Each runner runs its share longest first, so short harnesses fill in
beside the long ones, and the table holds the times measured on CI
with the harnesses that now wait on conditions. pnpm sets up only when
upstream has to be installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@opficdev
opficdev marked this pull request as ready for review December 5, 2026 19:10
@opficdev
opficdev merged commit eccf0b6 into main Dec 5, 2026
60 checks passed
@opficdev
opficdev deleted the fix/harness-flakes branch December 5, 2026 19:10
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