Skip to content

fix(context-pivot): preflight native compaction history - #320

Open
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-24-compaction-preflight
Open

fix(context-pivot): preflight native compaction history#320
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-24-compaction-preflight

Conversation

@testikun

Copy link
Copy Markdown
Contributor

Problem

Issue #24 describes a false-positive context-pivot path: OpenPI's 30k context-usage gate can pass when the session has no discardable conversation history, after which native Pi compaction fails with Nothing to compact (session too small).

Value

The pivot is now fail-closed before starting asynchronous compaction when Pi's public compaction cut-point logic finds no history to summarize. Users get the existing actionable /sessions / new Session guidance immediately, instead of a misleading “started” state or an unavailable follow-up tool request.

Approach

  • Add a small preflight built from Pi's public findCutPoint, sessionEntryToContextMessages, and DEFAULT_COMPACTION_SETTINGS exports.
  • Check the current branch before enabling or executing context_pivot; malformed branches and missing kept-entry IDs fail closed.
  • Apply the same check to the /context-pivot command path.
  • Keep ctx.compact() and its native error callback unchanged as the race-safe final guard; no second compressor, persistence format, or Session lifecycle is introduced.
  • Add regression coverage for metadata-only context, valid history, existing compaction boundaries, malformed entries, command behavior, and no-start execution.

The installed Pi 0.84.1 package does not actually export prepareCompaction at runtime, despite the internal type/source references, so this PR deliberately avoids a private deep import. The preflight mirrors the public cut-point boundary and documents that the asynchronous native call remains authoritative if the branch changes between checks.

Validation

  • npx --yes bun@1.3.14 run check — passed
  • npx --yes node@24 --test --experimental-strip-types tests/extensions/context-pivot/index.test.ts — 9/9 passed
  • npx --yes node@24 scripts/run-tests.mjs — 1079 passed, 0 failed, 1 skipped; Vitest 30/30 passed
  • git diff --check — passed

Impact

  • User-visible behavior: no-history pivots are rejected with actionable guidance before starting.
  • Model-visible context/tools: context_pivot is not exposed when the current branch has no discardable history.
  • Runtime/lifecycle: native Pi compaction remains the owner; preflight is best-effort and the existing error callback handles races.
  • Persisted config/data: none.
  • Compatibility/risk: low; custom non-default Pi compaction settings are not exposed through the current ExtensionContext, so the check uses Pi's documented defaults and fails closed on malformed input.

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