@jinn-network/client 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -1
- package/dist/adapters/mech/adapter.d.ts +19 -1
- package/dist/adapters/mech/adapter.js +130 -14
- package/dist/adapters/mech/adapter.js.map +1 -1
- package/dist/adapters/mech/contracts.d.ts +22 -1
- package/dist/adapters/mech/contracts.js +34 -24
- package/dist/adapters/mech/contracts.js.map +1 -1
- package/dist/adapters/mech/safe.d.ts +1 -1
- package/dist/adapters/mech/safe.js +5 -3
- package/dist/adapters/mech/safe.js.map +1 -1
- package/dist/adapters/mech/types.d.ts +6 -1
- package/dist/adapters/mech/types.js.map +1 -1
- package/dist/agent/operator-claude.js +8 -0
- package/dist/agent/operator-claude.js.map +1 -1
- package/dist/api/activity-events-endpoint.d.ts +14 -0
- package/dist/api/activity-events-endpoint.js +59 -0
- package/dist/api/activity-events-endpoint.js.map +1 -0
- package/dist/api/bootstrap-endpoint.d.ts +1 -2
- package/dist/api/bootstrap-endpoint.js +42 -24
- package/dist/api/bootstrap-endpoint.js.map +1 -1
- package/dist/api/codex-doctor-endpoint.d.ts +22 -5
- package/dist/api/codex-doctor-endpoint.js +136 -17
- package/dist/api/codex-doctor-endpoint.js.map +1 -1
- package/dist/api/debug-report-endpoint.d.ts +27 -0
- package/dist/api/debug-report-endpoint.js +157 -0
- package/dist/api/debug-report-endpoint.js.map +1 -0
- package/dist/api/gather-status.d.ts +33 -0
- package/dist/api/gather-status.js +211 -26
- package/dist/api/gather-status.js.map +1 -1
- package/dist/api/hermes-doctor-endpoint.d.ts +15 -7
- package/dist/api/hermes-doctor-endpoint.js +56 -19
- package/dist/api/hermes-doctor-endpoint.js.map +1 -1
- package/dist/api/launcher-status.d.ts +4 -2
- package/dist/api/launcher-status.js +11 -10
- package/dist/api/launcher-status.js.map +1 -1
- package/dist/api/launcher-tasks.d.ts +1 -1
- package/dist/api/launcher-tasks.js +12 -8
- package/dist/api/launcher-tasks.js.map +1 -1
- package/dist/api/operator-artifacts-endpoint.js +73 -6
- package/dist/api/operator-artifacts-endpoint.js.map +1 -1
- package/dist/api/portfolio-v0-build.d.ts +7 -1
- package/dist/api/portfolio-v0-build.js +6 -2
- package/dist/api/portfolio-v0-build.js.map +1 -1
- package/dist/api/prediction-v1-build.d.ts +6 -0
- package/dist/api/prediction-v1-build.js +3 -1
- package/dist/api/prediction-v1-build.js.map +1 -1
- package/dist/api/server.d.ts +17 -0
- package/dist/api/server.js +40 -1
- package/dist/api/server.js.map +1 -1
- package/dist/api/setup-endpoints.d.ts +0 -9
- package/dist/api/setup-endpoints.js +11 -153
- package/dist/api/setup-endpoints.js.map +1 -1
- package/dist/api/solvernets-endpoints.js +30 -63
- package/dist/api/solvernets-endpoints.js.map +1 -1
- package/dist/api/status-build.d.ts +115 -2
- package/dist/api/status-build.js +47 -11
- package/dist/api/status-build.js.map +1 -1
- package/dist/api/status-harness-rollup.d.ts +35 -0
- package/dist/api/status-harness-rollup.js +45 -0
- package/dist/api/status-harness-rollup.js.map +1 -0
- package/dist/api/task-runs-build.d.ts +8 -0
- package/dist/api/task-runs-build.js +5 -1
- package/dist/api/task-runs-build.js.map +1 -1
- package/dist/build-info.json +4 -4
- package/dist/build-meta.json +1 -1
- package/dist/captures/live-publisher.js +24 -4
- package/dist/captures/live-publisher.js.map +1 -1
- package/dist/captures/publish.d.ts +1 -1
- package/dist/chain-read-errors.d.ts +12 -0
- package/dist/chain-read-errors.js +26 -1
- package/dist/chain-read-errors.js.map +1 -1
- package/dist/cli/commands/codedigest-revert-check.d.ts +33 -0
- package/dist/cli/commands/codedigest-revert-check.js +249 -0
- package/dist/cli/commands/codedigest-revert-check.js.map +1 -0
- package/dist/cli/commands/solver-nets.d.ts +1 -0
- package/dist/cli/commands/solver-nets.js +177 -22
- package/dist/cli/commands/solver-nets.js.map +1 -1
- package/dist/cli/commands/solver-plugins-block.d.ts +33 -0
- package/dist/cli/commands/solver-plugins-block.js +118 -0
- package/dist/cli/commands/solver-plugins-block.js.map +1 -0
- package/dist/cli/commands/solver-plugins-feedback.d.ts +72 -0
- package/dist/cli/commands/solver-plugins-feedback.js +262 -0
- package/dist/cli/commands/solver-plugins-feedback.js.map +1 -0
- package/dist/cli/commands/solver-plugins-read.d.ts +54 -0
- package/dist/cli/commands/solver-plugins-read.js +259 -0
- package/dist/cli/commands/solver-plugins-read.js.map +1 -0
- package/dist/cli/commands/solver-plugins.d.ts +35 -0
- package/dist/cli/commands/solver-plugins.js +399 -2
- package/dist/cli/commands/solver-plugins.js.map +1 -1
- package/dist/cli/commands/tasks.js +15 -2
- package/dist/cli/commands/tasks.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/task-native-readiness.d.ts +7 -0
- package/dist/cli/task-native-readiness.js +7 -5
- package/dist/cli/task-native-readiness.js.map +1 -1
- package/dist/config.d.ts +183 -232
- package/dist/config.js +232 -107
- package/dist/config.js.map +1 -1
- package/dist/daemon/ai-units-gate.d.ts +54 -0
- package/dist/daemon/ai-units-gate.js +82 -0
- package/dist/daemon/ai-units-gate.js.map +1 -0
- package/dist/daemon/creator.js +13 -0
- package/dist/daemon/creator.js.map +1 -1
- package/dist/daemon/daemon.d.ts +10 -0
- package/dist/daemon/daemon.js +203 -30
- package/dist/daemon/daemon.js.map +1 -1
- package/dist/daemon/gate-logger.d.ts +9 -0
- package/dist/daemon/gate-logger.js +2 -0
- package/dist/daemon/gate-logger.js.map +1 -0
- package/dist/daemon/jinn-claim-loop.js +22 -4
- package/dist/daemon/jinn-claim-loop.js.map +1 -1
- package/dist/daemon/readiness-gate.d.ts +1 -4
- package/dist/daemon/readiness-gate.js.map +1 -1
- package/dist/daemon/spend-cap-gate.d.ts +40 -0
- package/dist/daemon/spend-cap-gate.js +46 -0
- package/dist/daemon/spend-cap-gate.js.map +1 -0
- package/dist/dashboard/assets/index-CzKxvMcU.css +32 -0
- package/dist/dashboard/assets/index-yVemxHot.js +351 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/discovery/http.js +328 -1
- package/dist/discovery/http.js.map +1 -1
- package/dist/discovery/onchain.js +42 -4
- package/dist/discovery/onchain.js.map +1 -1
- package/dist/discovery/types.d.ts +129 -0
- package/dist/discovery/types.js.map +1 -1
- package/dist/discovery/with-fallback.js +27 -0
- package/dist/discovery/with-fallback.js.map +1 -1
- package/dist/earning/bootstrap.d.ts +8 -3
- package/dist/earning/bootstrap.js +36 -13
- package/dist/earning/bootstrap.js.map +1 -1
- package/dist/earning/safe-adapter.js +23 -11
- package/dist/earning/safe-adapter.js.map +1 -1
- package/dist/earning/types.d.ts +6 -6
- package/dist/earning/viem-clients.d.ts +11 -4
- package/dist/earning/viem-clients.js +14 -5
- package/dist/earning/viem-clients.js.map +1 -1
- package/dist/erc8004/identity.d.ts +19 -3
- package/dist/erc8004/identity.js +38 -11
- package/dist/erc8004/identity.js.map +1 -1
- package/dist/erc8004/index.d.ts +1 -1
- package/dist/erc8004/index.js.map +1 -1
- package/dist/events/types.d.ts +2 -2
- package/dist/harnesses/cost-estimates.d.ts +10 -31
- package/dist/harnesses/cost-estimates.js +11 -43
- package/dist/harnesses/cost-estimates.js.map +1 -1
- package/dist/harnesses/engine/engine.d.ts +28 -4
- package/dist/harnesses/engine/engine.js +103 -17
- package/dist/harnesses/engine/engine.js.map +1 -1
- package/dist/harnesses/engine/persistence.d.ts +21 -4
- package/dist/harnesses/engine/persistence.js +43 -6
- package/dist/harnesses/engine/persistence.js.map +1 -1
- package/dist/harnesses/engine/state.d.ts +9 -0
- package/dist/harnesses/engine/state.js +23 -10
- package/dist/harnesses/engine/state.js.map +1 -1
- package/dist/harnesses/impls/hermes-agent/bootstrap.js +4 -2
- package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -1
- package/dist/harnesses/impls/hermes-agent/config-builder.d.ts +1 -1
- package/dist/harnesses/impls/hermes-agent/config-builder.js +4 -2
- package/dist/harnesses/impls/hermes-agent/config-builder.js.map +1 -1
- package/dist/harnesses/impls/hermes-agent/harness.d.ts +14 -0
- package/dist/harnesses/impls/hermes-agent/harness.js +16 -2
- package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -1
- package/dist/harnesses/impls/hermes-agent/prompt.d.ts +6 -6
- package/dist/harnesses/impls/hermes-agent/prompt.js +6 -6
- package/dist/harnesses/impls/learner/adapters/claude-code.d.ts +17 -0
- package/dist/harnesses/impls/learner/adapters/claude-code.js +113 -14
- package/dist/harnesses/impls/learner/adapters/claude-code.js.map +1 -1
- package/dist/harnesses/impls/learner/adapters/codex-code.d.ts +9 -0
- package/dist/harnesses/impls/learner/adapters/codex-code.js +30 -8
- package/dist/harnesses/impls/learner/adapters/codex-code.js.map +1 -1
- package/dist/harnesses/impls/learner/harness.d.ts +24 -0
- package/dist/harnesses/impls/learner/harness.js +27 -3
- package/dist/harnesses/impls/learner/harness.js.map +1 -1
- package/dist/harnesses/impls/learner/harvest.d.ts +1 -1
- package/dist/harnesses/impls/learner/harvest.js +23 -5
- package/dist/harnesses/impls/learner/harvest.js.map +1 -1
- package/dist/harnesses/impls/learner/restoration-patch.d.ts +2 -2
- package/dist/harnesses/impls/learner/restoration-patch.js +25 -6
- package/dist/harnesses/impls/learner/restoration-patch.js.map +1 -1
- package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +21 -1
- package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
- package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +74 -5
- package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +103 -32
- package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
- package/dist/harnesses/readiness-registry.d.ts +7 -0
- package/dist/harnesses/readiness-registry.js +9 -0
- package/dist/harnesses/readiness-registry.js.map +1 -1
- package/dist/learner/revert-decision.d.ts +59 -0
- package/dist/learner/revert-decision.js +53 -0
- package/dist/learner/revert-decision.js.map +1 -0
- package/dist/learner/revert-stats.d.ts +24 -0
- package/dist/learner/revert-stats.js +44 -0
- package/dist/learner/revert-stats.js.map +1 -0
- package/dist/main.js +177 -104
- package/dist/main.js.map +1 -1
- package/dist/mcp/get-codedigest-reward.d.ts +13 -0
- package/dist/mcp/get-codedigest-reward.js +23 -0
- package/dist/mcp/get-codedigest-reward.js.map +1 -0
- package/dist/mcp/server.js +23 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/observability/debug-report-assemble.d.ts +43 -0
- package/dist/observability/debug-report-assemble.js +80 -0
- package/dist/observability/debug-report-assemble.js.map +1 -0
- package/dist/observability/emit-event.d.ts +9 -2
- package/dist/observability/emit-event.js +36 -2
- package/dist/observability/emit-event.js.map +1 -1
- package/dist/observability/file-logger.d.ts +69 -0
- package/dist/observability/file-logger.js +177 -0
- package/dist/observability/file-logger.js.map +1 -0
- package/dist/observability/redact-secrets.d.ts +65 -0
- package/dist/observability/redact-secrets.js +300 -0
- package/dist/observability/redact-secrets.js.map +1 -0
- package/dist/observability/tar.d.ts +30 -0
- package/dist/observability/tar.js +102 -0
- package/dist/observability/tar.js.map +1 -0
- package/dist/plugins/learner/skills/learn/consolidator-prompt.md +18 -1
- package/dist/plugins/learner/skills/learn/promoter-prompt.md +72 -1
- package/dist/preflight/pidfile-liveness.d.ts +44 -0
- package/dist/preflight/pidfile-liveness.js +103 -0
- package/dist/preflight/pidfile-liveness.js.map +1 -0
- package/dist/preflight/rpc-network.d.ts +40 -0
- package/dist/preflight/rpc-network.js +67 -1
- package/dist/preflight/rpc-network.js.map +1 -1
- package/dist/rpc/transport.d.ts +109 -0
- package/dist/rpc/transport.js +220 -0
- package/dist/rpc/transport.js.map +1 -0
- package/dist/scripts/donation-consumption-acceptance.js +7 -28
- package/dist/scripts/donation-consumption-acceptance.js.map +1 -1
- package/dist/scripts/swe-rebench-v2-pytest-missing.json +16 -0
- package/dist/solver-nets/prediction-operator-ux.d.ts +1 -2
- package/dist/solver-nets/prediction-operator-ux.js +56 -53
- package/dist/solver-nets/prediction-operator-ux.js.map +1 -1
- package/dist/solver-nets/registry.d.ts +19 -1
- package/dist/solver-nets/registry.js +37 -24
- package/dist/solver-nets/registry.js.map +1 -1
- package/dist/solver-types/_swe-rebench-v2-pool.d.ts +9 -2
- package/dist/solver-types/_swe-rebench-v2-pool.js +15 -20
- package/dist/solver-types/_swe-rebench-v2-pool.js.map +1 -1
- package/dist/solver-types/_swe-rebench-v2-state.d.ts +15 -0
- package/dist/solver-types/_swe-rebench-v2-state.js +19 -0
- package/dist/solver-types/_swe-rebench-v2-state.js.map +1 -1
- package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +116 -2
- package/dist/solver-types/_swe-rebench-v2-validated-pool.js +296 -21
- package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
- package/dist/solver-types/swe-rebench-v2-auto.d.ts +20 -11
- package/dist/solver-types/swe-rebench-v2-auto.js +64 -19
- package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
- package/dist/solver-types/swe-rebench-v2.d.ts +8 -2
- package/dist/solver-types/swe-rebench-v2.js +127 -11
- package/dist/solver-types/swe-rebench-v2.js.map +1 -1
- package/dist/solvernets/daemon-init.d.ts +1 -1
- package/dist/solvernets/daemon-init.js +19 -4
- package/dist/solvernets/daemon-init.js.map +1 -1
- package/dist/solvernets/launched-record-dispatcher.d.ts +4 -0
- package/dist/solvernets/launched-record-dispatcher.js +10 -4
- package/dist/solvernets/launched-record-dispatcher.js.map +1 -1
- package/dist/solvernets/registry-client-erc8004.js +11 -0
- package/dist/solvernets/registry-client-erc8004.js.map +1 -1
- package/dist/solvernets/store.d.ts +2 -2
- package/dist/spend/ai-units-config.d.ts +39 -0
- package/dist/spend/ai-units-config.js +28 -0
- package/dist/spend/ai-units-config.js.map +1 -0
- package/dist/spend/ai-units.d.ts +89 -0
- package/dist/spend/ai-units.js +156 -0
- package/dist/spend/ai-units.js.map +1 -0
- package/dist/spend/cost-surface-status.d.ts +12 -0
- package/dist/spend/cost-surface-status.js +24 -0
- package/dist/spend/cost-surface-status.js.map +1 -0
- package/dist/spend/credential.d.ts +39 -0
- package/dist/spend/credential.js +71 -0
- package/dist/spend/credential.js.map +1 -0
- package/dist/spend/daemon-config.d.ts +13 -0
- package/dist/spend/daemon-config.js +24 -0
- package/dist/spend/daemon-config.js.map +1 -0
- package/dist/spend/pricing.d.ts +16 -0
- package/dist/spend/pricing.js +26 -0
- package/dist/spend/pricing.js.map +1 -0
- package/dist/spend/record.d.ts +13 -0
- package/dist/spend/record.js +36 -0
- package/dist/spend/record.js.map +1 -0
- package/dist/spend/usage.d.ts +27 -0
- package/dist/spend/usage.js +113 -0
- package/dist/spend/usage.js.map +1 -0
- package/dist/store/store.d.ts +101 -0
- package/dist/store/store.js +304 -4
- package/dist/store/store.js.map +1 -1
- package/dist/trajectory/transcript-parsers/codex-session.d.ts +12 -6
- package/dist/trajectory/transcript-parsers/codex-session.js +114 -13
- package/dist/trajectory/transcript-parsers/codex-session.js.map +1 -1
- package/dist/trajectory/transcript-parsers/types.d.ts +8 -8
- package/dist/trajectory/transcript-session-dirs.d.ts +18 -0
- package/dist/trajectory/transcript-session-dirs.js +85 -0
- package/dist/trajectory/transcript-session-dirs.js.map +1 -0
- package/dist/trajectory/transcript-watcher.d.ts +20 -1
- package/dist/trajectory/transcript-watcher.js +108 -32
- package/dist/trajectory/transcript-watcher.js.map +1 -1
- package/dist/tx-retry.d.ts +25 -0
- package/dist/tx-retry.js +95 -7
- package/dist/tx-retry.js.map +1 -1
- package/dist/types/payloads/portfolio-v0.d.ts +3 -3
- package/dist/types/payloads/prediction-apy-v0.d.ts +3 -3
- package/dist/types/payloads/prediction-v0.d.ts +12 -12
- package/package.json +11 -3
- package/plugins/learner/skills/learn/consolidator-prompt.md +18 -1
- package/plugins/learner/skills/learn/promoter-prompt.md +72 -1
- package/plugins/swe-rebench-v2-diffmin/README.md +10 -9
- package/plugins/swe-rebench-v2-diffmin/jinn.plugin.json +1 -1
- package/plugins/swe-rebench-v2-diffmin/skills/diffmin/SKILL.md +15 -10
- package/plugins/swe-rebench-v2-diffmin/skills/test-map/SKILL.md +10 -12
- package/plugins/swe-rebench-v2-runtime/.claude-plugin/plugin.json +1 -1
- package/plugins/swe-rebench-v2-runtime/.codex-plugin/plugin.json +3 -3
- package/plugins/swe-rebench-v2-runtime/README.md +6 -6
- package/plugins/swe-rebench-v2-runtime/jinn.plugin.json +2 -3
- package/plugins/swe-rebench-v2-runtime/skills/task/SKILL.md +81 -0
- package/dist/dashboard/assets/index-BUlE8F3Y.js +0 -330
- package/dist/dashboard/assets/index-blqc7eqq.css +0 -32
- package/plugins/swe-rebench-v2-runtime/skills/orient/SKILL.md +0 -29
- package/plugins/swe-rebench-v2-runtime/skills/plan/SKILL.md +0 -53
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pidfile liveness preflight (issue #649). Classifies the recorded PID and
|
|
3
|
+
* returns a discriminated decision; side-effect-free so the caller owns the
|
|
4
|
+
* unlink (mirrors the idiom at `client/src/mcp/operator-server.ts:209-213`).
|
|
5
|
+
*
|
|
6
|
+
* Branches (load-bearing — see #649 acceptance criteria):
|
|
7
|
+
* - File missing → { decision: 'proceed' }
|
|
8
|
+
* - File malformed (NaN/empty) → { decision: 'unlink-stale', reason: 'malformed' }
|
|
9
|
+
* - process.kill(pid, 0) ESRCH → { decision: 'unlink-stale', reason: 'esrch' }
|
|
10
|
+
* - process.kill(pid, 0) ok → { decision: 'refuse', reason: 'alive' }
|
|
11
|
+
* - process.kill(pid, 0) EPERM → { decision: 'refuse', reason: 'eperm' }
|
|
12
|
+
* - any other errno → { decision: 'refuse', reason: 'unknown' }
|
|
13
|
+
*
|
|
14
|
+
* `.trim()` before `parseInt` is required: `main.ts` writes the PID with a
|
|
15
|
+
* trailing `\n` (see `client/src/main.ts` writeFileSync near the pidfile site).
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, readFileSync, unlinkSync } from 'node:fs';
|
|
18
|
+
import { emitEnvelope } from '../errors/envelope.js';
|
|
19
|
+
import { emitStructured } from '../events/emitter.js';
|
|
20
|
+
export function checkPidfileLiveness(input) {
|
|
21
|
+
const { pidPath } = input;
|
|
22
|
+
if (!existsSync(pidPath)) {
|
|
23
|
+
return { decision: 'proceed' };
|
|
24
|
+
}
|
|
25
|
+
let raw;
|
|
26
|
+
try {
|
|
27
|
+
raw = readFileSync(pidPath, 'utf-8');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Unreadable pidfile: treat as stale. If the caller's subsequent write also
|
|
31
|
+
// fails, that surfaces via main.ts's `writeFileSync`.
|
|
32
|
+
return { decision: 'unlink-stale', pid: null, pidfilePath: pidPath, reason: 'malformed' };
|
|
33
|
+
}
|
|
34
|
+
const parsed = parseInt(raw.trim(), 10);
|
|
35
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
36
|
+
return { decision: 'unlink-stale', pid: null, pidfilePath: pidPath, reason: 'malformed' };
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
process.kill(parsed, 0);
|
|
40
|
+
return { decision: 'refuse', pid: parsed, pidfilePath: pidPath, reason: 'alive' };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
const errno = err.code;
|
|
44
|
+
if (errno === 'ESRCH') {
|
|
45
|
+
return { decision: 'unlink-stale', pid: parsed, pidfilePath: pidPath, reason: 'esrch' };
|
|
46
|
+
}
|
|
47
|
+
if (errno === 'EPERM') {
|
|
48
|
+
return { decision: 'refuse', pid: parsed, pidfilePath: pidPath, reason: 'eperm' };
|
|
49
|
+
}
|
|
50
|
+
// Any other errno: conservative refuse rather than risk trampling a daemon
|
|
51
|
+
// we can't classify.
|
|
52
|
+
return { decision: 'refuse', pid: parsed, pidfilePath: pidPath, reason: 'unknown' };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Apply the pidfile-liveness gate at `jinn run` startup (#649). On `refuse`
|
|
57
|
+
* emits the `invalid_invocation` envelope and exits (does not return); on
|
|
58
|
+
* `unlink-stale` logs the cleanup, removes the stale pidfile, and returns;
|
|
59
|
+
* on `proceed` returns immediately. Callers MUST write the pidfile themselves
|
|
60
|
+
* after this returns — the helper deliberately stops short of the write so the
|
|
61
|
+
* "// DO NOT add store mutations above this line — see #649" invariant in
|
|
62
|
+
* main.ts stays visible at the call site.
|
|
63
|
+
*/
|
|
64
|
+
export function applyPidfileLivenessGate(pidPath, sinks = {}) {
|
|
65
|
+
const liveness = checkPidfileLiveness({ pidPath });
|
|
66
|
+
if (liveness.decision === 'refuse') {
|
|
67
|
+
emitEnvelope({
|
|
68
|
+
code: 'invalid_invocation',
|
|
69
|
+
message: `Another jinn daemon is already running (PID ${liveness.pid}).`,
|
|
70
|
+
hint: 'Run `jinn stop` to terminate it, or set JINN_EARNING_DIR to a different earning directory.',
|
|
71
|
+
exampleCli: 'jinn stop',
|
|
72
|
+
details: {
|
|
73
|
+
field: 'daemon_pidfile',
|
|
74
|
+
pid: liveness.pid,
|
|
75
|
+
pidfilePath: pidPath,
|
|
76
|
+
reason: liveness.reason,
|
|
77
|
+
},
|
|
78
|
+
}, sinks);
|
|
79
|
+
// emitEnvelope calls process.exit in production; the test sink may throw
|
|
80
|
+
// or no-op. Either way control does not fall through to the writeFileSync
|
|
81
|
+
// in the caller.
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (liveness.decision === 'unlink-stale') {
|
|
85
|
+
emitStructured({
|
|
86
|
+
kind: 'system',
|
|
87
|
+
message: `cleaning up stale pidfile (${liveness.reason})`,
|
|
88
|
+
details: {
|
|
89
|
+
phase: 'preflight',
|
|
90
|
+
pidfilePath: pidPath,
|
|
91
|
+
reason: liveness.reason,
|
|
92
|
+
pid: liveness.pid,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
try {
|
|
96
|
+
unlinkSync(pidPath);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* best-effort — the writeFileSync that follows surfaces any real problem */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=pidfile-liveness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pidfile-liveness.js","sourceRoot":"","sources":["../../src/preflight/pidfile-liveness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAsB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAqBtD,MAAM,UAAU,oBAAoB,CAClC,KAAgC;IAEhC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;QAC5E,sDAAsD;QACtD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAC5F,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC5C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,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B;gBACvB,GAAG,EAAE,QAAQ,CAAC,GAAG;gBACjB,WAAW,EAAE,OAAO;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;aACxB;SACF,EACD,KAAK,CACN,CAAC;QACF,yEAAyE;QACzE,0EAA0E;QAC1E,iBAAiB;QACjB,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACzC,cAAc,CAAC;YACb,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,8BAA8B,QAAQ,CAAC,MAAM,GAAG;YACzD,OAAO,EAAE;gBACP,KAAK,EAAE,WAAW;gBAClB,WAAW,EAAE,OAAO;gBACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,GAAG,EAAE,QAAQ,CAAC,GAAG;aAClB;SACF,CAAC,CAAC;QACH,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,CAAC,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;QAC9E,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -42,3 +42,43 @@ export declare function logRpcLocalDevToStderr(r: RpcNetworkPreflightOk, write?:
|
|
|
42
42
|
export declare function rpcHostForDisplay(rpcUrl: string): string;
|
|
43
43
|
export declare function checkRpcNetwork(config: Pick<JinnConfig, 'network' | 'rpcUrl'>): Promise<RpcNetworkPreflightResult>;
|
|
44
44
|
export declare function rpcNetworkFailureHint(result: RpcNetworkPreflightFail): string;
|
|
45
|
+
/** Layer label for log lines and AC7 summary formatting. */
|
|
46
|
+
export type ProbeLayer = 'L1' | 'L2';
|
|
47
|
+
export type ProbeOk = {
|
|
48
|
+
ok: true;
|
|
49
|
+
host: string;
|
|
50
|
+
latencyMs: number;
|
|
51
|
+
};
|
|
52
|
+
export type ProbeFail = {
|
|
53
|
+
ok: false;
|
|
54
|
+
host: string;
|
|
55
|
+
/** HTTP status when applicable (4xx / 5xx). */
|
|
56
|
+
code?: number;
|
|
57
|
+
/** Failure shape when no HTTP status is available. */
|
|
58
|
+
reason?: 'unreachable' | 'unknown';
|
|
59
|
+
message: string;
|
|
60
|
+
};
|
|
61
|
+
export type ProbeResult = ProbeOk | ProbeFail;
|
|
62
|
+
export interface ProbeFallbackChainOptions {
|
|
63
|
+
/** Logger for per-slot lines. Defaults to `console.error`. */
|
|
64
|
+
log?: (message: string) => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Probe each URL in a fallback chain with a per-slot `eth_blockNumber` call.
|
|
68
|
+
* Records ok/latency or a structured failure (HTTP status / unreachable).
|
|
69
|
+
*
|
|
70
|
+
* The probe is **log-only** — it never throws on per-slot failures. Startup
|
|
71
|
+
* gating remains the job of {@link checkRpcNetwork}, which fails loud on
|
|
72
|
+
* chain-id mismatch.
|
|
73
|
+
*
|
|
74
|
+
* Per AC9 (issue #592): emits one log line per slot
|
|
75
|
+
* `[rpc] <layer> <host> ok latency=Nms`
|
|
76
|
+
* `[rpc] <layer> <host> warn <http-status>` (e.g. 429, 503)
|
|
77
|
+
* `[rpc] <layer> <host> warn unreachable: <message>`
|
|
78
|
+
*/
|
|
79
|
+
export declare function probeFallbackChain(urls: readonly string[], network: ExpectedRpcNetwork, layer: ProbeLayer, options?: ProbeFallbackChainOptions): Promise<ProbeResult[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Boot-log summary line for a fallback chain, formatted per AC7:
|
|
82
|
+
* `[rpc] L2 transport: fallback chain (N providers) — primary=<host>`
|
|
83
|
+
*/
|
|
84
|
+
export declare function summarizeFallbackChain(layer: ProbeLayer, urls: readonly string[]): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createPublicClient, http } from 'viem';
|
|
1
|
+
import { createPublicClient, http, HttpRequestError } from 'viem';
|
|
2
2
|
import { base, baseSepolia } from 'viem/chains';
|
|
3
|
+
import { describeFallbackChain, maskRpcHost } from '../rpc/transport.js';
|
|
3
4
|
export function expectedChainIdForNetwork(network) {
|
|
4
5
|
return network === 'testnet' ? 84532 : 8453;
|
|
5
6
|
}
|
|
@@ -118,4 +119,69 @@ export function rpcNetworkFailureHint(result) {
|
|
|
118
119
|
}
|
|
119
120
|
return 'Set rpcUrl to a Base mainnet endpoint such as https://mainnet.base.org, or set BASE_RPC_URL.';
|
|
120
121
|
}
|
|
122
|
+
function classifyProbeError(host, err) {
|
|
123
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
124
|
+
if (err instanceof HttpRequestError && typeof err.status === 'number') {
|
|
125
|
+
return { ok: false, host, code: err.status, message };
|
|
126
|
+
}
|
|
127
|
+
// viem wraps HTTP errors inside other shapes; walk the cause chain.
|
|
128
|
+
let cur = err?.cause;
|
|
129
|
+
while (cur) {
|
|
130
|
+
if (cur instanceof HttpRequestError && typeof cur.status === 'number') {
|
|
131
|
+
return { ok: false, host, code: cur.status, message };
|
|
132
|
+
}
|
|
133
|
+
cur = cur.cause;
|
|
134
|
+
}
|
|
135
|
+
return { ok: false, host, reason: 'unreachable', message };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Probe each URL in a fallback chain with a per-slot `eth_blockNumber` call.
|
|
139
|
+
* Records ok/latency or a structured failure (HTTP status / unreachable).
|
|
140
|
+
*
|
|
141
|
+
* The probe is **log-only** — it never throws on per-slot failures. Startup
|
|
142
|
+
* gating remains the job of {@link checkRpcNetwork}, which fails loud on
|
|
143
|
+
* chain-id mismatch.
|
|
144
|
+
*
|
|
145
|
+
* Per AC9 (issue #592): emits one log line per slot
|
|
146
|
+
* `[rpc] <layer> <host> ok latency=Nms`
|
|
147
|
+
* `[rpc] <layer> <host> warn <http-status>` (e.g. 429, 503)
|
|
148
|
+
* `[rpc] <layer> <host> warn unreachable: <message>`
|
|
149
|
+
*/
|
|
150
|
+
export async function probeFallbackChain(urls, network, layer, options = {}) {
|
|
151
|
+
const log = options.log ?? ((m) => process.stderr.write(`${m}\n`));
|
|
152
|
+
// Chain is informational only — eth_blockNumber doesn't depend on chain
|
|
153
|
+
// identity. Both L1 and L2 layers reuse the same Base/Base-Sepolia pair
|
|
154
|
+
// since this is just used to satisfy viem's typing.
|
|
155
|
+
const chain = network === 'testnet' ? baseSepolia : base;
|
|
156
|
+
const results = [];
|
|
157
|
+
for (const url of urls) {
|
|
158
|
+
const host = maskRpcHost(url);
|
|
159
|
+
const client = createPublicClient({ chain, transport: http(url, { retryCount: 0 }) });
|
|
160
|
+
const t0 = performance.now();
|
|
161
|
+
try {
|
|
162
|
+
await client.getBlockNumber();
|
|
163
|
+
const latencyMs = Math.max(0, Math.round(performance.now() - t0));
|
|
164
|
+
log(`[rpc] ${layer} ${host} ok latency=${latencyMs}ms`);
|
|
165
|
+
results.push({ ok: true, host, latencyMs });
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
const failure = classifyProbeError(host, err);
|
|
169
|
+
if (failure.code !== undefined) {
|
|
170
|
+
log(`[rpc] ${layer} ${host} warn ${failure.code}`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
log(`[rpc] ${layer} ${host} warn unreachable: ${failure.message.split('\n')[0]}`);
|
|
174
|
+
}
|
|
175
|
+
results.push(failure);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return results;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Boot-log summary line for a fallback chain, formatted per AC7:
|
|
182
|
+
* `[rpc] L2 transport: fallback chain (N providers) — primary=<host>`
|
|
183
|
+
*/
|
|
184
|
+
export function summarizeFallbackChain(layer, urls) {
|
|
185
|
+
return `[rpc] ${layer} transport: ${describeFallbackChain(urls)}`;
|
|
186
|
+
}
|
|
121
187
|
//# sourceMappingURL=rpc-network.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-network.js","sourceRoot":"","sources":["../../src/preflight/rpc-network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc-network.js","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AAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAiB,EAAE,IAAuB;IAC/E,OAAO,SAAS,KAAK,eAAe,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;AACpE,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;IAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM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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
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const
|
|
635
|
-
const
|
|
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,
|