Skip to content

feat(chat): queue prompts sent while compaction runs - #1426

Merged
agegr merged 10 commits into
agegr:mainfrom
vergram:feat/compaction-message-queueing
Oct 29, 2026
Merged

agegr merged 10 commits into
agegr:mainfrom
vergram:feat/compaction-message-queueing

Conversation

@vergram

@vergram vergram commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

pi's SDK refuses prompts while compaction runs ("Cannot submit a prompt while
compaction is in progress"), so nothing typed into a compacting session could reach
the agent. The wrapper now parks those submissions and flushes them when the
compaction ends, as pi's TUI's compactionQueuedMessages does. This is the
compaction-queueing part of #812, the focused follow-up its closing comment asked for.

send("prompt") while isCompacting
  inner.prompt()
    rejects "Cannot submit a prompt while compaction is in progress"
-   error notice + text back in the composer
+   park { message, images, streamingBehavior }   # admission stays outstanding
+   ack { queued: true }                          # composer clears, queue row appears
+   drop the optimistic bubble                    # not a sent message until delivered

on compaction_end / auto_compaction_end
+  for entry in parked, FIFO
+    inner.prompt(entry, streamingBehavior ?? "followUp")
+      "started" → prompt_done for its client
+      "queued"  → rides the live run's prompt_done
+      error     → back to the queue + prompt_error

Shipped alongside, a pre-existing composer bug this feature cannot ship without: the
/compact builtin awaited its blocking compact POST while runBuiltinCommand holds
the composer's <fieldset disabled>, so the input box took no text for the whole
compaction and came back only after a remount.

/compact (builtin slash command)
-  await the blocking compact POST   # <fieldset disabled> held meanwhile
+  complete at once, run handleCompact detached
+    Compacting status, Stop compaction, result banner, error report the outcome
  • Parking hooks the SDK's rejection, never pre-empts inner.prompt(), so an extension
    command typed during compaction still runs (the SDK executes commands before it refuses).
  • A parked prompt keeps its admission's pendingPromptCount outstanding until delivery or
    recall, so isRunning(), the idle shutdown and the reload/clone refusals see it.
  • The flush always carries a streamingBehavior, so AgentSession.prompt() queues into a
    run still finishing the compaction or starts one when idle. It never hits
    "Agent is already processing".
  • get_state.queuedMessages and every queue_update merge pi's queue with the parked
    ones; clear_queue returns both, and Recall puts the text back in the composer.
  • The composer stays editable: the placeholder says messages queue, and the status line
    reads "Compacting… · N queued" for a manual compaction too, where agentRunning alone
    left it unlabeled.

Evidence

Before: a prompt sent during compaction bounced with "Cannot submit a prompt while
compaction is in progress." and the text returned to the composer; with /compact the
composer was dead for the compaction's duration. Neither queued-message path worked.
After: the message is accepted, appears in the queued-messages panel, and is
delivered FIFO when the compaction ends.

New tests:

✔ /compact completes at once and runs the compaction detached      # holds the compact POST open forever
✔ /compact passes its instructions to the detached compaction
✔ prompts sent while compaction runs park and flush FIFO at compaction end
✔ recall returns parked prompts to the input and settles their admissions
✔ clear_queue returns pi's own queue beside the parked prompts
✔ a failed flush puts the prompt back in the queue and reports the error
✔ parked prompts carry their images through the flush

Plus the queued-count case in lib/chat-phase-label.test.mjs and an
editable-while-compacting case in components/ChatInput.test.mjs.

Checks: tsc --noEmit clean, npm run lint clean, npm test green end to end
(2880 tests, 2859 pass, 21 skipped, 0 fail).

The branch also carries one separable commit, test: run the suite green on Windows
(28 test files, test and fixture code only): 8.3 temp-path canonicalization, CRLF
normalization at source reads, chmod semantics, ESM absolute-path imports in the hooks
fixtures, ConPTY pid timing, and EBUSY teardown of fixture MCP servers. npm test
used to fail 66 here and hang without --test-force-exit; it now exits clean. Happy to
split it into its own PR if you prefer.

Merge Danger

Door: Two-way. A revert restores today's behavior on both paths, and there is no
schema, session-file or extension-API surface change.

Blast Radius: Prompt dispatch while a compaction runs, and the /compact builtin
command. Idle sessions, runs, steer/follow-up queueing outside compaction and other
slash commands are untouched.

  • Parked text lives in the wrapper instead of the composer, so a wrapper shutdown before
    the flush drops it. The queue panel and Recall are the user's recourse while it is
    parked, and isRunning() keeps the wrapper alive meanwhile.
  • A failed flush parks the message again; it retries at the next compaction end or on
    Recall, and reports prompt_error either way.
  • isPromptRunning reads true while a prompt is parked. Intended ("a prompt is pending"),
    but it is a new state the status polling can observe.
  • /compact no longer answers "Command completed"; the compaction's own status line,
    result banner and error banner report it. Anyone keying on that toast will notice.

qiyu and others added 10 commits October 21, 2026 21:16
pi's SDK rejects prompts during compaction ("Cannot submit a prompt while
compaction is in progress"), so every submission bounced back to the
composer with an error and the input read as dead. Park the submissions in
the wrapper and flush them FIFO at compaction end, as pi's TUI's
compactionQueuedMessages does. This is the compaction-queueing part of
agegr#812, the focused follow-up its closing comment asked for.

- Parking happens on the SDK's rejection, never before inner.prompt(), so
  an extension command typed during compaction still runs: the SDK
  executes commands before it refuses.
- A parked prompt keeps its admission's pendingPromptCount outstanding
  until delivery or recall, so isRunning(), the idle shutdown and the
  reload/clone refusals all see it.
- The flush is the TUI's flushCompactionQueue() in the wrapper: every
  delivery carries a streamingBehavior (a plain parked prompt as followUp),
  so AgentSession.prompt() queues it into a run still finishing the
  compaction or starts one when idle, never "Agent is already processing".
  A delivery that started the run emits its prompt_done, one that queued
  into another run rides that run's, and a failed delivery goes back to the
  queue with prompt_error and waits for Recall or the next compaction end.
- get_state.queuedMessages and every queue_update merge pi's queue with the
  parked ones; clear_queue returns both, and Recall puts the text back in
  the composer.
- The composer stays editable while compacting: the placeholder says
  messages queue, and the status line shows "Compacting... - N queued",
  for a manual compaction too (agentRunning alone left it unlabeled).

Tests: lib/rpc-manager-compaction-queue.test.mjs (park, FIFO flush,
recall, merge, failed flush, images), the queued-count case in
chat-phase-label, the editable-composer case in ChatInput. tsc, eslint and
the touched areas' 246 tests pass; the 66 suite failures on this Windows
machine are identical with and without the change.
…mpts out of the transcript

Two bugs from manual testing of the compaction queueing.

1. /compact disabled the composer for the whole compaction. The builtin
   slash handler awaited the blocking compact POST, and runBuiltinCommand
   holds the composer's <fieldset disabled> until the command resolves: the
   input box took no text until the session was switched away and back (a
   remount resets builtinCommandPending). The command now completes at once
   and runs the compaction detached through handleCompact, the Compact
   button's path, which reports itself (Compacting status, Stop compaction,
   result banner, error); its result is the silent action: "compact".
   handleCompact takes the optional custom instructions and promotes the
   session after its reload, as the inline path did.

2. A parked prompt rendered as a sent message. handleSend's optimistic
   bubble stayed in the transcript while the message waited in the queue.
   A queued submission is now acked { queued: true } (parked, or the SDK's
   "queued" disposition) and the client drops the bubble: the queue rows
   show it, and the transcript shows it when the flush delivers it.

Tests: hooks/compact-command.test.mjs pins the detached /compact against a
compact POST that never resolves; lib/rpc-manager-compaction-queue.test.mjs
pins the queued ack (and the extension command still answering null).
tsc, eslint and the touched areas' 258 tests pass.
28 test files fixed, test and fixture code only (plus one fixture server).
No product change. Root causes, by cluster:

- 8.3 temp paths: %TEMP% resolves to C:\Users\LINWEI~1\... while git,
  the SDK and $HOME report expanded names. Node's realpathSync keeps short
  names (only realpathSync.native expands them), so fixtures compared
  unequal paths and ancestor walks reached the real ~/.agents/skills from
  the scratch dir. Fixture roots now canonicalize with realpathSync.native.
- CRLF checkouts: source-reading tests sliced on ";\n" and regexes ended
  at \n before \r, so they extracted nothing. Repo convention
  .replace(/\r\n/g, "\n") applied at the read sites.
- chmod on Windows: 0o500/0o400 do not make directories unwritable and
  stat reports 0o666 regardless. Unwritable tests now lock the file too
  (same refusal path, different syscall); mode assertions keep POSIX.
- ESM absolute paths: hooks fixtures imported a raw G:\... path, which
  Node's ESM loader rejects (protocol 'g:'), and drive-letter-case drift
  would load a second shim instance. They now take the shim through
  jiti.import("react"), the alias route the hooks resolve react by.
- ConPTY: node-pty reports pid 0 until its worker connects and arms a 5s
  watchdog; tests now wait for the connection before asserting or ticking
  mock timers.
- EBUSY teardown: fixture MCP servers held cwd open while rm ran (Windows
  refuses); shutdown is awaited first and removal retries. A fixture's
  !touch marker wrote into the repo root (unquoted backslashes in bash -c);
  markers are quoted with forward slashes. Grandchild processes of the
  MCP fixture now exit with their parent.
- PATH assertions joined with the host delimiter for a case that tests
  another platform; PTY and skills-walk tests reached the developer's real
  home on Windows (temp under the profile): hermetic .git marker added.

npm test now passes end to end here (2880 tests, 2859 pass, 21 skipped,
0 fail) and exits without --test-force-exit; it used to hang on leaked
fixture processes and fail 66.
This reverts commit 63924a8. The Windows test fixes are unrelated to
compaction queueing, and most of them (14 of 29 files) overlap the open
Windows test PRs agegr#1364-agegr#1368. They belong in a PR of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The flush called inner.prompt() for every parked prompt at once, so an
  `input` handler that took longer on the first one let the second start
  the run: [slow, fast] went out as [fast, slow]. Each delivery now goes
  through the prompt admission chain, one submission at a time, so a
  prompt sent after compaction_end also queues behind them.
- Stop (`abort`) ends the compaction, and its compaction_end sent the
  parked prompts: Stop started a run, under forceShutdownOnIdle. Stop now
  recalls them first and returns their texts for the composer, as the
  TUI's abort restores queued messages to the editor. Stop compaction
  still flushes them, as Esc during compaction does in the TUI.
- A delivery that failed after it was accepted was parked again and
  would have been sent twice; a refused one kept its admission count, so
  the session stayed running until Recall. Now only a refused delivery
  goes back to the queue, with its admission settled; settle() is the
  admission's idempotent finishPrompt, so Recall never settles twice.
- Recall and Stop send prompt_done for a recalled plain prompt (its client
  waits for one); the delivery that started the run sends it whatever its
  streamingBehavior.
- Park only on the SDK's refusal before preflight: `inner.isCompacting`
  alone parked unrelated errors during auto-compaction. `queued: true` is
  the parked ack only, and auto_compaction_end (no pi 1.4 event) is gone.

lib/rpc-manager-compaction-queue.integration.test.mjs plays both bugs
against a real AgentSession and fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omposer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e flush

- The SDK's refusal reaches the wrapper's handler a microtask later, so
  compaction_end could flush before the prompt was parked: it stayed a
  queue row and the session read running for good. The handler now
  flushes itself when the compaction is already over.
- flushParkedPrompts() emptied the queue at once while each delivery
  waited for admission: during the first one's preflight, Recall returned
  nothing and Stop could not take the rest back, which were sent anyway.
  An entry now stays listed until its delivery holds admission; Recall
  and Stop take it, and the delivery skips an entry that is gone.
- A plain parked prompt is a steer, as the TUI parks Enter during
  compaction: as a followUp it was listed (and recalled) after the steers
  sent after it, so "A" then "B" came back as "B", "A". Delivery stays FIFO.
- Recall and Stop return the parked prompts' images beside their texts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Recall and Stop put the images of prompts parked behind a compaction back
in the composer with their texts (restoreSubmission, as a refused prompt
had them before). A /compact <instructions> whose compaction fails gives
the command back to the composer, where the awaited command left it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agegr

agegr commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thanks. This is the follow-up I asked for in #812, and the TUI parity is right. I checked it against pi 1.4.0's compactionQueuedMessages, using a real AgentSession with the faux provider. On main, a prompt sent during /compact or Compact is refused with "Cannot submit a prompt while compaction is in progress". /compact also disabled the whole composer, Stop compaction included, until the POST returned, so detaching it is right.

I pushed fixes on top:

  • Flush order: all parked prompts were handed to inner.prompt() at once. An extension input handler that is slower on the first one made [slow, fast] arrive as [fast, slow]. Each delivery now goes through the prompt admission chain, one at a time. A prompt stays a queue row until its turn comes, so Recall and Stop can still take it back.
  • Late refusal: the SDK's refusal reaches the wrapper a microtask later, after compaction_end may already have flushed. That prompt then stayed a queue row and the session read "running" for good. It is now flushed right away.
  • Order in rows: a plain parked prompt is a steer, as the TUI parks Enter during compaction. As a followUp, it was listed and recalled after the steers sent after it.
  • Stop: Stop aborted the compaction, and that compaction_end sent the parked prompts, so Stop started a run. Stop now returns them to the composer, as the TUI's abort restores queued messages to the editor. Stop compaction still flushes them, as Esc does in the TUI.
  • Failures: a delivery that failed after it was accepted was parked again and would have been sent twice. A refused delivery kept the session "running" until Recall. Now only a refused delivery goes back to the queue, and its admission is settled.
  • Recall and Stop: both send prompt_done for a recalled plain prompt and bring its images back along with the text.
  • /compact on failure: a failed /compact <instructions> puts the command back in the composer.
  • Parking: prompts are parked only on the SDK's refusal before preflight, not on any error while isCompacting. I dropped auto_compaction_end, which pi 1.4 does not emit.
  • Tests: lib/rpc-manager-compaction-queue.integration.test.mjs covers order, Stop, Recall during the flush and the late refusal against a real session.

I also reverted "test: run the suite green on Windows". It is unrelated to this change, and about half of it overlaps the open #1364–#1368, so please send the rest as its own PR. I merged main (pi 1.4.0) as well. tsc, lint and npm test pass.

@agegr
agegr merged commit a295025 into agegr:main Oct 29, 2026
2 checks passed
agegr added a commit to tossp/tsgw-agent that referenced this pull request Oct 29, 2026
The event handler flushes agegr#1426's parked prompts on compaction_end and
still marks agent_settled with subagentsActive; the subagent-runtime
import takes agegr#1386's getLiveSubagentStatus beside hasUnsettledSubagentRun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agegr added a commit to wowayou/pi-web that referenced this pull request Oct 29, 2026
Both sides added a ChatInput test at the same place (agegr#1426's compacting
composer); both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
windli2018 added a commit to aiti-ai/aiti-ai that referenced this pull request Nov 1, 2026
…0.13 integration)

- upstream v0.13.0: Debug panel, prompt parking during compaction (agegr#1426),
  unconfirmed-send recovery (agegr#1432), live-session rename (agegr#1451), spacer
  sidebar rhythm, code fence line wrap (agegr#1360/agegr#1369), svg fence preview,
  display-math copy, binary notice, pi packages 1.4.0
- fork features carried: event-bus convergence, ticket file channel,
  conn-guard, queue mirror w/ attachment flags, draft-keeper contract,
  lazy Prism chunk, stream-parse throttle, own toolbar/mobile composer
- fixes from post-merge inheritance testing: code fence wrap on the lazy
  highlighter path (agegr#1369), Debug panel entry re-homed + basePath-aware
  fetch, online reconcile bypass, wrapper registration order, TS6 test
  harness adaptation
windli2018 added a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…0.13 integration)

- upstream v0.13.0: Debug panel, prompt parking during compaction (agegr#1426),
  unconfirmed-send recovery (agegr#1432), live-session rename (agegr#1451), spacer
  sidebar rhythm, code fence line wrap (agegr#1360/agegr#1369), svg fence preview,
  display-math copy, binary notice, pi packages 1.4.0
- fork features carried: event-bus convergence, ticket file channel,
  conn-guard, queue mirror w/ attachment flags, draft-keeper contract,
  lazy Prism chunk, stream-parse throttle, own toolbar/mobile composer
- fixes from post-merge inheritance testing: code fence wrap on the lazy
  highlighter path (agegr#1369), Debug panel entry re-homed + basePath-aware
  fetch, online reconcile bypass, wrapper registration order, TS6 test
  harness adaptation
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
* feat(chat): queue prompts sent while compaction runs

pi's SDK rejects prompts during compaction ("Cannot submit a prompt while
compaction is in progress"), so every submission bounced back to the
composer with an error and the input read as dead. Park the submissions in
the wrapper and flush them FIFO at compaction end, as pi's TUI's
compactionQueuedMessages does. This is the compaction-queueing part of
agegr#812, the focused follow-up its closing comment asked for.

- Parking happens on the SDK's rejection, never before inner.prompt(), so
  an extension command typed during compaction still runs: the SDK
  executes commands before it refuses.
- A parked prompt keeps its admission's pendingPromptCount outstanding
  until delivery or recall, so isRunning(), the idle shutdown and the
  reload/clone refusals all see it.
- The flush is the TUI's flushCompactionQueue() in the wrapper: every
  delivery carries a streamingBehavior (a plain parked prompt as followUp),
  so AgentSession.prompt() queues it into a run still finishing the
  compaction or starts one when idle, never "Agent is already processing".
  A delivery that started the run emits its prompt_done, one that queued
  into another run rides that run's, and a failed delivery goes back to the
  queue with prompt_error and waits for Recall or the next compaction end.
- get_state.queuedMessages and every queue_update merge pi's queue with the
  parked ones; clear_queue returns both, and Recall puts the text back in
  the composer.
- The composer stays editable while compacting: the placeholder says
  messages queue, and the status line shows "Compacting... - N queued",
  for a manual compaction too (agentRunning alone left it unlabeled).

Tests: lib/rpc-manager-compaction-queue.test.mjs (park, FIFO flush,
recall, merge, failed flush, images), the queued-count case in
chat-phase-label, the editable-composer case in ChatInput. tsc, eslint and
the touched areas' 246 tests pass; the 66 suite failures on this Windows
machine are identical with and without the change.

* fix(chat): keep the composer usable during compaction, and queued prompts out of the transcript

Two bugs from manual testing of the compaction queueing.

1. /compact disabled the composer for the whole compaction. The builtin
   slash handler awaited the blocking compact POST, and runBuiltinCommand
   holds the composer's <fieldset disabled> until the command resolves: the
   input box took no text until the session was switched away and back (a
   remount resets builtinCommandPending). The command now completes at once
   and runs the compaction detached through handleCompact, the Compact
   button's path, which reports itself (Compacting status, Stop compaction,
   result banner, error); its result is the silent action: "compact".
   handleCompact takes the optional custom instructions and promotes the
   session after its reload, as the inline path did.

2. A parked prompt rendered as a sent message. handleSend's optimistic
   bubble stayed in the transcript while the message waited in the queue.
   A queued submission is now acked { queued: true } (parked, or the SDK's
   "queued" disposition) and the client drops the bubble: the queue rows
   show it, and the transcript shows it when the flush delivers it.

Tests: hooks/compact-command.test.mjs pins the detached /compact against a
compact POST that never resolves; lib/rpc-manager-compaction-queue.test.mjs
pins the queued ack (and the extension command still answering null).
tsc, eslint and the touched areas' 258 tests pass.

* test: run the suite green on Windows

28 test files fixed, test and fixture code only (plus one fixture server).
No product change. Root causes, by cluster:

- 8.3 temp paths: %TEMP% resolves to C:\Users\LINWEI~1\... while git,
  the SDK and $HOME report expanded names. Node's realpathSync keeps short
  names (only realpathSync.native expands them), so fixtures compared
  unequal paths and ancestor walks reached the real ~/.agents/skills from
  the scratch dir. Fixture roots now canonicalize with realpathSync.native.
- CRLF checkouts: source-reading tests sliced on ";\n" and regexes ended
  at \n before \r, so they extracted nothing. Repo convention
  .replace(/\r\n/g, "\n") applied at the read sites.
- chmod on Windows: 0o500/0o400 do not make directories unwritable and
  stat reports 0o666 regardless. Unwritable tests now lock the file too
  (same refusal path, different syscall); mode assertions keep POSIX.
- ESM absolute paths: hooks fixtures imported a raw G:\... path, which
  Node's ESM loader rejects (protocol 'g:'), and drive-letter-case drift
  would load a second shim instance. They now take the shim through
  jiti.import("react"), the alias route the hooks resolve react by.
- ConPTY: node-pty reports pid 0 until its worker connects and arms a 5s
  watchdog; tests now wait for the connection before asserting or ticking
  mock timers.
- EBUSY teardown: fixture MCP servers held cwd open while rm ran (Windows
  refuses); shutdown is awaited first and removal retries. A fixture's
  !touch marker wrote into the repo root (unquoted backslashes in bash -c);
  markers are quoted with forward slashes. Grandchild processes of the
  MCP fixture now exit with their parent.
- PATH assertions joined with the host delimiter for a case that tests
  another platform; PTY and skills-walk tests reached the developer's real
  home on Windows (temp under the profile): hermetic .git marker added.

npm test now passes end to end here (2880 tests, 2859 pass, 21 skipped,
0 fail) and exits without --test-force-exit; it used to hang on leaked
fixture processes and fail 66.

* Revert "test: run the suite green on Windows"

This reverts commit 63924a8. The Windows test fixes are unrelated to
compaction queueing, and most of them (14 of 29 files) overlap the open
Windows test PRs agegr#1364-agegr#1368. They belong in a PR of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): flush parked prompts in order and keep them on Stop

- The flush called inner.prompt() for every parked prompt at once, so an
  `input` handler that took longer on the first one let the second start
  the run: [slow, fast] went out as [fast, slow]. Each delivery now goes
  through the prompt admission chain, one submission at a time, so a
  prompt sent after compaction_end also queues behind them.
- Stop (`abort`) ends the compaction, and its compaction_end sent the
  parked prompts: Stop started a run, under forceShutdownOnIdle. Stop now
  recalls them first and returns their texts for the composer, as the
  TUI's abort restores queued messages to the editor. Stop compaction
  still flushes them, as Esc during compaction does in the TUI.
- A delivery that failed after it was accepted was parked again and
  would have been sent twice; a refused one kept its admission count, so
  the session stayed running until Recall. Now only a refused delivery
  goes back to the queue, with its admission settled; settle() is the
  admission's idempotent finishPrompt, so Recall never settles twice.
- Recall and Stop send prompt_done for a recalled plain prompt (its client
  waits for one); the delivery that started the run sends it whatever its
  streamingBehavior.
- Park only on the SDK's refusal before preflight: `inner.isCompacting`
  alone parked unrelated errors during auto-compaction. `queued: true` is
  the parked ack only, and auto_compaction_end (no pi 1.4 event) is gone.

lib/rpc-manager-compaction-queue.integration.test.mjs plays both bugs
against a real AgentSession and fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): Stop puts prompts parked behind a compaction back in the composer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): parked prompts survive a late refusal and Recall during the flush

- The SDK's refusal reaches the wrapper's handler a microtask later, so
  compaction_end could flush before the prompt was parked: it stayed a
  queue row and the session read running for good. The handler now
  flushes itself when the compaction is already over.
- flushParkedPrompts() emptied the queue at once while each delivery
  waited for admission: during the first one's preflight, Recall returned
  nothing and Stop could not take the rest back, which were sent anyway.
  An entry now stays listed until its delivery holds admission; Recall
  and Stop take it, and the delivery skips an entry that is gone.
- A plain parked prompt is a steer, as the TUI parks Enter during
  compaction: as a followUp it was listed (and recalled) after the steers
  sent after it, so "A" then "B" came back as "B", "A". Delivery stays FIFO.
- Recall and Stop return the parked prompts' images beside their texts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): restore recalled images, and /compact instructions on failure

Recall and Stop put the images of prompts parked behind a compaction back
in the composer with their texts (restoreSubmission, as a refused prompt
had them before). A /compact <instructions> whose compaction fails gives
the command back to the composer, where the awaited command left it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: qiyu <linweiguang@shangyoo.com>
Co-authored-by: Alex Yang <agegcn@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
windli2018 added a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…0.13 integration)

- upstream v0.13.0: Debug panel, prompt parking during compaction (agegr#1426),
  unconfirmed-send recovery (agegr#1432), live-session rename (agegr#1451), spacer
  sidebar rhythm, code fence line wrap (agegr#1360/agegr#1369), svg fence preview,
  display-math copy, binary notice, pi packages 1.4.0
- fork features carried: event-bus convergence, ticket file channel,
  conn-guard, queue mirror w/ attachment flags, draft-keeper contract,
  lazy Prism chunk, stream-parse throttle, own toolbar/mobile composer
- fixes from post-merge inheritance testing: code fence wrap on the lazy
  highlighter path (agegr#1369), Debug panel entry re-homed + basePath-aware
  fetch, online reconcile bypass, wrapper registration order, TS6 test
  harness adaptation
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
* feat(chat): queue prompts sent while compaction runs

pi's SDK rejects prompts during compaction ("Cannot submit a prompt while
compaction is in progress"), so every submission bounced back to the
composer with an error and the input read as dead. Park the submissions in
the wrapper and flush them FIFO at compaction end, as pi's TUI's
compactionQueuedMessages does. This is the compaction-queueing part of
agegr#812, the focused follow-up its closing comment asked for.

- Parking happens on the SDK's rejection, never before inner.prompt(), so
  an extension command typed during compaction still runs: the SDK
  executes commands before it refuses.
- A parked prompt keeps its admission's pendingPromptCount outstanding
  until delivery or recall, so isRunning(), the idle shutdown and the
  reload/clone refusals all see it.
- The flush is the TUI's flushCompactionQueue() in the wrapper: every
  delivery carries a streamingBehavior (a plain parked prompt as followUp),
  so AgentSession.prompt() queues it into a run still finishing the
  compaction or starts one when idle, never "Agent is already processing".
  A delivery that started the run emits its prompt_done, one that queued
  into another run rides that run's, and a failed delivery goes back to the
  queue with prompt_error and waits for Recall or the next compaction end.
- get_state.queuedMessages and every queue_update merge pi's queue with the
  parked ones; clear_queue returns both, and Recall puts the text back in
  the composer.
- The composer stays editable while compacting: the placeholder says
  messages queue, and the status line shows "Compacting... - N queued",
  for a manual compaction too (agentRunning alone left it unlabeled).

Tests: lib/rpc-manager-compaction-queue.test.mjs (park, FIFO flush,
recall, merge, failed flush, images), the queued-count case in
chat-phase-label, the editable-composer case in ChatInput. tsc, eslint and
the touched areas' 246 tests pass; the 66 suite failures on this Windows
machine are identical with and without the change.

* fix(chat): keep the composer usable during compaction, and queued prompts out of the transcript

Two bugs from manual testing of the compaction queueing.

1. /compact disabled the composer for the whole compaction. The builtin
   slash handler awaited the blocking compact POST, and runBuiltinCommand
   holds the composer's <fieldset disabled> until the command resolves: the
   input box took no text until the session was switched away and back (a
   remount resets builtinCommandPending). The command now completes at once
   and runs the compaction detached through handleCompact, the Compact
   button's path, which reports itself (Compacting status, Stop compaction,
   result banner, error); its result is the silent action: "compact".
   handleCompact takes the optional custom instructions and promotes the
   session after its reload, as the inline path did.

2. A parked prompt rendered as a sent message. handleSend's optimistic
   bubble stayed in the transcript while the message waited in the queue.
   A queued submission is now acked { queued: true } (parked, or the SDK's
   "queued" disposition) and the client drops the bubble: the queue rows
   show it, and the transcript shows it when the flush delivers it.

Tests: hooks/compact-command.test.mjs pins the detached /compact against a
compact POST that never resolves; lib/rpc-manager-compaction-queue.test.mjs
pins the queued ack (and the extension command still answering null).
tsc, eslint and the touched areas' 258 tests pass.

* test: run the suite green on Windows

28 test files fixed, test and fixture code only (plus one fixture server).
No product change. Root causes, by cluster:

- 8.3 temp paths: %TEMP% resolves to C:\Users\LINWEI~1\... while git,
  the SDK and $HOME report expanded names. Node's realpathSync keeps short
  names (only realpathSync.native expands them), so fixtures compared
  unequal paths and ancestor walks reached the real ~/.agents/skills from
  the scratch dir. Fixture roots now canonicalize with realpathSync.native.
- CRLF checkouts: source-reading tests sliced on ";\n" and regexes ended
  at \n before \r, so they extracted nothing. Repo convention
  .replace(/\r\n/g, "\n") applied at the read sites.
- chmod on Windows: 0o500/0o400 do not make directories unwritable and
  stat reports 0o666 regardless. Unwritable tests now lock the file too
  (same refusal path, different syscall); mode assertions keep POSIX.
- ESM absolute paths: hooks fixtures imported a raw G:\... path, which
  Node's ESM loader rejects (protocol 'g:'), and drive-letter-case drift
  would load a second shim instance. They now take the shim through
  jiti.import("react"), the alias route the hooks resolve react by.
- ConPTY: node-pty reports pid 0 until its worker connects and arms a 5s
  watchdog; tests now wait for the connection before asserting or ticking
  mock timers.
- EBUSY teardown: fixture MCP servers held cwd open while rm ran (Windows
  refuses); shutdown is awaited first and removal retries. A fixture's
  !touch marker wrote into the repo root (unquoted backslashes in bash -c);
  markers are quoted with forward slashes. Grandchild processes of the
  MCP fixture now exit with their parent.
- PATH assertions joined with the host delimiter for a case that tests
  another platform; PTY and skills-walk tests reached the developer's real
  home on Windows (temp under the profile): hermetic .git marker added.

npm test now passes end to end here (2880 tests, 2859 pass, 21 skipped,
0 fail) and exits without --test-force-exit; it used to hang on leaked
fixture processes and fail 66.

* Revert "test: run the suite green on Windows"

This reverts commit 63924a8. The Windows test fixes are unrelated to
compaction queueing, and most of them (14 of 29 files) overlap the open
Windows test PRs agegr#1364-agegr#1368. They belong in a PR of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): flush parked prompts in order and keep them on Stop

- The flush called inner.prompt() for every parked prompt at once, so an
  `input` handler that took longer on the first one let the second start
  the run: [slow, fast] went out as [fast, slow]. Each delivery now goes
  through the prompt admission chain, one submission at a time, so a
  prompt sent after compaction_end also queues behind them.
- Stop (`abort`) ends the compaction, and its compaction_end sent the
  parked prompts: Stop started a run, under forceShutdownOnIdle. Stop now
  recalls them first and returns their texts for the composer, as the
  TUI's abort restores queued messages to the editor. Stop compaction
  still flushes them, as Esc during compaction does in the TUI.
- A delivery that failed after it was accepted was parked again and
  would have been sent twice; a refused one kept its admission count, so
  the session stayed running until Recall. Now only a refused delivery
  goes back to the queue, with its admission settled; settle() is the
  admission's idempotent finishPrompt, so Recall never settles twice.
- Recall and Stop send prompt_done for a recalled plain prompt (its client
  waits for one); the delivery that started the run sends it whatever its
  streamingBehavior.
- Park only on the SDK's refusal before preflight: `inner.isCompacting`
  alone parked unrelated errors during auto-compaction. `queued: true` is
  the parked ack only, and auto_compaction_end (no pi 1.4 event) is gone.

lib/rpc-manager-compaction-queue.integration.test.mjs plays both bugs
against a real AgentSession and fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): Stop puts prompts parked behind a compaction back in the composer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): parked prompts survive a late refusal and Recall during the flush

- The SDK's refusal reaches the wrapper's handler a microtask later, so
  compaction_end could flush before the prompt was parked: it stayed a
  queue row and the session read running for good. The handler now
  flushes itself when the compaction is already over.
- flushParkedPrompts() emptied the queue at once while each delivery
  waited for admission: during the first one's preflight, Recall returned
  nothing and Stop could not take the rest back, which were sent anyway.
  An entry now stays listed until its delivery holds admission; Recall
  and Stop take it, and the delivery skips an entry that is gone.
- A plain parked prompt is a steer, as the TUI parks Enter during
  compaction: as a followUp it was listed (and recalled) after the steers
  sent after it, so "A" then "B" came back as "B", "A". Delivery stays FIFO.
- Recall and Stop return the parked prompts' images beside their texts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): restore recalled images, and /compact instructions on failure

Recall and Stop put the images of prompts parked behind a compaction back
in the composer with their texts (restoreSubmission, as a refused prompt
had them before). A /compact <instructions> whose compaction fails gives
the command back to the composer, where the awaited command left it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: qiyu <linweiguang@shangyoo.com>
Co-authored-by: Alex Yang <agegcn@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
* feat(chat): queue prompts sent while compaction runs

pi's SDK rejects prompts during compaction ("Cannot submit a prompt while
compaction is in progress"), so every submission bounced back to the
composer with an error and the input read as dead. Park the submissions in
the wrapper and flush them FIFO at compaction end, as pi's TUI's
compactionQueuedMessages does. This is the compaction-queueing part of
agegr#812, the focused follow-up its closing comment asked for.

- Parking happens on the SDK's rejection, never before inner.prompt(), so
  an extension command typed during compaction still runs: the SDK
  executes commands before it refuses.
- A parked prompt keeps its admission's pendingPromptCount outstanding
  until delivery or recall, so isRunning(), the idle shutdown and the
  reload/clone refusals all see it.
- The flush is the TUI's flushCompactionQueue() in the wrapper: every
  delivery carries a streamingBehavior (a plain parked prompt as followUp),
  so AgentSession.prompt() queues it into a run still finishing the
  compaction or starts one when idle, never "Agent is already processing".
  A delivery that started the run emits its prompt_done, one that queued
  into another run rides that run's, and a failed delivery goes back to the
  queue with prompt_error and waits for Recall or the next compaction end.
- get_state.queuedMessages and every queue_update merge pi's queue with the
  parked ones; clear_queue returns both, and Recall puts the text back in
  the composer.
- The composer stays editable while compacting: the placeholder says
  messages queue, and the status line shows "Compacting... - N queued",
  for a manual compaction too (agentRunning alone left it unlabeled).

Tests: lib/rpc-manager-compaction-queue.test.mjs (park, FIFO flush,
recall, merge, failed flush, images), the queued-count case in
chat-phase-label, the editable-composer case in ChatInput. tsc, eslint and
the touched areas' 246 tests pass; the 66 suite failures on this Windows
machine are identical with and without the change.

* fix(chat): keep the composer usable during compaction, and queued prompts out of the transcript

Two bugs from manual testing of the compaction queueing.

1. /compact disabled the composer for the whole compaction. The builtin
   slash handler awaited the blocking compact POST, and runBuiltinCommand
   holds the composer's <fieldset disabled> until the command resolves: the
   input box took no text until the session was switched away and back (a
   remount resets builtinCommandPending). The command now completes at once
   and runs the compaction detached through handleCompact, the Compact
   button's path, which reports itself (Compacting status, Stop compaction,
   result banner, error); its result is the silent action: "compact".
   handleCompact takes the optional custom instructions and promotes the
   session after its reload, as the inline path did.

2. A parked prompt rendered as a sent message. handleSend's optimistic
   bubble stayed in the transcript while the message waited in the queue.
   A queued submission is now acked { queued: true } (parked, or the SDK's
   "queued" disposition) and the client drops the bubble: the queue rows
   show it, and the transcript shows it when the flush delivers it.

Tests: hooks/compact-command.test.mjs pins the detached /compact against a
compact POST that never resolves; lib/rpc-manager-compaction-queue.test.mjs
pins the queued ack (and the extension command still answering null).
tsc, eslint and the touched areas' 258 tests pass.

* test: run the suite green on Windows

28 test files fixed, test and fixture code only (plus one fixture server).
No product change. Root causes, by cluster:

- 8.3 temp paths: %TEMP% resolves to C:\Users\LINWEI~1\... while git,
  the SDK and $HOME report expanded names. Node's realpathSync keeps short
  names (only realpathSync.native expands them), so fixtures compared
  unequal paths and ancestor walks reached the real ~/.agents/skills from
  the scratch dir. Fixture roots now canonicalize with realpathSync.native.
- CRLF checkouts: source-reading tests sliced on ";\n" and regexes ended
  at \n before \r, so they extracted nothing. Repo convention
  .replace(/\r\n/g, "\n") applied at the read sites.
- chmod on Windows: 0o500/0o400 do not make directories unwritable and
  stat reports 0o666 regardless. Unwritable tests now lock the file too
  (same refusal path, different syscall); mode assertions keep POSIX.
- ESM absolute paths: hooks fixtures imported a raw G:\... path, which
  Node's ESM loader rejects (protocol 'g:'), and drive-letter-case drift
  would load a second shim instance. They now take the shim through
  jiti.import("react"), the alias route the hooks resolve react by.
- ConPTY: node-pty reports pid 0 until its worker connects and arms a 5s
  watchdog; tests now wait for the connection before asserting or ticking
  mock timers.
- EBUSY teardown: fixture MCP servers held cwd open while rm ran (Windows
  refuses); shutdown is awaited first and removal retries. A fixture's
  !touch marker wrote into the repo root (unquoted backslashes in bash -c);
  markers are quoted with forward slashes. Grandchild processes of the
  MCP fixture now exit with their parent.
- PATH assertions joined with the host delimiter for a case that tests
  another platform; PTY and skills-walk tests reached the developer's real
  home on Windows (temp under the profile): hermetic .git marker added.

npm test now passes end to end here (2880 tests, 2859 pass, 21 skipped,
0 fail) and exits without --test-force-exit; it used to hang on leaked
fixture processes and fail 66.

* Revert "test: run the suite green on Windows"

This reverts commit 63924a8. The Windows test fixes are unrelated to
compaction queueing, and most of them (14 of 29 files) overlap the open
Windows test PRs agegr#1364-agegr#1368. They belong in a PR of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): flush parked prompts in order and keep them on Stop

- The flush called inner.prompt() for every parked prompt at once, so an
  `input` handler that took longer on the first one let the second start
  the run: [slow, fast] went out as [fast, slow]. Each delivery now goes
  through the prompt admission chain, one submission at a time, so a
  prompt sent after compaction_end also queues behind them.
- Stop (`abort`) ends the compaction, and its compaction_end sent the
  parked prompts: Stop started a run, under forceShutdownOnIdle. Stop now
  recalls them first and returns their texts for the composer, as the
  TUI's abort restores queued messages to the editor. Stop compaction
  still flushes them, as Esc during compaction does in the TUI.
- A delivery that failed after it was accepted was parked again and
  would have been sent twice; a refused one kept its admission count, so
  the session stayed running until Recall. Now only a refused delivery
  goes back to the queue, with its admission settled; settle() is the
  admission's idempotent finishPrompt, so Recall never settles twice.
- Recall and Stop send prompt_done for a recalled plain prompt (its client
  waits for one); the delivery that started the run sends it whatever its
  streamingBehavior.
- Park only on the SDK's refusal before preflight: `inner.isCompacting`
  alone parked unrelated errors during auto-compaction. `queued: true` is
  the parked ack only, and auto_compaction_end (no pi 1.4 event) is gone.

lib/rpc-manager-compaction-queue.integration.test.mjs plays both bugs
against a real AgentSession and fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): Stop puts prompts parked behind a compaction back in the composer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): parked prompts survive a late refusal and Recall during the flush

- The SDK's refusal reaches the wrapper's handler a microtask later, so
  compaction_end could flush before the prompt was parked: it stayed a
  queue row and the session read running for good. The handler now
  flushes itself when the compaction is already over.
- flushParkedPrompts() emptied the queue at once while each delivery
  waited for admission: during the first one's preflight, Recall returned
  nothing and Stop could not take the rest back, which were sent anyway.
  An entry now stays listed until its delivery holds admission; Recall
  and Stop take it, and the delivery skips an entry that is gone.
- A plain parked prompt is a steer, as the TUI parks Enter during
  compaction: as a followUp it was listed (and recalled) after the steers
  sent after it, so "A" then "B" came back as "B", "A". Delivery stays FIFO.
- Recall and Stop return the parked prompts' images beside their texts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): restore recalled images, and /compact instructions on failure

Recall and Stop put the images of prompts parked behind a compaction back
in the composer with their texts (restoreSubmission, as a refused prompt
had them before). A /compact <instructions> whose compaction fails gives
the command back to the composer, where the awaited command left it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: qiyu <linweiguang@shangyoo.com>
Co-authored-by: Alex Yang <agegcn@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants