Repository navigation
Description
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
matchFixtureDiagnosticcallsnoteStaleFixture(req, selected, effective), which stores the mark in aWeakMapkeyed by the request object it matched (router.ts#L772, request-hash.ts#L136-L150).journal.addlooks the mark up byentry.body(journal.ts#L261, request-hash.ts#L161), and the warning only reads that journal field (server.ts#L3343-L3350).- On the fallback path, each candidate is matched as a copy,
probe = { ...body, model: candidate }(server.ts#L1980-L1981), so the mark lands onprobe. - The journal entry is still written with the original
body(server.ts#L2817-L2822). staleMarks.get(body)finds nothing, so the entry has nostaleFixtureand no warning is logged, even though the same request withoutmodelsis 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 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"]
Question
Which fix would you prefer? Two ideas I had:
- After the fallback loop picks a winner, copy that probe's mark onto
bodybefore journaling. - Run the stale note against
body(afterrequestTransform) 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
joei4cm commentedon Dec 1, 2026
我们接手
jpr5 commentedon Dec 1, 2026
Fixed in #651, the way you laid out in option 1. Thanks for the clear trace, it made this a quick one.
fix(journal): flag stale fixtures served via the OpenRouter models fa…