Repository navigation
Commit 6e2a4c7
authored
test(drift): accept Cohere upstream no-generation outcomes on the live leg (#525)
## Problem
Two Cohere live-drift failures on `main` (9420afa). They have the same
root cause:
- **`cohere.drift.ts:688` `expected object`** in `cohereRecord` ←
`cohereUsage` ← `readCohereK5:884` (stream branch). Seen in both legs of
PR #524's drift-live-pr run 38157499382.
- **`cohere.drift.ts:324` `expected 422 to be 200`** in the
non-streaming shape test. Seen in post-merge Drift Tests run
38158387279.
Neither appears in any main drift report before 2026-10-11 ~17:00 UTC. I
scanned the artifacts of every main/PR drift run back to 37580386296.
## Diagnosis: upstream nondeterminism, not a contract change
Sometimes Cohere generates nothing. Live probes of the exact test
requests on 2026-10-11 (trial key; 429s excluded):
| Request | Outcome | Count |
|---|---|---|
| K5 object (`tool_choice: REQUIRED`, 128 tok) | 200 `MAX_TOKENS`,
normal usage | 15 |
| K5 object | **422**
`{"error_type":"NO_TOOL_CALL_OR_RESPONSE_GENERATED","id":…,"message":…}`
| 5 |
| K5 stream | 200 `TOOL_CALL`, normal usage | 29 |
| K5 stream | **200 SSE, `message-end` =
`{"finish_reason":"ERROR","usage":{},"error":"No tool calls or response
was generated…","error_type":"NO_TOOL_CALL_OR_RESPONSE_GENERATED"}`** |
8 |
| Shape leg `Say hello` (object) | 200 | 13 |
| Shape leg `Say hello` (object) | **422**
`{"error_type":"NO_VALID_RESPONSE_GENERATED",…}` | 2 |
| Shape leg `Say hello` (stream) | 200 | 12 |
| Shape leg `Say hello` (stream) | **422** `NO_VALID_RESPONSE_GENERATED`
| 3 |
The `usage: {}` on the stream ERROR terminal is exactly what fails at
line 688: `usage.tokens` is undefined. The 422 is what fails at line
324. Successful responses kept the same shape throughout, so aimock's
Cohere builder has nothing to follow. No `src/` code changes; only test
files.
## Fix (live leg only; aimock and replay legs stay strict)
- `cohere-model.ts`: `cohereNoGenerationError(status, body, allowed)`
matches only a 422 whose keys are exactly `{error_type,id,message}`
(non-empty strings) and whose code is in `allowed`. It returns
`{errorType, id}`. The codes are per request: the no-tools shape legs
(`COHERE_SHAPE_LEG_NO_GENERATION`) accept only
`NO_VALID_RESPONSE_GENERATED`, and the K5 tool request
(`COHERE_K5_NO_GENERATION`) accepts only
`NO_TOOL_CALL_OR_RESPONSE_GENERATED`.
`isCohereNoGenerationStreamEnd(delta)` matches only the exact observed
ERROR terminal.
- K5: `readCohereK5`/`compareCohereK5`/`runCohereK5Modes` take a `{ live
}` option. Only the live test sets it. The exact variants become
`UPSTREAM_NO_GENERATION`: a 422 on **either** send, or the stream ERROR
terminal. The stream variant must not have emitted any tool or content
first, and the SDK error must be a `CohereError` with status 422.
Anything else rethrows. A refused 422 rethrows with `cause: { sdk,
classifier }` so the classifier's reason is kept.
- **A K5 run where every send is `UPSTREAM_NO_GENERATION` is a skip, not
a pass.** Its reason cites each upstream code and id. One compared send
is still a pass.
- The shape legs (non-streaming and streaming) skip on the exact 422
envelope. Every `ctx.skip` carries a reason with the upstream code or
status and the response id.
- Genuine live captures are kept as hashed fixtures. The 422 on the K5
stream send is a constructed replay (not yet observed live) and is
marked as such.
## Local red/green
**RED: unmodified main @9420afa1, same filtered live command, 8 runs:**
run 5 reproduced the CI stack trace exactly:
```
× P1 Cohere native K5 object modeled and stream observed comparison
AssertionError: expected object
❯ cohereRecord cohere.drift.ts:688:3
❯ cohereUsage cohere.drift.ts:698:19
❯ readCohereK5 cohere.drift.ts:884:13
```
Replay RED: the new strict-leg test asserts that the unmodified reader
throws `expected object` on the captured stream and `HTTP failure` on
the captured 422.
**GREEN: this branch, same command, 8 consecutive live runs, all
passed.** They included real occurrences of the variants:
```
run 2: [object UPSTREAM_NO_GENERATION, stream UPSTREAM_NO_GENERATION] ✓
run 5: [object UPSTREAM_NO_GENERATION, stream TARGET] ✓
run 6: [object UPSTREAM_NO_GENERATION, stream TARGET] ✓
run 7: [object NOT_TRIGGERED, stream UPSTREAM_NO_GENERATION] ✓
runs 1,3,4,8: [object NOT_TRIGGERED, stream TARGET] ✓
```
**Mutants, round 1 (5/5 killed):** removing the live gate on stream,
removing the live gate on object, making the stream-end classifier
always true, making the 422 classifier accept any error type, and
dropping the tool-before-terminal check.
**Mutants, round 2 after review (12/12 killed):** all-no-generation skip
disabled · 422 accepted on the object send only · shape leg allows the
tool code · `allowed` filter dropped · bare rethrow instead of
rethrow-with-cause · `contentCount` guard deleted · `typeof` deleted on
id, message and stream `error` · `null`-body guard deleted · 422
`complete` guard deleted · 422 content-type guard deleted.
**Live after review, 6 consecutive runs, 0 failures.** Run 1 showed the
new skip working live:
```
↓ P1 Cohere native K5 … [Cohere upstream generated nothing (NO_TOOL_CALL_OR_RESPONSE_GENERATED id=53e39cc7-…; NO_TOOL_CALL_OR_RESPONSE_GENERATED id=88013390-…); no success envelope to compare]
↓ Cohere drift > non-streaming /v2/chat shape matches [Cohere upstream generated nothing (NO_VALID_RESPONSE_GENERATED id=7d6ebc99-…); …]
```
Runs 2–6: K5 passed every time (3× stream TARGET, 2× stream
UPSTREAM_NO_GENERATION with the object compared). Two shape-leg sends
were skipped with reasons.
**Gates (after review):** `pnpm typecheck` ✓, `pnpm lint` ✓, `pnpm
format:check` ✓, `pnpm build` ✓, `pnpm test` ✓ (377 files, 14079
passed). Cohere drift file offline: 23 passed / 3 skipped.
## Tradeoff
When the stream send hits no-generation (about 22% of probes), that run
does not observe K5 `TARGET`. If the object send is compared, the run
passes. If both sends generate nothing, the run is reported as skipped.
This follows the precedent approved today for genuine upstream
nondeterminism: accept the exact variants on the live leg rather than
retry.
## Backlog (out of scope)
- `parseDataOnlySSE` drops `event:` frames (pre-existing).
- The K5 422 path has no body-size check.6 files changed
Lines changed: 692 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
12 | 22 | | |
13 | 23 | | |
14 | 24 | | |
| |||
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
0 commit comments