@jinn-network/client 0.1.6 → 0.1.7-canary.17a8ecb8

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 (351) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +67 -1
  3. package/deployments/deployment-jinn-mvi-l1-sepolia-fast.json +23 -4
  4. package/deployments/deployment-jinn-mvi-l1-sepolia.json +23 -4
  5. package/deployments/deployment-jinn-mvi-l2-baseSepolia.json +5 -4
  6. package/dist/adapters/mech/adapter.d.ts +38 -1
  7. package/dist/adapters/mech/adapter.js +268 -57
  8. package/dist/adapters/mech/adapter.js.map +1 -1
  9. package/dist/adapters/mech/contracts.d.ts +17 -4
  10. package/dist/adapters/mech/contracts.js +8 -2
  11. package/dist/adapters/mech/contracts.js.map +1 -1
  12. package/dist/adapters/mech/safe-revert.d.ts +20 -0
  13. package/dist/adapters/mech/safe-revert.js +12 -4
  14. package/dist/adapters/mech/safe-revert.js.map +1 -1
  15. package/dist/adapters/mech/safe.d.ts +6 -2
  16. package/dist/adapters/mech/safe.js +32 -11
  17. package/dist/adapters/mech/safe.js.map +1 -1
  18. package/dist/adapters/mech/types.d.ts +6 -1
  19. package/dist/adapters/mech/types.js.map +1 -1
  20. package/dist/adapters/mech/verdict-code.d.ts +1 -0
  21. package/dist/adapters/mech/verdict-code.js +18 -0
  22. package/dist/adapters/mech/verdict-code.js.map +1 -1
  23. package/dist/api/activity-events-endpoint.d.ts +14 -0
  24. package/dist/api/activity-events-endpoint.js +59 -0
  25. package/dist/api/activity-events-endpoint.js.map +1 -0
  26. package/dist/api/admin-endpoint.d.ts +15 -3
  27. package/dist/api/admin-endpoint.js +24 -2
  28. package/dist/api/admin-endpoint.js.map +1 -1
  29. package/dist/api/bootstrap-endpoint.d.ts +1 -2
  30. package/dist/api/bootstrap-endpoint.js +49 -1
  31. package/dist/api/bootstrap-endpoint.js.map +1 -1
  32. package/dist/api/codex-doctor-endpoint.d.ts +73 -0
  33. package/dist/api/codex-doctor-endpoint.js +177 -0
  34. package/dist/api/codex-doctor-endpoint.js.map +1 -0
  35. package/dist/api/discovery-endpoint.d.ts +1 -0
  36. package/dist/api/discovery-endpoint.js +26 -0
  37. package/dist/api/discovery-endpoint.js.map +1 -1
  38. package/dist/api/fleet-build.d.ts +1 -0
  39. package/dist/api/fleet-build.js +2 -1
  40. package/dist/api/fleet-build.js.map +1 -1
  41. package/dist/api/gather-status.d.ts +14 -0
  42. package/dist/api/gather-status.js +494 -19
  43. package/dist/api/gather-status.js.map +1 -1
  44. package/dist/api/hermes-doctor-endpoint.d.ts +117 -0
  45. package/dist/api/hermes-doctor-endpoint.js +229 -23
  46. package/dist/api/hermes-doctor-endpoint.js.map +1 -1
  47. package/dist/api/launcher-status.d.ts +22 -17
  48. package/dist/api/launcher-status.js +13 -11
  49. package/dist/api/launcher-status.js.map +1 -1
  50. package/dist/api/launcher-tasks.d.ts +1 -1
  51. package/dist/api/launcher-tasks.js +12 -8
  52. package/dist/api/launcher-tasks.js.map +1 -1
  53. package/dist/api/portfolio-v0-build.d.ts +10 -0
  54. package/dist/api/portfolio-v0-build.js +24 -5
  55. package/dist/api/portfolio-v0-build.js.map +1 -1
  56. package/dist/api/prediction-v1-build.d.ts +10 -0
  57. package/dist/api/prediction-v1-build.js +7 -1
  58. package/dist/api/prediction-v1-build.js.map +1 -1
  59. package/dist/api/server.d.ts +31 -1
  60. package/dist/api/server.js +72 -1
  61. package/dist/api/server.js.map +1 -1
  62. package/dist/api/setup-endpoints.d.ts +16 -0
  63. package/dist/api/setup-endpoints.js +89 -135
  64. package/dist/api/setup-endpoints.js.map +1 -1
  65. package/dist/api/setup-retry-endpoint.d.ts +19 -0
  66. package/dist/api/setup-retry-endpoint.js +32 -0
  67. package/dist/api/setup-retry-endpoint.js.map +1 -0
  68. package/dist/api/solvernets-endpoints.d.ts +8 -0
  69. package/dist/api/solvernets-endpoints.js +71 -43
  70. package/dist/api/solvernets-endpoints.js.map +1 -1
  71. package/dist/api/status-build.d.ts +112 -0
  72. package/dist/api/status-build.js +98 -18
  73. package/dist/api/status-build.js.map +1 -1
  74. package/dist/api/task-run-routing.d.ts +7 -0
  75. package/dist/api/task-run-routing.js +12 -0
  76. package/dist/api/task-run-routing.js.map +1 -0
  77. package/dist/api/task-runs-build.d.ts +21 -0
  78. package/dist/api/task-runs-build.js +14 -1
  79. package/dist/api/task-runs-build.js.map +1 -1
  80. package/dist/build-info.json +4 -4
  81. package/dist/build-meta.json +1 -1
  82. package/dist/chain-read-errors.d.ts +10 -0
  83. package/dist/chain-read-errors.js +15 -0
  84. package/dist/chain-read-errors.js.map +1 -1
  85. package/dist/cli/commands/auth.js +1 -1
  86. package/dist/cli/commands/auth.js.map +1 -1
  87. package/dist/cli/commands/create.js +3 -2
  88. package/dist/cli/commands/create.js.map +1 -1
  89. package/dist/cli/commands/doctor.d.ts +2 -0
  90. package/dist/cli/commands/doctor.js +2 -0
  91. package/dist/cli/commands/doctor.js.map +1 -1
  92. package/dist/cli/commands/rewards.js +11 -7
  93. package/dist/cli/commands/rewards.js.map +1 -1
  94. package/dist/cli/commands/solver-nets.js +101 -15
  95. package/dist/cli/commands/solver-nets.js.map +1 -1
  96. package/dist/cli/commands/solver-plugins-block.d.ts +33 -0
  97. package/dist/cli/commands/solver-plugins-block.js +118 -0
  98. package/dist/cli/commands/solver-plugins-block.js.map +1 -0
  99. package/dist/cli/commands/solver-plugins-feedback.d.ts +72 -0
  100. package/dist/cli/commands/solver-plugins-feedback.js +262 -0
  101. package/dist/cli/commands/solver-plugins-feedback.js.map +1 -0
  102. package/dist/cli/commands/solver-plugins-read.d.ts +54 -0
  103. package/dist/cli/commands/solver-plugins-read.js +259 -0
  104. package/dist/cli/commands/solver-plugins-read.js.map +1 -0
  105. package/dist/cli/commands/solver-plugins.d.ts +35 -0
  106. package/dist/cli/commands/solver-plugins.js +399 -2
  107. package/dist/cli/commands/solver-plugins.js.map +1 -1
  108. package/dist/cli/commands/status.js +1 -1
  109. package/dist/cli/commands/status.js.map +1 -1
  110. package/dist/cli/commands/tasks.js +101 -11
  111. package/dist/cli/commands/tasks.js.map +1 -1
  112. package/dist/cli/commands/update.d.ts +10 -0
  113. package/dist/cli/commands/update.js +36 -0
  114. package/dist/cli/commands/update.js.map +1 -1
  115. package/dist/cli/introspection-context.js +5 -0
  116. package/dist/cli/introspection-context.js.map +1 -1
  117. package/dist/cli/task-native-readiness.d.ts +10 -1
  118. package/dist/cli/task-native-readiness.js +30 -6
  119. package/dist/cli/task-native-readiness.js.map +1 -1
  120. package/dist/config.d.ts +273 -235
  121. package/dist/config.js +305 -114
  122. package/dist/config.js.map +1 -1
  123. package/dist/daemon/checkpoint-loop.d.ts +48 -0
  124. package/dist/daemon/checkpoint-loop.js +76 -0
  125. package/dist/daemon/checkpoint-loop.js.map +1 -0
  126. package/dist/daemon/creator.d.ts +1 -1
  127. package/dist/daemon/creator.js +7 -3
  128. package/dist/daemon/creator.js.map +1 -1
  129. package/dist/daemon/daemon.d.ts +22 -0
  130. package/dist/daemon/daemon.js +156 -23
  131. package/dist/daemon/daemon.js.map +1 -1
  132. package/dist/daemon/eviction-loop.d.ts +40 -0
  133. package/dist/daemon/eviction-loop.js +67 -0
  134. package/dist/daemon/eviction-loop.js.map +1 -0
  135. package/dist/daemon/gate-logger.d.ts +9 -0
  136. package/dist/daemon/gate-logger.js +2 -0
  137. package/dist/daemon/gate-logger.js.map +1 -0
  138. package/dist/daemon/jinn-claim-loop-wiring.d.ts +33 -0
  139. package/dist/daemon/jinn-claim-loop-wiring.js +40 -0
  140. package/dist/daemon/jinn-claim-loop-wiring.js.map +1 -0
  141. package/dist/daemon/jinn-claim-loop.d.ts +24 -17
  142. package/dist/daemon/jinn-claim-loop.js +77 -23
  143. package/dist/daemon/jinn-claim-loop.js.map +1 -1
  144. package/dist/daemon/readiness-gate.d.ts +1 -4
  145. package/dist/daemon/readiness-gate.js.map +1 -1
  146. package/dist/daemon/skip-log-dedup.d.ts +69 -0
  147. package/dist/daemon/skip-log-dedup.js +106 -0
  148. package/dist/daemon/skip-log-dedup.js.map +1 -0
  149. package/dist/daemon/spend-cap-gate.d.ts +40 -0
  150. package/dist/daemon/spend-cap-gate.js +46 -0
  151. package/dist/daemon/spend-cap-gate.js.map +1 -0
  152. package/dist/dashboard/assets/index-8yHQgi7p.js +345 -0
  153. package/dist/dashboard/assets/index-BOBhJ76-.css +32 -0
  154. package/dist/dashboard/index.html +2 -2
  155. package/dist/discovery/factory.d.ts +17 -5
  156. package/dist/discovery/factory.js +46 -18
  157. package/dist/discovery/factory.js.map +1 -1
  158. package/dist/discovery/http.js +142 -3
  159. package/dist/discovery/http.js.map +1 -1
  160. package/dist/discovery/onchain.d.ts +5 -0
  161. package/dist/discovery/onchain.js +407 -15
  162. package/dist/discovery/onchain.js.map +1 -1
  163. package/dist/discovery/types.d.ts +45 -1
  164. package/dist/discovery/types.js +8 -10
  165. package/dist/discovery/types.js.map +1 -1
  166. package/dist/discovery/with-fallback.d.ts +7 -0
  167. package/dist/discovery/with-fallback.js +10 -0
  168. package/dist/discovery/with-fallback.js.map +1 -1
  169. package/dist/earning/bootstrap.d.ts +92 -1
  170. package/dist/earning/bootstrap.js +203 -63
  171. package/dist/earning/bootstrap.js.map +1 -1
  172. package/dist/earning/contracts.d.ts +14 -0
  173. package/dist/earning/contracts.js +17 -5
  174. package/dist/earning/contracts.js.map +1 -1
  175. package/dist/earning/funding-plan.js +27 -18
  176. package/dist/earning/funding-plan.js.map +1 -1
  177. package/dist/earning/jinn-rewards.d.ts +46 -0
  178. package/dist/earning/jinn-rewards.js +32 -0
  179. package/dist/earning/jinn-rewards.js.map +1 -1
  180. package/dist/earning/safe-adapter.d.ts +2 -0
  181. package/dist/earning/safe-adapter.js +37 -11
  182. package/dist/earning/safe-adapter.js.map +1 -1
  183. package/dist/earning/store.d.ts +8 -0
  184. package/dist/earning/store.js.map +1 -1
  185. package/dist/earning/testnet-setup-migration.d.ts +12 -0
  186. package/dist/earning/testnet-setup-migration.js +27 -1
  187. package/dist/earning/testnet-setup-migration.js.map +1 -1
  188. package/dist/earning/types.d.ts +21 -6
  189. package/dist/earning/viem-clients.d.ts +11 -4
  190. package/dist/earning/viem-clients.js +14 -5
  191. package/dist/earning/viem-clients.js.map +1 -1
  192. package/dist/erc8004/reputation.d.ts +8 -0
  193. package/dist/erc8004/reputation.js +22 -3
  194. package/dist/erc8004/reputation.js.map +1 -1
  195. package/dist/events/types.d.ts +2 -2
  196. package/dist/harnesses/cost-estimates.d.ts +145 -0
  197. package/dist/harnesses/cost-estimates.js +297 -0
  198. package/dist/harnesses/cost-estimates.js.map +1 -0
  199. package/dist/harnesses/engine/engine.d.ts +72 -0
  200. package/dist/harnesses/engine/engine.js +118 -8
  201. package/dist/harnesses/engine/engine.js.map +1 -1
  202. package/dist/harnesses/engine/persistence.d.ts +51 -1
  203. package/dist/harnesses/engine/persistence.js +118 -5
  204. package/dist/harnesses/engine/persistence.js.map +1 -1
  205. package/dist/harnesses/engine/work-dir-reaper.d.ts +65 -0
  206. package/dist/harnesses/engine/work-dir-reaper.js +100 -0
  207. package/dist/harnesses/engine/work-dir-reaper.js.map +1 -0
  208. package/dist/harnesses/impls/hermes-agent/adapter.js +40 -0
  209. package/dist/harnesses/impls/hermes-agent/adapter.js.map +1 -1
  210. package/dist/harnesses/impls/hermes-agent/bootstrap.d.ts +20 -0
  211. package/dist/harnesses/impls/hermes-agent/bootstrap.js +40 -6
  212. package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -1
  213. package/dist/harnesses/impls/hermes-agent/harness.d.ts +59 -1
  214. package/dist/harnesses/impls/hermes-agent/harness.js +104 -0
  215. package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -1
  216. package/dist/harnesses/impls/index.d.ts +7 -0
  217. package/dist/harnesses/impls/index.js +16 -1
  218. package/dist/harnesses/impls/index.js.map +1 -1
  219. package/dist/harnesses/impls/learner/harness.d.ts +38 -4
  220. package/dist/harnesses/impls/learner/harness.js +96 -2
  221. package/dist/harnesses/impls/learner/harness.js.map +1 -1
  222. package/dist/harnesses/impls/learner/plugin-path.d.ts +0 -13
  223. package/dist/harnesses/impls/learner/plugin-path.js +35 -15
  224. package/dist/harnesses/impls/learner/plugin-path.js.map +1 -1
  225. package/dist/harnesses/impls/learner/types.d.ts +11 -0
  226. package/dist/harnesses/impls/stub.d.ts +58 -0
  227. package/dist/harnesses/impls/stub.js +89 -0
  228. package/dist/harnesses/impls/stub.js.map +1 -0
  229. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.d.ts +69 -50
  230. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +178 -93
  231. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
  232. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.d.ts +12 -1
  233. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js +121 -7
  234. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js.map +1 -1
  235. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +88 -4
  236. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +143 -22
  237. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
  238. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.d.ts +6 -0
  239. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js +1 -1
  240. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js.map +1 -1
  241. package/dist/harnesses/readiness-registry.js +9 -1
  242. package/dist/harnesses/readiness-registry.js.map +1 -1
  243. package/dist/main.js +413 -111
  244. package/dist/main.js.map +1 -1
  245. package/dist/observability/emit-event.d.ts +3 -2
  246. package/dist/observability/emit-event.js +22 -1
  247. package/dist/observability/emit-event.js.map +1 -1
  248. package/dist/operator-errors.d.ts +7 -0
  249. package/dist/operator-errors.js +13 -1
  250. package/dist/operator-errors.js.map +1 -1
  251. package/dist/plugins/learner/.claude-plugin/plugin.json +9 -0
  252. package/dist/plugins/learner/.codex-plugin/plugin.json +39 -0
  253. package/dist/plugins/learner/AGENTS.md +40 -0
  254. package/dist/plugins/learner/CLAUDE.md +33 -0
  255. package/dist/plugins/learner/README.md +59 -0
  256. package/dist/plugins/learner/hooks/hooks.json +16 -0
  257. package/dist/plugins/learner/hooks/session-start +38 -0
  258. package/dist/plugins/learner/skills/learn/SKILL.md +412 -0
  259. package/dist/plugins/learner/skills/learn/analyst-prompt.md +68 -0
  260. package/dist/plugins/learner/skills/learn/consolidator-prompt.md +94 -0
  261. package/dist/plugins/learner/skills/learn/explorer-prompt.md +53 -0
  262. package/dist/plugins/learner/skills/learn/planner-prompt.md +87 -0
  263. package/dist/plugins/learner/skills/learn/promoter-prompt.md +113 -0
  264. package/dist/plugins/learner/skills/learn/step-worker-prompt.md +47 -0
  265. package/dist/plugins/learner/skills/learn/strategist-prompt.md +85 -0
  266. package/dist/preflight/rpc-network.d.ts +40 -0
  267. package/dist/preflight/rpc-network.js +67 -1
  268. package/dist/preflight/rpc-network.js.map +1 -1
  269. package/dist/restart-daemon.d.ts +90 -0
  270. package/dist/restart-daemon.js +95 -0
  271. package/dist/restart-daemon.js.map +1 -0
  272. package/dist/rpc/transport.d.ts +109 -0
  273. package/dist/rpc/transport.js +220 -0
  274. package/dist/rpc/transport.js.map +1 -0
  275. package/dist/scripts/donation-consumption-acceptance.js +7 -28
  276. package/dist/scripts/donation-consumption-acceptance.js.map +1 -1
  277. package/dist/setup/halt-mode.d.ts +14 -0
  278. package/dist/setup/halt-mode.js +17 -0
  279. package/dist/setup/halt-mode.js.map +1 -0
  280. package/dist/solver-nets/prediction-operator-ux.d.ts +1 -2
  281. package/dist/solver-nets/prediction-operator-ux.js +90 -47
  282. package/dist/solver-nets/prediction-operator-ux.js.map +1 -1
  283. package/dist/solver-nets/registry.d.ts +20 -1
  284. package/dist/solver-nets/registry.js +38 -25
  285. package/dist/solver-nets/registry.js.map +1 -1
  286. package/dist/solver-types/_swe-rebench-v2-pool-cache.d.ts +58 -0
  287. package/dist/solver-types/_swe-rebench-v2-pool-cache.js +87 -0
  288. package/dist/solver-types/_swe-rebench-v2-pool-cache.js.map +1 -0
  289. package/dist/solver-types/_swe-rebench-v2-pool.d.ts +9 -2
  290. package/dist/solver-types/_swe-rebench-v2-pool.js +15 -20
  291. package/dist/solver-types/_swe-rebench-v2-pool.js.map +1 -1
  292. package/dist/solver-types/_swe-rebench-v2-substrate.d.ts +1 -0
  293. package/dist/solver-types/_swe-rebench-v2-substrate.js +10 -0
  294. package/dist/solver-types/_swe-rebench-v2-substrate.js.map +1 -1
  295. package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +94 -1
  296. package/dist/solver-types/_swe-rebench-v2-validated-pool.js +305 -39
  297. package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
  298. package/dist/solver-types/swe-rebench-v2-auto.d.ts +22 -7
  299. package/dist/solver-types/swe-rebench-v2-auto.js +45 -20
  300. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
  301. package/dist/solver-types/swe-rebench-v2.d.ts +13 -2
  302. package/dist/solver-types/swe-rebench-v2.js +237 -95
  303. package/dist/solver-types/swe-rebench-v2.js.map +1 -1
  304. package/dist/solvernets/daemon-init.d.ts +10 -2
  305. package/dist/solvernets/daemon-init.js +22 -2
  306. package/dist/solvernets/daemon-init.js.map +1 -1
  307. package/dist/solvernets/launched-record-dispatcher.js +35 -7
  308. package/dist/solvernets/launched-record-dispatcher.js.map +1 -1
  309. package/dist/solvernets/store.d.ts +5 -0
  310. package/dist/solvernets/store.js +1 -0
  311. package/dist/solvernets/store.js.map +1 -1
  312. package/dist/spend/credential.d.ts +8 -0
  313. package/dist/spend/credential.js +30 -0
  314. package/dist/spend/credential.js.map +1 -0
  315. package/dist/spend/daemon-config.d.ts +13 -0
  316. package/dist/spend/daemon-config.js +24 -0
  317. package/dist/spend/daemon-config.js.map +1 -0
  318. package/dist/spend/pricing.d.ts +16 -0
  319. package/dist/spend/pricing.js +26 -0
  320. package/dist/spend/pricing.js.map +1 -0
  321. package/dist/spend/record.d.ts +13 -0
  322. package/dist/spend/record.js +30 -0
  323. package/dist/spend/record.js.map +1 -0
  324. package/dist/spend/usage.d.ts +27 -0
  325. package/dist/spend/usage.js +113 -0
  326. package/dist/spend/usage.js.map +1 -0
  327. package/dist/store/store.d.ts +43 -0
  328. package/dist/store/store.js +236 -7
  329. package/dist/store/store.js.map +1 -1
  330. package/dist/tasks/sources.d.ts +18 -1
  331. package/dist/tasks/sources.js +33 -5
  332. package/dist/tasks/sources.js.map +1 -1
  333. package/dist/trajectory/transcript-parsers/types.d.ts +8 -8
  334. package/dist/tx-retry.d.ts +166 -19
  335. package/dist/tx-retry.js +310 -32
  336. package/dist/tx-retry.js.map +1 -1
  337. package/dist/types/payloads/prediction-apy-v0.d.ts +5 -5
  338. package/dist/types/payloads/prediction-v0.d.ts +5 -5
  339. package/dist/types/task-document.d.ts +392 -0
  340. package/dist/types/task-document.js +10 -0
  341. package/dist/types/task-document.js.map +1 -1
  342. package/dist/types/task.d.ts +28 -0
  343. package/dist/util/extract-tx-hash.d.ts +14 -0
  344. package/dist/util/extract-tx-hash.js +19 -0
  345. package/dist/util/extract-tx-hash.js.map +1 -0
  346. package/dist/vendor/@jinn-network/sdk/dist/contracts.js +1 -1
  347. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.d.ts +3 -0
  348. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.js +1 -0
  349. package/package.json +30 -12
  350. package/dist/dashboard/assets/index-DOlzFN8a.css +0 -32
  351. package/dist/dashboard/assets/index-NkZ7CTAT.js +0 -140
@@ -0,0 +1,90 @@
1
+ /**
2
+ * In-process respawn helper for operator-triggered daemon restarts.
3
+ *
4
+ * Issue #289 added respawn-instead-of-exit so the operator panel survives a
5
+ * restart click. Issue #561 fixed the follow-on bug: the original respawn
6
+ * spawned the child *before* the parent had released its server sockets, so
7
+ * the child raced into `.listen(7332)` while the parent still held the port
8
+ * and died with EADDRINUSE / exitCode 11. The fix is `preSpawnCleanup` — an
9
+ * async hook the caller uses to close API + OTLP receivers before the child
10
+ * is spawned. With cleanup in place the port is free synchronously and the
11
+ * child binds on first try; without it (older callers, tests) the helper
12
+ * behaves as before.
13
+ *
14
+ * Every restart-required config change funnels through the same handler:
15
+ *
16
+ * - POST /v1/setup/network — RPC URL change
17
+ * - POST /v1/setup/change-password — keystore password rotation
18
+ * - POST /v1/setup/solvernets/:name — SolverNet enable/disable
19
+ * - POST /v1/operator/join/:cid — SolverNet join
20
+ *
21
+ * Headless gate: `JINN_NO_UI=1` (already the established headless flag in
22
+ * main.ts) skips the respawn — operators running `jinn run --no-ui` from a
23
+ * supervisor / systemd unit / docker entrypoint want the supervisor to
24
+ * decide whether to restart, not the daemon.
25
+ *
26
+ * The helper is split out from main.ts so it's unit-testable without
27
+ * touching the entry-point bootstrap path.
28
+ */
29
+ import { spawn } from 'node:child_process';
30
+ /**
31
+ * Options for `requestDaemonRestart`. All optional in production; the helper
32
+ * defaults to `process` / `node:child_process`. Tests inject doubles.
33
+ */
34
+ export interface RequestDaemonRestartOptions {
35
+ /** Defaults to `process.env`. */
36
+ env?: NodeJS.ProcessEnv;
37
+ /** Defaults to `process.argv` (`[node, scriptPath, ...args]`). */
38
+ argv?: readonly string[];
39
+ /** Defaults to `process.execPath` (the node binary). */
40
+ execPath?: string;
41
+ /**
42
+ * Defaults to `node:child_process.spawn`. Injected for tests so we can
43
+ * assert what was spawned without actually forking node.
44
+ */
45
+ spawnFn?: typeof spawn;
46
+ /** Defaults to `(code) => process.exit(code)`. Injected for tests. */
47
+ exitFn?: (code: number) => void;
48
+ /** Defaults to `console.log`. Injected for tests to capture output. */
49
+ log?: (message: string) => void;
50
+ /**
51
+ * Delay (ms) between spawning the child and exiting the parent. Gives the
52
+ * child a moment to bind the API port before the parent vacates it.
53
+ * Defaults to 250ms per the issue body. Tests can pass 0 for synchrony.
54
+ */
55
+ exitDelayMs?: number;
56
+ /**
57
+ * Bypass the headless gate. The operator-dashboard Restart button passes
58
+ * this — when the operator clicks Restart, they explicitly want the
59
+ * daemon to come back, even under a supervisor. Supervisor-driven
60
+ * restart flows (MCP tools, signals) leave this `false` so the
61
+ * supervisor stays in charge.
62
+ */
63
+ forceRespawn?: boolean;
64
+ /**
65
+ * Optional async hook run *before* the replacement child is spawned. The
66
+ * caller uses this to close listening sockets the child will need to
67
+ * bind — API server (7332) and OTLP receiver (4317/4318) — so the child
68
+ * doesn't lose an EADDRINUSE race with the parent. Errors are caught and
69
+ * logged; the respawn still proceeds because leaving the operator
70
+ * stranded is worse than a noisy close. Skipped in headless mode.
71
+ */
72
+ preSpawnCleanup?: () => Promise<void>;
73
+ }
74
+ /**
75
+ * Pure predicate: true when the current env is headless and respawn should
76
+ * be skipped. Exposed so callers and tests can share the same check.
77
+ */
78
+ export declare function isHeadless(env?: NodeJS.ProcessEnv): boolean;
79
+ /**
80
+ * Handle an operator-triggered restart request.
81
+ *
82
+ * - In **interactive** mode (default), spawn a detached child that re-runs
83
+ * the current node invocation, then exit after a short delay so the child
84
+ * can bind the API port.
85
+ * - In **headless** mode (`JINN_NO_UI=1`), exit without respawning. The
86
+ * supervisor is responsible for relaunching the daemon if it wants to.
87
+ *
88
+ * Returns the action taken (for tests). Production callers ignore the return.
89
+ */
90
+ export declare function requestDaemonRestart(opts?: RequestDaemonRestartOptions): Promise<'respawned' | 'headless-exit'>;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * In-process respawn helper for operator-triggered daemon restarts.
3
+ *
4
+ * Issue #289 added respawn-instead-of-exit so the operator panel survives a
5
+ * restart click. Issue #561 fixed the follow-on bug: the original respawn
6
+ * spawned the child *before* the parent had released its server sockets, so
7
+ * the child raced into `.listen(7332)` while the parent still held the port
8
+ * and died with EADDRINUSE / exitCode 11. The fix is `preSpawnCleanup` — an
9
+ * async hook the caller uses to close API + OTLP receivers before the child
10
+ * is spawned. With cleanup in place the port is free synchronously and the
11
+ * child binds on first try; without it (older callers, tests) the helper
12
+ * behaves as before.
13
+ *
14
+ * Every restart-required config change funnels through the same handler:
15
+ *
16
+ * - POST /v1/setup/network — RPC URL change
17
+ * - POST /v1/setup/change-password — keystore password rotation
18
+ * - POST /v1/setup/solvernets/:name — SolverNet enable/disable
19
+ * - POST /v1/operator/join/:cid — SolverNet join
20
+ *
21
+ * Headless gate: `JINN_NO_UI=1` (already the established headless flag in
22
+ * main.ts) skips the respawn — operators running `jinn run --no-ui` from a
23
+ * supervisor / systemd unit / docker entrypoint want the supervisor to
24
+ * decide whether to restart, not the daemon.
25
+ *
26
+ * The helper is split out from main.ts so it's unit-testable without
27
+ * touching the entry-point bootstrap path.
28
+ */
29
+ import { spawn } from 'node:child_process';
30
+ /**
31
+ * Pure predicate: true when the current env is headless and respawn should
32
+ * be skipped. Exposed so callers and tests can share the same check.
33
+ */
34
+ export function isHeadless(env = process.env) {
35
+ return env['JINN_NO_UI'] === '1';
36
+ }
37
+ /**
38
+ * Handle an operator-triggered restart request.
39
+ *
40
+ * - In **interactive** mode (default), spawn a detached child that re-runs
41
+ * the current node invocation, then exit after a short delay so the child
42
+ * can bind the API port.
43
+ * - In **headless** mode (`JINN_NO_UI=1`), exit without respawning. The
44
+ * supervisor is responsible for relaunching the daemon if it wants to.
45
+ *
46
+ * Returns the action taken (for tests). Production callers ignore the return.
47
+ */
48
+ export async function requestDaemonRestart(opts = {}) {
49
+ const env = opts.env ?? process.env;
50
+ const argv = opts.argv ?? process.argv;
51
+ const execPath = opts.execPath ?? process.execPath;
52
+ const spawnFn = opts.spawnFn ?? spawn;
53
+ const exitFn = opts.exitFn ?? ((code) => process.exit(code));
54
+ const log = opts.log ?? ((message) => console.log(message));
55
+ const exitDelayMs = opts.exitDelayMs ?? 250;
56
+ if (isHeadless(env) && !opts.forceRespawn) {
57
+ log('[main] Restart requested via operator MCP, but JINN_NO_UI=1 — exiting without respawn (let the supervisor decide).');
58
+ exitFn(0);
59
+ return 'headless-exit';
60
+ }
61
+ log('[main] Restart requested via operator MCP. Spawning replacement and exiting...');
62
+ // jinn-mono #561: release server sockets BEFORE the child spawns. Without
63
+ // this, the child loses an EADDRINUSE race on 7332 (and OTLP 4317/4318)
64
+ // and dies with exitCode 11 before it can take over.
65
+ if (opts.preSpawnCleanup) {
66
+ try {
67
+ await opts.preSpawnCleanup();
68
+ }
69
+ catch (err) {
70
+ log(`[main] preSpawnCleanup error (proceeding with respawn anyway): ${err instanceof Error ? err.message : String(err)}`);
71
+ }
72
+ }
73
+ // argv[0] is the node binary; argv[1..] are the script + flags. The child
74
+ // re-runs the same script with the same flags, under the same node binary.
75
+ const childArgs = argv.slice(1);
76
+ const spawnOptions = {
77
+ detached: true,
78
+ stdio: 'inherit',
79
+ env,
80
+ };
81
+ const child = spawnFn(execPath, childArgs, spawnOptions);
82
+ // Detach so the parent can exit without taking the child with it.
83
+ child.unref();
84
+ // With preSpawnCleanup the port is already free; the small delay is kept
85
+ // as a paranoid belt-and-suspenders against any kernel-level lingering on
86
+ // SO_LINGER-disabled sockets. Tests pass 0.
87
+ if (exitDelayMs <= 0) {
88
+ exitFn(0);
89
+ }
90
+ else {
91
+ setTimeout(() => exitFn(0), exitDelayMs);
92
+ }
93
+ return 'respawned';
94
+ }
95
+ //# sourceMappingURL=restart-daemon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart-daemon.js","sourceRoot":"","sources":["../src/restart-daemon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AA+C9D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC7D,OAAO,GAAG,CAAC,YAAY,CAAC,KAAK,GAAG,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAoC,EAAE;IAEtC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,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,YAAY,GAAiB;QACjC,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,SAAS;QAChB,GAAG;KACJ,CAAC;IACF,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IACzD,kEAAkE;IAClE,KAAK,CAAC,KAAK,EAAE,CAAC;IAEd,yEAAyE;IACzE,0EAA0E;IAC1E,4CAA4C;IAC5C,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,CAAC,CAAC,CAAC;IACZ,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * RPC transport helper — builds a viem `fallback()` transport from a single
3
+ * URL, an array of URLs, or a comma-separated string. The substrate for issue
4
+ * #592 (multi-RPC fallback chain across daemon / relayer / indexer / CI).
5
+ *
6
+ * Design:
7
+ * - `parseRpcUrls` normalises `string | readonly string[]` to a deduplicated
8
+ * non-empty array, splits comma-strings, trims, drops empties, and caps the
9
+ * chain at {@link MAX_RPC_CHAIN_LENGTH} providers (extras are dropped with a
10
+ * warning). Throws when no URLs remain.
11
+ * - `buildFallbackTransport` wraps `http(url)` per slot inside viem's
12
+ * `fallback([...], { rank: false, retryCount: 0 })`. `rank: false` is
13
+ * explicit — the issue's "Tenderly stays in slot 3" constraint requires
14
+ * order preservation (no latency-based reshuffling). `retryCount: 0` keeps
15
+ * the helper from doubling retries on top of the existing
16
+ * `withRecoverableRetry` wrapper used by callers like the mech adapter.
17
+ * - On exhausted fall-through the helper rejects with `AllRpcsFailedError`,
18
+ * which carries a structured `providers: readonly string[]` list of masked
19
+ * hosts so callers and tests can assert on it.
20
+ * - `describeFallbackChain` formats the canonical AC7 boot-log summary line:
21
+ * `fallback chain (N providers) — primary=<host>`.
22
+ *
23
+ * Do not conflate with `discovery.fallbackToOnchain` — that's a separate layer
24
+ * at the read-API level (Ponder → eth_getLogs floor). This helper sits beneath
25
+ * both layers at the JSON-RPC transport level.
26
+ */
27
+ import { type FallbackTransport, type Transport } from 'viem';
28
+ /**
29
+ * Hard cap on the number of providers in a single fallback chain. Four covers
30
+ * the "operator paid primary + public publicnode + public sepolia.base.org +
31
+ * Tenderly slot-3" shape from the issue; beyond that the boot probe takes too
32
+ * long and slot 5+ is almost always copy-paste noise.
33
+ */
34
+ export declare const MAX_RPC_CHAIN_LENGTH = 4;
35
+ export interface ParseRpcUrlsOptions {
36
+ /** Logger used to emit the "capped" warning. Defaults to `console.error`. */
37
+ log?: (message: string) => void;
38
+ }
39
+ /**
40
+ * Normalise `string | readonly string[]` into a non-empty, deduplicated,
41
+ * capped list of RPC URLs. Comma-separated strings are split (operator
42
+ * convention, see `peers` in `config.ts`). Duplicates are removed before the
43
+ * cap is applied so the effective chain length matches operator intent (an
44
+ * operator who prepends their paid primary to the existing fallback list
45
+ * shouldn't burn a slot on the duplicate).
46
+ *
47
+ * @throws if the input yields zero non-empty URLs.
48
+ */
49
+ export declare function parseRpcUrls(input: string | readonly string[], options?: ParseRpcUrlsOptions): string[];
50
+ /**
51
+ * Error thrown when every provider in a fallback chain has failed. Carries
52
+ * the masked host list so callers can surface a useful operator-facing message
53
+ * without leaking secret query strings (api-key paths).
54
+ */
55
+ export declare class AllRpcsFailedError extends Error {
56
+ readonly providers: readonly string[];
57
+ readonly cause?: unknown;
58
+ constructor(providers: readonly string[], cause?: unknown);
59
+ }
60
+ /**
61
+ * Detect errors that viem's `fallback()` short-circuits on (via its
62
+ * `shouldThrow(err)` fast-exit) — `ExecutionRevertedError`,
63
+ * `TransactionRejectedRpcError`, `UserRejectedRequestError`,
64
+ * `WalletConnectSessionSettlementError`, and CAIP user-rejected (code
65
+ * `5000`). These are EVM- or wallet-level signals, NOT transport-level
66
+ * failures, so they must propagate unchanged. Wrapping them as
67
+ * `AllRpcsFailedError` would give the operator-app a false-positive
68
+ * "all RPCs failed" message when the actual problem is e.g. a contract
69
+ * revert on a view function.
70
+ *
71
+ * Mirrors viem's own predicate at
72
+ * `node_modules/viem/clients/transports/fallback.ts` (`shouldThrow`),
73
+ * dispatching by **numeric JSON-RPC code** (the path that catches real
74
+ * `RpcRequestError` instances coming out of the HTTP transport) plus the
75
+ * `ExecutionRevertedError.nodeMessage` regex (the path that catches reverts
76
+ * surfaced as plain `Error` with no numeric code). The cause-chain walk by
77
+ * class `name` remains as a third path for wallet-provider stacks that
78
+ * deliver proper class instances (and for already-normalised errors after
79
+ * viem's `buildRequest` re-wrap pass).
80
+ */
81
+ export declare function isViemShouldThrowError(err: unknown): boolean;
82
+ /**
83
+ * Mask an RPC URL down to its hostname for display / error reporting. Drops
84
+ * the path so api-key segments in the URL don't leak into logs.
85
+ */
86
+ export declare function maskRpcHost(url: string): string;
87
+ export interface BuildFallbackTransportOptions {
88
+ /**
89
+ * Set to `true` to let viem rank providers by latency. Default `false` —
90
+ * order matters for operator-configured paid primaries and the
91
+ * "Tenderly stays in slot 3" constraint from the issue.
92
+ */
93
+ rank?: boolean;
94
+ }
95
+ /**
96
+ * Build a viem fallback transport over the given URLs. Returns a callable
97
+ * transport suitable for `createPublicClient({ transport })`.
98
+ *
99
+ * Errors that exhaust the chain are wrapped in `AllRpcsFailedError`.
100
+ */
101
+ export declare function buildFallbackTransport(urls: readonly string[], options?: BuildFallbackTransportOptions): FallbackTransport;
102
+ export declare namespace buildFallbackTransport {
103
+ var buildFromTransports: (transports: readonly Transport[], urls: readonly string[], options?: BuildFallbackTransportOptions) => FallbackTransport;
104
+ }
105
+ /**
106
+ * Boot-log summary line for a fallback chain. Matches the canonical AC7
107
+ * format: `fallback chain (N providers) — primary=<host>`.
108
+ */
109
+ export declare function describeFallbackChain(urls: readonly string[]): string;
@@ -0,0 +1,220 @@
1
+ /**
2
+ * RPC transport helper — builds a viem `fallback()` transport from a single
3
+ * URL, an array of URLs, or a comma-separated string. The substrate for issue
4
+ * #592 (multi-RPC fallback chain across daemon / relayer / indexer / CI).
5
+ *
6
+ * Design:
7
+ * - `parseRpcUrls` normalises `string | readonly string[]` to a deduplicated
8
+ * non-empty array, splits comma-strings, trims, drops empties, and caps the
9
+ * chain at {@link MAX_RPC_CHAIN_LENGTH} providers (extras are dropped with a
10
+ * warning). Throws when no URLs remain.
11
+ * - `buildFallbackTransport` wraps `http(url)` per slot inside viem's
12
+ * `fallback([...], { rank: false, retryCount: 0 })`. `rank: false` is
13
+ * explicit — the issue's "Tenderly stays in slot 3" constraint requires
14
+ * order preservation (no latency-based reshuffling). `retryCount: 0` keeps
15
+ * the helper from doubling retries on top of the existing
16
+ * `withRecoverableRetry` wrapper used by callers like the mech adapter.
17
+ * - On exhausted fall-through the helper rejects with `AllRpcsFailedError`,
18
+ * which carries a structured `providers: readonly string[]` list of masked
19
+ * hosts so callers and tests can assert on it.
20
+ * - `describeFallbackChain` formats the canonical AC7 boot-log summary line:
21
+ * `fallback chain (N providers) — primary=<host>`.
22
+ *
23
+ * Do not conflate with `discovery.fallbackToOnchain` — that's a separate layer
24
+ * at the read-API level (Ponder → eth_getLogs floor). This helper sits beneath
25
+ * both layers at the JSON-RPC transport level.
26
+ */
27
+ import { ExecutionRevertedError, fallback, http, TransactionRejectedRpcError, UserRejectedRequestError, } from 'viem';
28
+ /**
29
+ * Hard cap on the number of providers in a single fallback chain. Four covers
30
+ * the "operator paid primary + public publicnode + public sepolia.base.org +
31
+ * Tenderly slot-3" shape from the issue; beyond that the boot probe takes too
32
+ * long and slot 5+ is almost always copy-paste noise.
33
+ */
34
+ export const MAX_RPC_CHAIN_LENGTH = 4;
35
+ /**
36
+ * Normalise `string | readonly string[]` into a non-empty, deduplicated,
37
+ * capped list of RPC URLs. Comma-separated strings are split (operator
38
+ * convention, see `peers` in `config.ts`). Duplicates are removed before the
39
+ * cap is applied so the effective chain length matches operator intent (an
40
+ * operator who prepends their paid primary to the existing fallback list
41
+ * shouldn't burn a slot on the duplicate).
42
+ *
43
+ * @throws if the input yields zero non-empty URLs.
44
+ */
45
+ export function parseRpcUrls(input, options = {}) {
46
+ const log = options.log ?? ((m) => process.stderr.write(`${m}\n`));
47
+ const raw = typeof input === 'string' ? input.split(',') : [...input];
48
+ const cleaned = raw.map((u) => u.trim()).filter((u) => u.length > 0);
49
+ if (cleaned.length === 0) {
50
+ throw new Error('parseRpcUrls: at least one RPC URL is required');
51
+ }
52
+ // Dedup before applying the cap so repeated URLs (easy to introduce when an
53
+ // operator prepends a paid primary that already exists in the fallback list)
54
+ // don't burn slots of the 4-slot chain. `Set` preserves first-seen insertion
55
+ // order, which matches the "primary stays in slot 0" constraint.
56
+ const deduped = [...new Set(cleaned)];
57
+ if (deduped.length > MAX_RPC_CHAIN_LENGTH) {
58
+ log(`[rpc] capped fallback chain to ${MAX_RPC_CHAIN_LENGTH} providers ` +
59
+ `(dropped ${deduped.length - MAX_RPC_CHAIN_LENGTH} extra slots)`);
60
+ return deduped.slice(0, MAX_RPC_CHAIN_LENGTH);
61
+ }
62
+ return deduped;
63
+ }
64
+ /**
65
+ * Error thrown when every provider in a fallback chain has failed. Carries
66
+ * the masked host list so callers can surface a useful operator-facing message
67
+ * without leaking secret query strings (api-key paths).
68
+ */
69
+ export class AllRpcsFailedError extends Error {
70
+ providers;
71
+ cause;
72
+ constructor(providers, cause) {
73
+ super(`All RPC providers in the fallback chain failed (providers=${providers.join(', ')})`);
74
+ this.name = 'AllRpcsFailedError';
75
+ this.providers = providers;
76
+ this.cause = cause;
77
+ }
78
+ }
79
+ /**
80
+ * Detect errors that viem's `fallback()` short-circuits on (via its
81
+ * `shouldThrow(err)` fast-exit) — `ExecutionRevertedError`,
82
+ * `TransactionRejectedRpcError`, `UserRejectedRequestError`,
83
+ * `WalletConnectSessionSettlementError`, and CAIP user-rejected (code
84
+ * `5000`). These are EVM- or wallet-level signals, NOT transport-level
85
+ * failures, so they must propagate unchanged. Wrapping them as
86
+ * `AllRpcsFailedError` would give the operator-app a false-positive
87
+ * "all RPCs failed" message when the actual problem is e.g. a contract
88
+ * revert on a view function.
89
+ *
90
+ * Mirrors viem's own predicate at
91
+ * `node_modules/viem/clients/transports/fallback.ts` (`shouldThrow`),
92
+ * dispatching by **numeric JSON-RPC code** (the path that catches real
93
+ * `RpcRequestError` instances coming out of the HTTP transport) plus the
94
+ * `ExecutionRevertedError.nodeMessage` regex (the path that catches reverts
95
+ * surfaced as plain `Error` with no numeric code). The cause-chain walk by
96
+ * class `name` remains as a third path for wallet-provider stacks that
97
+ * deliver proper class instances (and for already-normalised errors after
98
+ * viem's `buildRequest` re-wrap pass).
99
+ */
100
+ export function isViemShouldThrowError(err) {
101
+ // 1. Code-based dispatch — matches what viem's own `shouldThrow` does,
102
+ // so a raw `RpcRequestError { code: 3 | -32003 | 4001 | 7000 | 5000 }`
103
+ // from the HTTP transport is caught here regardless of class name.
104
+ // Codes are pulled from the viem error classes (no magic numbers) where
105
+ // available; 7000 and 5000 are inline because
106
+ // `WalletConnectSessionSettlementError` is not re-exported from the
107
+ // top-level `viem` package and 5000 is the CAIP user-rejected code
108
+ // viem hard-codes alongside it.
109
+ if (err instanceof Error && 'code' in err && typeof err.code === 'number') {
110
+ const code = err.code;
111
+ if (code === ExecutionRevertedError.code || // 3 — contract revert
112
+ code === TransactionRejectedRpcError.code || // -32003 — tx rejected
113
+ code === UserRejectedRequestError.code || // 4001 — user-rejected
114
+ code === 7000 || // WalletConnectSessionSettlementError
115
+ code === 5000 // CAIP user-rejected
116
+ )
117
+ return true;
118
+ // 2. nodeMessage regex — catches reverts that arrive as a plain `Error`
119
+ // (no numeric code, no recognised class name). Viem's own
120
+ // `shouldThrow` runs this check too.
121
+ if (ExecutionRevertedError.nodeMessage.test(err.message))
122
+ return true;
123
+ }
124
+ // 3. Cause-chain walk — viem wraps low-level RPC errors in higher-level
125
+ // error classes (e.g. `ContractFunctionExecutionError` →
126
+ // `RpcRequestError` → `ExecutionRevertedError`), and wallet providers
127
+ // can deliver proper class instances directly. Walk with cycle
128
+ // detection so a self-referential `.cause` cannot infinite-loop.
129
+ const seen = new Set();
130
+ let cursor = err;
131
+ while (cursor instanceof Error && !seen.has(cursor)) {
132
+ seen.add(cursor);
133
+ if (cursor.name === 'ExecutionRevertedError')
134
+ return true;
135
+ if (cursor.name === 'TransactionRejectedRpcError')
136
+ return true;
137
+ if (cursor.name === 'UserRejectedRequestError')
138
+ return true;
139
+ if (cursor.name === 'WalletConnectSessionSettlementError')
140
+ return true;
141
+ cursor = cursor.cause;
142
+ }
143
+ return false;
144
+ }
145
+ /**
146
+ * Mask an RPC URL down to its hostname for display / error reporting. Drops
147
+ * the path so api-key segments in the URL don't leak into logs.
148
+ */
149
+ export function maskRpcHost(url) {
150
+ try {
151
+ const parsed = new URL(url);
152
+ return parsed.hostname || '(unknown host)';
153
+ }
154
+ catch {
155
+ return '(invalid rpc url)';
156
+ }
157
+ }
158
+ /**
159
+ * Build a viem fallback transport over the given URLs. Returns a callable
160
+ * transport suitable for `createPublicClient({ transport })`.
161
+ *
162
+ * Errors that exhaust the chain are wrapped in `AllRpcsFailedError`.
163
+ */
164
+ export function buildFallbackTransport(urls, options = {}) {
165
+ const transports = urls.map((url) => http(url));
166
+ return buildFallbackTransport.buildFromTransports(transports, urls, options);
167
+ }
168
+ /**
169
+ * Internal helper exposed for tests: build a fallback transport from
170
+ * pre-constructed viem transports (e.g. `custom()` mocks) so tests can drive
171
+ * each slot deterministically without an actual HTTP fetch.
172
+ */
173
+ buildFallbackTransport.buildFromTransports = function buildFromTransports(transports, urls, options = {}) {
174
+ const maskedProviders = urls.map(maskRpcHost);
175
+ const inner = fallback(transports, {
176
+ rank: options.rank ?? false,
177
+ retryCount: 0,
178
+ });
179
+ // Wrap the transport so that the final exhausted-chain rejection surfaces
180
+ // as our structured `AllRpcsFailedError` (carrying the masked host list).
181
+ // We do the wrap at the transport-factory level rather than swapping the
182
+ // returned function's `request` so the FallbackTransport's typed shape
183
+ // (`onResponse`, `transports`, etc.) is preserved.
184
+ const wrapped = ((config) => {
185
+ const t = inner(config);
186
+ const originalRequest = t.request.bind(t);
187
+ t.request = (async (args) => {
188
+ try {
189
+ return await originalRequest(args);
190
+ }
191
+ catch (err) {
192
+ // viem's fallback() short-circuits on shouldThrow-class errors
193
+ // (contract revert, user-rejected, CAIP 5000) — those are
194
+ // EVM/wallet-level, not transport-level failures. Propagate them
195
+ // unchanged so callers (and the operator-app's `rpc_all_failed`
196
+ // state message) don't misread a single-slot revert as an
197
+ // exhausted-chain outage.
198
+ if (isViemShouldThrowError(err))
199
+ throw err;
200
+ // Otherwise: viem doesn't expose a distinct "all transports failed"
201
+ // error class — when fallback exhausts the chain it throws the last
202
+ // underlying error. Wrap so the caller gets a stable structural
203
+ // error carrying the masked provider list.
204
+ throw new AllRpcsFailedError(maskedProviders, err);
205
+ }
206
+ });
207
+ return t;
208
+ });
209
+ return wrapped;
210
+ };
211
+ /**
212
+ * Boot-log summary line for a fallback chain. Matches the canonical AC7
213
+ * format: `fallback chain (N providers) — primary=<host>`.
214
+ */
215
+ export function describeFallbackChain(urls) {
216
+ if (urls.length === 0)
217
+ return 'fallback chain (0 providers)';
218
+ return `fallback chain (${urls.length} providers) — primary=${maskRpcHost(urls[0])}`;
219
+ }
220
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/rpc/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,sBAAsB,EACtB,QAAQ,EACR,IAAI,EACJ,2BAA2B,EAC3B,wBAAwB,GAGzB,MAAM,MAAM,CAAC;AAEd;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAOtC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAiC,EACjC,UAA+B,EAAE;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0E;IAC1E,0EAA0E;IAC1E,yEAAyE;IACzE,uEAAuE;IACvE,mDAAmD;IACnD,MAAM,OAAO,GAAsB,CAAC,CAAC,MAAM,EAAE,EAAE;QAC7C,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACxB,MAAM,eAAe,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAA2C,EAAE,EAAE;YACjE,IAAI,CAAC;gBACH,OAAO,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,+DAA+D;gBAC/D,0DAA0D;gBAC1D,iEAAiE;gBACjE,gEAAgE;gBAChE,0DAA0D;gBAC1D,0BAA0B;gBAC1B,IAAI,sBAAsB,CAAC,GAAG,CAAC;oBAAE,MAAM,GAAG,CAAC;gBAC3C,oEAAoE;gBACpE,oEAAoE;gBACpE,gEAAgE;gBAChE,2CAA2C;gBAC3C,MAAM,IAAI,kBAAkB,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAqB,CAAC;QACvB,OAAO,CAAC,CAAC;IACX,CAAC,CAAsB,CAAC;IAExB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAuB;IAC3D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,8BAA8B,CAAC;IAC7D,OAAO,mBAAmB,IAAI,CAAC,MAAM,yBAAyB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC;AACxF,CAAC"}
@@ -503,7 +503,6 @@ function buildConsumerHarnesses(raw) {
503
503
  }
504
504
  export function buildConsumerConfig(opts) {
505
505
  const clientHome = defaultClientHome(opts.consumerHome);
506
- const solverNets = cloneSolverNetsForConsumer(opts.producerConfig.solverNets);
507
506
  const base = {
508
507
  network: opts.producerConfig.network ?? 'testnet',
509
508
  rpcUrl: opts.producerConfig.rpcUrl,
@@ -525,7 +524,8 @@ export function buildConsumerConfig(opts) {
525
524
  ...(opts.producerConfig.runtimeMode ? { runtimeMode: opts.producerConfig.runtimeMode } : {}),
526
525
  ...(opts.producerConfig.harness ? { harness: opts.producerConfig.harness } : {}),
527
526
  harnesses: buildConsumerHarnesses(opts.producerConfig.harnesses),
528
- ...(solverNets ? { solverNets } : {}),
527
+ // Issue #421: the legacy `solverNets` block is retired; consumer config
528
+ // inherits the producer's `joinedSolverNets` only.
529
529
  ...(opts.producerConfig.joinedSolverNets ? { joinedSolverNets: opts.producerConfig.joinedSolverNets } : {}),
530
530
  engine: {
531
531
  workingDirRoot: join(clientHome, 'engine', 'work'),
@@ -582,22 +582,6 @@ export function ensureConsumerSweEvaluatorState(opts) {
582
582
  }
583
583
  return consumerStatePath;
584
584
  }
585
- function cloneSolverNetsForConsumer(raw) {
586
- if (!raw || typeof raw !== 'object' || Array.isArray(raw))
587
- return undefined;
588
- const out = {};
589
- for (const [name, value] of Object.entries(raw)) {
590
- if (!value || typeof value !== 'object' || Array.isArray(value))
591
- continue;
592
- const entry = { ...value };
593
- const taskGenerator = entry.taskGenerator && typeof entry.taskGenerator === 'object' && !Array.isArray(entry.taskGenerator)
594
- ? { ...entry.taskGenerator, enabled: false }
595
- : { enabled: false };
596
- entry.taskGenerator = taskGenerator;
597
- out[name] = entry;
598
- }
599
- return Object.keys(out).length > 0 ? out : undefined;
600
- }
601
585
  function sourceName(value) {
602
586
  if (typeof value === 'string')
603
587
  return value;
@@ -628,16 +612,11 @@ function assertConsumerConfiguredForSwe(config, configPath) {
628
612
  const solverEntries = sweEntries.filter((entry) => (Array.isArray(entry.roles) && entry.roles.includes('solver')));
629
613
  const evaluatorEntries = sweEntries.filter((entry) => (Array.isArray(entry.roles) && entry.roles.includes('evaluator')));
630
614
  const joinedRuntimeEnabled = solverEntries.some((entry) => (!disablesSweRuntime(entry.disabledDefaultPlugins) || includesSweRuntimePlugin(entry.plugins)));
631
- const solverNets = config.solverNets && typeof config.solverNets === 'object' && !Array.isArray(config.solverNets)
632
- ? Object.values(config.solverNets)
633
- : [];
634
- const legacySweEntries = solverNets.filter((entry) => (entry.enabled !== false && entry.solverType === 'swe-rebench-v2.v1'));
635
- const legacyHasSolver = legacySweEntries.some((entry) => (!Array.isArray(entry.roles) || entry.roles.includes('solving')));
636
- const legacyHasEvaluator = legacySweEntries.some((entry) => (Array.isArray(entry.roles) && entry.roles.includes('evaluating')));
637
- const legacyRuntimeEnabled = legacySweEntries.some((entry) => includesSweRuntimePlugin(entry.plugins));
638
- const hasSolver = solverEntries.length > 0 || legacyHasSolver;
639
- const hasEvaluator = evaluatorEntries.length > 0 || legacyHasEvaluator;
640
- const runtimeEnabled = joinedRuntimeEnabled || legacyRuntimeEnabled;
615
+ // Issue #421: legacy `solverNets` is retired; SWE-rebench v2 SolverNet
616
+ // membership is asserted via joinedSolverNets exclusively.
617
+ const hasSolver = solverEntries.length > 0;
618
+ const hasEvaluator = evaluatorEntries.length > 0;
619
+ const runtimeEnabled = joinedRuntimeEnabled;
641
620
  if (!hasSolver || !hasEvaluator || !runtimeEnabled) {
642
621
  fail('consumer_swe_join_required', 'Consumer config is not joined to SWE-rebench v2 for the live donation gate.', {
643
622
  configPath,