Skip to content

A stale keepalive response can disarm a replacement request snapshot #6077

Closed

Description

@Afloat16

Problem

An in-flight Anthropic cache keepalive can disarm a newer successful request's snapshot.

At master 541cf26, firePing checks entry ownership before awaiting response.text(), then handles HTTP 429 and cache misses by session ID. A real request can re-arm that session while the body is pending. When the old body finishes, its stop decision removes the replacement entry and cancels its fresh timer.

Reproduction

  1. Arm a 5-minute snapshot and fire its scheduled ping.
  2. Resolve fetch headers, but hold response.text() pending.
  3. Record a new successful 1-hour request for the same session.
  4. Complete the old response with either HTTP 429 or cache_read_input_tokens: 0.
  5. The newly armed entry is gone, although the response belongs to the previous snapshot.

The deterministic regression against the current base produces 37 passing and 2 failing tests in tests/cache-keepalive.test.ts; a stale cache-hit control passes. The two failures both observe undefined instead of the newly armed 1-hour snapshot.

Expected behavior

Only the currently registered entry may apply a body-dependent stop or success decision. A superseded response must leave the replacement snapshot and timer alone. Normal current-entry hit/miss/429 behavior remains intact.

Scope and prior work

This is a new response-body completion race. #3390 introduced keepalive; #5669/#5672 (integrated through #5847) cover default TTL detection and timer unref, not snapshot ownership after body consumption. It is independent of the previous contribution batch #6046–#6055.

Category A (prefix-cache continuity), proposed priority p2, scope/other.

Activity

  1. ranxianglei commented on Nov 12, 2026

    @ranxianglei
    Owner

    Fixed in batch PR #6439 (merged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions