Skip to content

fix(journal): flag stale fixtures served via the OpenRouter models fallback - #651

Merged
jpr5 merged 3 commits into
mainfrom
fix/stale-fixture-openrouter-fallback
Dec 1, 2026
Merged

jpr5 merged 3 commits into
mainfrom
fix/stale-fixture-openrouter-fallback

Conversation

@jpr5

@jpr5 jpr5 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #647

What was wrong

When a request goes through the OpenRouter models: [...] fallback, each candidate is matched as a copy of the request ({ ...body, model: candidate }). The stale-fixture check stores its mark on the object it matched, so the mark landed on that copy. The journal then looks the mark up on the original body and finds nothing. The recorded reply was still served, but response.staleFixture was never written and the STALE FIXTURE warning never fired.

The fix

A small helper, copyStaleFixtureMark(from, to), in request-hash.ts copies the mark (or clears it) from one object to another. The fallback resolver calls it once, right after a candidate matches a fixture, to put that candidate's mark on body. The served fixture is always the last candidate that matched (a success or terminal error breaks the loop, and when every candidate fails the last error is served), so the last copy is the right one. staleFixtureFor also checks that the mark belongs to the served fixture.

The hash uses the winning candidate's model, because that is the request the fixture matched. models is not part of the hash. So a fallback request hashes the same as a plain request with that model, and the test checks this.

Serving does not change. Only the journal field and the warning now show up on this path. The non-fallback path is untouched.

Red / green

New test: flags a stale fixture served through the OpenRouter models fallback (#647) in src/__tests__/stale-fixture.test.ts. It records a real fixture, then replays /api/v1/chat/completions with model: "missing-model", models: ["missing-model", "gpt-5"]. The first candidate misses and gpt-5 hits the recording. It checks the journal's staleFixture (equal to the plain request's), one STALE FIXTURE warning, and that the unchanged request served the same way is not flagged.

RED, on unmodified main (445235e):

 FAIL  src/__tests__/stale-fixture.test.ts > stale fixture detection (#638) > flags a stale fixture served through the OpenRouter models fallback (#647)
AssertionError: expected undefined to deeply equal { expected: '2fb4ea5f453cee78', …(1) }
- Expected:
{
  "actual": "c9b9e66b6f11804e",
  "expected": "2fb4ea5f453cee78",
}
+ Received:
undefined
      Tests  1 failed | 23 skipped (24)

GREEN, with the fix:

 Test Files  1 passed (1)
      Tests  24 passed (24)

Mutation check, with only the copyStaleFixtureMark(probe, body) call commented out:

AssertionError: expected undefined to deeply equal { expected: '2fb4ea5f453cee78', …(1) }
      Tests  1 failed | 23 skipped (24)

Full gates locally: build, typecheck, eslint, prettier all clean; pnpm test 502 files, 20330 passed, 11 skipped.

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@651

commit: c6db41f

@jpr5
jpr5 merged commit c3a3a50 into main Dec 1, 2026
30 checks passed
@jpr5
jpr5 deleted the fix/stale-fixture-openrouter-fallback branch December 1, 2026 03:19
jpr5 added a commit that referenced this pull request Dec 1, 2026
## [1.49.0] - 2026-11-30

### Added

- Replayable seeded chaos: `--chaos-seed`/`x-aimock-chaos-seed`; journal `chaosOrigin` (#618, #653)
- Recorder writes `requestHash`; stale replays get journal `staleFixture` and a warning (#640, #651)

### Changed

- `aimock-pytest` 0.7.4 defaults to `@copilotkit/aimock` 1.49.0

### Fixed

- Split image turns match `userMessage` on Anthropic, Gemini (+Live), Bedrock, Cohere (#643, #648)
- `llmock` now errors on blank `--port`/`--host`/`--latency`/... values instead of starting (#644)
jpr5 added a commit that referenced this pull request Dec 1, 2026
**Merging this publishes @copilotkit/aimock 1.49.0 to npm and
aimock-pytest 0.7.4 to PyPI.**

## [1.49.0] - 2026-11-30

### Added

- Replayable seeded chaos: `--chaos-seed`/`x-aimock-chaos-seed`; journal
`chaosOrigin` (#618, #653)
- Recorder writes `requestHash`; stale replays get journal
`staleFixture` and a warning (#640, #651)

### Changed

- `aimock-pytest` 0.7.4 defaults to `@copilotkit/aimock` 1.49.0

### Fixed

- Split image turns match `userMessage` on Anthropic, Gemini (+Live),
Bedrock, Cohere (#643, #648)
- `llmock` now errors on blank `--port`/`--host`/`--latency`/... values
instead of starting (#644)

Two new features, so this is a minor release.

## Version carriers (from `git grep -F 1.48.1`)

Bumped to 1.49.0:
- `package.json` version
- `charts/aimock/Chart.yaml` appVersion
- `.claude-plugin/plugin.json` version
- `.claude-plugin/marketplace.json` source version (`^1.49.0`)
- `docs/index.html` banner
- `packages/aimock-pytest/README.md` `--aimock-version` default
- `packages/aimock-pytest/src/aimock_pytest/_version.py`
`AIMOCK_VERSION`

Also bumped: `packages/aimock-pytest/pyproject.toml` 0.7.3 → 0.7.4,
because the pin moved (same pattern as #628).

Left as is: the `## [1.48.1]` CHANGELOG section.

## CHANGELOG edits

- `## [Unreleased]` becomes `## [1.49.0] - 2026-11-30`.
- Seven bullets became four, plus the aimock-pytest `Changed` line: the
two #618 lines are one, #643 and #648 are one, and #651 joins the
stale-fixture line.
- The stale-fixture line now references PR #640 instead of issue #638.

## Docs

- `docs/record-replay`: the `llmock` flag table gets `--chaos-seed` and
`--chaos-keys-max`, and a note that blank
`--port`/`--host`/`--latency`/`--journal-max`/`--fixture-counts-max`
values are a usage error (#644).
- `docs/fixtures`: the "last user message" rule now says a trailing
image-only user message is skipped (#643, #648).
- `README.md`: the Record & Replay line mentions stale-fixture flagging.
Seeded chaos was already in the Chaos Testing line.

Already covered, left alone: `docs/chaos-testing` (seeds,
`x-aimock-chaos-seed`, `chaosOrigin`, `--chaos-keys-max`) and the Stale
Fixtures section of `docs/record-replay` (`requestHash`, `staleFixture`,
the `STALE FIXTURE` warning, `requestTransform`). The `package.json`
description already matches the README subtitle.

## Local checks
- `pnpm install --frozen-lockfile`, `format:check`, `lint`, `typecheck`,
`build`: pass
- `api:report`: 14 entries, 0 failed, no report change
- `vitest run`: 503 files, 20,346 passed, 11 skipped
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.

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

1 participant