Skip to content

fix(host): survive transient readiness stalls on loaded hosts - #1315

Merged
ace331 merged 9 commits into
mainfrom
pr/dev-ace331
Oct 23, 2026
Merged

ace331 merged 9 commits into
mainfrom
pr/dev-ace331

Conversation

@ace331

@ace331 ace331 commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Why

On an HPC login node the headless host exited on its own:

FutureOS: Agent readiness could not be verified: handshake timed out; local startup is forbidden

There was no received SIGINT/SIGTERM/SIGHUP line and the remote bridge was healthy (normal credential rotation, no authorization violation); the exit came from the local Agent supervision loop. probe_local_agent classified a single readiness-handshake timeout — ConnectionError::Unverified("handshake timed out") — as Blocked, and every entry point treats Blocked as final. The host's data root (session database, credential store, log file, IPC socket) lives on a hard-mounted NFS home there, so a transient stall longer than the 2 s handshake deadline was enough to end the process; with nothing supervising it, the machine then stayed offline.

Changes

  • fix(host): give the headless runtimes five workers (9603307)
    • The host runtime and the embedded-Agent runtime go from worker_threads(2) to 5 through one shared RUNTIME_WORKER_THREADS.
    • Two workers could both be parked in synchronous I/O on the data root, leaving the runtime unable to poll the readiness deadline even though the Agent itself was healthy.
  • fix(host): retry a transient readiness probe with backoff (5c8d7bb)
    • probe_local_agent retries Unverified answers up to READINESS_PROBE_ATTEMPTS (3) with 250 ms / 500 ms / 1 s backoff, each attempt on a fresh connection and a fresh deadline.
    • Definite answers (version/protocol mismatch, changed instance identity, refused start) are still reported immediately as Blocked.
    • Unit tests cover the backoff curve, the retryable classification, retries until giving up, no retry for definite answers, and recovery on a later attempt.

Verification

  • cargo fmt -p future-rpc -p future-cli --check
  • cargo clippy -p future-rpc -p future-cli --all-targets -- -D warnings
  • cargo test -p future-rpc --lib: 226 passed. One environment-dependent test (transport::tests::an_endpoint_that_never_answers_is_bounded_by_the_connect_budget) fails identically on an unmodified main checkout on this machine because TEST-NET addresses are accepted through the local proxy; it is unrelated to this change and was skipped locally.
  • python3 scripts/docs/check-docs.py: 321 docs OK.

Behavior change

A single stall longer than 2 s no longer ends the host; only three consecutive failed probes (~7 s of unresponsiveness, including backoff) still report Blocked and exit. Running the host under a supervisor (Restart=always) and keeping the data root off a stalled NFS share remain recommended operational hardening.

A conversation whose journal shows no open run is the normal case, but the
startup recovery pass returned it as `Err("no interrupted run")` and logged
one line per conversation on every start; the summary then labelled the
candidate count "interrupted and eligible", so a healthy data root read as if
eight conversations needed attention. On a machine where `future tui` hosts
the Agent in-process those lines were written straight onto the TUI's
alternate screen.

- `resume_one` returns an `Outcome` (`Continued` / `NotInterrupted` /
  `Held`) so a finished conversation is a silent skip instead of a failure;
  `Err` is reserved for a real journal or session read failure
- the pass keeps a tally and emits one summary line only when something was
  interrupted, reporting checked / interrupted / continued / left
  interrupted / failed / skipped honestly
- the stale "default off" wording is corrected and the duplicated doc block
  on `resumeInterruptedOnStart` is folded into the one that says on by
  default

Tests cover the healthy (silent) start, the tally/summary, and that a
finished conversation settles as `NotInterrupted` without calling the model.
`future tui` may host the Agent in its own process, so `eprintln!` from the
Agent and from the TUI's own supervisor is written to the terminal the TUI
owns. Raw mode clears OPOST, so `\n` no longer returns to column 0; and the
diff renderer never reads the screen back, so an external write staircases
across the frame and the rows it paints afterwards land on the wrong ones.
The witness was the startup recovery pass: one line per conversation over a
freshly painted welcome screen.

- `stderr_log` points fd 2 (POSIX) / the stderr handle (Windows) at
  `~/.future/tui/stderr.log` for as long as the alternate screen is up, and
  hands the real stderr back when the terminal is released
- the crash hook restores stderr first, so its teardown sequences and the
  panic note still reach the terminal instead of the log; the signal failsafe
  and `Drop` restore it too
- home the cursor when entering the alternate screen: terminals that keep the
  cursor row across `1049h` (tmux, for one) would otherwise shift the whole
  first frame down by the lines printed before the screen was taken
- tests: capture/restore/double-restore, the temp-path wiring through
  `Terminal::start`/`stop`, and the default path under `~/.future/tui/`
A manual-approval run pushes a `System` row ("Allowed: Approve shell
command") into the transcript between a tool call and the text that follows
it. The assistant-text helpers only treated a trailing `Tool` message as the
start of a new assistant message, so the answer was appended to the run's
opening assistant message — above the tool calls and approval rows that
produced it. The user sees the final result at the top with the activity
below it.

- `append_to_last_message` and `update_last_message` start a new assistant
  message when the transcript tail is this turn's activity (`Tool`/`System`);
  a queued `User` prompt still belongs to the next turn and does not split
  the running one
- regression tests at both layers: the chat-area ordering and the app's real
  event sequence (agent_start → tool → "Allowed" row → text_chunk →
  agent_end)

Measured on a `[manual]` HPC session: the partition table answer rendered
above the `read`/`sinfo` calls and their approval rows.
The host and embedded-Agent Tokio runtimes ran two workers each. The host runtime carries the session loop, the readiness probe, the remote bridge and the store; synchronous file I/O on the data root (session database, credential store, log file - an NFS home on a server) can park a worker in an uninterruptible write. With both workers parked the runtime cannot poll the probe's deadline, so a healthy Agent was reported as a timed-out handshake. Five workers keep the loop and the probe running while several blocking operations are in flight. The stack size and blocking-pool limits are unchanged.
probe_local_agent classified every non-transport failure as Blocked, including ConnectionError::Unverified("handshake timed out"), and every entry point treats Blocked as final. One probe whose 2 s deadline expired while the process was descheduled (a CPU quota on a login node, a page-fault storm, a synchronous write into a stalled shared home) therefore ended the host even though the Agent answered as soon as the process ran again. Retry Unverified answers up to READINESS_PROBE_ATTEMPTS (3) with 250 ms/500 ms/1 s backoff, each attempt on a fresh connection and deadline; definite answers (version/protocol mismatch, changed instance identity, refused start) are still reported immediately. The retry helper and the backoff/classification policy are unit-tested.
@ace331
ace331 enabled auto-merge (squash) October 23, 2026 03:39
@ace331
ace331 merged commit e1d5276 into main Oct 23, 2026
37 checks passed
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