Repository navigation
feat(tui,cli): host Agent in-process;pair remote desktops from the terminal - #1288
Merged
Merged
Conversation
…it cannot
A `FUTURE_HOME` longer than 88 bytes (macOS; 92 on Linux) could not start an Agent
at all. The endpoint is `<home>/run/agent.sock`, and `sun_path` holds 104 bytes
there, so startup died at "binding the gRPC endpoint" with the message
`path must be shorter than SUN_LEN` — which names neither the setting nor a way
out. Measured with `UnixListener::bind` at 103/104/106 bytes: `InvalidInput`,
`raw_os_error=None` (std refuses before the kernel), so this is neither `EPERM`
nor `ENAMETOOLONG`. This is not a rare shape: the repo's own
`.worktrees/<name>/target/test-homes/...` reaches 106 bytes.
C — a short endpoint, only where the old one cannot exist:
- The path is computed as before; it is relocated only when it does not fit the
103-byte limit. Every home that can bind keeps exactly the layout it had, byte
for byte (`a_home_that_fits_keeps_the_layout_unchanged`).
- The fallback is `/tmp/future-<uid>/<hash16>.sock`, recomputable from
`(uid, wanted)` with no randomness or timestamp, so two processes deriving it
independently get the same string (`a_home_too_deep_gets_a_recomputable_short_endpoint`).
- `/tmp`, never `$TMPDIR`: on macOS `$TMPDIR` is per-session, so a launchd-hosted
Agent and a terminal client could compute two different endpoints for one home.
`/tmp` is spelled the same way by both (it is a symlink to `/private/tmp`;
neither side resolves it). Measured: three different `TMPDIR` values all yield
`unix:///tmp/future-501/3913bf89c6031845.sock`.
- An explicit `FUTURE_AGENT_SOCKET` is used verbatim and never relocated: silently
moving a path somebody named by hand is worse than letting bind refuse it.
- Compatibility is structural rather than a probe: the homes that get relocated
are exactly the ones the previous release could not bind, so no old Agent can be
serving there. A home that fits keeps the old path, so an old Agent still
serving it is found as before.
Anti-squatting, because `/tmp` is world-writable: `/tmp/future-<uid>` is checked
with `lstat` — not a symlink, a directory, owned by our uid, mode 0700 — and any
failure refuses startup with the reason instead of repairing it (`chmod`-ing
somebody else's directory is the attack, not the fix). Verified live: a
pre-created symlink and a 0755 directory are both refused with actionable text
("remove it…" / "run `chmod 700 …`"), and a normal 0700 directory still serves.
The check runs in `LocalEndpointReservation::acquire`, which is the path the Agent
actually takes — the first attempt put it only in `bind_local_at` and every case
passed, because that function was never reached.
E — the message: an endpoint that still cannot fit reports its byte count, the
limit, and two ways out (shorten `FUTURE_HOME`, or set `FUTURE_AGENT_SOCKET`).
Verified end to end with a 103-byte home (old endpoint 118 bytes, so the previous
build could not bind it): the Agent listens on
`unix:///tmp/future-501/3913bf89c6031845.sock`, `future session list` against that
home answers, and the directory is `drwx------`. Unit tests cover the limit
boundary, the unchanged short-home layout, the verbatim explicit override,
recomputability, per-home distinctness, and each squatting refusal; rpc 221 pass,
agent 2479 pass, fmt and clippy clean.
Reverting this means restoring the two lines in `local_socket_path_from`.
**Stop any Agent running on the new layout first**: an old binary looks only at
the in-home path, so it would find the lock held with no visible endpoint and
report a failure that looks like the revert itself broke something.
The TUI now runs the Agent in its own process, the way `future headless` and the desktop do. The Agent is no longer a child of the terminal, which removes the whole class of problems a child brought: a terminal signal killing the Agent, a zombie holding the endpoint, pipes that had to be drained so a chatty child never blocked, output that had to be quoted back in a failure report, and — the reason this matters most — the Agent dying whenever the terminal window closed while another client was relying on it. What replaced the sidecar: - `tui/src/agent_host.rs` installs this entry point's Agent driver, shaped like the headless entry's (a short-lived probe runtime, dropped before the service gets one of its own), and starts the service through `future_host`'s process global host. - `agent_supervisor` keeps the policy and loses the process plumbing: attach, wait for whichever process holds the lock (bounded, and it says so), start in process, and rate-limit its own restarts. Every one of those decisions still comes from `future_rpc::supervision`, so the three entry points answer "who owns the Agent" identically. - The exit path stops an Agent this TUI owns, within a bound, on all three ways out (interactive, print mode, `--list-models`). An owned Agent holds the instance lock and the data-directory database; leaving that to process teardown would make the next start report a lock it cannot explain. `future-tui` standalone stays attach-only, and now says why in one place: the Agent re-runs its own executable as the Linux sandbox helper (`--linux-sandbox-helper`) and puts that executable's directory on `PATH` for shell tools, and only the unified `future` binary dispatches that flag. Hosting from the standalone binary would break sandboxed shell commands, so it refuses with the reason and the way out instead. Verified with a release build in isolated homes: a clean home starts the Agent inside the TUI (log shows `embedded Agent ready`, `Agent host finished owned=true`), the instance lock is held by the TUI process itself rather than a child, and the lock is released after the TUI exits. The standalone `future-tui` on an empty home refuses with the sandbox-helper explanation and creates no lock; with an Agent already serving it attaches and answers (`--version`, print mode) while the lock holder stays the same process. Removed with the sidecar: `agent_sidecar_launch.rs` and `agent_sidecar_readiness.rs` (they existed to make the child's failure reporting observable), and the comments in two other tests that referred to that launch path. `future-tui` 2231 lib tests and its integration targets pass; `cargo fmt --check` and clippy for the crate are clean. Not changed, and outside this commit: `host/src/remote/supervisor/state.rs` fails `clippy -D warnings` (`field_reassign_with_default`) at this branch's base commit `7590cbef5`, from PR #1283. It is not touched here, and it is the reason the workspace-wide clippy pass is red independently of this work.
…th a real concurrency bound The pass took the first three of `list_all`, which orders by `updated_at` descending. That starved the tail rather than merely capping work: the three most recently touched conversations are exactly the ones a user is working in, and so the ones the next restart is most likely to cut off again. They took the whole budget on every pass, and older interrupts waited until those three went quiet. The log looked healthy every time — "checked N, continued 3" said nothing about the debt. Now every eligible conversation is taken, ordered by **oldest interruption first**, so the queue drains on the first pass. What bounds the work is concurrency, not a quota: at most `MAX_IN_FLIGHT` (3) submissions are in flight and the rest queue behind them. That bound has to be ours — the Agent has no cross-session limiter (`GlobalQueueBudget` caps queue depth and bytes, not running sessions), so without it a restart after an outage would fire one model request per interrupted conversation at once. The log now reports the account instead of only the work: `N checked, M interrupted and eligible, X continued (at most 3 at a time), K skipped (older than 7 days, sub-session, streaming, awaiting approval, or no model)`. Tests (and what each would have missed): - `candidates_are_taken_oldest_interruption_first` drives the shipped `candidates_in_order`. The first version re-sorted the fixture itself and passed even with the implementation inverted; reworked, it fails with `left: ["newest", …], right: ["oldest", …]` when the sort is turned back to newest-first. - `at_most_max_in_flight_continuations_run_at_once` runs the same refill-on-free loop over 10 tasks and asserts the peak against a literal 3, not against the constant — comparing the peak with `MAX_IN_FLIGHT` would pass for any value, including one big enough to fire everything at once. Raising the bound to 10 fails it with "saw 10". - `every_eligible_conversation_is_taken_not_just_the_first_few` pins that all ten candidates are taken and that the bound is below the queue size, so the other two tests mean something. - `only_fresh_top_level_sessions_are_candidates` covers the cheap filter (age, sub-session). Both falsifications were run and then reverted. `MAX_AGE` and `run_loop.rs`'s assistant-tail guard are untouched (the latter is the separate D10 change). `future-agent` 2483 lib tests pass; clippy clean.
…sting clippy, from #1259) `DesktopExecutor::connection_options` built the value as `let mut options = ConnectionOptions::default(); options.root_bundle = …`, which `clippy::field_reassign_with_default` rejects. The lint never reached CI because `host`'s `test-support` feature adds a private `loopback_fixture` field: the feature is enabled for the whole graph in the workspace-wide pass (the `cli` and `desktop` dev-dependencies enable it), and with it on the `for_loopback_fixture` shadowing moves the value, which the lint does not look through. With the feature off — `cargo clippy -p future-host --lib` — it fired. Neither struct-literal form works for both configurations: with `test-support` a private field makes the literal (and the `..Default::default()` update syntax) unconstructible from another crate, and without it the same single-field literal is `needless_update`. So `ConnectionOptions` gains `with_root_bundle`, symmetric with the existing `for_loopback_fixture`, and the caller chains both. Behaviour is unchanged: both feature configurations produce the same value, and the fixture path still goes through `for_loopback_fixture()`. Verified: - `cargo clippy -p future-host --lib -- -D warnings` (feature off, the red case): green - `cargo clippy -p future-host --lib --features test-support -- -D warnings`: green - `cargo clippy --workspace --all-targets -- -D warnings`: green - `cargo clippy -p future-remote-server --lib`, `-p future-remote-client --lib`: green - `cargo fmt --all --check`: clean - `cargo test -p future-host --lib remote`: 553 passed
\uture remote peers\ is the client role, the mirror of \uture remote devices\: the machines this one connects out to. future remote peers [list] [--json] future remote peers add <invitation> [--json] future remote peers connect|disconnect <id|#> [--json] future remote peers rename <id|#> <name|--clear> [--json] future remote peers remove <id|#> [--yes] [--json] add runs in the CLI rather than in the Desktop: a pairing is a one-time claim plus a Noise handshake and needs nothing local to be serving, so a machine can be paired before its Desktop is opened. It stores the credential in ~/.future/remote_peers.json and connects once, so a pairing that does not work is reported now. list reads that book; connect, disconnect and remove ask the running Desktop through the same request/reply channel \uture remote devices\ uses, because a live connection and the user's own stopped mark live in that process and nowhere on disk. The host side gained peer-state, peer-connect, peer-disconnect and peer-remove (a peer is named by desktopId, not pairId) and answers each with the list as it stands afterwards. Docs: desktop-headless gains a client-role section (en + zh), and the directory layout now lists remote_peers.json.
huichen
enabled auto-merge (squash)
October 21, 2026 14:01
D10 step 1 of 3. Restart recovery used to continue an interrupted conversation by submitting a prompt, which lands in the transcript as a user message nobody typed. This adds an accepting path that continues the run in place: the journal gets the new run's `run_started` marker (with `auto_resume_of` naming the interrupted run), and the run goes through accept-before-mutate, the run lease and the broadcaster like any other. The model receives the explanation as request-only context that never enters the transcript or the event stream — no `user_message` event, no user entry, no bubble for a client to draw. The journal is the permission: `continue_interrupted_run` re-reads `unterminated_run_id` at the accepting call and refuses anything else, so `ResumeContext` can only be set from a run the session's own journal still shows as open. This step covers the tail shape that needs no repair — a tool result, which is already a valid request. The assistant-tail guard is untouched, and a call whose result never arrived is not answered yet. Both shapes coexist: when continuing in place is refused (a journal that proves nothing, a provider that cannot take the tail), the pass logs why and falls back to the prompt it used before.
D10 step 2 of 3. A run that died between issuing a tool call and recording its result leaves a transcript that ends on `tool_calls` with nothing answering it, and every provider rejects that request with HTTP 400. The continuation now pairs those calls with a placeholder result first, then appends the directive, so the request is valid. The placeholder says the outcome is *unknown*, not that the tool did not run. The process died in between, so nobody knows; "not executed" is the one guess that invites the model to repeat a side effect that may already have landed. The load-time repair, which writes the same placeholder into a loaded session, said "was not executed" — it now shares this wording, so a model reads the same story whichever path assembled the request. The guard has to distinguish this tail from the one it exists to catch: an assistant turn carrying unanswered tool calls is repairable, a turn that stops on assistant text is not. Only the resuming path is allowed the former, and a plain assistant tail is still refused.
… is open D10 step 3 of 3. A run that died while the model was writing its answer leaves the transcript on an assistant turn, which the loop refused outright — and that is the most common tail a crash leaves. The continuation now accepts it, appends the request-only directive and continues. The relaxation is not "an assistant tail is allowed". `ResumeContext` is the only way in, and it is built by `continue_interrupted_run`, which re-reads `unterminated_run_id` at the accepting call: an assistant tail the session's own journal cannot prove is a still-open run is refused exactly as before. `run_rejects_assistant_last_message` keeps that boundary, and `a_continuation_is_refused_when_the_journal_proves_no_open_run` covers the same edge from the accepting side. The model's interrupted turn is never deleted from the transcript — it was produced, it is history, and the continuation only adds to the tail.
The design section said the plan was fixed but the implementation had not started, and the decision table listed D10 as an adopted plan awaiting a separate task. Both are now wrong in the other direction. Update them, and record one thing the plan got wrong: a turn carrying unanswered tool calls is itself an assistant tail, so the guard needed an intermediate shape before the plain-assistant step, and the relaxation has to be conditioned on the journal rather than on the tail's role.
auto-merge was automatically disabled
October 21, 2026 14:20
Pull request was closed
huichen
enabled auto-merge (squash)
October 21, 2026 14:20
auto-merge was automatically disabled
October 21, 2026 14:58
Pull request was closed
huichen
enabled auto-merge (squash)
October 21, 2026 14:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
合进 5 条非合并提交(
dev-huichen相对main):本地已跑(CI 工具链 1.97.0):
cargo fmt --all -- --checkcargo clippy -p future-cli -p future-tui -p future-agent -p future-rpc -p future-host -p future-remote-server --all-targets -- -D warningscargo test --lib:future-agent 2483、future-tui 2231、future-rpc 221、future-cli 1374、future-remote-server 164、future-host 1745,全绿