Skip to content

refactor(hooks)!: rename anthropic-context-window-limit-recovery to generic provider-agnostic context-window-limit-recovery (P2.2) - #68

Merged
klpanagi merged 2 commits into
devfrom
refactor/p2.2-generic-recovery
Sep 8, 2026
Merged

refactor(hooks)!: rename anthropic-context-window-limit-recovery to generic provider-agnostic context-window-limit-recovery (P2.2)#68
klpanagi merged 2 commits into
devfrom
refactor/p2.2-generic-recovery

Conversation

@klpanagi

@klpanagi klpanagi commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

Renames anthropic-context-window-limit-recovery (20 files, 1788 LOC) to provider-agnostic context-window-limit-recovery (17 files, 1267 LOC, -29%) and makes the implementation lighter and generic. Follow-up to P2.1 (#67). No behavior removal — reactive recovery is kept, provider coupling removed.

Plan: .matrixx/plans/p2.2-generic-recovery-refactor.md (5 tasks / 3 waves, all complete).

BREAKING CHANGE

Hook name anthropic-context-window-limit-recovery renamed to context-window-limit-recovery.

Migration is automatic:

  • HookNameSchema accepts the legacy name via z.union transform and normalizes it to the new name (61 entries preserved).
  • src/shared/migration/hook-names.ts maps legacy disabled_hooks entries to the new name.
  • Deprecated aliases kept for one minor: createAnthropicContextWindowLimitRecoveryHook, parseAnthropicTokenLimitError, AnthropicErrorData. Removal in v2.7.

Users with "anthropic-context-window-limit-recovery" in disabled_hooks need no action.

What changed

  • Rename (git mv): src/hooks/anthropic-context-window-limit-recovery/ -> src/hooks/context-window-limit-recovery/; tests/hooks/... renamed likewise (4 files, 1 SDK test deleted with its source).
  • Schema + migration: src/config/schema/hooks.ts (76 LOC) union shim; src/shared/migration/hook-names.ts NEW (34 LOC).
  • Generic parser: parser.ts 209 -> 161 LOC + parser-patterns.ts NEW (58 LOC). parseTokenLimitError primary, AnthropicErrorData -> GenericErrorData alias. providerID logging-only, no gating. Thinking-block errors still excluded (routed to session-recovery).
  • Storage consolidation: tool-result-storage.ts + -sdk.ts (239) -> unified tool-result-store.ts (199) via isSqliteBackend() + truncateResultsLoop; deleted message-storage-directory.ts / storage-paths.ts; target-token-truncation.ts 196 -> 37.
  • State reduction: empty-content-recovery.ts 126 -> 89 via session-recovery/storage delegation (SDK file deleted); message-builder.ts 169 -> 86; caps maxTruncateAttempts: 5, maxAttempts: 2 (worst-case API calls 22 -> ~7).
  • Cross-hook dedup: src/shared/context-limits.ts NEW (50 LOC) single-sources CONTEXT_WARNING_THRESHOLD=0.70 / PREEMPTIVE_COMPACTION_THRESHOLD=0.78 + limits; consumed by context-window-monitor.ts and preemptive-compaction*.ts. Boundary documented: monitor 70% warn (read-only) -> preemptive 78% proactive (60s summarize/cooldown) -> recovery reactive (error-parse only).
  • Registration: create-session-hooks.ts, hooks/index.ts, plugin/event.ts renamed with deprecated re-exports.
  • Docs + schema: context-management.md §3.5, configurations.md, cost-performance-proposals.md, features.md, headroom.ts, hooks/AGENTS.md updated; assets/dist matrixx.schema.json regenerated via bun run build:schema.
  • CI: script/mock-heavy-list.txt synced (single source, no duplication).

Verification

  • bun run typecheck -> tsc --noEmit, exit 0
  • bun run lint -> Checked 959 files, No fixes, exit 0
  • bun run build -> Bundled 1138 + 155 modules, schema regenerated, exit 0
  • bun test tests/hooks/context-window-limit-recovery/ -> 21 pass, 0 fail
  • bun test tests/hooks/preemptive-compaction.test.ts tests/plugin/tool-execute-before.test.ts -> 15 pass, 0 fail
  • Orphan rg anthropic-context-window-limit-recovery src/ -> only hooks.ts:72 shim + migration/hook-names.ts:4
  • Every file <=200 LOC (max 199)
  • Functional bun -e: generic parse 150000 > 128000 correct, context_length_exceeded handled, thinking-block returns null, legacy alias identical, legacy disabled_hooks normalizes, thresholds 0.7 / 0.78

Known gaps

  • 17 files / 1267 LOC vs plan target 11-13 files / ~1100 LOC — lighter (-29%) but not as lean as planned; further empty-content/message-builder merge possible as follow-up.
  • Full bun test suite not run (affected + adjacent only); no live long-session session.summarize e2e, parser-level trigger only.

Checklist

  • Targets dev (never master), merge commit only
  • Branch refactor/p2.2-generic-recovery, Bun 1.4.0
  • No as any / @ts-ignore, no src/index.ts exports, no todo-continuation-enforcer touch
  • Rollback: revert merge commit, git mv back, build:schema, restore tests + mock list (see plan §Rollback)

…eneric provider-agnostic context-window-limit-recovery (P2.2)

BREAKING CHANGE: HookName `anthropic-context-window-limit-recovery` renamed to `context-window-limit-recovery`. Deprecated alias shim via z.union transform keeps backwards compat until v2.7 (disabled_hooks auto-migrated via src/shared/migration/hook-names.ts). Provider-agnostic parser (parseTokenLimitError + deprecated parseAnthropicTokenLimitError alias, GenericErrorData), storage unified (tool-result-store 199 LOC), empty-content 58+48 LOC via session-recovery delegation, shared context-limits (70% monitor, 78% preemptive). Docs + schema regenerated, tests renamed, mock-heavy synced. 51 files, +738/-1330.

Co-Authored-By: internal-model
…rable via experimental

Adds experimental.context_warning_threshold (default 0.70) and experimental.preemptive_compaction_threshold (default 0.78), Zod-validated 0.1-0.95. Resolvers in shared/context-limits.ts fall back to existing consts; monitor + preemptive trigger consume them (no bare literals left). Misordering logs a warning instead of crashing. Schema regenerated, docs updated.

Co-Authored-By: internal-model
@klpanagi
klpanagi merged commit b68942b into dev Sep 8, 2026
6 checks passed
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