Repository navigation
Shake after handoff only when pruning is not enough - #16
Merged
Merged
Conversation
turn_end checked Pi's raw token count, not the planned result, before shaking after a handoff. When pruning alone reached the target, the default methodOrder still elided old code blocks and broke the cache once more. The README said old file reads are still replaced with Pi's compaction off. Since edits happen only at the threshold, nothing changes then; the README now says so. Install dependencies without lifecycle scripts in CI and release: the release job can request an npm publish token, and no dependency needs its install script for the checks.
HugoLopes45
added a commit
that referenced
this pull request
Nov 11, 2026
## Why The `turn_end` handler had a cyclomatic complexity of 35. A change to one strategy risked another, as the shake-gate bug fixed in #16 showed. This PR adds pi-claude-pro's complexity lint (ESLint `complexity` at most 10, run on Node's type-stripped source) to `npm run check`, and splits the five functions above the limit. ## Changes - `scripts/lint.ts`, `npm run lint`, and `check` now runs the lint. `tsconfig.json` includes `scripts`. CONTRIBUTING documents the rule. - Split without behavior change: `turn_end` and `session_before_compact` in `extensions/index.ts`, `src/prune.ts`, `src/shake.ts`, `src/stale.ts`. `src/tool-calls.ts` gets a shared `newestToolResults` generator. - Two intended deltas: - `turn_end` returns early without a model, after `background.invalidate`. Before, it computed a plan with no edits and returned nothing. - A focused `/compact` no longer cancels the background note itself, because `handoff` cancels it before it requests a note. A new test pins this. - `eslint` devDependency with a `minimatch` ^11 override: every minimatch 10.x has GHSA-g3hv-75wg-m249, and ESLint 10.14 pins ^10.2.6. `npm audit` reports 0 vulnerabilities. The lockfile adds 67 packages from registry.npmjs.org and removes none. ## Verification - `npm run check`: tsc, lint clean, 97 tests passed. - Four new characterization tests (early-threshold wait, note start below the threshold, no retry of a failed note at Pi's threshold, focused `/compact` cancel) pass on the code before the split. Each one fails when its branch is removed, in the old code and in the new. - An independent read-only review (hl-code-review) compared the code line by line with the base and found the two deltas safe. Its two findings are fixed in d2af352: the messages are built inside the `try` again, and the focused-cancel test is added.
HugoLopes45
added a commit
that referenced
this pull request
Nov 11, 2026
## Why #16 changed the shake gate after a handoff from Pi's raw token count to the planned result. The #16 review noted a second case that the change affects, and no test covered it: replacing superseded reads alone brings the context under the threshold, but not to `progressRatio` of it. Then `turn_end` keeps only those edits and does not shake. That is the intended behavior: one cache break instead of two, and the code blocks stay visible until the next threshold. ## Changed behavior None. Test only. ## Verification - Head `e0f57ca`, repository root: `npm run check`, 1 run, tsc and lint clean, 101 tests passed. - The test fails when the gate uses Pi's raw token count (`tokens > limit`), the bug fixed in #16: it finds an `Elided block` edit next to the superseded read. 1 run. - Calibration: the threshold is 11,000 tokens. Replacing the read leaves about 10,500 tokens, above 8,800 (80%). With a threshold of 10,000, the context stays above the threshold and the shake runs, so the test is about 500 tokens from that edge. A change to Pi's token estimate can move it. The failure would then show as a second edit, not as a silent pass. - The test also fails when `planMaintenance` returns the raw token count after the stale edit: it finds 1 compaction entry where it expects 0. 1 run. - Independent review (fresh-context reviewer, hl-code-review): Clear, 1 limited finding. A handoff compaction could pass the edit-count assertion. Fixed in `e0f57ca` with the no-compaction and `done` assertions. ## Risk and rollback Low: one new test in `test/extension.test.ts`. Rollback: revert the squash commit. Owner: HugoLopes45.
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.
Why
turn_enddecided whether to shake from Pi's raw token count, not from the planned result. With the defaultmethodOrder, pruning could bring the context under the target and old code blocks were still elided. That is one more cache break and lost content the model may still need.compaction.enabled: false. Since Support Pi 1.5 and edit the context only at the threshold #14, edits happen only at the threshold. With Pi's compaction off there is no threshold, so nothing changes. The README said old file reads were still replaced.id-token: writefor npm trusted publishing. Three transitive dev dependencies (@google/genai,protobufjs,fsevents) declare install scripts; the checks do not need them.Changes
extensions/index.ts: gate the shake after handoff onresult.tokens.test/extension.test.ts: regression test. It failed before the fix with anElided blockreplacement and passes after.README.md: two lines oncompaction.enabled: false.ci.yml,release.yml:npm ci --ignore-scripts, and--ignore-scriptsfor the Pi 1.0.3 and latest installs.Verification
npx tsc --noEmit: pass.npx vitest --run: 93 passed.npm ci --ignore-scriptspasses the full suite.Found by an
hl-improvesurvey and anhl-security-auditpass (no confirmed vulnerability; this is hardening).