Skip to content

fix: execute deferred Anthropic leaf debt after TTL expiry despite cache smoothing#434

Merged
jalehman merged 2 commits intomainfrom
sting-90db846d-362-narrow-follow-up
Apr 14, 2026
Merged

fix: execute deferred Anthropic leaf debt after TTL expiry despite cache smoothing#434
jalehman merged 2 commits intomainfrom
sting-90db846d-362-narrow-follow-up

Conversation

@jalehman
Copy link
Copy Markdown
Contributor

What

This PR fixes an interaction between cache-aware routing-noise protection (#362) and deferred proactive compaction (#408). When incremental evaluation suppresses compaction due to hot-cache hysteresis, deferred Anthropic sessions were incorrectly terminating their maintenance debt instead of continuing after the prompt-cache TTL expired.

Why

The #362 fix introduced cache-aware hysteresis that suppresses unnecessary compaction when a cache is 'effectively hot' for routing purposes. However, this was also suppressing legitimate deferred leaf compaction in Anthropic sessions whose actual cache TTL had gone stale. The TTL-safety check in #408 said 'safe to compact,' but the routing-noise heuristic could override that decision.

Changes

  • Adds shouldForceDeferredAnthropicLeafCompaction() to check whether deferred Anthropic leaf debt should override cache-aware 'no compaction' once TTL is stale
  • Routes override through executeLeafCompactionCore instead of terminating maintenance debt early
  • Adds regression test for the specific case (TTL stale + routing-noise hysteresis keeping cache state 'effectively hot')
  • Preserves existing behavior for inline mode and non-TTL-gated paths

Testing

  • Focused Vitest regression coverage: 'assemble() still executes deferred Anthropic leaf debt after TTL expiry when cache smoothing remains effectively hot'
  • Full test/engine.test.ts suite passing
  • Build check passing

Fixes: #408
Related to: #362

…che smoothing

Narrow fix for the interaction between #362 (cache-aware routing noise
protection) and #408 (deferred proactive compaction). The issue: when
incremental evaluation returns 'no compaction needed' due to hot-cache
budget-headroom or hot-cache-defer (routing-noise suppression), deferred
Anthropic sessions were incorrectly terminating their maintenance debt
instead of continuing to execute after the prompt-cache TTL had expired.

The fix: check whether deferred Anthropic sessions should override the
cache-aware 'no compaction' decision once the TTL-safe hold has elapsed.
If so, allow leaf compaction to execute despite the routing-noise
hysteresis. Inline and non-deferred paths keep existing behavior unchanged.

- Adds shouldForceDeferredAnthropicLeafCompaction() to gate override
- Routes deferred Anthropic leaf compaction through executeLeafCompactionCore
  when TTL is stale
- Adds regression test: 'assemble() still executes deferred Anthropic
  leaf debt after TTL expiry when cache smoothing remains effectively hot'
- No changes to routing-noise protection or incremental evaluation logic

Fixes: #408
Related: #362
@jalehman jalehman self-assigned this Apr 14, 2026
When deferred Anthropic leaf debt overrides hot-cache smoothing after the prompt-cache TTL expires, run the leaf compaction with the cold-cache catch-up envelope instead of the original hot-cache single-pass settings. This preserves the intended deferred recovery behavior and prevents the maintenance record from being cleared after a single underpowered pass.\n\nAdd a regression that proves the stale-TTL override enables catch-up execution rather than reusing the hot-cache defer envelope, and update the existing stale-TTL test to assert the new execution parameters.\n\nRegeneration-Prompt: |\n  Address the review finding on PR #434 in lossless-claw. The stale-TTL deferred Anthropic compaction fix should not merely force one hot-cache-sized leaf compaction pass and then clear the maintenance debt. Keep the change narrow and additive inside the deferred-compaction path. When the Anthropic prompt-cache TTL has expired and deferred debt must override cache smoothing, execute with the same catch-up envelope that cold-cache recovery uses, especially the extra pass allowance and condensed-pass setting. Add regression coverage that would fail if the forced path still used maxPasses=1 or allowCondensedPasses=false, and update any stale expectations in the existing TTL-expiry test.
@jalehman jalehman merged commit 049ce3b into main Apr 14, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 14, 2026
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