Skip to content

Fix issue #2180 preemptive compaction warnings#2212

Merged
Yeachan-Heo merged 2 commits intodevfrom
fix/issue-2180-hook-registration
Apr 6, 2026
Merged

Fix issue #2180 preemptive compaction warnings#2212
Yeachan-Heo merged 2 commits intodevfrom
fix/issue-2180-hook-registration

Conversation

@Yeachan-Heo
Copy link
Copy Markdown
Owner

Summary\n- move preemptive context warnings onto the already-registered PostToolUse runtime\n- read transcript usage from the transcript tail and persist cooldown by directory + session\n- add regression coverage for warning thresholds, cross-process cooldown, session isolation, and escalation\n\nCloses #2180\n\n## Verification\n- npm test -- --run src/tests/post-tool-verifier.test.mjs src/tests/preemptive-compaction-hook.test.ts src/tests/hooks-command-escaping.test.ts\n- npx tsc --noEmit\n- npm run lint (passes with one pre-existing warning in src/hooks/setup/tests/stdin-symlink.test.ts)

The legacy preemptive-compaction helper was never wired into hooks/hooks.json and depended on in-memory Maps that cannot survive Claude Code's one-shot shell hook processes. This change moves the warning logic into the already-registered post-tool-verifier runtime, reads transcript usage from the transcript tail, and persists cooldown by directory+session so warnings stay accurate across subprocess invocations without cross-session suppression.

Constraint: PostToolUse runtime is delivered via hooks/hooks.json + scripts/post-tool-verifier.mjs
Constraint: Fix must remain small and avoid registering the non-viable legacy helper directly
Rejected: Register a standalone preemptive-compaction script in hooks.json | Would add another runtime surface when the existing PostToolUse path already supports additionalContext
Rejected: Reuse directory-only cooldown state | Incorrectly suppresses warnings across different sessions in the same repo
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep preemptive warning persistence scoped to session-aware hook state; do not revert to process-local Maps for shell hook runtime behavior
Tested: vitest --run src/__tests__/post-tool-verifier.test.mjs src/__tests__/preemptive-compaction-hook.test.ts src/__tests__/hooks-command-escaping.test.ts
Tested: npx tsc --noEmit
Tested: npm run lint (passes with one pre-existing warning in src/hooks/setup/__tests__/stdin-symlink.test.ts)
Not-tested: Full repository test suite
Related: #2180
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions bot added the size/M label Apr 6, 2026
…ommand

CI runs the repository's current hooks.json, which may invoke run.cjs via either a plain node launcher or a pinned node binary path. The regression test should prove that preemptive compaction stays on the active PostToolUse runtime path without overfitting to the exact launcher prefix.

Constraint: hooks.json command prefixes can vary between environments while the run.cjs -> post-tool-verifier.mjs path stays invariant
Rejected: Assert the full command string starts with plain node | fails when hooks.json uses an absolute node launcher path
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep this regression focused on the active hook route invariant, not the launcher prefix
Tested: vitest --run src/__tests__/preemptive-compaction-hook.test.ts src/__tests__/post-tool-verifier.test.mjs src/__tests__/hooks-command-escaping.test.ts src/__tests__/context-guard-stop.test.ts
Tested: eslint src/__tests__/preemptive-compaction-hook.test.ts
Not-tested: Full repository test suite
Related: #2180
Related: #2212
@Yeachan-Heo Yeachan-Heo merged commit b777195 into dev Apr 6, 2026
8 checks passed
@Yeachan-Heo Yeachan-Heo deleted the fix/issue-2180-hook-registration branch April 6, 2026 04:33
pgagarinov pushed a commit to pgagarinov/oh-my-claudecode that referenced this pull request Apr 12, 2026
…o#2212)

* Restore preemptive context warnings on the active PostToolUse path

The legacy preemptive-compaction helper was never wired into hooks/hooks.json and depended on in-memory Maps that cannot survive Claude Code's one-shot shell hook processes. This change moves the warning logic into the already-registered post-tool-verifier runtime, reads transcript usage from the transcript tail, and persists cooldown by directory+session so warnings stay accurate across subprocess invocations without cross-session suppression.

Constraint: PostToolUse runtime is delivered via hooks/hooks.json + scripts/post-tool-verifier.mjs
Constraint: Fix must remain small and avoid registering the non-viable legacy helper directly
Rejected: Register a standalone preemptive-compaction script in hooks.json | Would add another runtime surface when the existing PostToolUse path already supports additionalContext
Rejected: Reuse directory-only cooldown state | Incorrectly suppresses warnings across different sessions in the same repo
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep preemptive warning persistence scoped to session-aware hook state; do not revert to process-local Maps for shell hook runtime behavior
Tested: vitest --run src/__tests__/post-tool-verifier.test.mjs src/__tests__/preemptive-compaction-hook.test.ts src/__tests__/hooks-command-escaping.test.ts
Tested: npx tsc --noEmit
Tested: npm run lint (passes with one pre-existing warning in src/hooks/setup/__tests__/stdin-symlink.test.ts)
Not-tested: Full repository test suite
Related: Yeachan-Heo#2180

* Keep preemptive hook regression aligned with the active PostToolUse command

CI runs the repository's current hooks.json, which may invoke run.cjs via either a plain node launcher or a pinned node binary path. The regression test should prove that preemptive compaction stays on the active PostToolUse runtime path without overfitting to the exact launcher prefix.

Constraint: hooks.json command prefixes can vary between environments while the run.cjs -> post-tool-verifier.mjs path stays invariant
Rejected: Assert the full command string starts with plain node | fails when hooks.json uses an absolute node launcher path
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep this regression focused on the active hook route invariant, not the launcher prefix
Tested: vitest --run src/__tests__/preemptive-compaction-hook.test.ts src/__tests__/post-tool-verifier.test.mjs src/__tests__/hooks-command-escaping.test.ts src/__tests__/context-guard-stop.test.ts
Tested: eslint src/__tests__/preemptive-compaction-hook.test.ts
Not-tested: Full repository test suite
Related: Yeachan-Heo#2180
Related: Yeachan-Heo#2212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant