pi-harness-runtime 1.1.440 → 1.1.441

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 (349) hide show
  1. package/harness/e2e/auto-test-loop.ts +2 -0
  2. package/harness/e2e/browser-scrapers/base-browser-scraper.ts +2 -0
  3. package/harness/e2e/browser-scrapers/chrome-profile-manager.ts +2 -0
  4. package/harness/e2e/browser-scrapers/codex-browser-scraper.ts +2 -0
  5. package/harness/e2e/tools-detector.ts +2 -0
  6. package/harness/key-loader.ts +2 -0
  7. package/harness/langchain/checkpointer.ts +2 -0
  8. package/harness/langchain/cron-cli.ts +2 -0
  9. package/harness/langchain/graph.ts +2 -0
  10. package/harness/notification-center.ts +2 -0
  11. package/harness/secret-provider.ts +2 -0
  12. package/index.ts +2 -0
  13. package/package.json +7 -1
  14. package/packages/a2a-adapter/package.json +1 -1
  15. package/packages/agent-policy/dist/extension.d.ts.map +1 -1
  16. package/packages/agent-policy/dist/extension.js +2 -0
  17. package/packages/agent-policy/dist/extension.js.map +1 -1
  18. package/packages/agent-policy/package.json +1 -1
  19. package/packages/agent-policy/src/extension.ts +2 -0
  20. package/packages/architecture-generator/package.json +1 -1
  21. package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
  22. package/packages/auth/dist/minimax-browser-auth.js +23 -1
  23. package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
  24. package/packages/auth/package.json +1 -1
  25. package/packages/auth/src/minimax-browser-auth.ts +30 -5
  26. package/packages/autonomous-refactor/package.json +1 -1
  27. package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
  28. package/packages/autonomous-runtime/dist/inbox.js +2 -0
  29. package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
  30. package/packages/autonomous-runtime/package.json +1 -1
  31. package/packages/autonomous-runtime/src/inbox.ts +2 -0
  32. package/packages/cache-strategy/package.json +1 -1
  33. package/packages/capability-registry/package.json +1 -1
  34. package/packages/checkpoint/package.json +1 -1
  35. package/packages/cli-plugin-sdk/package.json +1 -1
  36. package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
  37. package/packages/clipboard/dist/src/clipboard.js +2 -0
  38. package/packages/clipboard/dist/src/clipboard.js.map +1 -1
  39. package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
  40. package/packages/clipboard/dist/src/copy-sync.js +2 -0
  41. package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
  42. package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
  43. package/packages/clipboard/dist/src/gist-relay.js +2 -0
  44. package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
  45. package/packages/clipboard/package.json +1 -1
  46. package/packages/clipboard/src/clipboard.ts +2 -0
  47. package/packages/clipboard/src/copy-sync.ts +2 -0
  48. package/packages/clipboard/src/gist-relay.ts +2 -0
  49. package/packages/clipboard-plugin/package.json +1 -1
  50. package/packages/code-generation/package.json +1 -1
  51. package/packages/code-review/package.json +1 -1
  52. package/packages/codex-adapter/package.json +1 -1
  53. package/packages/codex-watcher/package.json +1 -1
  54. package/packages/config-capture/package.json +1 -1
  55. package/packages/connection-runtime/package.json +1 -1
  56. package/packages/context-compiler/package.json +1 -1
  57. package/packages/context-discovery/package.json +1 -1
  58. package/packages/context-manager/package.json +1 -1
  59. package/packages/contracts/dist/delegation-store.js +1 -4
  60. package/packages/contracts/dist/workspace-env.js +28 -1
  61. package/packages/contracts/package.json +1 -1
  62. package/packages/contracts/src/delegation-store.ts +9 -4
  63. package/packages/contracts/src/workspace-env.ts +29 -4
  64. package/packages/cookie-sanitizer/package.json +1 -1
  65. package/packages/cost-optimizer/package.json +1 -1
  66. package/packages/dependency-analyzer/package.json +1 -1
  67. package/packages/django-plugin/package.json +1 -1
  68. package/packages/doc-generator/package.json +1 -1
  69. package/packages/durable-review/package.json +1 -1
  70. package/packages/e2e-tester/package.json +1 -1
  71. package/packages/evaluation-engine/package.json +1 -1
  72. package/packages/evaluation-runner/package.json +1 -1
  73. package/packages/event-bus/package.json +1 -1
  74. package/packages/event-sink/package.json +1 -1
  75. package/packages/event-store/dist/src/store.d.ts.map +1 -1
  76. package/packages/event-store/dist/src/store.js +2 -0
  77. package/packages/event-store/dist/src/store.js.map +1 -1
  78. package/packages/event-store/package.json +1 -1
  79. package/packages/event-store/src/store.ts +3 -0
  80. package/packages/experience-replay/package.json +1 -1
  81. package/packages/feedback-collector/package.json +1 -1
  82. package/packages/file-copy-helper/package.json +1 -1
  83. package/packages/framework-detector/package.json +1 -1
  84. package/packages/framework-plugin-sdk/package.json +1 -1
  85. package/packages/frappe-plugin/package.json +1 -1
  86. package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
  87. package/packages/generic-web-plugin/dist/analyzer.js +2 -0
  88. package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
  89. package/packages/generic-web-plugin/package.json +1 -1
  90. package/packages/generic-web-plugin/src/analyzer.ts +3 -0
  91. package/packages/health-monitor/package.json +1 -1
  92. package/packages/intent-analyzer/package.json +1 -1
  93. package/packages/jev-judge/package.json +1 -1
  94. package/packages/knowledge-graph/package.json +1 -1
  95. package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
  96. package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
  97. package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
  98. package/packages/knowledge-retrieval/package.json +1 -4
  99. package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
  100. package/packages/laravel-plugin/package.json +1 -1
  101. package/packages/learning-engine/package.json +1 -1
  102. package/packages/logging/package.json +1 -1
  103. package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
  104. package/packages/mcp-adapter/dist/server.js +2 -0
  105. package/packages/mcp-adapter/dist/server.js.map +1 -1
  106. package/packages/mcp-adapter/package.json +1 -1
  107. package/packages/mcp-adapter/src/server.ts +3 -0
  108. package/packages/memory-engine/package.json +1 -1
  109. package/packages/milestone-manager/package.json +1 -1
  110. package/packages/model-registry/package.json +1 -1
  111. package/packages/nextjs-plugin/package.json +1 -1
  112. package/packages/notification/package.json +1 -1
  113. package/packages/observability/package.json +1 -1
  114. package/packages/okf-indexer/package.json +1 -1
  115. package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
  116. package/packages/paperclip-integration/dist/index.js +2 -0
  117. package/packages/paperclip-integration/dist/index.js.map +1 -1
  118. package/packages/paperclip-integration/package.json +1 -1
  119. package/packages/paperclip-integration/src/index.ts +2 -0
  120. package/packages/performance-optimizer/package.json +1 -1
  121. package/packages/permission-mode/package.json +1 -1
  122. package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
  123. package/packages/privilege-broker/dist/audit.js +2 -0
  124. package/packages/privilege-broker/dist/audit.js.map +1 -1
  125. package/packages/privilege-broker/package.json +1 -1
  126. package/packages/privilege-broker/src/audit.ts +2 -0
  127. package/packages/project-analyzer/package.json +1 -1
  128. package/packages/project-bootstrap/package.json +1 -1
  129. package/packages/projection-engine/package.json +1 -1
  130. package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
  131. package/packages/prompt-compiler/dist/compiler.js +2 -0
  132. package/packages/prompt-compiler/dist/compiler.js.map +1 -1
  133. package/packages/prompt-compiler/package.json +1 -1
  134. package/packages/prompt-compiler/src/compiler.ts +2 -0
  135. package/packages/prompt-versioning/package.json +1 -1
  136. package/packages/provider-adapter-sdk/package.json +1 -1
  137. package/packages/provider-router/package.json +1 -1
  138. package/packages/provider-selector/package.json +1 -1
  139. package/packages/providers/package.json +1 -1
  140. package/packages/qdrant-skills/package.json +1 -1
  141. package/packages/quota-manager/package.json +1 -1
  142. package/packages/rate-limiter/package.json +1 -1
  143. package/packages/react-vite-plugin/package.json +1 -1
  144. package/packages/relay/package.json +1 -1
  145. package/packages/release-manager/package.json +1 -1
  146. package/packages/requirement-compiler/package.json +1 -1
  147. package/packages/runtime/package.json +1 -1
  148. package/packages/scheduler/package.json +1 -1
  149. package/packages/scheduler-adapter/package.json +1 -1
  150. package/packages/session/package.json +1 -1
  151. package/packages/session-api/package.json +1 -1
  152. package/packages/session-export/package.json +1 -1
  153. package/packages/shared-context/package.json +1 -1
  154. package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
  155. package/packages/skill-mcp-client/dist/client.js +0 -1
  156. package/packages/skill-mcp-client/dist/client.js.map +1 -1
  157. package/packages/skill-mcp-client/package.json +1 -4
  158. package/packages/skill-mcp-client/src/client.ts +0 -1
  159. package/packages/skill-registry/package.json +1 -1
  160. package/packages/skills/dist/parser.d.ts.map +1 -1
  161. package/packages/skills/dist/parser.js +2 -0
  162. package/packages/skills/dist/parser.js.map +1 -1
  163. package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
  164. package/packages/skills/dist/skill-versioning.js +2 -0
  165. package/packages/skills/dist/skill-versioning.js.map +1 -1
  166. package/packages/skills/package.json +1 -1
  167. package/packages/skills/src/parser.ts +3 -0
  168. package/packages/skills/src/skill-versioning.ts +2 -0
  169. package/packages/sprint-planner/package.json +1 -1
  170. package/packages/subscription-engine/package.json +1 -1
  171. package/packages/task-compiler/package.json +1 -1
  172. package/packages/tencentdb-memory/package.json +1 -1
  173. package/packages/tencentdb-sync/package.json +1 -1
  174. package/packages/test-data-generator/package.json +1 -1
  175. package/packages/test-generator/package.json +1 -1
  176. package/packages/todo-bd-sync/package.json +1 -1
  177. package/packages/token-estimation/package.json +1 -1
  178. package/packages/token-optimizer/package.json +1 -1
  179. package/packages/tooling-preference/package.json +1 -1
  180. package/packages/trajectory/package.json +1 -1
  181. package/packages/tui/package.json +1 -1
  182. package/packages/two-phase-review/package.json +1 -1
  183. package/packages/types/package.json +1 -1
  184. package/packages/voice-api/package.json +1 -1
  185. package/packages/webmcp-tester/dist/index.js +0 -2
  186. package/packages/webmcp-tester/package.json +1 -1
  187. package/packages/webmcp-tester/src/index.ts +0 -3
  188. package/packages/wiki/package.json +1 -1
  189. package/packages/workflow-events/package.json +1 -1
  190. package/packages/workspace-scanner/package.json +1 -1
  191. package/packages/worktree/package.json +1 -1
  192. package/packages/write-review/dist/trigger.d.ts.map +1 -1
  193. package/packages/write-review/dist/trigger.js +1 -2
  194. package/packages/write-review/dist/trigger.js.map +1 -1
  195. package/packages/write-review/package.json +1 -1
  196. package/packages/write-review/src/trigger.ts +1 -2
  197. package/scripts/lib/runtime-imports.ts +189 -3
  198. package/scripts/telegram-webhook-server.ts +2 -0
  199. package/scripts/verify-package-contents.ts +148 -1
  200. package/harness/e2e/tools-detector.test.ts +0 -155
  201. package/harness/glm-quota-countdown.test.ts +0 -323
  202. package/harness/langchain/agents.test.ts +0 -39
  203. package/harness/langchain/checkpointer.test.ts +0 -243
  204. package/harness/langchain/daemon.test.ts +0 -459
  205. package/harness/langchain/model-router.test.ts +0 -191
  206. package/harness/langchain/ping-pong-middleware.test.ts +0 -69
  207. package/harness/langchain/scoreboard.test.ts +0 -267
  208. package/harness/langchain/status-line.test.ts +0 -106
  209. package/harness/langchain/surge.test.ts +0 -467
  210. package/harness/langchain/widget.test.ts +0 -251
  211. package/harness/skill-sync.test.ts +0 -57
  212. package/harness/ssh-detach-interceptor.test.ts +0 -263
  213. package/harness/ssh-hang-recovery.test.ts +0 -86
  214. package/packages/a2a-adapter/test/a2a.test.ts +0 -151
  215. package/packages/agent-policy/test/interlock.test.ts +0 -101
  216. package/packages/agent-policy/test/policy-retention.test.ts +0 -380
  217. package/packages/agent-policy/test/policy.test.ts +0 -387
  218. package/packages/auth/test/auth.test.ts +0 -238
  219. package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
  220. package/packages/autonomous-runtime/test/types.test.ts +0 -95
  221. package/packages/cache-strategy/test/cache.test.ts +0 -137
  222. package/packages/capability-registry/test/registry.test.ts +0 -204
  223. package/packages/checkpoint/test/engine.test.ts +0 -265
  224. package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
  225. package/packages/code-generation/test/generator.test.ts +0 -238
  226. package/packages/code-review/test/engine.test.ts +0 -302
  227. package/packages/codex-adapter/test/provider.test.ts +0 -142
  228. package/packages/codex-watcher/test/watch.test.ts +0 -453
  229. package/packages/context-compiler/test/context-compiler.test.ts +0 -746
  230. package/packages/context-manager/test/context.test.ts +0 -198
  231. package/packages/contracts/test/delegation.test.ts +0 -350
  232. package/packages/contracts/test/workspace-env.test.ts +0 -802
  233. package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
  234. package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
  235. package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
  236. package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
  237. package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
  238. package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
  239. package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
  240. package/packages/django-plugin/test/analyzer.test.ts +0 -195
  241. package/packages/doc-generator/test/docs.test.ts +0 -168
  242. package/packages/durable-review/test/acceptance.test.ts +0 -357
  243. package/packages/durable-review/test/smoke.test.ts +0 -107
  244. package/packages/evaluation-engine/test/engine.test.ts +0 -277
  245. package/packages/evaluation-runner/test/runner.test.ts +0 -168
  246. package/packages/event-bus/test/bus.test.ts +0 -100
  247. package/packages/event-store/test/store.test.ts +0 -115
  248. package/packages/experience-replay/test/replay.test.ts +0 -267
  249. package/packages/feedback-collector/test/collector.test.ts +0 -142
  250. package/packages/framework-detector/test/detector.test.ts +0 -75
  251. package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
  252. package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
  253. package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
  254. package/packages/health-monitor/test/health.test.ts +0 -231
  255. package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
  256. package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
  257. package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
  258. package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
  259. package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
  260. package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
  261. package/packages/jev-judge/tests/question-risk.test.ts +0 -129
  262. package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
  263. package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
  264. package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
  265. package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
  266. package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
  267. package/packages/learning-engine/test/engine.test.ts +0 -331
  268. package/packages/logging/test/buffer.test.ts +0 -44
  269. package/packages/logging/test/classification.test.ts +0 -137
  270. package/packages/logging/test/config.test.ts +0 -97
  271. package/packages/logging/test/fanout.test.ts +0 -186
  272. package/packages/logging/test/identity-transport.test.ts +0 -197
  273. package/packages/logging/test/incidents.test.ts +0 -404
  274. package/packages/logging/test/ingest-schema.test.ts +0 -184
  275. package/packages/logging/test/integration.test.ts +0 -140
  276. package/packages/logging/test/log-http.test.ts +0 -246
  277. package/packages/logging/test/redact.test.ts +0 -109
  278. package/packages/logging/test/sampler.test.ts +0 -57
  279. package/packages/logging/test/server.test.ts +0 -444
  280. package/packages/logging/test/shipper.test.ts +0 -152
  281. package/packages/logging/test/spool.test.ts +0 -96
  282. package/packages/mcp-adapter/test/server.test.ts +0 -91
  283. package/packages/memory-engine/test/engine.test.ts +0 -456
  284. package/packages/model-registry/test/registry.test.ts +0 -342
  285. package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
  286. package/packages/notification/test/approval-payload.test.ts +0 -269
  287. package/packages/notification/test/detail-format.test.ts +0 -106
  288. package/packages/notification/test/notification.test.ts +0 -375
  289. package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
  290. package/packages/notification/test/pending-question.test.ts +0 -331
  291. package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
  292. package/packages/observability/test/observability.test.ts +0 -1350
  293. package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
  294. package/packages/project-analyzer/test/index.test.ts +0 -1719
  295. package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
  296. package/packages/prompt-versioning/test/versioning.test.ts +0 -112
  297. package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
  298. package/packages/provider-router/test/provider-router.test.ts +0 -405
  299. package/packages/provider-selector/test/selector.test.ts +0 -192
  300. package/packages/providers/test/providers.test.ts +0 -225
  301. package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
  302. package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
  303. package/packages/qdrant-skills/test/embedder.test.ts +0 -97
  304. package/packages/quota-manager/test/quota.test.ts +0 -432
  305. package/packages/rate-limiter/test/limiter.test.ts +0 -128
  306. package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
  307. package/packages/relay/test/client.test.ts +0 -446
  308. package/packages/relay/test/relay-e2e.test.ts +0 -299
  309. package/packages/relay/test/relay-endpoint.test.ts +0 -278
  310. package/packages/release-manager/test/release.test.ts +0 -215
  311. package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
  312. package/packages/runtime/test/runtime-api.test.ts +0 -169
  313. package/packages/runtime/test/runtime.test.ts +0 -297
  314. package/packages/scheduler/test/scheduler.test.ts +0 -125
  315. package/packages/session/test/manager.test.ts +0 -233
  316. package/packages/shared-context/test/shared-context.test.ts +0 -114
  317. package/packages/skill-registry/test/registry.test.ts +0 -508
  318. package/packages/skills/test/init-skills.test.ts +0 -114
  319. package/packages/skills/test/remote-skills.test.ts +0 -360
  320. package/packages/skills/test/remote-source.test.ts +0 -248
  321. package/packages/skills/test/sanitize.test.ts +0 -250
  322. package/packages/skills/test/vector-indexing.test.ts +0 -205
  323. package/packages/skills/test/vector-schema.test.ts +0 -180
  324. package/packages/skills/test/vector-threshold.test.ts +0 -108
  325. package/packages/sprint-planner/test/planner.test.ts +0 -187
  326. package/packages/task-compiler/test/task-compiler.test.ts +0 -628
  327. package/packages/test-data-generator/test/generator.test.ts +0 -265
  328. package/packages/test-generator/test/generator.test.ts +0 -156
  329. package/packages/token-estimation/test/token-estimation.test.ts +0 -207
  330. package/packages/token-optimizer/test/optimizer.test.ts +0 -141
  331. package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
  332. package/packages/tooling-preference/tests/detect.test.ts +0 -188
  333. package/packages/tooling-preference/tests/proposal.test.ts +0 -107
  334. package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
  335. package/packages/tooling-preference/tests/registry.test.ts +0 -51
  336. package/packages/tooling-preference/tests/store.test.ts +0 -99
  337. package/packages/trajectory/test/store.test.ts +0 -250
  338. package/packages/tui/test/harness-footer.test.ts +0 -559
  339. package/packages/tui/test/harness-header.test.ts +0 -590
  340. package/packages/two-phase-review/test/classify.test.ts +0 -102
  341. package/packages/two-phase-review/test/helpers.ts +0 -72
  342. package/packages/two-phase-review/test/rules.test.ts +0 -150
  343. package/packages/two-phase-review/test/runtime.test.ts +0 -362
  344. package/packages/two-phase-review/test/scope.test.ts +0 -186
  345. package/packages/two-phase-review/test/signals.test.ts +0 -183
  346. package/packages/two-phase-review/test/state.test.ts +0 -201
  347. package/packages/wiki/test/basic.test.ts +0 -242
  348. package/packages/workspace-scanner/test/scanner.test.ts +0 -43
  349. package/packages/worktree/test/worktree.test.ts +0 -163
@@ -1,467 +0,0 @@
1
- /**
2
- * Surge auto-resume tests — S2/S4 acceptance (wiki/peak-hour-surge-auto-resume.md)
3
- *
4
- * All deterministic via injected sleep/rand — no real timers, no API keys.
5
- *
6
- * Run:
7
- * bun test harness/langchain/surge.test.ts
8
- */
9
-
10
- import { describe, it } from "node:test";
11
- import assert from "node:assert";
12
-
13
- import {
14
- classifySurge,
15
- computeSurgeDelayMs,
16
- invokeWithSurgeRetry,
17
- SurgeScheduler,
18
- type SurgePolicy,
19
- } from "./surge.js";
20
- import type { LoopDeps } from "./graph.js";
21
-
22
- // ─── Fixtures ────────────────────────────────────────────────────────────────
23
-
24
- /** The exact incident message from the amos-saas E2E failure (2026-08-31). */
25
- const INCIDENT =
26
- '529 {"type":"error","error":{"type":"overloaded_error","message":"The system is currently experiencing a peak-hour surge, and the server is temporarily busy. It usually recovers within 1–5 minutes. Please try again shortly (2064)"},"request_id":"06e405e2e5965672576925264941a057"}';
27
-
28
- const SIGNAL_3MIN = {
29
- retryAfterMs: 180_000,
30
- explicit: true,
31
- sourceText: INCIDENT,
32
- };
33
-
34
- const FAST_POLICY: Partial<SurgePolicy> = {
35
- baseDelayMs: 100,
36
- multiplier: 2,
37
- minDelayMs: 10,
38
- maxDelayMs: 1_000,
39
- jitterRatio: 0,
40
- maxAttempts: 3,
41
- };
42
-
43
- // ─── T1 Classification ───────────────────────────────────────────────────────
44
-
45
- describe("T1 — classifySurge", () => {
46
- it("classifies the incident message (midpoint of 1–5 min = 3 min)", () => {
47
- const sig = classifySurge(new Error(INCIDENT));
48
- assert.ok(sig, "should classify");
49
- assert.equal(sig?.retryAfterMs, 180_000);
50
- assert.equal(sig?.explicit, true);
51
- });
52
-
53
- it("classifies plain 529 status", () => {
54
- const sig = classifySurge(new Error("HTTP 529"));
55
- assert.ok(sig);
56
- assert.equal(sig?.explicit, false); // no stated delay → 2 min default
57
- assert.equal(sig?.retryAfterMs, 120_000);
58
- });
59
-
60
- it("parses 'retry after 30 seconds'", () => {
61
- const sig = classifySurge(
62
- new Error("overloaded — please retry after 30 seconds"),
63
- );
64
- assert.ok(sig);
65
- assert.equal(sig?.retryAfterMs, 30_000);
66
- });
67
-
68
- it("parses retry-after milliseconds", () => {
69
- const sig = classifySurge(new Error("529; retry-after: 45000ms"));
70
- assert.ok(sig);
71
- assert.equal(sig?.retryAfterMs, 45_000);
72
- });
73
-
74
- it("rejects non-surge errors", () => {
75
- assert.equal(classifySurge(new Error("429 too many requests")), null);
76
- assert.equal(classifySurge(new Error("ECONNREFUSED")), null);
77
- assert.equal(classifySurge("file not found"), null);
78
- });
79
-
80
- it("classifies 'Request timed out.'", () => {
81
- const sig = classifySurge(new Error("Request timed out."));
82
- assert.ok(sig, "should classify timeout");
83
- assert.equal(sig?.explicit, false); // no stated delay → 2 min default
84
- assert.equal(sig?.retryAfterMs, 120_000);
85
- });
86
-
87
- it("classifies 'timed out' without 'request' prefix", () => {
88
- const sig = classifySurge(new Error("timed out"));
89
- assert.ok(sig, "should classify");
90
- assert.equal(sig?.retryAfterMs, 120_000);
91
- });
92
-
93
- it("parses 'timed out after Xms'", () => {
94
- const sig = classifySurge(new Error("timed out after 30000ms"));
95
- assert.ok(sig);
96
- assert.equal(sig?.retryAfterMs, 30_000);
97
- assert.equal(sig?.explicit, true);
98
- });
99
-
100
- it("parses 'Request timed out after X seconds'", () => {
101
- const sig = classifySurge(new Error("Request timed out after 60 seconds"));
102
- assert.ok(sig);
103
- assert.equal(sig?.retryAfterMs, 60_000);
104
- assert.equal(sig?.explicit, true);
105
- });
106
-
107
- it("parses 'timed out after Xms' (milliseconds keyword)", () => {
108
- const sig = classifySurge(new Error("command timed out after 15000 milliseconds"));
109
- assert.ok(sig);
110
- assert.equal(sig?.retryAfterMs, 15_000);
111
- assert.equal(sig?.explicit, true);
112
- });
113
-
114
- it("'Retry failed after 3 attempts: Request timed out.'", () => {
115
- const sig = classifySurge(
116
- new Error("Retry failed after 3 attempts: Request timed out."),
117
- );
118
- assert.ok(sig, "should classify inner timeout");
119
- assert.equal(sig?.retryAfterMs, 120_000);
120
- });
121
- });
122
-
123
- // ─── T2/T3 Delay computation & escalation ────────────────────────────────────
124
-
125
- describe("T2 — computeSurgeDelayMs escalation", () => {
126
- it("escalates 3 → 6 → 12 min and caps at max", () => {
127
- const p = { jitterRatio: 0 } as const; // deterministic
128
- assert.equal(computeSurgeDelayMs(SIGNAL_3MIN, 1, p), 180_000);
129
- assert.equal(computeSurgeDelayMs(SIGNAL_3MIN, 2, p), 360_000);
130
- assert.equal(computeSurgeDelayMs(SIGNAL_3MIN, 3, p), 720_000);
131
- assert.equal(computeSurgeDelayMs(SIGNAL_3MIN, 9, p), 900_000); // 15 min cap
132
- });
133
-
134
- it("floors at minDelayMs (never hammer)", () => {
135
- const d = computeSurgeDelayMs({ ...SIGNAL_3MIN, retryAfterMs: 1_000 }, 1, {
136
- minDelayMs: 30_000,
137
- jitterRatio: 0,
138
- });
139
- assert.equal(d, 30_000);
140
- });
141
-
142
- it("jitter stays inside ±ratio and within bounds", () => {
143
- const lo = computeSurgeDelayMs(SIGNAL_3MIN, 1, { jitterRatio: 0.2 }, 0);
144
- const hi = computeSurgeDelayMs(SIGNAL_3MIN, 1, { jitterRatio: 0.2 }, 1);
145
- assert.ok(lo >= 180_000 * 0.8 && lo < 180_000);
146
- assert.ok(hi > 180_000 && hi <= 180_000 * 1.2);
147
- });
148
- });
149
-
150
- describe("T3 — SurgeScheduler attempt cap", () => {
151
- it("counts 1..maxAttempts then null", () => {
152
- const s = new SurgeScheduler({ maxAttempts: 3 });
153
- assert.equal(s.nextAttempt(), 1);
154
- assert.equal(s.nextAttempt(), 2);
155
- assert.equal(s.nextAttempt(), 3);
156
- assert.equal(s.nextAttempt(), null);
157
- assert.equal(s.attempts, 3);
158
- });
159
- });
160
-
161
- // ─── T-surge-retry Wrapper behavior ─────────────────────────────────────────
162
-
163
- describe("invokeWithSurgeRetry", () => {
164
- it("retries through a 529 and succeeds (the incident scenario)", async () => {
165
- const sleeps: number[] = [];
166
- let calls = 0;
167
- const result = await invokeWithSurgeRetry(
168
- async () => {
169
- calls += 1;
170
- if (calls < 3) throw new Error(INCIDENT);
171
- return "approved";
172
- },
173
- { policy: FAST_POLICY, sleep: async (ms) => void sleeps.push(ms) },
174
- );
175
- assert.equal(result, "approved");
176
- assert.equal(calls, 3);
177
- assert.deepEqual(sleeps, [100, 200]); // escalated, no jitter
178
- });
179
-
180
- it("rethrows non-surge errors immediately (no retry)", async () => {
181
- const sleeps: number[] = [];
182
- let calls = 0;
183
- await assert.rejects(
184
- invokeWithSurgeRetry(
185
- async () => {
186
- calls += 1;
187
- throw new Error("ECONNREFUSED");
188
- },
189
- { policy: FAST_POLICY, sleep: async (ms) => void sleeps.push(ms) },
190
- ),
191
- /ECONNREFUSED/,
192
- );
193
- assert.equal(calls, 1);
194
- assert.equal(sleeps.length, 0);
195
- });
196
-
197
- it("gives up after maxAttempts, fires onExhausted, rethrows last error", async () => {
198
- const pauses: number[] = [];
199
- let exhausted = false;
200
- let calls = 0;
201
- await assert.rejects(
202
- invokeWithSurgeRetry(
203
- async () => {
204
- calls += 1;
205
- throw new Error(INCIDENT);
206
- },
207
- {
208
- policy: FAST_POLICY,
209
- sleep: async (ms) => void pauses.push(ms),
210
- onSurge: ({ attempt }) => assert.ok(attempt >= 1 && attempt <= 3),
211
- onExhausted: () => {
212
- exhausted = true;
213
- },
214
- },
215
- ),
216
- /overloaded_error/,
217
- );
218
- assert.equal(calls, 4); // initial + 3 retries
219
- assert.deepEqual(pauses, [100, 200, 400]);
220
- assert.equal(exhausted, true);
221
- });
222
- });
223
-
224
- // ─── T8 Daemon-level: graph deps that surge once, then succeed ───────────────
225
-
226
- describe("T8 — loop deps surviving a mid-graph 529", () => {
227
- it("writeStep throws the incident once; retry wrapper completes the loop", async () => {
228
- const { buildWriteReviewLoop, buildDryRunDeps } = await import("./graph.js");
229
-
230
- const base = buildDryRunDeps({ maxIterations: 1 });
231
- let writeCalls = 0;
232
- const deps: LoopDeps = {
233
- ...base,
234
- write: async (plan, review) => {
235
- writeCalls += 1;
236
- if (writeCalls === 1) throw new Error(INCIDENT);
237
- return base.write(plan, review);
238
- },
239
- };
240
-
241
- const loop = buildWriteReviewLoop(deps);
242
- const sleeps: number[] = [];
243
- const state = await invokeWithSurgeRetry(
244
- () =>
245
- loop.invoke(
246
- { request: "surge survival test" },
247
- { configurable: { thread_id: "t8-surge" } },
248
- ),
249
- { policy: FAST_POLICY, sleep: async (ms) => void sleeps.push(ms) },
250
- );
251
-
252
- assert.equal(writeCalls, 2); // first surged, retry succeeded
253
- assert.ok(state.review, "loop produced a review");
254
- assert.deepEqual(sleeps, [100]);
255
- });
256
- });
257
-
258
- // ─── GLM Quota Tests ─────────────────────────────────────────────────────────
259
-
260
- import { classifyGLMQuota, invokeWithGLMRetry } from "./surge.js";
261
-
262
- describe("classifyGLMQuota", () => {
263
- // The reset timestamps are computed RELATIVE to now. A hardcoded date
264
- // is a time bomb: it was "in the past by < 1 day" when this test was
265
- // written and is now far in the past, which makes the +1 day shift
266
- // land in the past as well.
267
- const stamp = (date: Date): string => date.toISOString().slice(0, 19);
268
- const inDays = (days: number): Date =>
269
- new Date(Date.now() + days * 24 * 60 * 60 * 1000);
270
-
271
- it("parses GLM 1308 error with reset timestamp", () => {
272
- const reset = inDays(2);
273
- const err = new Error(
274
- `429: {"code":"1308","message":"Usage limit reached for 5 hour. Your limit will reset at ${stamp(reset)}"}`,
275
- );
276
- const sig = classifyGLMQuota(err);
277
- assert.ok(sig, "should be classified as GLM quota");
278
- // A reset time in the future is used verbatim.
279
- assert.ok(sig!.resetAtEpoch > Date.now(), "resetAtEpoch is in the future");
280
- assert.ok(
281
- sig!.resetAt.includes(stamp(reset).slice(0, 10)),
282
- "date preserved verbatim",
283
- );
284
- assert.ok(
285
- sig!.resetAt.includes(stamp(reset).slice(11)),
286
- "time preserved verbatim",
287
- );
288
- });
289
-
290
- it("parses 1308 from plain string error", () => {
291
- // A reset time in the past is shifted to the NEXT occurrence (+1 day).
292
- const reset = inDays(-0.5);
293
- const err = `{"code":"1308","message":"Usage limit reached. Your limit will reset at ${stamp(reset)}"}`;
294
- const sig = classifyGLMQuota(err);
295
- assert.ok(sig, "should be classified as GLM quota");
296
- const shifted = stamp(new Date(reset.getTime() + 24 * 60 * 60 * 1000));
297
- assert.ok(
298
- sig!.resetAt.includes(shifted.slice(0, 10)),
299
- "space normalised and date shifted to the next occurrence",
300
- );
301
- assert.ok(sig!.resetAtEpoch > Date.now(), "shifted epoch is in the future");
302
- });
303
-
304
- it("parses reset time with T separator", () => {
305
- const reset = inDays(2);
306
- const err = new Error(
307
- `{"code":"1308","message":"Usage limit reached. Your limit will reset at ${stamp(reset)}"}`,
308
- );
309
- const sig = classifyGLMQuota(err);
310
- assert.ok(sig, "should be classified as GLM quota");
311
- assert.ok(
312
- sig!.resetAt.includes(stamp(reset).slice(0, 10)),
313
- "date preserved verbatim",
314
- );
315
- assert.ok(sig!.resetAt.includes("T"), "T separator preserved verbatim");
316
- assert.ok(
317
- sig!.resetAt.includes(stamp(reset).slice(11)),
318
- "time preserved verbatim",
319
- );
320
- });
321
-
322
- it("returns null for non-GLM errors", () => {
323
- const err = new Error("529: overloaded error");
324
- assert.equal(classifyGLMQuota(err), null);
325
- });
326
-
327
- it("returns null for plain errors without 1308", () => {
328
- const err = new Error("Something went wrong");
329
- assert.equal(classifyGLMQuota(err), null);
330
- });
331
-
332
- it("1308 without reset time uses 5-min fallback", () => {
333
- const err = new Error('{"code":"1308","message":"Usage limit reached"}');
334
- const sig = classifyGLMQuota(err);
335
- assert.ok(sig, "should be classified");
336
- const diffMs = sig!.resetAtEpoch - Date.now();
337
- // Should be approximately 5 minutes
338
- assert.ok(diffMs >= 4 * 60_000 && diffMs <= 6 * 60_000, "5-min fallback");
339
- });
340
- });
341
-
342
- describe("invokeWithGLMRetry", () => {
343
- it("succeeds immediately when fn succeeds", async () => {
344
- const result = await invokeWithGLMRetry(() => Promise.resolve("ok"));
345
- assert.equal(result, "ok");
346
- });
347
-
348
- it("throws non-GLM errors immediately", async () => {
349
- await assert.rejects(
350
- () =>
351
- invokeWithGLMRetry(() => {
352
- throw new Error("not a GLM error");
353
- }),
354
- /not a GLM error/,
355
- );
356
- });
357
-
358
- it("waits until reset time before retry", async () => {
359
- const sleeps: number[] = [];
360
- // The fake sleep must yield to the event loop: the countdown loop
361
- // waits for the WALL CLOCK, so a sleep that returns immediately
362
- // turns the countdown into a busy loop.
363
- const sleep = async (ms: number) => {
364
- sleeps.push(ms);
365
- await new Promise((resolve) => setTimeout(resolve, 1));
366
- };
367
- // Use a reset time in the future. The reset time is parsed with
368
- // SECOND precision, so it has to be far enough in the future that
369
- // the truncation cannot push it into the past (a past reset time is
370
- // shifted by a whole day).
371
- const resetIn = 1500;
372
- const resetAt = new Date(Date.now() + resetIn).toISOString();
373
-
374
- let attempts = 0;
375
- const result = await invokeWithGLMRetry(
376
- async () => {
377
- attempts++;
378
- if (attempts === 1) {
379
- throw new Error(
380
- `{"code":"1308","message":"Usage limit. Reset at ${resetAt}"}`,
381
- );
382
- }
383
- return "success after retry";
384
- },
385
- { sleep, tickMs: 10 },
386
- );
387
-
388
- assert.equal(result, "success after retry");
389
- assert.equal(attempts, 2, "retried after wait");
390
- assert.ok(sleeps.length >= 1, "slept at least once during countdown");
391
- assert.ok(
392
- sleeps.every((ms) => ms === 10),
393
- "tick interval used",
394
- );
395
- });
396
-
397
- it("fires onGLMQuota callback during countdown", async () => {
398
- const ticks: string[] = [];
399
- const sleep = async (ms: number) => {
400
- ticks.push(`sleep:${ms}`);
401
- await new Promise((resolve) => setTimeout(resolve, 1));
402
- };
403
- // The reset time is parsed with SECOND precision, so it has to be
404
- // far enough in the future that the truncation cannot push it into
405
- // the past (a past reset time is shifted by a whole day).
406
- const resetAt = new Date(Date.now() + 1500).toISOString();
407
-
408
- let attempts = 0;
409
- await invokeWithGLMRetry(
410
- async () => {
411
- attempts++;
412
- if (attempts === 1) {
413
- throw new Error(
414
- `{"code":"1308","message":"Usage limit. Reset at ${resetAt}"}`,
415
- );
416
- }
417
- return "done";
418
- },
419
- {
420
- sleep,
421
- tickMs: 10,
422
- onGLMQuota: (sig) => ticks.push(`quota:${sig.resetAtEpoch}`),
423
- },
424
- );
425
-
426
- assert.ok(
427
- ticks.some((t) => t.startsWith("quota:")),
428
- "onGLMQuota was called at least once",
429
- );
430
- });
431
-
432
- it("fires onGLMRetry callback after countdown expires", async () => {
433
- const events: string[] = [];
434
- const sleep = async (_ms: number) => {
435
- await new Promise((resolve) => setTimeout(resolve, 1));
436
- };
437
- // Same as above: second precision, so stay safely in the future.
438
- const resetAt = new Date(Date.now() + 1200).toISOString();
439
-
440
- let attempts = 0;
441
- await invokeWithGLMRetry(
442
- async () => {
443
- attempts++;
444
- if (attempts === 1) {
445
- throw new Error(
446
- `{"code":"1308","message":"Usage limit. Reset at ${resetAt}"}`,
447
- );
448
- }
449
- return "done";
450
- },
451
- {
452
- sleep,
453
- tickMs: 10,
454
- onGLMQuota: () => events.push("quota"),
455
- onGLMRetry: () => events.push("retry"),
456
- },
457
- );
458
-
459
- assert.ok(events.includes("quota"), "quota fired");
460
- assert.ok(events.includes("retry"), "retry fired");
461
- // retry fires AFTER quota
462
- assert.ok(
463
- events.indexOf("retry") > events.indexOf("quota"),
464
- "retry after quota",
465
- );
466
- });
467
- });