Skip to content

feat: mark_block + batch cleanup for deferred block consolidation#13

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-06-26_mark-block-batch-cleanup
Open

feat: mark_block + batch cleanup for deferred block consolidation#13
ranxianglei wants to merge 2 commits into
masterfrom
2026-06-26_mark-block-batch-cleanup

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Adds mark_block tool + three-tier batch cleanup to ACP, separating block-cleanup intent from execution for minimum cache impact.

Problem

ACP blocks are only-in-not-out — the model can compress/decompress but cannot delete. The only deletion mechanism is GC (age-based deactivation at maxBlockAge=15), which fires regardless of context pressure and causes unnecessary cache misses + loss of important info (task_ids).

Solution

  1. mark_block(blockId) — model marks a block for deferred cleanup. Zero cache impact (block stays fully active, only sets internal flag).

  2. Three-tier batch cleanup in the message transform pipeline:

    • Tier 1 (60%): nudge model about marked blocks
    • Tier 2 (75%): auto merge-compress all marked blocks into one summary
    • Tier 3 (90%): force merge ALL old-gen blocks (new fallback before GC)
  3. Existing GC retained as ultimate fallback at 100%. New mechanism is additive — no changes to existing behavior.

Cache impact

Scenario Cache breaks
mark_block (any time) 0
Tier 1 nudge 0 (appends to last message)
Tier 2/3 merge 1 (single break at block position)

Files

New: lib/gc/merge.ts (mergeMarkedBlocks + runBatchCleanup), lib/compress/mark-block.ts (mark_block/unmark_block tools)
Modified: types, config, config-validation, hooks, index, prompts, persistence, state-utils, schema, 10 test files

Verification

  • npm run typecheck
  • npm run build
  • npm run test ✅ (386/386, unchanged from baseline)
  • Devlog: devlog/2026-06-26_mark-block-batch-cleanup/ (REQ.md + DESIGN.md + WORKLOG.md)

Model can now mark blocks for deferred cleanup via mark_block tool (zero
cache impact — block stays fully active). Marked blocks are merge-compressed
together when context pressure rises, minimizing cache breaks.

Three-tier batch cleanup in message transform pipeline:
- Tier 1 (60%): nudge model about marked blocks
- Tier 2 (75%): auto merge-compress all marked blocks into one
- Tier 3 (90%): force merge ALL old-gen blocks (new fallback before GC)

Existing GC retained as ultimate fallback at 100%. New mechanism is
additive — no changes to existing GC or compression behavior.

New files: lib/gc/merge.ts, lib/compress/mark-block.ts
Modified: types, config, hooks, index, prompts, persistence, 10 test files
Review fixes (3 medium issues):
- b0→b1 in all tool descriptions (BLOCK_REF_REGEX rejects b0)
- Conditional nudge text for single-block case (no false auto-merge promise)
- Selective markedForCleanup clearing (only merged IDs, preserves young marks)

Tests (1 high issue):
- tests/gc-merge.test.ts: 16 tests covering mergeMarkedBlocks (8) + runBatchCleanup (8)
- Full suite: 402/402 pass (386 baseline + 16 new)
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