Skip to content

Stale fixture warning never fires on the OpenRouter models: [...] fallback path #647

Description

@abhiramshaji-cyber

Hi, hope you're doing well! Hey, it's me again from #639 (thanks again for the quick and kind help there and on #643).

When a request goes through the OpenRouter models: [...] fallback path, the stale fixture check from #640 never reaches the journal, so a changed request is served silently again.

What this code is for

First, thank you for #640. Recordings now carry a requestHash, and a replay whose request no longer matches it still gets served but is flagged with response.staleFixture and a STALE FIXTURE warning. That's a really nice fix for the silent drift in #638, and I've been leaning on it.

Current behavior

  1. matchFixtureDiagnostic calls noteStaleFixture(req, selected, effective), which stores the mark in a WeakMap keyed by the request object it matched (router.ts#L772, request-hash.ts#L136-L150).
  2. journal.add looks the mark up by entry.body (journal.ts#L261, request-hash.ts#L161), and the warning only reads that journal field (server.ts#L3343-L3350).
  3. On the fallback path, each candidate is matched as a copy, probe = { ...body, model: candidate } (server.ts#L1980-L1981), so the mark lands on probe.
  4. The journal entry is still written with the original body (server.ts#L2817-L2822).
  5. staleMarks.get(body) finds nothing, so the entry has no staleFixture and no warning is logged, even though the same request without models is flagged.
// src/request-hash.ts#L149: the mark is keyed by the matched object
else staleMarks.set(req, { fixture, expected, actual });

// src/server.ts#L1980-L1981: on fallback, that object is a copy
const probe: ChatCompletionRequest = { ...body, model: candidate };
const attempt = selectFixture(probe, matchCounts);

// src/journal.ts#L261: lookup uses the original body
const staleFixture = staleFixtureFor(entry.body, entry.response.fixture);

This is reachable with normal recordings, since the recorder writes requestHash whenever the request has a system prompt or tools (recorder.ts#L2644-L2666). stale-fixture.test.ts doesn't have a fallback case yet, which is probably why it slipped through.

noteStaleFixture has one caller, matchFixtureDiagnostic
noteStaleFixture and its only caller, matchFixtureDiagnostic, Functions view in Architect

Expected behavior

A fallback request that serves a fixture recorded on a different request gets response.staleFixture and one STALE FIXTURE warning, the same as a plain request.

Minimal repro

On main (445235e), reusing the record, replay, openaiBody and staleWarnings helpers from src/__tests__/stale-fixture.test.ts:

it("flags a stale fixture on the models fallback path", async () => {
  const fixtures = await record("/v1/chat/completions", openaiBody('{"refunded":true}'));
  const changed = openaiBody('{"refunded":false,"error":"card_declined"}');

  const single = await replay(fixtures, "/api/v1/chat/completions", JSON.stringify(changed));
  const multi = await replay(
    fixtures,
    "/api/v1/chat/completions",
    JSON.stringify({ ...changed, models: ["gpt-5", "other-model"] }),
  );

  for (const [name, r] of [["single", single], ["models", multi]] as const) {
    const stale = JSON.stringify(r.entry.response.staleFixture ?? null);
    console.log(name, r.status, `staleFixture=${stale}`, `warnings=${staleWarnings(r.warnings).length}`);
  }
});

Output (the recording has requestHash d80b1e14e51b6d88):

single 200 staleFixture={"expected":"d80b1e14e51b6d88","actual":"3e1ac219fff29203"} warnings=1
models 200 staleFixture=null warnings=0

The recorded reply is still served in both cases, only the flag goes missing.

flowchart LR
  A["request body"] --> B{"models list?"}
  B -- no --> C["match body"]
  C --> D["mark set on body"]
  D --> E["journal.add(body) finds mark"]
  B -- yes --> F["match probe copy per candidate"]
  F --> G["mark set on probe"]
  G --> H["journal.add(body) finds nothing"]
Loading

Question

Which fix would you prefer? Two ideas I had:

  1. After the fallback loop picks a winner, copy that probe's mark onto body before journaling.
  2. Run the stale note against body (after requestTransform) once the winning fixture is known, instead of relying on the probe.

One thing I wasn't sure about: the hash includes model, so when a secondary candidate wins, its probe hashes with that candidate's model, while the recording was probably made with body.model. Which model should the hash use for fallback requests, the winning candidate or body.model?

Happy to send a PR with a fallback case in stale-fixture.test.ts once you let me know which way you'd like it. Thanks so much!

Activity

  1. joei4cm commented on Dec 1, 2026

    @joei4cm

    我们接手

  2. jpr5 commented on Dec 1, 2026

    @jpr5
    Contributor

    Fixed in #651, the way you laid out in option 1. Thanks for the clear trace, it made this a quick one.

  3. added a commit that references this issue on Dec 3, 2026
    c3a3a50
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions