Skip to content

feat(remote,host,mobile): continue any stopped reply; log slow commands; isolate test roots - #1412

Merged
huichen merged 19 commits into
mainfrom
pr/huichen
Oct 28, 2026
Merged

huichen merged 19 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

A reply the desktop's restart had interrupted could not be continued from the phone, a phone send could die as a generic "message failed to send" because a client-side projection still said the session was busy, and a desktop that answered a remote command slowly left no record of its own timing. This branch makes "why a reply stopped" information for the reader instead of a permission, records the desktop's half of every remote command, bounds the Agent's stop so a connected client cannot hold instance ownership, and makes the test fixtures isolate the whole FutureOS root instead of only HOME.

Commits

  • test(host): withdraw the FutureOS root too when a test needs "no home"
  • fix(remote): say when a history page is short of the requested exchanges
  • fix(mobile): a fatal client is rebuilt on recover, not probed forever
  • test(cli,host,agent,channels,rpc): move the FutureOS root, never drop it
  • fix(mobile): send, and say why, instead of guessing from local state
  • feat(remote): continue any reply that stopped, whatever the reason
  • fix(i18n): name an app restart as the reason a reply stopped
  • feat(host): record the desktop's half of every remote command
  • fix(remote): continue a reply an app restart interrupted
  • fix(agent): bound the shutdown's listener drain
  • test(agent,cli): a root the fixture owns and a port nothing else can take

Verification

Local pass at d7ef468a8 (rustc/clippy 1.99.1 from ~/.rustup, ulimit -n 8192), then re-checked at the merged tip 920602643:

  • cargo fmt --all -- --check — clean
  • cargo clippy -p future-agent -p future-channel -p future-cli -p future-host -p future-rpc --all-targets -- -D warnings — clean
  • cargo test -p future-agent --test shutdown_bounded — 3 passed
  • cargo test -p future-channel --lib config — 83 passed
  • cargo test -p future-cli --lib test_env — 3 passed
  • cargo test -p future-rpc --lib transport — 31 passed
  • cargo test -p future-host --lib -- command_diagnostics 5 passed, -- auth_store 13 passed
  • cargo test -p future-host --lib -- remote_host first reported 177 passed / 1 failed: pairing_path_requires_a_home was a real regression of the new HomeGuard (it publishes FUTURE_HOME instead of removing it, so the test no longer simulated a missing home). Fixed in 067c277e5; the full cargo test -p future-host --lib then reported 1847 passed / 0 failed / 11 ignored, and the single test is green at 920602643.
  • desktop: tsc --noEmit clean, eslint clean, vitest run MessageBlock.behaviour + agentMessageFormatters 45 passed
  • mobile: jest on useSendMessage / useComposerSubmission / TimelineCardMessage / usePromptOutbox 106 passed, tsc --noEmit clean
  • packages/thread-projection: vitest run 422 passed (16 files), tsc --noEmit clean
  • packages/remote-client: jest tests/recovery.test.ts 7 passed

Second local pass at 82f960916 after the CI findings below (cargo fmt -p future-agent -p future-cli --check clean, re-verified here):

  • cargo clippy -p future-agent --all-targets -- -D warnings and -p future-cli — both clean
  • cargo test -p future-agent --lib — test_support::env_restore_tests 2 passed (was deterministically red before the fix on Linux, macOS and Windows)
  • cargo test -p future-cli --lib — 1452 passed; the safari probe suite ran 40 consecutive rounds with 0 failures after the fix (it was red on Linux before)
  • Parallel-load noise seen locally on unrelated tests (recovery_is_ordered_after_already_accepted_appends, session_reset_tests) reproduces on the unmodified 920602643 tree as well, so it is pre-existing full-core load noise rather than this change.

Notes

  • continue_run now accepts a run that stopped without finishing — failed, or the cancelled row a restart leaves (error_type = interrupted). A completed run and one the user stopped themselves are still refused, and the refusal carries the stable continue_unavailable token so a client can name the reason.
  • The desktop writes a desktop.log row for every remote business command that took 1 s or more, or failed (remote command slow: / remote command failed:). Heartbeat commands never report, and the row carries no content — only type, session, elapsed time, reply bytes for binary pages, and the error string.
  • The phone no longer refuses or swallows a send over its own projection of whether the session is running; the desktop owns that truth and refuses an in-flight run before persisting, with session_busy.
  • Agent stop no longer waits on clients: the listener gets 500 ms of the five-second stop budget to drain gracefully and is then abandoned, so a connected peer can no longer retain instance ownership and block every later Agent start. A drain that still times out keeps the previous behaviour.
  • Test fixtures now point FUTURE_HOME at <temp>/.future rather than unsetting it, and HomeGuard::withdraw_home withdraws HOME, USERPROFILE and FUTURE_HOME together for tests whose subject is "no home". test_support::env_restore_tests asserts the moved root and its restoration, and the safari probe fixture now draws ports from test_env::reserved_port() — a band below every platform's ephemeral range — instead of binding :0 and racing other tests in the same binary.

huichen and others added 18 commits October 28, 2026 21:39
A stop reached its deadline at "RPC listener and streams" whenever a client
stayed connected — measured 2026-10-28 20:07: the Desktop's stop failed there,
the failure retained instance ownership for the life of the process (the
Desktop), and no Agent could start for ~40 minutes. Every scheduled task in
that window failed with "unable to connect", and a 48-minute run was cut off.

The wait was for Tonic's graceful shutdown, which only ends when every
connection ends. One peer that never finished its request was enough, and
nothing inside the service could bound it.

The listener's share of the stop is now decided by the drain, not the clients:
stop_listener keeps the graceful drain, wait_within gives it 500 ms of the
five-second budget, and abandon_listener makes the serving future drop the
server — closing the listener, its endpoint and every connection — so
server_running clears in that same poll and the stop finishes as Stopped.
A drain that still times out (a stuck storage write, a host that never polls
`serve`) keeps today's behaviour: instance ownership is retained.

The Desktop watchdog also stops skipping a refused recovery in silence; the
one state that still needs a process restart now says so, rate-limited.

Tests: agent/tests/shutdown_bounded.rs (a raw TCP client held open across the
stop: Stopped in ~520 ms, replacement service in ~30 ms) and the host fixture
`stalled`, which used to assert the opposite behaviour.
A run the desktop's startup convergence settles cancelled/interrupted was
refused by continue_run's source guard, which accepted only `failed`. The
failure text tells the user to restart and then click Continue, so on the
phone that button could never work — it answered "Only a failed run can be
continued." and the client showed its generic "message failed to send".

- host: a continuation source is a run that stopped without finishing —
  `failed`, or the `cancelled` row a restart leaves (`error_type =
  interrupted`). A completed run, and one the user stopped themselves, are
  still refused.
- host: refusal carries the stable `continue_unavailable` token (same
  pattern as `session_not_on_desktop`) so a client can name the reason.
- mobile: a refused continuation says the reply can no longer be continued
  instead of reading as a send/network failure.
A phone that reports a conversation load timeout leaves exactly one question:
was the desktop slow to answer, or was the relay slow to carry the answer? On
2026-10-28 that question was answered twice by guessing, and both answers were
wrong, because the desktop kept no record of its own execution time.

Measure every business command the desktop executes (`get_state`,
`get_session_entries`, `get_read_chunk`, `get_events_since`, ...) and write a
row into `desktop.log` when it was slow (>= 1 s) or failed:

    remote command slow: type=get_session_entries session=... elapsed=...ms
    remote command failed: type=get_state session=... elapsed=42ms error=...

Heartbeat commands never report. A phone timeout with no slow row here is a
transport symptom; a slow row names the exact read that was expensive. The row
carries the command's type, session, elapsed time, reply bytes (binary pages
only: measuring a JSON reply's size would serialize it for telemetry) and the
error string, never its content.

The sink decorator forwards both reply carriers: relying on the trait's
default `send_binary` would downgrade a negotiated binary page to
base64-in-JSON, which is a different wire shape from the one the connection
declared, so the carrier test runs in this change's own set.
A restart settles the run the app was in the middle of as
`cancelled`/`interrupted` with "Interrupted by application restart.", and
the shared classifier fell through to the generic `failure.run`, whose title
is "the model service failed". Nothing was wrong with the model, and the
advice underneath (retry the request) points at the wrong thing.

Classify it as its own outcome — "an app restart interrupted this reply,
click Continue to pick it up" — in the desktop's zh/en bundles and the
phone's, since both render from the one classifier.
Three surfaces each decided for the user whether a reply was worth resuming,
and none of them agreed on the shapes they accepted:

- host: continue_run's source guard took only a `failed` run, so the row a
  restart leaves (`cancelled`/`interrupted`) could never be continued — the
  one thing the failure text tells the user to do after a restart;
- desktop: the retry/continue row appeared only for `failed` and never for a
  stopped reply, and Continue was withheld for model-paused, content-filter
  and software-error failures;
- phone: the same predicate, plus a refusal whenever a stale "still
  streaming" flag was set — from the outside, one generic "message failed to
  send" for all of them.

The reason a reply stopped is information for the reader, not a permission:
the desktop's Continue has always been a plain prompt re-send, and `#1355`
retired the automatic resume, so a blocked button has no fallback path. The
guard is now identity only — a run that belongs to the addressed session —
and every client offers retry/continue on the latest reply that stopped
(failed, user-stopped, truncated).

Host: identity-only continuation test plus a command-level test that each
terminal shape reaches the Agent. Desktop and phone: the recovery rows and
their tests follow the same rule.
A phone send answered "message failed to send" and never reached the
desktop (no run row, no remote-command log). Two local gates can do that:
the outbox refused while its own `streaming` flag said the session was
busy, and the composer quietly dropped the submit when the timeline said
the same. That flag is a projection: it lags a run that already ended — a
missed terminal event, a socket that died mid-stream — and with automatic
resume retired (#1355) nothing ever clears it, so the session reads busy
forever and every message dies as a generic failure.

- the phone no longer refuses or swallows a send over its own idea of
  whether the session is running. The desktop owns that truth: a run still
  in flight is refused there *before* anything is persisted, and the
  refusal now carries the stable `session_busy` token (same pattern as
  `session_not_on_desktop` / `continue_unavailable`).
- one catch-all toast is replaced by the sentence that is true: still
  generating, connection dropped (including a transport timeout), pairing
  changed, a previous send not yet settled, a reply that cannot continue.
  The unknown remainder keeps "message failed to send".
- the in-flight lane and the physical limits stay: they are about this
  device, not about guessing the run.
`FUTURE_HOME` is not a second way to say `HOME`: the files follow either, but the
local endpoint is named from the override alone (an absent one resolves to the
untagged default socket/pipe). So a fixture that redirected `HOME` and *removed*
the override had isolated files and nothing else — its auth.json assertions passed
while the process still reached the developer's running Agent, and any path the
fixture printed looked isolated.

Every isolation helper now points the root at `<temp>/.future` instead of
unsetting it: `cli::test_env::EnvGuard` (both `set` and `with_temp_home`),
`host::auth_store::test_support::HomeGuard` (which the Desktop's wrapper
delegates to), `agent`'s `TestHome`, and `channels`' `IsolatedHome`. That value is
what "override absent + this HOME" already resolved to, so no path assertion
changed.

`EnvGuard::set` also derives it, because that constructor is what the ~130 cli
fixtures that keep their own `Home`/`Fixture` structs go through: with an ambient
override in the developer's shell, those wrote their app database, workspaces and
task store into the real `~/.future`. A decoy override run of `cargo test -p
future-cli --lib` proved it — 70 failures, every one an ambient-clean assumption —
and the same run is now 1358/1358.

`cli/tests/golden-diff.sh` exports `FUTURE_HOME="${HOME}/.future"` and clears
`FUTURE_AGENT_SOCKET`. All 15 goldens that embed a path name
`<case_home>/.future/...`, so the value reproduces them byte-for-byte.

Two ambient-dependent assertions are pinned rather than relaxed, since they only
held on a machine with no override:
`browser::screenshot_writer::browser_dir_honors_future_home_env` now names the
home it derives from instead of reading `dirs::home_dir()`, and
`channels::config::default_path_contains_channels` now asserts the path is under
the fixture's own root.

New guards, both directions:
* `packages/rpc` `local_pipe_name_moves_with_the_future_home_override_and_not_with_home`
  — with the override the pipe carries the home tag; `HOME` alone leaves it the
  untagged default (the running Agent's name). Names only, nothing is bound.
* `host` `a_live_home_guard_redirects_the_future_home_root_it_created` — deleting
  the one line that fixes the guard turns it red.
* `cli` `set_redirects_the_future_home_root_with_the_home_it_redirects` — an
  ambient value is replaced while the guard lives and restored on drop, and an
  explicit `FUTURE_HOME` is still the caller's decision.
A fatal RemoteClient is terminal by design: `transition` keeps it in `failed`
and `assertBusinessReady` answers `communication_frozen` to every request, so
a conversation stops opening and a prompt stops sending. The state machine's
own answer is "a manual reconnect creates a fresh RemoteClient" -- but the
phone only ever called `connect()` at bootstrap, so nothing in the app could
perform that manual reconnect. `recoverNow` returns immediately for a terminal
client, and the timeline's Retry called exactly that. The only way out was to
kill the app, which is what the user reported doing.

The runtime's recovery now reads `client.connectionState` (a new public
getter) and rebuilds the client with the same credentials when it is `failed`;
a `revoked` pairing still waits for a fresh pair, as before. The timeline's
Retry goes through that runtime recovery instead of `client.recoverNow`, so
the button reaches the branch that can actually heal the connection.

A recovery skipped because AppState says the app is not active is now logged
too: that is the other state an app restart used to be the only way out of,
and a log line turns it from a spinner into evidence.

Measured: the new mobile test fails without the rebuild branch (`recoverNow`
is called and no new client is created), and the lifecycle test proves a fatal
open leaves `connectionState === "failed"` with `recoverNow` a no-op.
The phone opens a conversation with a backward read for three user
exchanges. It can be answered with fewer: the byte budget sheds whole oldest
exchanges, and the Agent itself cuts a backward read at its own row and byte
limits (64 display rows), so a tool-dense exchange comes back as a fragment.
`trimmed` reported only the first bound, so a page shortened by the second
arrived looking complete.

Measured 2026-10-28 on session 4a107f50 (213 display rows, three exchanges,
the newest a 15-minute run with 50 tool calls), replaying the shipping path
against the live Agent:

- the tail read returned 64 tool rows with no prompt among them;
- history assembly completed that prefix back to its prompt, so the
  delivered page was one exchange of 870 KB with `hasMore: true` and
  `trimmed: false` — the byte budget had nothing left to shed, because only
  one exchange was there;
- the phone installed it as the whole window: the transcript drew the newest
  reply with nothing above it, and a pull-to-refresh re-read the same page,
  which is exactly what the user reported.

`mark_short_backward_page` closes the gap in the contract the client already
implements: a page holding fewer user exchanges than were requested, with
more history behind it, says `trimmed` however it was shortened, and the
client backfills to the window it asked for. A page with nothing behind it,
and a page the caller asked to keep whole, stay unmarked. Replaying the same
session with the flag set gives the phone the three exchanges it asked for
(212 rows, 4.9 MB over three reads) instead of the last question and answer.
`HomeGuard` now publishes `FUTURE_HOME` at `<temp>/.future` so that a fixture
isolates the whole FutureOS root and not only its files. Eight host tests still
produced "no home" by removing `HOME`/`USERPROFILE` under that guard, and the
override kept answering with a real root: `pairing_path_requires_a_home` failed
outright (`pairing_path()` resolved the fixture root), and the rest had
silently degraded into their ordinary-case arm — `unpair` persisted when the
persist was supposed to fail, `load_creds()` reported "no pairings" instead of
an error, and the agent-credentials guard, the chat-scratch root and the
preview-cache root all resolved.

`HomeGuard::withdraw_home` withdraws every way to name a root — `HOME`,
`USERPROFILE` and `FUTURE_HOME` — for the rest of the guard's life, and
`restore` puts all of them back; `USERPROFILE` is saved now too, so a Windows
run no longer leaves it cleared. The tests use it instead of one-off
`remove_var` plumbing, and each asserts its premise (`future_dir()`,
`chat_workspaces_root()` or `remote_previews_dir()` must fail), so none of them
can pass while a root still resolves: dropping the `FUTURE_HOME` line from the
fixture turns all nine red, the new guard self-test included.

Left alone, because their subject is a guard's own restore arm rather than a
product path resolution that needs "no home": `fixture_drop_removes_home_when_unset_before`,
`channels::isolated_home_without_prior_home_removes_it`, and the
`None => remove_var` arms themselves.

Verified: `cargo test -p future-host --lib` 1847 passed / 0 failed / 11 ignored,
`-- remote_host` 178 passed, `-- auth_store` 14 passed, `cargo fmt --all --
--check` and `cargo clippy -p future-host --all-targets -- -D warnings` clean.
@huichen
huichen enabled auto-merge (squash) October 28, 2026 14:56
…take

The agent fixture now moves the FutureOS root into its own home instead of
dropping an inherited override, but
`test_home_isolates_and_restores_an_inherited_future_home` still asserted the
old semantics, so `TestHome::new()`'s own `FUTURE_HOME` failed the test on
every platform. The test now asserts what the fixture does: the override is
replaced by `<canonical home>/.future` and differs from the inherited value,
`future_home()` follows it, and dropping the fixture restores the inherited
override for both the env var and the resolver.

The safari probe-budget test asked `bind("127.0.0.1:0")` for a free port and
dropped the listener, which only proves the port was free at that instant:
another fixture's `:0` bind can be handed it before the driver is asked to
listen, and the poll then meets a stranger's mock instead of silence
(`No sessionId in createSession response: {}` on CI). Test ports now come from
`test_env::reserved_port`, a band below every supported platform's ephemeral
range, proved free and handed out once per process, so no `:0` bind can claim
it.
@huichen
huichen merged commit 684a4fd into main Oct 28, 2026
80 of 82 checks passed
@huichen
huichen deleted the pr/huichen branch October 28, 2026 17:19
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