Skip to content

fix(coding-agent): harden compaction lifecycle ownership#325

Closed
minpeter wants to merge 10 commits into
code-yeongyu:mainfrom
minpeter:fix/compaction-lifecycle-reviewed
Closed

fix(coding-agent): harden compaction lifecycle ownership#325
minpeter wants to merge 10 commits into
code-yeongyu:mainfrom
minpeter:fix/compaction-lifecycle-reviewed

Conversation

@minpeter

@minpeter minpeter commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • supersede fix(coding-agent): stabilize compaction lifecycle #310 with a clean replay directly on current main
  • own every compaction generation with operation identity, terminal-state retention, and source revision checks
  • keep queued prompts fail-closed while required compaction is pending or rejected
  • synchronize retry fallback model/context selection before provider admission
  • preserve provider-confirmed fallback overflow through stale threshold suppression
  • retain hidden PreCompact diagnostics without accepting unrelated concurrent source mutation

This branch incorporates the complete maintainer review/pr-310 lifecycle/fallback review line without its merged-main
commit. The final overflow regression and implementation are one GREEN commit; no commit in this PR intentionally
leaves the focused suite RED.

Why replace #310

PR #310 contains the original two commits, but the upstream review branch added seven tightly coupled lifecycle,
queue-admission, fallback-window, and resumed-compaction corrections. Updating the old branch without a merge commit
would require rewriting its published history. This replacement preserves reviewable atomic commits, starts from
current main, and has no stacked dependency.

Reported failures covered

  • overlapping compaction generations overwriting terminal feedback
  • queued follow-up/native messages draining after required compaction rejection
  • retry fallback entering a smaller context window without revalidation
  • current-model restoration and resume divergence
  • provider-confirmed fallback overflow being reclassified as threshold after a post-retry skip
  • hidden PreCompact diagnostics being mistaken for unrelated stale-source mutation

RED -> GREEN

  • Review branch terminal RED:
    • expected rejected reason: "overflow"
    • observed rejected reason: "threshold"
  • GREEN:
    • explicit one-shot skip-next-threshold state with retry-window provenance
    • successful stale usage remains suppressible
    • stopReason: "error" provider overflow remains required
    • target 1/1, two-compaction characterization 2/2, focused retry/fallback file 10/10
  • Full-suite-discovered RED:
    • hidden PreCompact diagnostic caused stale-revision
  • GREEN:
    • only exact hidden senpi.hook and pending message_end appends with matching revision deltas are operation-owned
    • hook target 1/1, concurrent stale-source regression 4/4, snapshot group 26/26

Verification

  • focused compaction/retry matrix: 12 files / 75 tests passed
  • retry/fallback engine: 10/10 passed
  • compaction snapshot group: 5 files / 26 tests passed
  • root build: passed
  • root npm run check: passed
  • changed-file Biome and git diff --check: passed
  • real source CLI mock loop: exit 0, exactly one local provider request, expected assistant text, auth unchanged
  • built CLI --help: exit 0
  • built CLI invalid install input: exit 1 with usage

The four-worker full coding-agent suite completed 557/558 files and 4,584/4,585 tests. Its only failure was the
unrelated app-server StdioClient.close() process-group regression timing out under suite load; that exact file passed
directly at 11/11. Earlier higher-parallel runs produced different MCP/app-server timeout/resource failures which also
passed directly. No failing compaction/lifecycle test remains.

PR topology


Summary by cubic

Hardens the compaction lifecycle to own each generation, reject stale updates, and gate provider admissions to prevent races and bad queue drains. Stabilizes retries, preserves overflow semantics, and keeps interactive input safe after compaction.

  • New Features

    • Added a lifecycle coordinator with monotonic generations and operation IDs; snapshots model/provider at start and retains terminal state until the next operation.
    • Unified required-compaction admission for preflight, extension turns, and next turns; fail-closed on provider overflow or threshold.
    • Added Agent.suppressQueuedMessageDrain() to keep steering/follow-up queues after agent_end without aborting.
    • Extensions now pass an optional operation AbortSignal through beginCompaction, updateCompaction, endCompaction, and applyCompaction; superseded feedback is ignored.
    • Builtin compaction exposes only active tools to the summarizer; context builder excludes older summaries; prepareCompaction can force progress and allow summary-only.
  • Bug Fixes

    • Prevented older compaction feedback from overwriting newer generations; emit exactly one terminal event per operation.
    • Stopped auto-draining queued input after rejected/failed required compaction; interactive-mode replays only after accept and restores the Escape handler once.
    • Preserved provider-confirmed fallback overflow as overflow (not threshold) with correct retry provenance.
    • Restored current model and tool state when retrying, with context window revalidation on fallback.
    • Accepted hidden PreCompact diagnostics as operation-owned while rejecting unrelated source mutations as stale-revision; preserved compaction boundaries to avoid double-counting.

Written for commit 3549278. Summary will update on new commits.

Review in cubic

@minpeter

Copy link
Copy Markdown
Contributor Author

Superseded by the actual upstream merge of #310 plus its one-commit follow-up #326: #326. PR #310 advanced and merged while this replacement was being verified, already incorporating the lifecycle/overflow/hook review fixes; #326 contains only the remaining merged-main compaction-attempt regression.

@minpeter minpeter closed this Jul 24, 2026
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