Skip to content

feat(agent): accept a prompt during manual compaction and run it after - #1680

Merged
huichen merged 2 commits into
mainfrom
pr/huichen
Nov 24, 2026
Merged

huichen merged 2 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

A manual (standalone) context compaction used to hold a read guard on the session for the entire summary — minutes of model time on a long conversation. Every mutating command queued behind it, the dispatcher refused prompts with session_busy for that window, and all three client surfaces greyed out Send. That window is exactly when a reader watching a long conversation being summarised writes the next message.

The summary now runs without the session lock: StandaloneCompaction captures the handles it needs under one short guard and drops it before the model call, so the session stays addressable and its queue keeps accepting prompts. A prompt written meanwhile is accepted and queued like one written behind a run, and starts when the checkpoint commits (SchedulerWake::CompactionFinished). compaction_in_progress still fences the transcript, so the summary's snapshot and its commit cannot disagree: a history reset still refuses prompts, and set_model / set_tools / fork / abort_session keep failing fast with session_busy. The client-side holds are removed — mobile, desktop and the TUI send as usual during a compaction, and their composers keep showing it as information rather than as a block.

Commits

  • feat(agent): accept a prompt during manual compaction and run it after

Verification

Local, on the branch tip 88702172c (Rust pinned to 1.99.1 per rust-toolchain.toml; Homebrew's 1.96.0 shadows it, so the pinned bin went first on PATH; ulimit -n 8192):

  • cargo fmt --all -- --check → clean
  • cargo check -p future-agent -p future-tui --all-targets → clean
  • cargo clippy -p future-agent -p future-tui --all-targets -- -D warnings → clean
  • cargo test -p future-agent --lib → 3129 passed, 0 failed, 7 ignored
  • cargo test -p future-tui --lib → 1849 passed, 0 failed, 4 ignored on re-run. The first run had one failure, workbench::run::driver_tests::menus_and_verbs::the_worktree_verbs_plan_create_and_refuse_a_second_copy, panicking on failed to spawn git: No such file or directory (os error 2); that individual test passes in isolation and the whole suite passes on re-run at the same SHA, tui/src/workbench/run.rs is untouched by this branch, and the hazard is documented in that file (sibling tests swap the process-global PATH for stub and empty directories while a repository test spawns git by name). Known cross-test PATH race, not this change.
  • desktop: tsc --noEmit clean; eslint on the touched files clean; vitest run src/features/agent/Composer.delivery.test.tsx → 9 passed
  • mobile: tsc --noEmit clean; npx jest --runInBand on the five touched suites → 181 passed

User-visible changes

Prompting while a manual compaction runs, on mobile, desktop and the TUI:

  • Before: Send was disabled for the whole summary (the composer read "Compacting"), and a prompt arriving by any other path was refused with session_busy.
  • After: all three surfaces accept the message and send it; the agent keeps it at the front of the session queue and runs it when the checkpoint lands. On mobile a tap is held and the button reads as busy while the composer says the message will be sent once compaction finishes (both locales carry their own wording); a draft edited during the wait is not sent, and leaving the screen cancels the wait. A history reset still refuses a prompt during its own window.
  • Rollback: commit 88702172c (with the merge b32b0bb33 that carried it into this branch).

bin/notice.py does not exist in this repository, so this section is the record.

`compact` acknowledged and then summarised on its own worker, but that worker
held a read guard on the session for the whole summary — minutes on a long
conversation. Every mutating command queued behind it, so the dispatcher refused
prompts outright with `session_busy` for that window and every surface greyed out
its send button. The window is exactly when a reader, watching a long
conversation be summarised, writes their next message.

The summary now runs without the session lock: `StandaloneCompaction` captures
the handles it needs (all of them Arc clones the live session shares) under one
short guard, and the worker drops the guard before the model call. A prompt
written into the session meanwhile is accepted, receipted and queued exactly like
one written behind a run. `compaction_in_progress` still fences the transcript —
the summary's snapshot and its commit must not disagree — so the queued prompt
starts when the worker opens the fence and hands the session's scheduler a turn
through the channel the completion monitor already uses
(`SchedulerWake::CompactionFinished`). The fence is read after the acceptance, so
a compaction that settles in between cannot leave a prompt queued forever: its
wake runs under the same session lock and either sees this prompt or has already
cleared the flag, in which case the prompt starts itself.

The client-side holds from the previous commit go away: mobile, desktop and the
TUI send as usual during a compaction, and their composers keep showing it as
information rather than as a block.

A history reset still refuses prompts — a half-replaced transcript is no place
for a queued message — and the other transcript mutators (`set_model`,
`set_tools`, `fork`, `abort_session`, …) keep failing fast with `session_busy`.
@huichen
huichen enabled auto-merge (squash) November 24, 2026 02:25
@huichen
huichen merged commit 7c1e27c into main Nov 24, 2026
27 checks passed
@huichen
huichen deleted the pr/huichen branch November 24, 2026 02:51
huichen added a commit that referenced this pull request Nov 25, 2026
…nding it to the queue

A manual compaction owns the session for as long as the summary takes — minutes
on a long conversation. The Agent takes a prompt written meanwhile and runs it
when the fence opens (#1680), but that leaves the message in a queue this window
says nothing about: the draft vanished from the box and nothing arrived, which
reads as "my message disappeared".

Take the click instead, the way the phone already does (#1679): the draft stays
in the box, the send control reads busy, the control row says 压缩完成后发送…,
and the words that were there when the button was pressed go out when the
compaction ends. Four endings are not a send and all keep the draft — edited
during the wait (text, attachments or the card's answer), switched conversation,
a run taking the session meanwhile, or the window closing. The wait is local
state, not the Agent's queue: a held message dies with the window, which is the
behaviour the user picked for this surface.

The send path itself is untouched: compaction still is not a reason to disable
the button, and nothing about the Agent's compaction or queue semantics changes.

Verified: tsc --noEmit, eslint, and the whole desktop suite (442 files / 6296
tests) green; the new `Composer.compaction.test.tsx` fails outright with the
hold removed and separately with the "edited meanwhile" comparison removed.
Captured against the demo data in headless Chrome: the same click before (draft
gone, message queued silently) and after (draft kept, control busy, hint shown).
huichen added a commit that referenced this pull request Nov 25, 2026
…nding it to the queue (#1696)

A manual compaction owns the session for as long as the summary takes — minutes
on a long conversation. The Agent takes a prompt written meanwhile and runs it
when the fence opens (#1680), but that leaves the message in a queue this window
says nothing about: the draft vanished from the box and nothing arrived, which
reads as "my message disappeared".

Take the click instead, the way the phone already does (#1679): the draft stays
in the box, the send control reads busy, the control row says 压缩完成后发送…,
and the words that were there when the button was pressed go out when the
compaction ends. Four endings are not a send and all keep the draft — edited
during the wait (text, attachments or the card's answer), switched conversation,
a run taking the session meanwhile, or the window closing. The wait is local
state, not the Agent's queue: a held message dies with the window, which is the
behaviour the user picked for this surface.

The send path itself is untouched: compaction still is not a reason to disable
the button, and nothing about the Agent's compaction or queue semantics changes.

Verified: tsc --noEmit, eslint, and the whole desktop suite (442 files / 6296
tests) green; the new `Composer.compaction.test.tsx` fails outright with the
hold removed and separately with the "edited meanwhile" comparison removed.
Captured against the demo data in headless Chrome: the same click before (draft
gone, message queued silently) and after (draft kept, control busy, hint shown).
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