johns-harness 2026.11.9 → 2026.11.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 2026.11.10
4
+
5
+ ### Replayed thinking bound to a different conversation (Family 97)
6
+ - Anthropic now binds each signed thinking block to the exact request prefix (system, tools, earlier messages). The harness rewrites that prefix between turns (compaction, memory context, announce runs, model switches), so replayed blocks came back as `400 Invalid signature in thinking block. The block is bound to a different conversation`, which ended the main session on 2026-11-09 on Fable 5.2.
7
+ - Direct api.anthropic.com adaptive-thinking requests, API key and subscription alike, now send the `thinking-binding-controls-2026-08-01` beta and `thinking.block_binding.prefix_mismatch_behavior: "drop_block"`, so the API drops stale blocks (unbilled) instead of failing. Budget-thinking models, thinking-off requests, proxies and Copilot are untouched.
8
+ - Any remaining invalid-signature 400 strips the named block and every later thinking block and retries once, before any stream event, with a logged warning. Endpoints that reject the control are retried once without it and remembered.
9
+ - `JOHNNESS_THINKING_BLOCK_BINDING=off` disables the control; the strip-and-retry stays on.
10
+ - Patcher `scripts/patch-thinking-block-binding-97.py`, verifier checks 97.1 to 97.5, focused tests on both auth paths, historical replay layers updated.
11
+
12
+ Official sources checked 2026-11-09:
13
+ - https://platform.claude.com/docs/en/build-with-claude/preserved-thinking
14
+ - https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting
15
+
16
+ Validation: verifier **591 pass, 0 fail**; full suite **1381 pass, 0 fail, 5 skip** (1386 tests).
17
+
18
+ Rollback: `npm i -g johns-harness@2026.11.9`. John owns activation via `/update`; no global install or gateway restart is part of this release.
19
+
3
20
  ## 2026.11.9
4
21
 
5
22
  ### Claude Fable 5.2
package/docs/PATCHES.md CHANGED
@@ -3237,3 +3237,46 @@ Tests add generation override/fallback/API-mock cases. No live probes run inside
3237
3237
  Validation: 586 verifier passes; 1,363 tests pass, five existing skips, zero failures/cancellations.
3238
3238
  Real after-edit proof still reports low, qualityVerified=false, 1254x1254 versus requested
3239
3239
  max/1024x1024. This release must not be sold as a verified max-rendering fix. Rollback: 2026.11.7.
3240
+
3241
+ ## Family 97: replayed thinking bound to a different conversation (2026.11.10)
3242
+
3243
+ Anthropic binds each signed thinking block to the exact prefix it was produced under: the
3244
+ top-level system prompt, the tools list and every earlier message. The harness legitimately
3245
+ rewrites that prefix between turns (compaction, the memory context tail, announce runs, model
3246
+ switches), so a replayed block can come back as a 400: "messages.N.content.M: Invalid
3247
+ `signature` in `thinking` block. The block is bound to a different conversation." On Fable 5.2
3248
+ and Mythos 5.2 that is a hard error for every account; on Fable 5.1, Opus 5.5, Sonnet 5.5 and
3249
+ Haiku 5.5 it is a hard error for accounts created on or after 2026-08-31. It killed the main
3250
+ session four times on 2026-11-09 (16:47 to 16:49 PT) plus one subagent announce run.
3251
+
3252
+ Three generic layers in the pi-ai Anthropic adapter (`JOHNNESS_PATCH_THINKING_BLOCK_BINDING_97`):
3253
+
3254
+ 1. Direct api.anthropic.com requests with adaptive thinking (API key and subscription) send the
3255
+ `thinking-binding-controls-2026-08-01` beta and
3256
+ `thinking.block_binding.prefix_mismatch_behavior: "drop_block"`. The API drops the failing
3257
+ block and every later thinking block and answers; dropped blocks are not billed. The control
3258
+ is only valid with `thinking.type: "adaptive"`, so budget-thinking models, thinking-off
3259
+ requests, proxies and Copilot keep their exact requests.
3260
+ 2. Any request that still gets the invalid-signature 400 (other endpoints, tampered signatures,
3261
+ the control disabled) strips the named block and every later thinking/redacted_thinking
3262
+ block and retries once. The 400 arrives before any stream event, so nothing partial reached
3263
+ the caller; a second 400 surfaces unchanged. The retry logs a warning, as the docs ask.
3264
+ 3. If an endpoint rejects `block_binding` or the beta itself, the request is retried once
3265
+ without them and the endpoint is remembered per provider, baseUrl and model.
3266
+
3267
+ `JOHNNESS_THINKING_BLOCK_BINDING=off` disables layers 1 and 3; the strip-and-retry stays on.
3268
+ The one `client.messages.stream` call site routes through the recovery generator, so no
3269
+ request bypasses it. Family 90's extended-cache beta is preserved on both auth paths.
3270
+
3271
+ Docs: https://platform.claude.com/docs/en/build-with-claude/preserved-thinking (beta header
3272
+ name, allowed values `"error"` and `"drop_block"`, the adaptive-only rule, the retry guidance
3273
+ for libraries and gateways) and
3274
+ https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting, both read
3275
+ 2026-11-09. Claude Code 2.1.292 ships the same beta string.
3276
+
3277
+ Patcher: `scripts/patch-thinking-block-binding-97.py` (exact hunks in
3278
+ `patches/thinking-block-binding-97/changes.json`, `--check`, `--present-only`,
3279
+ `--dependency-only`). Verifier 97.1 to 97.5. Tests: `tests/thinking-block-binding-97.test.mjs`
3280
+ drives the real adapter over scripted SSE/400 responses on both auth paths. Historical replays
3281
+ (families 67, 82, 86 to 95) layer 97 so hash-pinned fixtures still round trip.
3282
+ Rollback: `npm i -g johns-harness@2026.11.9`.
@@ -39,6 +39,122 @@ buildParams = function johnnessMasterAnthropicBuildParams(model, context, isOAut
39
39
  return params;
40
40
  };
41
41
  /* JOHNNESS_MODELS_MASTER:END */
42
+ /* JOHNNESS_PATCH_THINKING_BLOCK_BINDING_97 (family 97): Anthropic binds each replayed signed thinking
43
+ * block to the exact prefix it was produced under (top-level system, tools, every earlier message).
44
+ * The harness legitimately rewrites that prefix (compaction, memory context, announce runs, model
45
+ * switches), so a replayed block can come back as a 400: "messages.i.content.j: Invalid `signature`
46
+ * in `thinking` block. The block is bound to a different conversation." Three layers, all generic:
47
+ * 1. Direct Claude API requests (API key and subscription) send the thinking-binding-controls beta and
48
+ * thinking.block_binding.prefix_mismatch_behavior "drop_block" whenever thinking is adaptive (the
49
+ * only thinking type that accepts block_binding), so the API drops stale blocks instead of failing.
50
+ * 2. Any request that still gets that 400 (other thinking modes, proxies, corrupted signatures) strips
51
+ * the named block and every later thinking/redacted_thinking block, then retries once. The 400 is
52
+ * returned before any stream event, so nothing partial ever reached the caller.
53
+ * 3. If an endpoint rejects the control itself, it is remembered per provider+baseUrl+model, the request
54
+ * is retried once without it, and later requests to that endpoint omit it.
55
+ * Docs: https://platform.claude.com/docs/en/build-with-claude/preserved-thinking and
56
+ * https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting (checked 2026-11-09).
57
+ * JOHNNESS_THINKING_BLOCK_BINDING=off disables layers 1 and 3; the strip retry always stays on. */
58
+ const JOHNNESS_THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
59
+ const JOHNNESS_THINKING_SIGNATURE_ERROR = /messages\.(\d+)\.content\.(\d+): Invalid `signature` in `thinking` block/;
60
+ const johnnessThinkingBindingRejected = new Set();
61
+ function johnnessThinkingBindingKey(model) {
62
+ return `${model?.provider}|${model?.baseUrl}|${model?.id}`;
63
+ }
64
+ function johnnessThinkingBindingEligible(model) {
65
+ if (typeof process !== "undefined" && /^(off|0|false|no)$/i.test(String(process.env.JOHNNESS_THINKING_BLOCK_BINDING ?? "").trim())) return false;
66
+ return model?.provider !== "github-copilot" && String(model?.baseUrl ?? "").includes("api.anthropic.com") &&
67
+ !johnnessThinkingBindingRejected.has(johnnessThinkingBindingKey(model));
68
+ }
69
+ const johnnessHistoricalThinkingBindingHeaders = withAnthropicCacheBeta;
70
+ withAnthropicCacheBeta = function johnnessThinkingBindingHeaders(headers, model, cacheRetention) {
71
+ const merged = { ...johnnessHistoricalThinkingBindingHeaders(headers, model, cacheRetention) };
72
+ // Only models that can think adaptively can carry block_binding; others keep their exact headers.
73
+ if (!model?.reasoning || !supportsAdaptiveThinking(model.id) || !johnnessThinkingBindingEligible(model)) return merged;
74
+ const keys = Object.keys(merged).filter((key) => key.toLowerCase() === "anthropic-beta");
75
+ const betas = keys.flatMap((key) => String(merged[key] ?? "").split(",").map((value) => value.trim()).filter(Boolean));
76
+ for (const key of keys) delete merged[key];
77
+ merged["anthropic-beta"] = [...new Set([...betas, JOHNNESS_THINKING_BINDING_BETA])].join(",");
78
+ return merged;
79
+ };
80
+ const johnnessHistoricalThinkingBindingBuildParams = buildParams;
81
+ buildParams = function johnnessThinkingBindingBuildParams(model, context, isOAuthToken, options) {
82
+ const params = johnnessHistoricalThinkingBindingBuildParams(model, context, isOAuthToken, options);
83
+ if (params.thinking?.type === "adaptive" && !params.thinking.block_binding && johnnessThinkingBindingEligible(model)) {
84
+ params.thinking = { ...params.thinking, block_binding: { prefix_mismatch_behavior: "drop_block" } };
85
+ }
86
+ return params;
87
+ };
88
+ function johnnessThinkingBindingErrorText(error) {
89
+ return [error?.message, error?.error?.error?.message, error?.error?.message]
90
+ .filter((value) => typeof value === "string").join("\n");
91
+ }
92
+ function johnnessStripReplayedThinking(params, messageIndex, blockIndex) {
93
+ let stripped = 0;
94
+ const messages = [];
95
+ params.messages.forEach((message, i) => {
96
+ if (i < messageIndex || !Array.isArray(message?.content)) {
97
+ messages.push(message);
98
+ return;
99
+ }
100
+ const content = message.content.filter((block, j) => {
101
+ const drop = (block?.type === "thinking" || block?.type === "redacted_thinking") && (i > messageIndex || j >= blockIndex);
102
+ if (drop) stripped++;
103
+ return !drop;
104
+ });
105
+ if (content.length > 0) messages.push(content.length === message.content.length ? message : { ...message, content });
106
+ });
107
+ return stripped > 0 ? { params: { ...params, messages }, stripped } : undefined;
108
+ }
109
+ function johnnessThinkingBindingRecovery(params, error, model, state) {
110
+ if (error?.status !== undefined && error.status !== 400) return undefined;
111
+ const text = johnnessThinkingBindingErrorText(error);
112
+ const match = text.match(JOHNNESS_THINKING_SIGNATURE_ERROR);
113
+ if (match) {
114
+ if (state.stripped) return undefined;
115
+ state.stripped = true;
116
+ const next = johnnessStripReplayedThinking(params, Number(match[1]), Number(match[2])) ?? johnnessStripReplayedThinking(params, 0, 0);
117
+ if (!next) return undefined;
118
+ console.warn(`[johnness] anthropic ${model?.id}: replayed thinking bound to a different conversation at messages.${match[1]}.content.${match[2]}; stripped ${next.stripped} thinking block(s) and retrying once (family 97)`);
119
+ return { params: next.params };
120
+ }
121
+ const rejectsField = params.thinking?.block_binding && /block_binding/.test(text) && /extra inputs|not permitted|unsupported|not supported|unknown/i.test(text);
122
+ const rejectsBeta = text.includes(JOHNNESS_THINKING_BINDING_BETA) && /anthropic-beta/.test(text) && /unexpected|invalid|unsupported|not supported|unknown/i.test(text);
123
+ if ((rejectsField || rejectsBeta) && !state.control) {
124
+ state.control = true;
125
+ johnnessThinkingBindingRejected.add(johnnessThinkingBindingKey(model));
126
+ const next = { ...params };
127
+ if (next.thinking?.block_binding) {
128
+ const { block_binding, ...thinking } = next.thinking;
129
+ next.thinking = thinking;
130
+ }
131
+ console.warn(`[johnness] anthropic ${model?.id}: endpoint rejected thinking block_binding; retrying once without it (family 97)`);
132
+ return { params: next, rebuild: true };
133
+ }
134
+ return undefined;
135
+ }
136
+ async function* johnnessThinkingBindingStream(client, params, options, model, rebuildClient) {
137
+ const state = {};
138
+ let attempt = params;
139
+ for (;;) {
140
+ let emitted = false;
141
+ try {
142
+ const stream = client.messages.stream({ ...attempt, stream: true }, { signal: options?.signal });
143
+ for await (const event of stream) {
144
+ emitted = true;
145
+ yield event;
146
+ }
147
+ return;
148
+ }
149
+ catch (error) {
150
+ if (emitted || options?.signal?.aborted) throw error;
151
+ const recovery = johnnessThinkingBindingRecovery(attempt, error, model, state);
152
+ if (!recovery) throw error;
153
+ attempt = recovery.params;
154
+ if (recovery.rebuild) client = rebuildClient();
155
+ }
156
+ }
157
+ }
42
158
  /**
43
159
  * Resolve cache retention preference.
44
160
  * JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic defaults to 1h for API keys and subscriptions.
@@ -227,7 +343,8 @@ export const streamAnthropic = (model, context, options) => {
227
343
  const billingModel = isOAuthToken ? { ...model, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } : model;
228
344
  const params = buildParams(model, context, isOAuthToken, options);
229
345
  options?.onPayload?.(params);
230
- const anthropicStream = client.messages.stream({ ...params, stream: true }, { signal: options?.signal });
346
+ // JOHNNESS_PATCH_THINKING_BLOCK_BINDING_97: one recovery for stale replayed thinking, before any event.
347
+ const anthropicStream = johnnessThinkingBindingStream(client, params, options, model, () => createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders, options?.cacheRetention).client);
231
348
  stream.push({ type: "start", partial: output });
232
349
  const blocks = output.content;
233
350
  for await (const event of anthropicStream) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "johns-harness",
3
- "version": "2026.11.9",
3
+ "version": "2026.11.10",
4
4
  "description": "John's Harness: a production agent harness that runs autonomous coding agents as one cooperative swarm.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -39,6 +39,122 @@ buildParams = function johnnessMasterAnthropicBuildParams(model, context, isOAut
39
39
  return params;
40
40
  };
41
41
  /* JOHNNESS_MODELS_MASTER:END */
42
+ /* JOHNNESS_PATCH_THINKING_BLOCK_BINDING_97 (family 97): Anthropic binds each replayed signed thinking
43
+ * block to the exact prefix it was produced under (top-level system, tools, every earlier message).
44
+ * The harness legitimately rewrites that prefix (compaction, memory context, announce runs, model
45
+ * switches), so a replayed block can come back as a 400: "messages.i.content.j: Invalid `signature`
46
+ * in `thinking` block. The block is bound to a different conversation." Three layers, all generic:
47
+ * 1. Direct Claude API requests (API key and subscription) send the thinking-binding-controls beta and
48
+ * thinking.block_binding.prefix_mismatch_behavior "drop_block" whenever thinking is adaptive (the
49
+ * only thinking type that accepts block_binding), so the API drops stale blocks instead of failing.
50
+ * 2. Any request that still gets that 400 (other thinking modes, proxies, corrupted signatures) strips
51
+ * the named block and every later thinking/redacted_thinking block, then retries once. The 400 is
52
+ * returned before any stream event, so nothing partial ever reached the caller.
53
+ * 3. If an endpoint rejects the control itself, it is remembered per provider+baseUrl+model, the request
54
+ * is retried once without it, and later requests to that endpoint omit it.
55
+ * Docs: https://platform.claude.com/docs/en/build-with-claude/preserved-thinking and
56
+ * https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting (checked 2026-11-09).
57
+ * JOHNNESS_THINKING_BLOCK_BINDING=off disables layers 1 and 3; the strip retry always stays on. */
58
+ const JOHNNESS_THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
59
+ const JOHNNESS_THINKING_SIGNATURE_ERROR = /messages\.(\d+)\.content\.(\d+): Invalid `signature` in `thinking` block/;
60
+ const johnnessThinkingBindingRejected = new Set();
61
+ function johnnessThinkingBindingKey(model) {
62
+ return `${model?.provider}|${model?.baseUrl}|${model?.id}`;
63
+ }
64
+ function johnnessThinkingBindingEligible(model) {
65
+ if (typeof process !== "undefined" && /^(off|0|false|no)$/i.test(String(process.env.JOHNNESS_THINKING_BLOCK_BINDING ?? "").trim())) return false;
66
+ return model?.provider !== "github-copilot" && String(model?.baseUrl ?? "").includes("api.anthropic.com") &&
67
+ !johnnessThinkingBindingRejected.has(johnnessThinkingBindingKey(model));
68
+ }
69
+ const johnnessHistoricalThinkingBindingHeaders = withAnthropicCacheBeta;
70
+ withAnthropicCacheBeta = function johnnessThinkingBindingHeaders(headers, model, cacheRetention) {
71
+ const merged = { ...johnnessHistoricalThinkingBindingHeaders(headers, model, cacheRetention) };
72
+ // Only models that can think adaptively can carry block_binding; others keep their exact headers.
73
+ if (!model?.reasoning || !supportsAdaptiveThinking(model.id) || !johnnessThinkingBindingEligible(model)) return merged;
74
+ const keys = Object.keys(merged).filter((key) => key.toLowerCase() === "anthropic-beta");
75
+ const betas = keys.flatMap((key) => String(merged[key] ?? "").split(",").map((value) => value.trim()).filter(Boolean));
76
+ for (const key of keys) delete merged[key];
77
+ merged["anthropic-beta"] = [...new Set([...betas, JOHNNESS_THINKING_BINDING_BETA])].join(",");
78
+ return merged;
79
+ };
80
+ const johnnessHistoricalThinkingBindingBuildParams = buildParams;
81
+ buildParams = function johnnessThinkingBindingBuildParams(model, context, isOAuthToken, options) {
82
+ const params = johnnessHistoricalThinkingBindingBuildParams(model, context, isOAuthToken, options);
83
+ if (params.thinking?.type === "adaptive" && !params.thinking.block_binding && johnnessThinkingBindingEligible(model)) {
84
+ params.thinking = { ...params.thinking, block_binding: { prefix_mismatch_behavior: "drop_block" } };
85
+ }
86
+ return params;
87
+ };
88
+ function johnnessThinkingBindingErrorText(error) {
89
+ return [error?.message, error?.error?.error?.message, error?.error?.message]
90
+ .filter((value) => typeof value === "string").join("\n");
91
+ }
92
+ function johnnessStripReplayedThinking(params, messageIndex, blockIndex) {
93
+ let stripped = 0;
94
+ const messages = [];
95
+ params.messages.forEach((message, i) => {
96
+ if (i < messageIndex || !Array.isArray(message?.content)) {
97
+ messages.push(message);
98
+ return;
99
+ }
100
+ const content = message.content.filter((block, j) => {
101
+ const drop = (block?.type === "thinking" || block?.type === "redacted_thinking") && (i > messageIndex || j >= blockIndex);
102
+ if (drop) stripped++;
103
+ return !drop;
104
+ });
105
+ if (content.length > 0) messages.push(content.length === message.content.length ? message : { ...message, content });
106
+ });
107
+ return stripped > 0 ? { params: { ...params, messages }, stripped } : undefined;
108
+ }
109
+ function johnnessThinkingBindingRecovery(params, error, model, state) {
110
+ if (error?.status !== undefined && error.status !== 400) return undefined;
111
+ const text = johnnessThinkingBindingErrorText(error);
112
+ const match = text.match(JOHNNESS_THINKING_SIGNATURE_ERROR);
113
+ if (match) {
114
+ if (state.stripped) return undefined;
115
+ state.stripped = true;
116
+ const next = johnnessStripReplayedThinking(params, Number(match[1]), Number(match[2])) ?? johnnessStripReplayedThinking(params, 0, 0);
117
+ if (!next) return undefined;
118
+ console.warn(`[johnness] anthropic ${model?.id}: replayed thinking bound to a different conversation at messages.${match[1]}.content.${match[2]}; stripped ${next.stripped} thinking block(s) and retrying once (family 97)`);
119
+ return { params: next.params };
120
+ }
121
+ const rejectsField = params.thinking?.block_binding && /block_binding/.test(text) && /extra inputs|not permitted|unsupported|not supported|unknown/i.test(text);
122
+ const rejectsBeta = text.includes(JOHNNESS_THINKING_BINDING_BETA) && /anthropic-beta/.test(text) && /unexpected|invalid|unsupported|not supported|unknown/i.test(text);
123
+ if ((rejectsField || rejectsBeta) && !state.control) {
124
+ state.control = true;
125
+ johnnessThinkingBindingRejected.add(johnnessThinkingBindingKey(model));
126
+ const next = { ...params };
127
+ if (next.thinking?.block_binding) {
128
+ const { block_binding, ...thinking } = next.thinking;
129
+ next.thinking = thinking;
130
+ }
131
+ console.warn(`[johnness] anthropic ${model?.id}: endpoint rejected thinking block_binding; retrying once without it (family 97)`);
132
+ return { params: next, rebuild: true };
133
+ }
134
+ return undefined;
135
+ }
136
+ async function* johnnessThinkingBindingStream(client, params, options, model, rebuildClient) {
137
+ const state = {};
138
+ let attempt = params;
139
+ for (;;) {
140
+ let emitted = false;
141
+ try {
142
+ const stream = client.messages.stream({ ...attempt, stream: true }, { signal: options?.signal });
143
+ for await (const event of stream) {
144
+ emitted = true;
145
+ yield event;
146
+ }
147
+ return;
148
+ }
149
+ catch (error) {
150
+ if (emitted || options?.signal?.aborted) throw error;
151
+ const recovery = johnnessThinkingBindingRecovery(attempt, error, model, state);
152
+ if (!recovery) throw error;
153
+ attempt = recovery.params;
154
+ if (recovery.rebuild) client = rebuildClient();
155
+ }
156
+ }
157
+ }
42
158
  /**
43
159
  * Resolve cache retention preference.
44
160
  * JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic defaults to 1h for API keys and subscriptions.
@@ -227,7 +343,8 @@ export const streamAnthropic = (model, context, options) => {
227
343
  const billingModel = isOAuthToken ? { ...model, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } : model;
228
344
  const params = buildParams(model, context, isOAuthToken, options);
229
345
  options?.onPayload?.(params);
230
- const anthropicStream = client.messages.stream({ ...params, stream: true }, { signal: options?.signal });
346
+ // JOHNNESS_PATCH_THINKING_BLOCK_BINDING_97: one recovery for stale replayed thinking, before any event.
347
+ const anthropicStream = johnnessThinkingBindingStream(client, params, options, model, () => createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders, options?.cacheRetention).client);
231
348
  stream.push({ type: "start", partial: output });
232
349
  const blocks = output.content;
233
350
  for await (const event of anthropicStream) {