@stigmer/runner 3.11.0 → 3.11.1-dev.20260812192248

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.
Files changed (177) hide show
  1. package/README.md +2 -0
  2. package/dist/.build-fingerprint +1 -1
  3. package/dist/activities/discover-mcp-server.d.ts +7 -0
  4. package/dist/activities/discover-mcp-server.js +6 -4
  5. package/dist/activities/discover-mcp-server.js.map +1 -1
  6. package/dist/activities/emit-event.d.ts +14 -2
  7. package/dist/activities/emit-event.js +52 -17
  8. package/dist/activities/emit-event.js.map +1 -1
  9. package/dist/activities/execute-cursor/error-classifier.d.ts +19 -0
  10. package/dist/activities/execute-cursor/error-classifier.js +34 -3
  11. package/dist/activities/execute-cursor/error-classifier.js.map +1 -1
  12. package/dist/activities/execute-cursor/index.d.ts +46 -10
  13. package/dist/activities/execute-cursor/index.js +126 -36
  14. package/dist/activities/execute-cursor/index.js.map +1 -1
  15. package/dist/activities/execute-cursor/model-pricing-data.d.ts +2 -0
  16. package/dist/activities/execute-cursor/model-pricing-data.js +13 -3
  17. package/dist/activities/execute-cursor/model-pricing-data.js.map +1 -1
  18. package/dist/activities/execute-cursor/prompt-builder.d.ts +33 -0
  19. package/dist/activities/execute-cursor/prompt-builder.js +37 -0
  20. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  21. package/dist/activities/execute-cursor/turn-recovery.d.ts +52 -0
  22. package/dist/activities/execute-cursor/turn-recovery.js +193 -0
  23. package/dist/activities/execute-cursor/turn-recovery.js.map +1 -0
  24. package/dist/activities/execute-deep-agent/setup.js +16 -7
  25. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  26. package/dist/activities/execute-deep-agent/shell-env.d.ts +5 -1
  27. package/dist/activities/execute-deep-agent/shell-env.js +7 -9
  28. package/dist/activities/execute-deep-agent/shell-env.js.map +1 -1
  29. package/dist/activities/execute-deep-agent/subagent-transformer.js +7 -1
  30. package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
  31. package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +17 -3
  32. package/dist/activities/execute-deep-agent/subagent-wiring.js +14 -2
  33. package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
  34. package/dist/activities/hydrate-workflow-execution.js +8 -5
  35. package/dist/activities/hydrate-workflow-execution.js.map +1 -1
  36. package/dist/activities/run-command.d.ts +5 -2
  37. package/dist/activities/run-command.js +22 -10
  38. package/dist/activities/run-command.js.map +1 -1
  39. package/dist/activities/run-env.d.ts +40 -0
  40. package/dist/activities/run-env.js +66 -0
  41. package/dist/activities/run-env.js.map +1 -0
  42. package/dist/bootstrap.js +5 -0
  43. package/dist/bootstrap.js.map +1 -1
  44. package/dist/client/stigmer-client.d.ts +83 -26
  45. package/dist/client/stigmer-client.js +88 -24
  46. package/dist/client/stigmer-client.js.map +1 -1
  47. package/dist/encryption/config.d.ts +41 -9
  48. package/dist/encryption/config.js +63 -23
  49. package/dist/encryption/config.js.map +1 -1
  50. package/dist/middleware/index.d.ts +3 -0
  51. package/dist/middleware/index.js +7 -0
  52. package/dist/middleware/index.js.map +1 -1
  53. package/dist/middleware/path-normalization.d.ts +57 -0
  54. package/dist/middleware/path-normalization.js +109 -0
  55. package/dist/middleware/path-normalization.js.map +1 -0
  56. package/dist/middleware/types.d.ts +8 -0
  57. package/dist/payload-codecs.d.ts +2 -1
  58. package/dist/payload-codecs.js +7 -3
  59. package/dist/payload-codecs.js.map +1 -1
  60. package/dist/runner-manager.js +17 -3
  61. package/dist/runner-manager.js.map +1 -1
  62. package/dist/runner.js +7 -3
  63. package/dist/runner.js.map +1 -1
  64. package/dist/shared/artifact-storage.d.ts +23 -1
  65. package/dist/shared/artifact-storage.js +51 -10
  66. package/dist/shared/artifact-storage.js.map +1 -1
  67. package/dist/shared/checkpointer/http-saver.d.ts +4 -20
  68. package/dist/shared/checkpointer/http-saver.js +15 -57
  69. package/dist/shared/checkpointer/http-saver.js.map +1 -1
  70. package/dist/shared/conversation-catchup.d.ts +9 -2
  71. package/dist/shared/conversation-catchup.js +39 -6
  72. package/dist/shared/conversation-catchup.js.map +1 -1
  73. package/dist/shared/grpc-retry.d.ts +5 -1
  74. package/dist/shared/grpc-retry.js +5 -1
  75. package/dist/shared/grpc-retry.js.map +1 -1
  76. package/dist/shared/http-retry.d.ts +51 -9
  77. package/dist/shared/http-retry.js +60 -9
  78. package/dist/shared/http-retry.js.map +1 -1
  79. package/dist/shared/mcp-manager.d.ts +8 -4
  80. package/dist/shared/mcp-manager.js +30 -4
  81. package/dist/shared/mcp-manager.js.map +1 -1
  82. package/dist/shared/mcp-schema-sanitizer.d.ts +70 -0
  83. package/dist/shared/mcp-schema-sanitizer.js +197 -0
  84. package/dist/shared/mcp-schema-sanitizer.js.map +1 -0
  85. package/dist/shared/model-client.d.ts +6 -0
  86. package/dist/shared/model-client.js +14 -3
  87. package/dist/shared/model-client.js.map +1 -1
  88. package/dist/shared/model-pricing-data.d.ts +2 -0
  89. package/dist/shared/model-pricing-data.js +13 -3
  90. package/dist/shared/model-pricing-data.js.map +1 -1
  91. package/dist/shared/model-registry.js +3 -2
  92. package/dist/shared/model-registry.js.map +1 -1
  93. package/dist/shared/plan-mode-permissions.d.ts +7 -0
  94. package/dist/shared/plan-mode-permissions.js +7 -0
  95. package/dist/shared/plan-mode-permissions.js.map +1 -1
  96. package/dist/shared/registry-endpoint.d.ts +20 -0
  97. package/dist/shared/registry-endpoint.js +25 -0
  98. package/dist/shared/registry-endpoint.js.map +1 -1
  99. package/dist/shared/runner-credential-keys.d.ts +24 -0
  100. package/dist/shared/runner-credential-keys.js +47 -0
  101. package/dist/shared/runner-credential-keys.js.map +1 -0
  102. package/dist/workflow-engine/resolve.d.ts +19 -1
  103. package/dist/workflow-engine/resolve.js +37 -2
  104. package/dist/workflow-engine/resolve.js.map +1 -1
  105. package/dist/workflows/connect-mcp-server.js +2 -0
  106. package/dist/workflows/connect-mcp-server.js.map +1 -1
  107. package/dist/workflows/types.d.ts +8 -0
  108. package/package.json +3 -4
  109. package/src/__test-utils__/__tests__/vitest-global-setup.test.ts +37 -0
  110. package/src/__test-utils__/vitest-global-setup.ts +50 -0
  111. package/src/__tests__/bootstrap.test.ts +43 -0
  112. package/src/__tests__/encryption-codec.test.ts +53 -0
  113. package/src/__tests__/preflight.test.ts +15 -0
  114. package/src/activities/__tests__/discover-mcp-server.test.ts +39 -1
  115. package/src/activities/__tests__/error-classifier.test.ts +94 -2
  116. package/src/activities/__tests__/run-command.test.ts +221 -0
  117. package/src/activities/discover-mcp-server.ts +16 -2
  118. package/src/activities/emit-event.ts +65 -21
  119. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +111 -2
  120. package/src/activities/execute-cursor/__tests__/model-pricing.test.ts +62 -1
  121. package/src/activities/execute-cursor/__tests__/turn-recovery.test.ts +160 -0
  122. package/src/activities/execute-cursor/error-classifier.ts +40 -3
  123. package/src/activities/execute-cursor/index.ts +154 -38
  124. package/src/activities/execute-cursor/model-pricing-data.ts +22 -3
  125. package/src/activities/execute-cursor/prompt-builder.ts +51 -0
  126. package/src/activities/execute-cursor/turn-recovery.ts +208 -0
  127. package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +174 -0
  128. package/src/activities/execute-deep-agent/__tests__/shell-env.test.ts +24 -10
  129. package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +22 -17
  130. package/src/activities/execute-deep-agent/setup.ts +16 -8
  131. package/src/activities/execute-deep-agent/shell-env.ts +8 -9
  132. package/src/activities/execute-deep-agent/subagent-transformer.ts +7 -1
  133. package/src/activities/execute-deep-agent/subagent-wiring.ts +26 -3
  134. package/src/activities/hydrate-workflow-execution.ts +8 -5
  135. package/src/activities/run-command.ts +25 -12
  136. package/src/activities/run-env.ts +79 -0
  137. package/src/bootstrap.ts +5 -0
  138. package/src/client/__tests__/stigmer-client.test.ts +104 -5
  139. package/src/client/stigmer-client.ts +128 -29
  140. package/src/encryption/config.ts +87 -23
  141. package/src/middleware/__tests__/path-normalization.test.ts +140 -0
  142. package/src/middleware/index.ts +8 -0
  143. package/src/middleware/path-normalization.ts +125 -0
  144. package/src/middleware/types.ts +11 -0
  145. package/src/payload-codecs.ts +8 -2
  146. package/src/runner-manager.ts +21 -3
  147. package/src/runner.ts +7 -3
  148. package/src/shared/__tests__/artifact-storage.test.ts +145 -2
  149. package/src/shared/__tests__/conversation-catchup.test.ts +24 -0
  150. package/src/shared/__tests__/http-retry.test.ts +5 -4
  151. package/src/shared/__tests__/mcp-manager.test.ts +53 -13
  152. package/src/shared/__tests__/mcp-schema-sanitizer.test.ts +267 -0
  153. package/src/shared/__tests__/model-client.test.ts +46 -0
  154. package/src/shared/__tests__/model-pricing.test.ts +62 -2
  155. package/src/shared/__tests__/model-registry.test.ts +22 -0
  156. package/src/shared/artifact-storage.ts +75 -10
  157. package/src/shared/checkpointer/http-saver.ts +15 -60
  158. package/src/shared/conversation-catchup.ts +39 -6
  159. package/src/shared/grpc-retry.ts +5 -1
  160. package/src/shared/http-retry.ts +98 -9
  161. package/src/shared/mcp-manager.ts +35 -4
  162. package/src/shared/mcp-schema-sanitizer.ts +224 -0
  163. package/src/shared/model-client.ts +21 -3
  164. package/src/shared/model-pricing-data.ts +22 -3
  165. package/src/shared/model-registry.ts +7 -2
  166. package/src/shared/plan-mode-permissions.ts +7 -0
  167. package/src/shared/registry-endpoint.ts +27 -0
  168. package/src/shared/runner-credential-keys.ts +46 -0
  169. package/src/workflow-engine/__tests__/tasks/emit-event.test.ts +127 -49
  170. package/src/workflow-engine/resolve.ts +48 -2
  171. package/src/workflows/__tests__/connect-mcp-server.test.ts +25 -0
  172. package/src/workflows/connect-mcp-server.ts +2 -0
  173. package/src/workflows/types.ts +8 -0
  174. package/dist/activities/execute-cursor/mcp-config.d.ts +0 -30
  175. package/dist/activities/execute-cursor/mcp-config.js +0 -39
  176. package/dist/activities/execute-cursor/mcp-config.js.map +0 -1
  177. package/src/activities/execute-cursor/mcp-config.ts +0 -66
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Unicode-flag regex sanitization for MCP tool input schemas (issue #420).
3
+ *
4
+ * Why this exists: real-world MCP servers ship JSON-schema `pattern` values
5
+ * that are legal as plain ECMAScript regexes but invalid under the unicode
6
+ * flag (PayPal's `^https\:\/\/` — `\:` is an invalid escape under /u).
7
+ * @langchain/core validates tool input on EVERY call with
8
+ * @cfworker/json-schema, which compiles patterns via `new RegExp(p, "u")`
9
+ * at exactly two uncaught sites: the `pattern` keyword and each
10
+ * `patternProperties` key. One bad vendor pattern therefore makes the tool
11
+ * permanently uncallable on the deep-agent path — every invocation dies
12
+ * with a cryptic SyntaxError before the tool is ever reached. (The third
13
+ * /u compile site, `format: "regex"`, validates instance values inside a
14
+ * try/catch and fails gracefully — not a crash surface.)
15
+ *
16
+ * The fix: at the deep-agent connect funnel (mcp-manager.ts
17
+ * connectMcpServers), drop every pattern that cannot compile under /u.
18
+ * Dropping is deliberate — rewriting to a /u-safe equivalent would need an
19
+ * Annex-B-aware regex transpiler, disproportionate machinery for what is
20
+ * best-effort client-side validation; the MCP server still validates its
21
+ * own inputs server-side. This mirrors the loosening posture of
22
+ * @langchain/mcp-adapters' own schema pipeline (dereferenceJsonSchema →
23
+ * simplifyJsonSchemaForLLM), which already normalizes schemas for this
24
+ * exact validator.
25
+ *
26
+ * THE INVARIANT: sanitization may only ever LOOSEN validation, never
27
+ * tighten it. Dropping a `patternProperties` entry naively would violate
28
+ * this — @cfworker marks pattern-matched keys as "evaluated" and routes
29
+ * unevaluated keys into the `additionalProperties` / `unevaluatedProperties`
30
+ * checks, so under `additionalProperties: false` the drop would flip a
31
+ * crash into a false REJECTION of valid inputs. Whenever a
32
+ * `patternProperties` entry is dropped, any restrictive
33
+ * `additionalProperties` / `unevaluatedProperties` at that schema level is
34
+ * therefore relaxed too.
35
+ *
36
+ * Scope: this sanitizer serves the EXECUTION path only. Discovery
37
+ * (activities/discover-mcp-server.ts) persists tool schemas verbatim from
38
+ * listTools — deliberately: the stored schema is the vendor's truth for
39
+ * display, and discovery never invokes tools, so it cannot hit the crash.
40
+ * Do not "extend" sanitization there.
41
+ */
42
+
43
+ /** One dropped regex constraint, for the caller's log line. */
44
+ export interface DroppedPattern {
45
+ /** JSON-pointer-style path of the dropped constraint within the schema. */
46
+ location: string;
47
+ /** The pattern source that failed to compile under the unicode flag. */
48
+ pattern: string;
49
+ /**
50
+ * True when the pattern compiles WITHOUT the /u flag — vendor sloppiness
51
+ * (Annex B legacy syntax), the oss#420 class. False means the regex is
52
+ * broken outright; either way validation could only crash, so both drop.
53
+ */
54
+ compilesWithoutUnicodeFlag: boolean;
55
+ }
56
+
57
+ /** Keywords whose value is a single subschema. */
58
+ const SINGLE_SCHEMA_KEYWORDS = [
59
+ "additionalProperties",
60
+ "unevaluatedProperties",
61
+ "propertyNames",
62
+ "items",
63
+ "additionalItems",
64
+ "unevaluatedItems",
65
+ "contains",
66
+ "not",
67
+ "if",
68
+ "then",
69
+ "else",
70
+ ] as const;
71
+
72
+ /** Keywords whose value is an array of subschemas. */
73
+ const SCHEMA_ARRAY_KEYWORDS = ["anyOf", "allOf", "oneOf", "prefixItems"] as const;
74
+
75
+ /** Keywords whose value is an object mapping names to subschemas. */
76
+ const SCHEMA_MAP_KEYWORDS = [
77
+ "properties",
78
+ "patternProperties",
79
+ "dependentSchemas",
80
+ "$defs",
81
+ "definitions",
82
+ ] as const;
83
+
84
+ function compilesUnderUnicodeFlag(pattern: string): boolean {
85
+ try {
86
+ new RegExp(pattern, "u");
87
+ return true;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ function compilesWithoutUnicodeFlag(pattern: string): boolean {
94
+ try {
95
+ new RegExp(pattern);
96
+ return true;
97
+ } catch {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
103
+ return typeof value === "object" && value !== null && !Array.isArray(value);
104
+ }
105
+
106
+ /** JSON-pointer token escaping (RFC 6901): `~` → `~0`, `/` → `~1`. */
107
+ function pointerToken(token: string): string {
108
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
109
+ }
110
+
111
+ /**
112
+ * Drop unicode-invalid regex patterns from a JSON schema, in place.
113
+ *
114
+ * Walks only schema positions (the recursion set is @cfworker's own
115
+ * validated-keyword list), so a property literally NAMED "pattern" under
116
+ * `properties` is never touched. The walker handles composition keywords
117
+ * (anyOf/allOf/oneOf/not/if-then-else) even though the adapter's
118
+ * simplifyJsonSchemaForLLM currently strips them, and carries a visited-set
119
+ * cycle guard even though the adapter's $ref inlining currently guarantees
120
+ * an acyclic result — correctness here must not depend on another
121
+ * package's internals holding across dependency bumps.
122
+ *
123
+ * Returns the dropped constraints (empty for clean schemas — the common
124
+ * case, which this walk leaves byte-identical).
125
+ */
126
+ export function sanitizeSchemaPatterns(schema: unknown): DroppedPattern[] {
127
+ const dropped: DroppedPattern[] = [];
128
+ if (!isPlainObject(schema)) return dropped;
129
+ walkSchema(schema, "", dropped, new Set());
130
+ return dropped;
131
+ }
132
+
133
+ function recordDrop(dropped: DroppedPattern[], location: string, pattern: string): void {
134
+ dropped.push({
135
+ location,
136
+ pattern,
137
+ compilesWithoutUnicodeFlag: compilesWithoutUnicodeFlag(pattern),
138
+ });
139
+ }
140
+
141
+ function walkSchema(
142
+ node: Record<string, unknown>,
143
+ path: string,
144
+ dropped: DroppedPattern[],
145
+ seen: Set<object>,
146
+ ): void {
147
+ if (seen.has(node)) return;
148
+ seen.add(node);
149
+
150
+ if (typeof node.pattern === "string" && !compilesUnderUnicodeFlag(node.pattern)) {
151
+ recordDrop(dropped, `${path}/pattern`, node.pattern);
152
+ delete node.pattern;
153
+ }
154
+
155
+ if (isPlainObject(node.patternProperties)) {
156
+ const patternProperties = node.patternProperties;
157
+ let droppedEntry = false;
158
+ for (const key of Object.keys(patternProperties)) {
159
+ if (compilesUnderUnicodeFlag(key)) continue;
160
+ recordDrop(dropped, `${path}/patternProperties/${pointerToken(key)}`, key);
161
+ delete patternProperties[key];
162
+ droppedEntry = true;
163
+ }
164
+ if (droppedEntry) {
165
+ // Never-tighten: keys the dropped pattern used to match would now
166
+ // fall through to these checks and could be falsely rejected.
167
+ if (node.additionalProperties !== undefined && node.additionalProperties !== true) {
168
+ delete node.additionalProperties;
169
+ }
170
+ if (node.unevaluatedProperties !== undefined && node.unevaluatedProperties !== true) {
171
+ delete node.unevaluatedProperties;
172
+ }
173
+ if (Object.keys(patternProperties).length === 0) {
174
+ delete node.patternProperties;
175
+ }
176
+ }
177
+ }
178
+
179
+ for (const keyword of SINGLE_SCHEMA_KEYWORDS) {
180
+ const value = node[keyword];
181
+ if (isPlainObject(value)) {
182
+ walkSchema(value, `${path}/${keyword}`, dropped, seen);
183
+ }
184
+ }
185
+
186
+ for (const keyword of SCHEMA_ARRAY_KEYWORDS) {
187
+ const value = node[keyword];
188
+ if (!Array.isArray(value)) continue;
189
+ value.forEach((entry, index) => {
190
+ if (isPlainObject(entry)) {
191
+ walkSchema(entry, `${path}/${keyword}/${index}`, dropped, seen);
192
+ }
193
+ });
194
+ }
195
+
196
+ for (const keyword of SCHEMA_MAP_KEYWORDS) {
197
+ const value = node[keyword];
198
+ if (!isPlainObject(value)) continue;
199
+ for (const [name, entry] of Object.entries(value)) {
200
+ if (isPlainObject(entry)) {
201
+ walkSchema(entry, `${path}/${keyword}/${pointerToken(name)}`, dropped, seen);
202
+ }
203
+ }
204
+ }
205
+
206
+ // Draft-07 `items` tuple form and `dependencies` schema form — both
207
+ // keywords are dual-shaped, so the typed loops above miss these arms.
208
+ if (Array.isArray(node.items)) {
209
+ node.items.forEach((entry, index) => {
210
+ if (isPlainObject(entry)) {
211
+ walkSchema(entry, `${path}/items/${index}`, dropped, seen);
212
+ }
213
+ });
214
+ }
215
+ if (isPlainObject(node.dependencies)) {
216
+ for (const [name, entry] of Object.entries(node.dependencies)) {
217
+ // Array-valued entries are dependentRequired (property names, not
218
+ // schemas) — only schema-valued entries are walked.
219
+ if (isPlainObject(entry)) {
220
+ walkSchema(entry, `${path}/dependencies/${pointerToken(name)}`, dropped, seen);
221
+ }
222
+ }
223
+ }
224
+ }
@@ -55,10 +55,27 @@ export interface BuildChatModelOptions {
55
55
  * stays the caller's decision to avoid silently changing behavior.
56
56
  */
57
57
  readonly maxTokens?: number;
58
+ /**
59
+ * Per-request bound. When omitted, defaults to the operator's
60
+ * STIGMER_LLM_REQUEST_TIMEOUT_MS — resolved HERE, not per caller, so no
61
+ * call site can drop the bound by forgetting to plumb it (the sub-agent
62
+ * factory did exactly that; stigmer/stigmer#468). An explicit value wins.
63
+ */
58
64
  readonly timeoutMs?: number;
59
65
  readonly maxRetries?: number;
60
66
  }
61
67
 
68
+ /**
69
+ * The operator's request-timeout bound. Only a positive integer means
70
+ * "bound the request" — unset, non-numeric, zero, and negative all
71
+ * normalize to no bound. Deployment-static env, read here the same way
72
+ * provider API keys are.
73
+ */
74
+ function resolveDefaultTimeoutMs(): number | undefined {
75
+ const parsed = Number.parseInt(process.env.STIGMER_LLM_REQUEST_TIMEOUT_MS ?? "", 10);
76
+ return parsed > 0 ? parsed : undefined;
77
+ }
78
+
62
79
  export interface BuiltChatModel {
63
80
  readonly model: BaseChatModel;
64
81
  readonly provider: LlmProvider;
@@ -82,6 +99,7 @@ export async function buildChatModel(opts: BuildChatModelOptions): Promise<Built
82
99
  const resolved = await resolveToApiModelId(opts.modelName);
83
100
  const provider = inferProvider(resolved);
84
101
  const apiModelId = stripProviderPrefix(resolved);
102
+ const timeoutMs = opts.timeoutMs ?? resolveDefaultTimeoutMs();
85
103
 
86
104
  // Backend precedence by construction: a proxied call never consults the
87
105
  // backend var — the proxy owns provider routing (the factories' preflight
@@ -201,7 +219,7 @@ export async function buildChatModel(opts: BuildChatModelOptions): Promise<Built
201
219
  temperature: opts.temperature ?? 0,
202
220
  apiKey,
203
221
  ...(maxTokens ? { maxTokens } : {}),
204
- ...(opts.timeoutMs ? { maxRetries: opts.maxRetries ?? 0 } : {}),
222
+ ...(timeoutMs ? { maxRetries: opts.maxRetries ?? 0 } : {}),
205
223
  };
206
224
 
207
225
  // The request timeout lives in a different slot per wrapper: ChatOpenAI
@@ -215,7 +233,7 @@ export async function buildChatModel(opts: BuildChatModelOptions): Promise<Built
215
233
  // that is LangChain's own retry knob, distinct from the SDK-level
216
234
  // maxRetries the factories receive.
217
235
  const anthropicClientOptions = {
218
- ...(opts.timeoutMs ? { timeout: opts.timeoutMs } : {}),
236
+ ...(timeoutMs ? { timeout: timeoutMs } : {}),
219
237
  ...(baseUrl ? { baseURL: baseUrl } : {}),
220
238
  ...(headers ? { defaultHeaders: headers } : {}),
221
239
  };
@@ -231,7 +249,7 @@ export async function buildChatModel(opts: BuildChatModelOptions): Promise<Built
231
249
  ? new ChatOpenAI({
232
250
  model: apiModelId,
233
251
  ...common,
234
- ...(opts.timeoutMs ? { timeout: opts.timeoutMs } : {}),
252
+ ...(timeoutMs ? { timeout: timeoutMs } : {}),
235
253
  ...(baseUrl || headers
236
254
  ? {
237
255
  configuration: {
@@ -30,9 +30,18 @@ interface RegistryEntry {
30
30
  };
31
31
  }
32
32
 
33
- import { resolveModelRegistryUrl, buildRegistryHeaders } from "./registry-endpoint.js";
33
+ import {
34
+ resolveModelRegistryUrl,
35
+ buildRegistryHeaders,
36
+ REGISTRY_RETRY_POLICY,
37
+ } from "./registry-endpoint.js";
38
+ import { fetchWithRetry } from "./http-retry.js";
34
39
 
35
40
  const CACHE_TTL_MS = 3_600_000;
41
+ // Failed fetches are cached much shorter than successes (the model-registry.ts
42
+ // policy): a transient failure must not pin DEFAULT_PRICING — wrong rates for
43
+ // cost tracking — for a full hour.
44
+ const FAILURE_CACHE_TTL_MS = 60_000;
36
45
 
37
46
  export const DEFAULT_PRICING: ModelPricing = {
38
47
  model: "unknown",
@@ -66,7 +75,11 @@ function parsePricingTable(json: unknown): ModelPricing[] {
66
75
  }
67
76
 
68
77
  async function fetchFromApi(): Promise<readonly ModelPricing[]> {
69
- const res = await fetch(resolveModelRegistryUrl(), { headers: buildRegistryHeaders() });
78
+ const res = await fetchWithRetry(
79
+ resolveModelRegistryUrl(),
80
+ { headers: buildRegistryHeaders() },
81
+ REGISTRY_RETRY_POLICY,
82
+ );
70
83
  if (!res.ok) throw new Error(`Model registry fetch failed: ${res.status}`);
71
84
  const data: unknown = await res.json();
72
85
  const table = parsePricingTable(data);
@@ -93,7 +106,7 @@ export async function getPricingTable(): Promise<readonly ModelPricing[]> {
93
106
  `Failed to fetch model registry, using default pricing: ${err}`,
94
107
  );
95
108
  const fallback = [DEFAULT_PRICING];
96
- cache = { data: fallback, expiresAt: Date.now() + CACHE_TTL_MS };
109
+ cache = { data: fallback, expiresAt: Date.now() + FAILURE_CACHE_TTL_MS };
97
110
  return fallback;
98
111
  })
99
112
  .finally(() => {
@@ -102,3 +115,9 @@ export async function getPricingTable(): Promise<readonly ModelPricing[]> {
102
115
 
103
116
  return inflightFetch;
104
117
  }
118
+
119
+ /** Exposed for testing — resets the in-memory cache. */
120
+ export function _resetPricingCache(): void {
121
+ cache = null;
122
+ inflightFetch = null;
123
+ }
@@ -10,7 +10,12 @@
10
10
  * (getModelVisionCapability).
11
11
  */
12
12
 
13
- import { resolveModelRegistryUrl, buildRegistryHeaders } from "./registry-endpoint.js";
13
+ import {
14
+ resolveModelRegistryUrl,
15
+ buildRegistryHeaders,
16
+ REGISTRY_RETRY_POLICY,
17
+ } from "./registry-endpoint.js";
18
+ import { fetchWithRetry } from "./http-retry.js";
14
19
 
15
20
  const CACHE_TTL_MS = 3_600_000;
16
21
  // Failed fetches are cached much shorter than successes: a transient failure
@@ -68,7 +73,7 @@ function parseVisionCapability(capabilities: unknown): boolean | undefined {
68
73
 
69
74
  async function fetchRegistry(): Promise<readonly RegistryModel[]> {
70
75
  const url = resolveModelRegistryUrl();
71
- const res = await fetch(url, { headers: buildRegistryHeaders() });
76
+ const res = await fetchWithRetry(url, { headers: buildRegistryHeaders() }, REGISTRY_RETRY_POLICY);
72
77
  if (!res.ok) throw new Error(`Model registry fetch failed: ${res.status}`);
73
78
  const data: unknown = await res.json();
74
79
  return parseRegistry(data);
@@ -16,6 +16,13 @@
16
16
  * (issue #255). Kept as its own side-effect-free module so tests can pin the
17
17
  * production rules without dragging in setup.ts's import graph.
18
18
  *
19
+ * Rules travel with a companion: every graph that carries them also installs
20
+ * the path-normalization middleware (middleware/path-normalization.ts,
21
+ * issue #429), because deepagents' rule validation refuses workspace-relative
22
+ * paths outright — without the shim, prompt-compliant relative READS die in
23
+ * validation instead of just working. Both are derived from the same
24
+ * expression at each composition site so they cannot drift apart.
25
+ *
19
26
  * Invariant: never combine these rules with a shell-capable (sandbox)
20
27
  * backend — deepagents rejects that pairing at graph construction (see the
21
28
  * cas-capture-backend.ts header). Plan mode guarantees it by construction:
@@ -20,10 +20,37 @@
20
20
  */
21
21
 
22
22
  import { normalizeEndpoint } from "../config.js";
23
+ import type { FetchRetryPolicy } from "./http-retry.js";
23
24
 
24
25
  /** Default local stigmer-server origin — mirrors config.ts's local-mode default. */
25
26
  const DEFAULT_LOCAL_BACKEND = "http://localhost:7234";
26
27
 
28
+ /**
29
+ * Shared retry policy for the three registry fetch clients (model-registry.ts
30
+ * and both model-pricing-data.ts modules) — stigmer/stigmer#468.
31
+ *
32
+ * The timeout is the load-bearing half: each consumer deduplicates callers
33
+ * through a single in-flight promise, so one hung fetch strands every
34
+ * concurrent caller behind it — model-registry.ts's sits in front of every
35
+ * LLM client build. 10 s (not the checkpointer's 30 s) because the response
36
+ * is a small JSON document and the callers degrade gracefully; what they must
37
+ * never do is wait forever.
38
+ *
39
+ * The retry half matters because the degrade is not free: a failed registry
40
+ * fetch is cached (60 s empty registry → unresolved model ids that 404 at the
41
+ * provider; pricing falls back to defaults), so a budget spanning a
42
+ * pod-restart reroute converts that poisoned window into ~1.75 s of backoff.
43
+ * Worst case fully bounded: ~31 s of cold-cache stall when the control plane
44
+ * is genuinely down, versus an infinite hang before #468.
45
+ */
46
+ export const REGISTRY_RETRY_POLICY: FetchRetryPolicy = {
47
+ label: "registry-endpoint",
48
+ baseDelayMs: 250,
49
+ backoffFactor: 2,
50
+ maxRetries: 3,
51
+ requestTimeoutMs: 10_000,
52
+ };
53
+
27
54
  /**
28
55
  * Resolve the base URL (origin, no path) for model-registry and pricing
29
56
  * fetches. See module doc for the tier order.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Env var names of the runner's own credentials — the single source of truth
3
+ * for every surface that isolates agent-spawned processes from the runner's
4
+ * process env (issue #385).
5
+ *
6
+ * Inclusion rule: a name belongs here iff the runner reads it from its own
7
+ * `process.env` to authenticate the runner's own outbound calls. User-supplied
8
+ * credentials resolved from ExecutionContext (e.g. GITHUB_TOKEN, read only
9
+ * from mergedEnvVars) must NEVER be listed — the ExecutionContext overlay is
10
+ * their sanctioned delivery channel, and denying them here would break it.
11
+ *
12
+ * Consumers:
13
+ * - shell-env.ts: SHELL_ENV_DENYLIST for the native harness `execute` tool.
14
+ * - mcp-manager.test.ts: leak-tripwire canaries for MCP stdio subprocesses
15
+ * (that path passes NO runner env by construction; the test plants these
16
+ * names to prove none leak through).
17
+ *
18
+ * Ambient cloud-SDK chain vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
19
+ * GOOGLE_APPLICATION_CREDENTIALS, ...) are deliberately absent: they are
20
+ * dual-use on local runners (operators expect agent shells to keep their
21
+ * ambient aws/gcloud auth), and on a local backend the shell can read the
22
+ * credential files off disk regardless (owner ruling on #385).
23
+ */
24
+ export const RUNNER_CREDENTIAL_ENV_KEYS: readonly string[] = [
25
+ // Derives HITL approval fingerprints (fingerprint-secret.ts) — an agent
26
+ // that reads this could forge approval receipts.
27
+ "STIGMER_RUNNER_HITL_SECRET",
28
+ // Stigmer control-plane auth (config.ts; rotated at runtime by
29
+ // runner-manager.ts). Executions receive theirs via ExecutionContext.
30
+ "STIGMER_TOKEN",
31
+ // Fallback bearer token for model-registry/pricing fetches when
32
+ // STIGMER_TOKEN is unset (registry-endpoint.ts).
33
+ "STIGMER_AUTH_TOKEN",
34
+ // Cursor harness credential (config.ts) — agent-spawned processes never
35
+ // need direct Cursor API access.
36
+ "CURSOR_API_KEY",
37
+ // Direct-mode Anthropic key for the native harness (model-client.ts).
38
+ "ANTHROPIC_API_KEY",
39
+ // Direct-mode OpenAI key for the native harness (model-client.ts).
40
+ "OPENAI_API_KEY",
41
+ // Azure AI Foundry backend key (model-client.ts).
42
+ "ANTHROPIC_FOUNDRY_API_KEY",
43
+ // Bedrock backend bearer credential, read by the AWS SDK's chain
44
+ // (llm-backend.ts documents it as a supported auth path).
45
+ "AWS_BEARER_TOKEN_BEDROCK",
46
+ ];