fix(context-pivot): preflight native compaction history - #320
Open
testikun wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
findCutPoint,sessionEntryToContextMessages, andDEFAULT_COMPACTION_SETTINGSexports.context_pivot; malformed branches and missing kept-entry IDs fail closed./context-pivotcommand path.ctx.compact()and its native error callback unchanged as the race-safe final guard; no second compressor, persistence format, or Session lifecycle is introduced.The installed Pi 0.84.1 package does not actually export
prepareCompactionat 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— passednpx --yes node@24 --test --experimental-strip-types tests/extensions/context-pivot/index.test.ts— 9/9 passednpx --yes node@24 scripts/run-tests.mjs— 1079 passed, 0 failed, 1 skipped; Vitest 30/30 passedgit diff --check— passedImpact
context_pivotis not exposed when the current branch has no discardable history.