Repository navigation
feat(desktop,mobile,agent): a session-owned send queue, paged replay, journal fixes - #1485
Merged
Merged
Conversation
…the journal
A model stream that runs out before its terminal frame is closed by the
provider layer (`finish_stream` emits `ReasoningEnd`/`TextEnd`), and the
stream-retry path then closed the same reasoning display again. The duplicate
reached the durable journal as a *new* block at offset zero under an identity
that already holds the first attempt's bytes:
{message}:thinking:{block_id}
with `block_id` a fixed per-stream name (`reasoning`), so the second close
sealed an empty body over durable content. The journal refuses that
contradiction, and because the refusal is not a per-event one it marked the
session's journal unhealthy — which makes `run_snapshot`, and therefore
`get_events_since`, fail for the rest of the process's life. On the phone that
is a conversation whose transcript never finishes syncing, retrying forever.
Measured on this machine (2026-11-03): four sessions went unhealthy, every one
of them immediately after "LLM stream disconnected; reconnecting", and the
desktop logged `get_events_since` failing on each for hours afterwards.
- The retry closes only displays still open, and records that it closed them.
- The broadcaster drops a repeated close for a block this message already
sealed instead of opening an empty block over it, so a duplicate close from
any other producer stays a no-op rather than a refused batch.
Tests: a scripted disconnect either side of the provider layer's close, and
the content-sequence duplicate-close case.
…sion A canonical batch whose content conflicts with what is already durable (a gap, a divergent retry, a seal whose digest disagrees with the bytes) fails identically on every retry. The writer classified it as a storage failure, so the poisoned batch was kept and every later batch queued behind it failed too: the run went persistence_degraded, every cancel was a no-op because the terminal it must commit goes through the same journal, and nothing short of an agent restart released it. Four conversations on this machine were wedged that way in one hour. The journal already has the right contract for a refusal - name it, drop that one event, keep the session writable - but only the raw journal path ever produced one. The canonical writer now reports a non-storage failure as that permanent refusal, and the per-event retry goes back through the semantic writer it just used (a canonical conversation's raw append refuses everything, so the old retry would have dropped the whole batch). A durable event the journal refuses is no longer recorded as a session-wide outage either.
The composer used to hold a send during a streaming reply in an in-memory queue and flush it once the run settled, so the message only existed in the window that wrote it: closing the window or losing the renderer lost it, and no other client on the conversation could see it waiting. It now leaves immediately with busy_policy enqueue_coalescing, which the host forwards to the Agent's scheduler: the Agent holds the prompt in the session's own queue, a burst folds into one turn at the run boundary (the join the client used to do), and get_state's queuedRuns is where every client reads it from. A queued ack already returns as run_queued, which the send pipeline reads as 'accepted and alive'; the queued send deliberately runs outside the one-send-at-a-time lock, since the run it waits behind is the one holding it.
Sending while a reply streams now leaves the message with the Agent, so the panel that used to mirror a client-side queue has to read the queue back: useAgentQueue reads session_queue (get_state's queuedRuns) and polls only while a run is in flight or rows are waiting. Removing a row cancels it on the Agent by run id; editing cancels and sends the corrected text again (there is no update-in-place command); a row the Agent parked as stale gets the start-now control, which the client-side queues of a paired computer never show.
The live reply is a projection of the run's journal, read once per pushed update. When those reads stop succeeding the bubble keeps the last projection it built and simply never grows again — on 2026-11-03 that was `get_events_since` failing with a refused event batch for minutes while the run kept streaming, and the reader was left looking at reasoning frozen on "The" with nothing on screen to explain it. The only trace was a console warning. The note is presentation only: it never touches the reattach path, the retry cadence or the event read itself, and it disappears on the first successful read (the field is cleared where the projection is written). - Sustained, not a blip: the streak is measured from the first failure after the last success and must span `PREVIEW_STALL_AFTER_MS` (5 s ≈ 50 of the 100 ms coalesced live ticks). A single racy read recovers on the next tick, well inside that window, so a thread switch or a reattach stays silent. Anchoring on failures rather than a wall clock also keeps a legitimately quiet run (no pushes, nothing being attempted) out of it. - `stage` and the raw reason ride the error from where they happened (`read` vs `projection`), so opening the note names the stage, the streak length and the diagnostic instead of "something went wrong". - A preview that gave up rebuilding this run's log is covered too: those ticks return before reading anything, so without recording that verdict the frozen-forever case would stay the one case with no note. - Never an error, never a popup, never interrupts input: one muted line in the reply's footer, collapsed by default, and only ever on a streaming reply. Tests: the threshold (silent at 4 999 ms, speaking at 5 000 ms), a single failed read staying silent, recovery withdrawing the note, the give-up path naming `projection` without adding reads, a reset dropping an earlier note, and a render test asserting the collapsed label, the expanded stage/reason, its disappearance on recovery and on a settled reply.
The remote sync measurement harness moved from Desktop into future-host in #1259, where the Agent channel runtime and the app store became entry-owned. A lib test is now the entry, so serve_real_snapshot answered every business command with " Entry must configure the Agent channel runtime before starting
…ntry-owned runtimes
The badge rendered the app-wide `approvalTier` default, but the gate that decides whether a tool call stops for approval is the agent session's own policy. A session another client created or drives (a CLI `future session set --sandbox manual`, another agent) keeps that tier, so the composer advertised 完全访问 while every shell command still asked — the badge was describing a different session than the one on screen. Read the tier the agent already reports: `get_state`'s `sandboxTier` was in the payload and never parsed, and `sandbox_policy_changed` was not forwarded to the webview, so a change made anywhere never repainted it. Both are wired now. When the session reports no tier (it never chose one, the agent is older, or the first state read has not landed) the badge says 按会话 / Per session. It does not fall back to the default: that fallback is the very claim this fixes. Display only. No approval decision changes and no write to a session's policy; a picker change still reaches sessions exactly the way it always did.
A send made while a paired computer's reply streams used to wait in this window's memory (`remoteSendQueue`) and be flushed as one joined message when the host reported the run over. That copy could only ever be a guess: it died with the window, no other client of that conversation (the phone, the host's own screen) could see it, and a `session_busy` refusal had to be ridden out by a client-side retry loop. The prompt command already carries what a send means while the session is busy, so the queue moves to the side that runs it: * `promptRemoteConversation` passes `busyPolicy` through, and `sendRemotePrompt` keeps it on the durable outbox entry so a delivery retried after a reconnect still means what the reader asked for. * A draft sent behind a streaming reply now goes out immediately with `enqueue_coalescing`. The session holds the row on its own receipt and folds the consecutive ones into a single turn — exactly the "send the queue as one message" behaviour this client used to implement itself. * The panel reads that session's queue (`get_queue`, via `useRemoteQueue`) and its controls are the host's commands: remove = `cancel_queued_run`, edit = cancel then re-send (the host has no "change this row"), and a parked row offers "send this one now" = `release_queued_run`. Nothing waits in this app's memory or localStorage. * Queueing is still not interrupting: the menu keeps both answers, but the interrupt now happens *after* the message was handed over and only if the host took it, so a refused send keeps both the draft and the reply. Removed with the client-side queue: `remote-peer/sendQueue.ts`, `remote-peer/queueDelivery.ts` (the retry loop whose rules belonged to that flush) and `lib/sendQueue.ts` with its test — its last consumer was the remote store, because the local GUI path already queues in the Agent. The phone keeps its own copy until that path is migrated.
A message written while a reply streams is now handed to the desktop at once with a busy policy (`enqueue_coalescing`) instead of being held in the phone's memory and AsyncStorage. The session keeps it on a durable receipt and runs it at the turn boundary, so the queue is the conversation's own list: the same rows the desktop's window shows, still there after this app is gone, and visible to every device on the conversation. A queue kept here could only ever be a guess about a conversation that lives on a paired machine — and an uninstall took it with it. The panel therefore reads `get_queue` (the host's `session_queue_snapshot`) and its verbs are the session's: delete cancels that run id, edit takes the row back and sends the new words (a queued prompt has no editable text on the session), and a row the session parked offers "send this one now" as a release. Acting on a row re-reads the panel whatever the answer was, so a row leaves when the session says it left. Rows are kept with the session they were read for, and the panel polls only while a run can still fill it or rows are waiting. Deleted with the client-side queue: `features/chat/sendQueue.ts`, `sendQueuePersistence.ts` (AsyncStorage), `queueDelivery.ts` (the four delivery rules the retry loop needed) and `lib/sendQueue.ts`, plus their tests. The composer's send slot no longer refuses a running reply: it offers "hand it to the session" or "interrupt and send", and keyboard submit sends the same way. "Stop and send the queue" is gone — the session starts waiting rows itself. A refused send is still told to the reader rather than dropped: the phone adds the policy only when it reads the reply as streaming, so a stale `false` leaves the desktop's own `session_busy` refusal, which the toast already maps to a sentence.
The remote view and the phone now hand a queued message to the session that runs it and read the waiting rows back from that host, so the product description no longer says those two keep their own copies (memory / local storage).
Two review defects on the queue that moved from the clients into the session. D1 — a queued row that never ran disappeared without a word. Both readers (`desktop/src/features/remote-peer/remoteQueue.ts` and `mobile/src/remote/sessionQueue.ts`) parsed only `get_state`'s `queued` and dropped `recentTerminalAcks`, so a row folded into the turn ahead (`merged`), taken back on another device (`cancelled`), replaced (`superseded`) or lost with a deleted conversation (`session_deleted`) simply vanished, and the reader believed the message had been sent. Both now read the acks and say one sentence about the newest one, plus a count when a burst left together. The sentence is drawn outside the panel, because it matters most once the panel is empty; it is said once (an ack that stays inside the host's window is not repeated on every poll), it does not greet the reader with acks that predate the view, and it is not shown for a row this window cancelled itself (`forget`). The same defect existed on the desktop's local path (`agentQueue.ts`) and is fixed the same way. D2 — editing a waiting row re-sends `attachments: []`, and the panel claimed `attachmentCount: 0` for rows whose files it never saw. The queue wire carries a message's text and acceptance time only (`QueuedRunState` has no attachment field, and adding one is a proto + agent change this task does not span), so the count is now reported as unreported rather than zero, and the editor states the trade where it is made: saving sends the new text only, and the files that message was sent with do not come back. A files-only row offers no edit at all — there is nothing to correct, and an empty save is a removal the bin beside it already performs. If a re-send is refused after the cancel, the corrected words go back into the composer (desktop remote and phone) instead of being lost along with the row; the local desktop path keeps them in the failed bubble its send pipeline writes. Targeted checks: desktop `tsc --noEmit`, `vitest run src/features/agent src/features/remote-peer src/i18n`, `eslint` on the touched files; mobile `npm run typecheck`, `jest src/features/chat src/remote src/i18n`, `eslint` on the touched files.
The canonical writer classifies a failed batch by type: a `rusqlite` or `io`
error in the chain is a storage failure a retry can clear, anything else is the
journal's permanent refusal of that one event. A storage lane whose worker has
died reports its own message instead ("SQLite worker is unavailable"), which
matched neither, so a dead database was read as a bad batch: the writer dropped
a durable event and shutdown reported the journal as cleanly flushed next to
the storage stage's real failure.
The lane's own availability errors are now the typed `StorageUnavailable` and
`refusal_unless_storage` counts them as storage. Verified by removing only that
clause: `a_dead_storage_worker_stays_retryable` and the service-level
`a_dead_storage_worker_is_reported_by_the_journal_and_storage_stages` both go
red with the reported symptom, and green with it restored.
Also repairs two encoding accidents in `content/journal.rs` from 30673f1: a
UTF-8 BOM on the first line and a mangled em dash in the `persist` doc comment.
…e whole run Two reads answered a page by building the whole answer first. The agent's replay read used ORDER BY epoch,idx over a unique index that orders (session_id,run_id,idx,epoch), so SQLite applied the idx> range there and then sorted every matching row: a 1001-event page of a 136k-event run cost 23 ms of database work and touched all 136k rows. Adding the epoch-major index alone changed nothing (EXPLAIN still planned the temp b-tree), and INDEXED BY would have made a near-tail cursor 10x worse (16.8 ms vs 1.7 ms). So the read walks epochs in ascending order instead: per-epoch idx > ? is a real index range, which returns the same rows in the same order by construction. Measured 1.0 ms against 20.4 ms for the same page, and 0.07 ms for a 20-event page. The host only paged when offset was 0; every continuation page re-read the run from since=-1 and then trimmed, so page 2 cost a full replay (16.2 s for 136k events) whatever the offset was. A continuation page is now a cursor read from offset-1, with the envelope's offset/nextOffset/total preserved so the client still advances, and a fallback to the old read whenever the first event is not the offset asked for. A/B on one isolated 997k-event home, debug build, same requests: continuation pages 16.2 s -> 127 ms (offset 1000), 13.4 s -> 121 ms (offset 5000), 16.0 s -> 5.7 ms (tail), 23.8 s -> 5.5 ms; 24/24 event replies byte-identical.
huichen
enabled auto-merge (squash)
November 3, 2026 14:22
huichen
added a commit
that referenced
this pull request
Nov 15, 2026
…ol it lost `send-queue-refused-edit` still asserted a `重试` control inside the phone's queue panel. That control went away with #1485, when the queue became the session's own list rather than something this phone held and retried, so the scenario could not fail: it was guarding a state the product no longer has. Rewritten against what the phone does now. The fixture seats two waiting rows (`?queue=2`), so the panel is there as its header line — `2 条等待中` and `当前回复结束后合并成一条发送` — and draws no rows until that line is tapped. A hand-over refused by the host (`?queueFail=1` → `session_busy`) must leave the sentence in the field, add no row and stop no run. Then one tap opens the queue and the first waiting row opens into a field holding its own words, with `保存`/`取消` beside it and its bin still on the row. That refusal sentence itself goes through `Alert.alert`, which react-native-web does not draw, so the capture asserts the state the refusal leaves behind rather than its copy — said plainly in the scenario's note, so nobody reads the missing sentence as a bug. Falsified twice, both red on the harness: putting the old `重试` assertion back fails with "the panel offers no retry", and dropping the header tap fails with "one tap did not open the queue: 0". Green: `capture-mobile` captures 1/1, and the same run together with `send-queue-choice` captures 2/2.
huichen
added a commit
that referenced
this pull request
Nov 15, 2026
…ol it lost `send-queue-refused-edit` still asserted a `重试` control inside the phone's queue panel. That control went away with #1485, when the queue became the session's own list rather than something this phone held and retried, so the scenario could not fail: it was guarding a state the product no longer has. Rewritten against what the phone does now. The fixture seats two waiting rows (`?queue=2`), so the panel is there as its header line — `2 条等待中` and `当前回复结束后合并成一条发送` — and draws no rows until that line is tapped. A hand-over refused by the host (`?queueFail=1` → `session_busy`) must leave the sentence in the field, add no row and stop no run. Then one tap opens the queue and the first waiting row opens into a field holding its own words, with `保存`/`取消` beside it and its bin still on the row. That refusal sentence itself goes through `Alert.alert`, which react-native-web does not draw, so the capture asserts the state the refusal leaves behind rather than its copy — said plainly in the scenario's note, so nobody reads the missing sentence as a bug. Falsified twice, both red on the harness: putting the old `重试` assertion back fails with "the panel offers no retry", and dropping the header tap fails with "one tap did not open the queue: 0". Green: `capture-mobile` captures 1/1, and the same run together with `send-queue-choice` captures 2/2.
huichen
added a commit
that referenced
this pull request
Nov 15, 2026
…ol it lost (#1618) `send-queue-refused-edit` still asserted a `重试` control inside the phone's queue panel. That control went away with #1485, when the queue became the session's own list rather than something this phone held and retried, so the scenario could not fail: it was guarding a state the product no longer has. Rewritten against what the phone does now. The fixture seats two waiting rows (`?queue=2`), so the panel is there as its header line — `2 条等待中` and `当前回复结束后合并成一条发送` — and draws no rows until that line is tapped. A hand-over refused by the host (`?queueFail=1` → `session_busy`) must leave the sentence in the field, add no row and stop no run. Then one tap opens the queue and the first waiting row opens into a field holding its own words, with `保存`/`取消` beside it and its bin still on the row. That refusal sentence itself goes through `Alert.alert`, which react-native-web does not draw, so the capture asserts the state the refusal leaves behind rather than its copy — said plainly in the scenario's note, so nobody reads the missing sentence as a bug. Falsified twice, both red on the harness: putting the old `重试` assertion back fails with "the panel offers no retry", and dropping the header tap fails with "one tap did not open the queue: 0". Green: `capture-mobile` captures 1/1, and the same run together with `send-queue-choice` captures 2/2.
huichen
added a commit
that referenced
this pull request
Nov 16, 2026
The local composer's interrupt control had a branch that said "Stop and send the queued messages" instead of "Stop", and it could never be reached: it reads `Composer.queueCount`, and nothing supplied it. The prop was not always missing. #1485 moved the send queue from the clients into the session and deleted `queueCount={` from both composers with it — the phone's `queueItems.length` and this app's `sendQueue.items.length`. The phone lost nothing, because "Stop and send the queue" was retired along with the client-side queue. Here the deleted source was the only one, the branch that reads it stayed, and the control has said plain "Stop" ever since however many rows were waiting behind the run. The Agent's own queue is the source that replaced it, so the count comes from `agentQueue` now. It has to say something true: ending the run is what lets the waiting rows go (the session starts them at the turn boundary), so the wording holds for the rows that will run. A parked row is counted out rather than in — it waits for a person to release it, and a stop does not release it. `screenshot: send-queue-local-queued` asserted exactly this and had been red on the base commit; it now passes, and reverting only this line reddens it again.
huichen
added a commit
that referenced
this pull request
Nov 16, 2026
…s; fold a shot burst (#1629) * fix(desktop): open the send queue as its header line The desktop panel drew every waiting row over the conversation whenever the queue was non-empty, so a reply could come back hidden behind seven rows. Mobile already collapses it and opens it on press; this brings the desktop to the same behaviour — closed by default, the header line (title, count, what will become of them) is what the reader sees, and one press on that line draws the rows. The header itself is the toggle rather than a chevron beside it: it is a line of text and folding a queue should not mean hitting a 14px arrow. Retry for a failed delivery stays outside the toggle so rescuing a message does not also fold the rows, and folding clears an open editor or answer menu so a half-typed edit is not redrawn on the next expand. Shared panel, so both composers (this app's queue and a paired computer's) get it. Tests open the panel first; two new ones cover the closed state and the cleared editor. * fix(desktop): tell the composer how many waiting rows a stop carries The local composer's interrupt control had a branch that said "Stop and send the queued messages" instead of "Stop", and it could never be reached: it reads `Composer.queueCount`, and nothing supplied it. The prop was not always missing. #1485 moved the send queue from the clients into the session and deleted `queueCount={` from both composers with it — the phone's `queueItems.length` and this app's `sendQueue.items.length`. The phone lost nothing, because "Stop and send the queue" was retired along with the client-side queue. Here the deleted source was the only one, the branch that reads it stayed, and the control has said plain "Stop" ever since however many rows were waiting behind the run. The Agent's own queue is the source that replaced it, so the count comes from `agentQueue` now. It has to say something true: ending the run is what lets the waiting rows go (the session starts them at the turn boundary), so the wording holds for the rows that will run. A parked row is counted out rather than in — it waits for a person to release it, and a stop does not release it. `screenshot: send-queue-local-queued` asserted exactly this and had been red on the base commit; it now passes, and reverting only this line reddens it again. * fix(screenshots): fold a waiting burst into one turn, as the Agent does `send-queue-local-interrupt` had been red on the base commit, and the reason was the fixture rather than the product: `drainShotQueue` handed queued messages out one at a time, so pressing "interrupt and send all" with one row held and one in the field left *two* messages in the transcript. The Agent does not work that way. Every send opts into `enqueue_coalescing` (`QUEUED_SEND_POLICY`), and at the turn boundary `drain_coalescing_after_first` joins everything queued directly behind the front request into it — their texts in queue order, one paragraph each — and records the folded rows terminal with reason `merged`, which is how their client learns the submission was answered as part of another run. The fixture's own comment above `streamShotRun` already described that fold, so the behaviour it produced was the one thing the comment did not. `drainShotQueue` now folds the batch and reports the `merged` acks through `session_queue`, whose `recentTerminalAcks` used to be hard-coded empty. That also exercises the notice those acks drive, which no capture could reach before. The scenario's final step asserted the panel was already gone on the same frame the message appeared. The panel reads the queue on its own tick (`QUEUE_POLL_MS`, 2 s) and learns about a folded row from `recentTerminalAcks` on the next read, so that assertion lost a race it was never meant to run: measured 949 ms to the merged message, 2067 ms to the panel going. The wait is now its own step, which keeps "the rows merged" from being judged by a panel that has not caught up yet. Verified: the scenario captures green and says `one message carried both` / `the queue emptied`; a probe confirmed the two sentences land in one `[data-message-id]` row. `send-queue-local-queued`, `send-queue-local-choice`, `send-queue-choice`, `choice-card-queue` and `choice-card-queue-remote` all still capture; 2359 JS tests pass.
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.
A send queued while a reply is still streaming now belongs to the session instead of to the client that typed it: the desktop and the phone both keep it on the Agent's side, render it as waiting, and let the reader take it back before it runs. Around that, a refused canonical event no longer wedges a session, a run's replay is paged by cursor instead of read whole, a stuck live preview says its sync is paused rather than looking like a stalled model, and a macOS install trap is written down.
Commits
perf(agent,host): page a run's replay by cursor instead of reading the whole runfix(agent): keep a dead storage worker a storage failurefix(queue): say what became of a row that left the session's queuedocs(desktop): every client queues on the session, not in itselffeat(mobile): a queued send is the session's, not this phone'sfeat(desktop): hold a remote conversation's send queue in its sessionfix(desktop): show the session's approval tier in the composer badgefix(host): wire the sync measurement probe's entry-owned runtimesfeat(desktop): say so when a reply's live preview cannot read its eventsfeat(desktop): the waiting rows are the Agent's, and can be taken backfeat(desktop): a message queued while a reply streams is the Agent's ownfix(agent): drop a refused canonical event instead of wedging the sessionfix(agent): close a reasoning display once, so a retry cannot poison the journaldocs(macos): mirror the macOS install notes on the English sidedocs(macos): record the Intel PREFIX trap, bare-binary install and release artifactsVerification
Local self-test at
a6998df78, pinnedrustc 1.99.1,ulimit -n 8192:cargo fmt --all -- --check— cleancargo clippy -p future-agent -p future-host --all-targets -- -D warnings— cleancargo test -p future-agent --lib -- session::sqlite_store session::database rpc::broadcaster session::content— 303 passed / 0 failed / 4 ignoredcargo test -p future-host --lib -- remote_host agent_bridge— 638 passed / 0 failed / 2 ignoredtsc --noEmitclean,eslint "src/**/*.{ts,tsx}"0 errors,vitest run src/features/agent src/features/remote-peer src/integrations/agent src/lib src/components/layout— 243 files / 3536 tests passedtsc --noEmitclean,eslint .clean,jest --runInBand src/features/chat src/remote/__tests__ src/lib/__tests__— 84 suites / 1786 tests passedNotes
agent/src/session/database/schema.rsadds an idempotent indexrun_events_replay_orderonrun_events(session_id,run_id,epoch,idx), created on every open rather than in a versioned migration (no data changes, one-time build on an existing database). It turns the replay page read from ~23 ms into ~1 ms on a large run.mobile/src/features/chat/sendQueue.ts+sendQueuePersistence.tsand the desktoplib/sendQueue.tsare deleted in favour of the session-owned queue (mobile/src/remote/sessionQueue.ts,desktop/src/features/agent/agentQueue.ts).packages/thread-projectiongains apreviewStalledfield (stage: "read" | "projection") onAgentMessage; it is presentation only, set while streaming, and cleared by the first successful read.docs/internals/desktop/PRODUCT.mdand its zh-CN mirror describe the session-owned queue model.