Skip to content

Make command rows compaction-aware - #9

Merged
tmustier merged 4 commits into
mainfrom
feat/compaction-aware-command-rows
Aug 9, 2026
Merged

Make command rows compaction-aware#9
tmustier merged 4 commits into
mainfrom
feat/compaction-aware-command-rows

Conversation

@tmustier

@tmustier tmustier commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

This completes compaction-aware command rows as an extension-only implementation using public Pi APIs.

  • execute queued /compact [instructions] and /reload rows at their FIFO position
  • hold extension-owned rows through manual compaction, automatic overflow/threshold compaction, retry decisions, and native post-compaction input
  • preserve committed row IDs, lanes, images, recency, and pause state across repeated runtime reloads
  • keep image-bearing command text as a normal message so attachments are never discarded
  • keep RPC, JSON, and print-mode input outside queue ownership
  • expand queued prompt templates and Agent Skills from the active runtime at delivery
  • restore only unsent rows after synchronous handoff failure and pause a /compact row when compaction cannot start
  • remove stale editor guards on shutdown, including after late editor recomposition

Queue state remains session-local. It is not written to the transcript, session data, or validation artifacts.

Ordering and recovery behavior

  • Pi's steering and follow-up lanes remain independent FIFOs.
  • one-at-a-time and all delivery settings still apply per lane.
  • Ordinary input submitted during compaction remains in Pi's native compaction queue. A later queued command waits for that native turn to settle.
  • Length, error, and overflow stops hold follow-ups until Pi has made its retry or auto-compaction decision.
  • /reload snapshots the queue during session_shutdown, so rows added after reload scheduling are included. Repeated queued reloads retain row identity and do not duplicate rows.
  • Aborting a user run pauses both visible lanes. Aborts caused by tracked compaction do not incorrectly pause them.

Dependency policy

Pi package ranges are intentionally unpinned (*) in both peerDependencies and development dependencies. The lockfile records Pi 0.84.1 for a reproducible checkout, but the package manifest does not declare an artificial compatibility target.

Refresh compatibility validation to the current Pi packages with:

npm update --ignore-scripts \
  @earendil-works/pi-ai \
  @earendil-works/pi-coding-agent \
  @earendil-works/pi-tui
npm run ci

Automated validation

npm ci --ignore-scripts
npm run ci

Result with the current resolved Pi 0.84.1 packages: 81 tests passed, 0 failed. This includes real AgentSession paths for manual compaction success/failure, retry-before-release ordering, and public-prompt overflow compaction.

Real TUI evidence

./test/tui-evidence.sh /tmp/pi-queue-pr9-evidence-final-unpinned

Final clean-tree run:

pi: 0.84.1
commit: 37fcd1433b8960f13c030d9ba1a5e8cc36535e05
working tree: clean
manual events: {"event":"session_before_compact","reason":"manual"} {"event":"session_before_compact","reason":"manual"}
overflow events: {"event":"session_before_compact","reason":"overflow"} {"event":"session_before_compact","reason":"threshold"}
runtime initializations across two queued reloads: 3
captures: abort-paused, manual-reload-resources, native-before-command, automatic-overflow, all-mode

The harness uses Pi's real 0.84.1 TUI under tmux with a deterministic faux provider. It mechanically verifies:

  • successful and failed manual compaction
  • abort, visible pause, and explicit resume
  • two queued runtime reloads followed by exactly one trailing message
  • prompt-template and Agent Skill expansion after reload
  • ordinary native post-compaction input completing before queued /reload
  • public overflow compaction followed by an exactly-once queued completion
  • all-mode rows reaching one provider context exactly once in FIFO order

See docs/validation.md for artifact names and interpretation.

Public API limits

ExtensionAPI.sendUserMessage and the TUI editor submit callback return void. The extension restores synchronous dispatch and preflight failures, but cannot observe a later asynchronous rejection without risking duplicate delivery. Queued /reload likewise has no acknowledgement channel. These limits are documented rather than hidden behind timing heuristics.

@tmustier

tmustier commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Normal-Pi adversarial evidence

Media note: the first capture requested an unavailable JetBrains Mono font, which made VHS use mismatched fallback glyph metrics. These assets were recaptured with the installed Menlo font and explicit zero letter spacing. The assertions were rerun against the replacement sessions.

Tested commit 37fcd1433b8960f13c030d9ba1a5e8cc36535e05 on Pi 0.84.1 by launching plain pi inside tmux. No --extension, -e, --no-extensions, provider fixture, alternate agent directory, or Pi settings override was used. The normal configured extension set was active, including pi-queue-steer, pi-auto-compact, and model-aware-compaction.

Historical sessions were copied and deterministically content-redacted before use. Structure and usage accounting were preserved, and SHA-256 verification confirms the source session remained byte-identical. A private tmux server used extended-keys on so Option+Enter reached Pi. Hostname pixels are redacted in the public media.

Automatic 200k compaction, queued reload, trailing follow-up

The copied session started at 220,714 tokens. The live request reached 273k, the installed 200k policy injected the overflow after a real tool turn, Pi recorded a compaction at 273,196 tokens and retried, /reload ran, then the restored trailing row produced AUTO_FOLLOWUP_DONE.

auto-200k-reload.mp4

Queued command and follow-up:

Automatic compaction queue

Successful compaction, reload, and trailing response:

Automatic compaction final state

Manual compaction with native post-compaction input

Ordinary Enter and Option+Enter submissions made while manual compaction was active stayed in Pi's native post-compaction queues. The visible /reload command remained extension-owned. Pi compacted from 220,714 tokens, delivered both native messages once, then ran the queued reload. This confirms the public-API ordering boundary: Pi's private post-compaction queues run before visible extension command rows.

manual-compact-native-reload.mp4

During compaction:

Manual compaction queues

After compaction and both native messages, with reload starting:

Manual compaction final state

Abort, pause, two reloads, recovery

A real bash tool was aborted while four follow-up rows were visible: /reload, a marker message, /reload, and a final marker. Escape paused all four. Empty Enter resumed them. The recording shows the first runtime reload before RELOAD_MIDDLE_DONE, then the second before ABORT_RECOVERED_DONE. No /reload command was persisted as a user message.

abort-repeated-reload.mp4

Paused queue:

Paused repeated reload queue

First and second runtime swaps, extracted at 24s and 32s:

First reload

Second reload

Final response:

Abort recovery final state

Reproducible evidence bundle

The bundle contains the VHS tapes, three MP4s, screenshots, redacted transcript captures, sanitized session snapshots, deterministic harness captures, provenance, machine-checked assertions, and SHA256SUMS.

Download pi-queue-steer-normal-pi-evidence-37fcd14.zip

Archive SHA-256: c6b1150f13fccc195eb5747aa6af63c4589b73df116e3d36d27e92fb85a45e98

Final validation:

  • npm run ci: 81 tests passed.
  • ./test/tui-evidence.sh: passed on Pi 0.84.1 with a clean tree.
  • Deterministic TUI evidence recorded three runtime initializations for two queued reloads and also covers all-mode batching, editor operations, images, resource expansion, failure restoration, real retry ordering, manual compaction failures, and automatic overflow.
  • PR checks remain green.

This is strong, independently checkable evidence for the tested paths, not a claim about every possible terminal, provider, timing, or third-party extension combination.

This comment is AI-generated.

@tmustier
tmustier merged commit c654add into main Aug 9, 2026
2 checks passed
@tmustier
tmustier deleted the feat/compaction-aware-command-rows branch August 9, 2026 12:54
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