@sema-agent/core 7.69.1 → 7.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2477 -0
- package/dist/agents/agent-definition.d.ts +18 -0
- package/dist/agents/agent-definition.js +10 -0
- package/dist/agents/agent-transcript-tool.d.ts +2 -1
- package/dist/agents/agent-transcript-tool.js +2 -0
- package/dist/agents/cascade.d.ts +10 -0
- package/dist/agents/cascade.js +33 -5
- package/dist/agents/cc-peer-directory.d.ts +1 -1
- package/dist/agents/cc-peer-directory.js +2 -1
- package/dist/agents/child-model-seat.d.ts +1 -1
- package/dist/agents/composition-allowance.d.ts +63 -19
- package/dist/agents/composition-allowance.js +62 -45
- package/dist/agents/composition-placement.d.ts +22 -4
- package/dist/agents/composition-placement.js +10 -1
- package/dist/agents/cross-session-envelope.d.ts +4 -5
- package/dist/agents/cross-session-envelope.js +4 -5
- package/dist/agents/inherited-tool-pool.js +1 -2
- package/dist/agents/list-agents-tool.js +2 -1
- package/dist/agents/parked-resume-drive.d.ts +38 -0
- package/dist/agents/parked-resume-drive.js +57 -0
- package/dist/agents/peer-admission.js +4 -3
- package/dist/agents/peer-held-queue.d.ts +4 -2
- package/dist/agents/peer-held-queue.js +2 -1
- package/dist/agents/peer-session-drain.d.ts +2 -0
- package/dist/agents/peer-session-drain.js +49 -29
- package/dist/agents/repair-loop.js +15 -11
- package/dist/agents/retain-ledger.d.ts +71 -18
- package/dist/agents/retain-ledger.js +45 -13
- package/dist/agents/roster-store.d.ts +11 -3
- package/dist/agents/roster-store.js +6 -2
- package/dist/agents/send-message-tool.d.ts +2 -1
- package/dist/agents/send-message-tool.js +10 -7
- package/dist/agents/subagent.d.ts +24 -7
- package/dist/agents/subagent.js +256 -144
- package/dist/agents/tool-filter.js +1 -1
- package/dist/agents/verify.d.ts +4 -1
- package/dist/agents/verify.js +22 -16
- package/dist/agents/yield-adoption.js +2 -1
- package/dist/bench/metrics.js +2 -2
- package/dist/brain/anthropic.d.ts +2 -1
- package/dist/brain/anthropic.js +3 -3
- package/dist/brain/circuit-breaker.js +1 -1
- package/dist/brain/model-lane.d.ts +2 -1
- package/dist/brain/model-lane.js +22 -9
- package/dist/brain/open-responses.d.ts +77 -1
- package/dist/brain/open-responses.js +1 -1
- package/dist/brain/openai.d.ts +2 -1
- package/dist/brain/openai.js +3 -3
- package/dist/brain/reasoning.d.ts +8 -1
- package/dist/brain/reasoning.js +3 -0
- package/dist/brain/reference-model-traits.d.ts +13 -12
- package/dist/brain/reference-model-traits.js +11 -10
- package/dist/brain/request-route.d.ts +1 -1
- package/dist/brain/request-route.js +2 -2
- package/dist/brain/route-adjudicator.d.ts +72 -2
- package/dist/brain/route-adjudicator.js +210 -69
- package/dist/brain/route-conformance.js +35 -0
- package/dist/brain/routing.js +2 -2
- package/dist/brain/spend-meter.d.ts +56 -0
- package/dist/brain/spend-meter.js +263 -0
- package/dist/brain/stream-shared.d.ts +1 -1
- package/dist/brain/stream-shared.js +3 -1
- package/dist/core/a2a-bound-grant.d.ts +110 -0
- package/dist/core/a2a-bound-grant.js +83 -0
- package/dist/core/a2a-task-state.d.ts +153 -51
- package/dist/core/a2a-task-state.js +85 -45
- package/dist/core/a2a.d.ts +62 -14
- package/dist/core/a2a.js +298 -57
- package/dist/core/agent-config-dir.d.ts +53 -6
- package/dist/core/agent-config-dir.js +59 -6
- package/dist/core/agent-definition.d.ts +1 -1
- package/dist/core/agent-state.d.ts +10 -1
- package/dist/core/agent-state.js +11 -4
- package/dist/core/allow-entry.d.ts +80 -42
- package/dist/core/allow-entry.js +119 -61
- package/dist/core/allow-rule-shadow.d.ts +25 -3
- package/dist/core/allow-rule-shadow.js +7 -0
- package/dist/core/approval-object.js +2 -2
- package/dist/core/artifact-host.d.ts +109 -6
- package/dist/core/artifact-host.js +68 -0
- package/dist/core/ask-headline.d.ts +10 -9
- package/dist/core/ask-headline.js +9 -3
- package/dist/core/ask-origin.d.ts +88 -28
- package/dist/core/ask-origin.js +73 -43
- package/dist/core/ask-question.d.ts +76 -38
- package/dist/core/ask-question.js +151 -22
- package/dist/core/ask-unresolvable-notice.d.ts +66 -10
- package/dist/core/ask-unresolvable-notice.js +38 -14
- package/dist/core/auto-compaction.d.ts +3 -49
- package/dist/core/auto-compaction.js +3 -8
- package/dist/core/auto-mode-directive.d.ts +17 -5
- package/dist/core/auto-mode-directive.js +12 -3
- package/dist/core/auto-mode.d.ts +34 -5
- package/dist/core/auto-mode.js +43 -5
- package/dist/core/background-agent-store.d.ts +100 -11
- package/dist/core/background-agent-store.js +64 -6
- package/dist/core/background-shell.d.ts +9 -0
- package/dist/core/background-shell.js +10 -0
- package/dist/core/caller-text.d.ts +2 -2
- package/dist/core/caller-tool-name.d.ts +6 -0
- package/dist/core/caller-tool-name.js +2 -1
- package/dist/core/checkpoint-features.d.ts +38 -422
- package/dist/core/checkpoint-features.js +44 -0
- package/dist/core/checkpoint-queries.d.ts +14 -3
- package/dist/core/checkpoint-queries.js +9 -4
- package/dist/core/checkpoint-requirements.d.ts +69 -2
- package/dist/core/checkpoint-requirements.js +12 -2
- package/dist/core/checkpoint-row-verdict.d.ts +70 -17
- package/dist/core/checkpoint-row-verdict.js +75 -29
- package/dist/core/checkpoint-store.d.ts +75 -69
- package/dist/core/checkpoint-store.js +24 -22
- package/dist/core/classifier-unavailable-arm.d.ts +6 -1
- package/dist/core/classifier-unavailable-arm.js +8 -5
- package/dist/core/config-refusal-codes.d.ts +7 -5
- package/dist/core/config-refusal-codes.js +7 -2
- package/dist/core/config-refusal-input.d.ts +46 -0
- package/dist/core/config-refusal-input.js +62 -0
- package/dist/core/context-edit.d.ts +18 -1
- package/dist/core/context-edit.js +13 -2
- package/dist/core/context-guard.d.ts +60 -13
- package/dist/core/context-guard.js +77 -35
- package/dist/core/context-settings.d.ts +2 -1
- package/dist/core/context-settings.js +10 -6
- package/dist/core/corrupt-session-form.d.ts +97 -0
- package/dist/core/corrupt-session-form.js +54 -0
- package/dist/core/cross-boundary-taint.d.ts +3 -3
- package/dist/core/data-root.d.ts +32 -0
- package/dist/core/data-root.js +86 -0
- package/dist/core/decision-receipt.d.ts +2 -0
- package/dist/core/decision-receipt.js +3 -2
- package/dist/core/declaration-words.d.ts +37 -0
- package/dist/core/declaration-words.js +21 -0
- package/dist/core/delegation-frames.d.ts +76 -35
- package/dist/core/delegation-frames.js +21 -1
- package/dist/core/durable-sync.d.ts +9 -0
- package/dist/core/durable-sync.js +37 -0
- package/dist/core/engine-capabilities.d.ts +110 -3
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +259 -139
- package/dist/core/engine-notice.js +13 -19
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +22 -0
- package/dist/core/entries-not-applied.js +26 -0
- package/dist/core/exec-gate.d.ts +8 -1
- package/dist/core/exec-gate.js +24 -9
- package/dist/core/exec-outcome.d.ts +102 -0
- package/dist/core/exec-outcome.js +79 -0
- package/dist/core/existing-target.d.ts +45 -0
- package/dist/core/existing-target.js +54 -8
- package/dist/core/fast-tier-door.d.ts +2 -2
- package/dist/core/fast-tier-door.js +3 -3
- package/dist/core/file-history-store.d.ts +138 -19
- package/dist/core/file-history-store.js +124 -33
- package/dist/core/gate-fold.js +8 -1
- package/dist/core/gate-lanes.js +65 -38
- package/dist/core/gate-outcome.d.ts +3 -1
- package/dist/core/gate-outcome.js +7 -1
- package/dist/core/git-worktree-env.d.ts +25 -5
- package/dist/core/git-worktree-env.js +38 -13
- package/dist/core/governance-codes.d.ts +179 -40
- package/dist/core/governance-codes.js +450 -43
- package/dist/core/hands-band.d.ts +1 -1
- package/dist/core/hooks.d.ts +75 -13
- package/dist/core/hooks.js +4 -0
- package/dist/core/host-floor.d.ts +1 -1
- package/dist/core/host-floor.js +1 -1
- package/dist/core/identity-rekey.d.ts +2 -1
- package/dist/core/identity-rekey.js +5 -5
- package/dist/core/image-admission.d.ts +2 -2
- package/dist/core/image-admission.js +1 -1
- package/dist/core/isolation-scope.d.ts +42 -17
- package/dist/core/isolation-scope.js +12 -4
- package/dist/core/leg-identity.d.ts +17 -2
- package/dist/core/leg-identity.js +6 -1
- package/dist/core/locked-config.d.ts +86 -16
- package/dist/core/locked-config.js +100 -34
- package/dist/core/mailbox-store.d.ts +4 -0
- package/dist/core/mailbox-store.js +7 -0
- package/dist/core/mcp-failure.d.ts +13 -4
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-injection-drop.d.ts +30 -13
- package/dist/core/mcp-injection-drop.js +25 -7
- package/dist/core/mcp-leg-wait.d.ts +88 -0
- package/dist/core/mcp-leg-wait.js +100 -0
- package/dist/core/mcp-name-judge.js +1 -2
- package/dist/core/mcp-probe.d.ts +30 -1
- package/dist/core/mcp-probe.js +5 -3
- package/dist/core/mcp-read-bound.d.ts +51 -0
- package/dist/core/mcp-read-bound.js +49 -0
- package/dist/core/mcp-server-link.js +4 -3
- package/dist/core/mcp-server-spec.d.ts +97 -26
- package/dist/core/mcp-server-spec.js +51 -19
- package/dist/core/mcp-server-unavailable-notice.d.ts +15 -6
- package/dist/core/mcp-server-unavailable-notice.js +12 -11
- package/dist/core/mcp-stderr-lines.d.ts +69 -0
- package/dist/core/mcp-stderr-lines.js +333 -0
- package/dist/core/mcp.d.ts +32 -9
- package/dist/core/mcp.js +187 -44
- package/dist/core/member-outcome.d.ts +281 -0
- package/dist/core/member-outcome.js +293 -0
- package/dist/core/memory-engine/consolidation.js +3 -3
- package/dist/core/memory-engine/content-origin.js +5 -4
- package/dist/core/memory-engine/control-objects.js +6 -4
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +12 -5
- package/dist/core/memory-engine/dual-root.js +13 -7
- package/dist/core/memory-engine/engine.d.ts +27 -31
- package/dist/core/memory-engine/engine.js +103 -61
- package/dist/core/memory-engine/file-backend.d.ts +16 -3
- package/dist/core/memory-engine/file-backend.js +15 -20
- package/dist/core/memory-engine/index-copies.d.ts +8 -6
- package/dist/core/memory-engine/index-copies.js +2 -1
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +3 -2
- package/dist/core/memory-engine/layout.d.ts +166 -23
- package/dist/core/memory-engine/layout.js +235 -40
- package/dist/core/memory-engine/memory-backend-contract.js +20 -20
- package/dist/core/memory-engine/memory-deployment.d.ts +29 -16
- package/dist/core/memory-engine/memory-deployment.js +30 -20
- package/dist/core/memory-engine/mount-failed-notice.d.ts +64 -0
- package/dist/core/memory-engine/mount-failed-notice.js +50 -2
- package/dist/core/memory-engine/projection-ledger.d.ts +48 -0
- package/dist/core/memory-engine/projection-ledger.js +130 -0
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.js +1 -2
- package/dist/core/memory-engine/types.d.ts +10 -4
- package/dist/core/memory.js +3 -5
- package/dist/core/mode-policy.d.ts +82 -16
- package/dist/core/mode-policy.js +63 -29
- package/dist/core/model-seat.d.ts +13 -1
- package/dist/core/mods/classic-events.d.ts +13 -1
- package/dist/core/mods/dollar.js +2 -1
- package/dist/core/mods/extension-call.d.ts +3 -0
- package/dist/core/mods/extension-call.js +3 -0
- package/dist/core/mods/kernel/dispatch.d.ts +4 -0
- package/dist/core/mods/kernel/dispatch.js +3 -3
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +4 -4
- package/dist/core/mods/message-display.d.ts +6 -3
- package/dist/core/mods/message-display.js +13 -5
- package/dist/core/mods/stations.d.ts +8 -1
- package/dist/core/mods/stations.js +5 -3
- package/dist/core/mods/teammate-stations.d.ts +75 -0
- package/dist/core/mods/teammate-stations.js +108 -0
- package/dist/core/mounted-mcp.js +1 -2
- package/dist/core/namespaced-rule-name.d.ts +1 -1
- package/dist/core/namespaced-rule-name.js +1 -1
- package/dist/core/notice-fact.d.ts +28 -0
- package/dist/core/notice-fact.js +25 -0
- package/dist/core/owner-identity.d.ts +8 -3
- package/dist/core/owner-identity.js +6 -3
- package/dist/core/parent-spec-seat.d.ts +16 -6
- package/dist/core/parent-spec-seat.js +28 -6
- package/dist/core/park-resumability.d.ts +10 -5
- package/dist/core/park-resumability.js +3 -0
- package/dist/core/park-selfcheck.js +2 -1
- package/dist/core/peer-seat.d.ts +1 -2
- package/dist/core/permission-rule-consent.d.ts +50 -1
- package/dist/core/permission-rule-consent.js +121 -14
- package/dist/core/permission-rule-model.d.ts +135 -39
- package/dist/core/permission-rule-model.js +151 -24
- package/dist/core/permission-rule-org.d.ts +13 -0
- package/dist/core/permission-rule-org.js +8 -0
- package/dist/core/permission-rule-provider.d.ts +107 -7
- package/dist/core/permission-rule-provider.js +434 -29
- package/dist/core/permission-rule-session.js +3 -1
- package/dist/core/permission-rule-store.d.ts +19 -2
- package/dist/core/permission-rule-store.js +29 -10
- package/dist/core/permission-rule-sync.js +5 -2
- package/dist/core/permission-rules.js +8 -3
- package/dist/core/persisted-rule-arms.d.ts +10 -4
- package/dist/core/persisted-rule-arms.js +16 -11
- package/dist/core/persisted-rule-buckets.d.ts +66 -0
- package/dist/core/persisted-rule-buckets.js +57 -0
- package/dist/core/plan-review-facts.d.ts +33 -0
- package/dist/core/plan-review-facts.js +25 -0
- package/dist/core/prefix-declaration.d.ts +50 -0
- package/dist/core/prefix-declaration.js +13 -0
- package/dist/core/present-plan-tool.d.ts +13 -3
- package/dist/core/present-plan-tool.js +14 -3
- package/dist/core/pricing.d.ts +5 -1
- package/dist/core/pricing.js +8 -5
- package/dist/core/principal-name.d.ts +55 -5
- package/dist/core/principal-name.js +57 -16
- package/dist/core/process-identity.d.ts +11 -7
- package/dist/core/process-identity.js +26 -36
- package/dist/core/process-table.d.ts +67 -0
- package/dist/core/process-table.js +177 -0
- package/dist/core/protocol-http-auth.d.ts +75 -12
- package/dist/core/protocol-http-auth.js +223 -26
- package/dist/core/protocol-revocation.d.ts +29 -10
- package/dist/core/protocol-revocation.js +9 -5
- package/dist/core/read-only-shell.d.ts +1 -1
- package/dist/core/read-only-shell.js +1 -1
- package/dist/core/read-root-grant-screen.d.ts +17 -6
- package/dist/core/read-root-grant-screen.js +15 -5
- package/dist/core/reminder-mint.d.ts +6 -0
- package/dist/core/reminder-mint.js +13 -0
- package/dist/core/remote-env.d.ts +111 -3
- package/dist/core/remote-env.js +20 -0
- package/dist/core/request-copy-projection.js +97 -18
- package/dist/core/resource-limit-reasons.d.ts +52 -0
- package/dist/core/resource-limit-reasons.js +6 -0
- package/dist/core/resume-at-refusal.d.ts +10 -6
- package/dist/core/resume-at-refusal.js +2 -2
- package/dist/core/resume-config-judge.d.ts +3 -2
- package/dist/core/resume-config-judge.js +2 -1
- package/dist/core/resume-startup-cause.d.ts +18 -4
- package/dist/core/resume-startup-cause.js +30 -6
- package/dist/core/retention.d.ts +12 -2
- package/dist/core/retention.js +6 -1
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +12 -0
- package/dist/core/rewind-conversation.d.ts +54 -0
- package/dist/core/rewind-conversation.js +1 -0
- package/dist/core/roles.d.ts +61 -3
- package/dist/core/roles.js +81 -28
- package/dist/core/rule-lane-reads.d.ts +2 -1
- package/dist/core/rule-lane-reads.js +54 -29
- package/dist/core/rule-offer-read.js +5 -2
- package/dist/core/rule-owner.d.ts +6 -1
- package/dist/core/rule-owner.js +8 -2
- package/dist/core/rule-store-fault.d.ts +4 -2
- package/dist/core/rule-store-fault.js +4 -1
- package/dist/core/runner/advertised-writable-dirs.d.ts +17 -0
- package/dist/core/runner/advertised-writable-dirs.js +15 -9
- package/dist/core/runner/announce-once-ledger.js +12 -11
- package/dist/core/runner/assemble-result.d.ts +15 -6
- package/dist/core/runner/assemble-result.js +12 -5
- package/dist/core/runner/auto-strip-notice.d.ts +1 -1
- package/dist/core/runner/branch-window.d.ts +25 -2
- package/dist/core/runner/branch-window.js +47 -11
- package/dist/core/runner/chain-refusal-throw.d.ts +19 -0
- package/dist/core/runner/chain-refusal-throw.js +30 -0
- package/dist/core/runner/changes-git.d.ts +21 -0
- package/dist/core/runner/changes-git.js +291 -0
- package/dist/core/runner/changes-history.d.ts +80 -0
- package/dist/core/runner/changes-history.js +351 -0
- package/dist/core/runner/checkpoint-scope.d.ts +16 -8
- package/dist/core/runner/checkpoint-scope.js +6 -4
- package/dist/core/runner/child-tree.d.ts +31 -20
- package/dist/core/runner/child-tree.js +24 -9
- package/dist/core/runner/classifier-ladder.d.ts +4 -2
- package/dist/core/runner/classifier-ladder.js +14 -12
- package/dist/core/runner/clock-and-limits.d.ts +0 -3
- package/dist/core/runner/clock-and-limits.js +1 -2
- package/dist/core/runner/compact-session.js +19 -50
- package/dist/core/runner/compaction-restate.js +2 -1
- package/dist/core/runner/constraint-layers.d.ts +101 -0
- package/dist/core/runner/constraint-layers.js +96 -0
- package/dist/core/runner/construction-doors.js +2 -0
- package/dist/core/runner/content-ask-bindings.d.ts +3 -3
- package/dist/core/runner/continuation-gate.d.ts +8 -4
- package/dist/core/runner/continuation-gate.js +2 -0
- package/dist/core/runner/continues-from.d.ts +7 -0
- package/dist/core/runner/continues-from.js +9 -0
- package/dist/core/runner/contracts.d.ts +144 -44
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/denial-limit-arms.js +3 -4
- package/dist/core/runner/earlier-grammar-notice.js +5 -3
- package/dist/core/runner/env-capability-census.js +2 -1
- package/dist/core/runner/file-history-restore.d.ts +35 -9
- package/dist/core/runner/file-history-restore.js +36 -9
- package/dist/core/runner/finish-reason-seat.js +13 -4
- package/dist/core/runner/gate-exit.d.ts +8 -0
- package/dist/core/runner/gate-exit.js +36 -11
- package/dist/core/runner/halt-attribution.js +1 -1
- package/dist/core/runner/initial-run-state.d.ts +1 -1
- package/dist/core/runner/initial-run-state.js +2 -2
- package/dist/core/runner/left-as-is-seat.js +1 -1
- package/dist/core/runner/mcp-redial.d.ts +15 -4
- package/dist/core/runner/mcp-redial.js +53 -6
- package/dist/core/runner/memory-capture-optout.d.ts +7 -11
- package/dist/core/runner/memory-capture-optout.js +7 -4
- package/dist/core/runner/memory-phase-refusals.d.ts +19 -0
- package/dist/core/runner/memory-phase-refusals.js +18 -0
- package/dist/core/runner/messages-omitted-seat.d.ts +24 -1
- package/dist/core/runner/messages-omitted-seat.js +30 -9
- package/dist/core/runner/model-fallback-seat.d.ts +18 -5
- package/dist/core/runner/model-fallback-seat.js +29 -24
- package/dist/core/runner/model-lane-seat.d.ts +23 -1
- package/dist/core/runner/model-lane-seat.js +20 -2
- package/dist/core/runner/nested-memory-lane.d.ts +64 -57
- package/dist/core/runner/nested-memory-lane.js +310 -110
- package/dist/core/runner/park-commit.d.ts +26 -5
- package/dist/core/runner/park-commit.js +19 -8
- package/dist/core/runner/permission-rule-lanes.d.ts +5 -0
- package/dist/core/runner/permission-rule-lanes.js +44 -11
- package/dist/core/runner/person-path-rows.d.ts +124 -21
- package/dist/core/runner/person-path-rows.js +179 -20
- package/dist/core/runner/prefix-ledger.d.ts +57 -3
- package/dist/core/runner/prefix-ledger.js +98 -8
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +2 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +13 -65
- package/dist/core/runner/prepare-advisor.js +2 -1
- package/dist/core/runner/prepare-artifact.d.ts +4 -1
- package/dist/core/runner/prepare-artifact.js +3 -3
- package/dist/core/runner/prepare-ask-lane.d.ts +4 -0
- package/dist/core/runner/prepare-ask-lane.js +7 -5
- package/dist/core/runner/prepare-boundary-parks.js +9 -3
- package/dist/core/runner/prepare-caps-and-workflow.js +37 -25
- package/dist/core/runner/prepare-config-doors.d.ts +13 -14
- package/dist/core/runner/prepare-config-doors.js +121 -122
- package/dist/core/runner/prepare-context-lane.d.ts +32 -11
- package/dist/core/runner/prepare-context-lane.js +77 -48
- package/dist/core/runner/prepare-defer-classify.d.ts +12 -0
- package/dist/core/runner/prepare-defer-classify.js +29 -7
- package/dist/core/runner/prepare-delegation-surface.d.ts +2 -0
- package/dist/core/runner/prepare-delegation-surface.js +8 -4
- package/dist/core/runner/prepare-execution-env.d.ts +3 -0
- package/dist/core/runner/prepare-execution-env.js +10 -5
- package/dist/core/runner/prepare-file-history.js +4 -1
- package/dist/core/runner/prepare-gate-stations.d.ts +10 -0
- package/dist/core/runner/prepare-gate-stations.js +15 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +28 -7
- package/dist/core/runner/prepare-hands-readface.js +83 -23
- package/dist/core/runner/prepare-inherited-gate.d.ts +20 -11
- package/dist/core/runner/prepare-inherited-gate.js +27 -16
- package/dist/core/runner/prepare-memory-engine-session.js +4 -2
- package/dist/core/runner/prepare-memory.d.ts +8 -1
- package/dist/core/runner/prepare-memory.js +37 -33
- package/dist/core/runner/prepare-offload-wrappers.d.ts +7 -7
- package/dist/core/runner/prepare-offload-wrappers.js +26 -17
- package/dist/core/runner/prepare-park-ask.d.ts +8 -11
- package/dist/core/runner/prepare-park-ask.js +11 -8
- package/dist/core/runner/prepare-policy-chain.d.ts +24 -1
- package/dist/core/runner/prepare-policy-chain.js +53 -28
- package/dist/core/runner/prepare-project-context.d.ts +4 -0
- package/dist/core/runner/prepare-project-context.js +9 -8
- package/dist/core/runner/prepare-prompt-assembly.js +2 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +2 -2
- package/dist/core/runner/prepare-protocol-tools.js +44 -24
- package/dist/core/runner/prepare-question-face.d.ts +4 -9
- package/dist/core/runner/prepare-question-face.js +8 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +7 -1
- package/dist/core/runner/prepare-suspend-saga.js +10 -4
- package/dist/core/runner/prepare-task.d.ts +2 -2
- package/dist/core/runner/prepare-task.js +141 -57
- package/dist/core/runner/prepare-tool-disclosure-mount.js +10 -5
- package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
- package/dist/core/runner/prepare-turn-wiring.js +10 -8
- package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -19
- package/dist/core/runner/prepare-wiring-manifest.js +17 -35
- package/dist/core/runner/prepare-workspace-restore.d.ts +4 -11
- package/dist/core/runner/prepare-workspace-restore.js +1 -14
- package/dist/core/runner/read-root-grant.d.ts +48 -13
- package/dist/core/runner/read-root-grant.js +53 -19
- package/dist/core/runner/read-session-changes.d.ts +9 -0
- package/dist/core/runner/read-session-changes.js +192 -0
- package/dist/core/runner/remote-env-retry.d.ts +4 -4
- package/dist/core/runner/resume-admission.d.ts +11 -7
- package/dist/core/runner/resume-admission.js +25 -15
- package/dist/core/runner/resume-apply.js +2 -1
- package/dist/core/runner/resume-checkpoint-screen.d.ts +7 -2
- package/dist/core/runner/resume-checkpoint-screen.js +32 -17
- package/dist/core/runner/resume-internals-and-config.d.ts +3 -0
- package/dist/core/runner/resume-internals-and-config.js +10 -7
- package/dist/core/runner/resume-policy-outcome.d.ts +4 -3
- package/dist/core/runner/resume-policy-outcome.js +2 -2
- package/dist/core/runner/retired-name-policy.d.ts +15 -0
- package/dist/core/runner/retired-name-policy.js +37 -0
- package/dist/core/runner/retired-runner-deps.js +3 -1
- package/dist/core/runner/rewind-conversation.d.ts +10 -0
- package/dist/core/runner/rewind-conversation.js +100 -0
- package/dist/core/runner/rewind-files.js +37 -20
- package/dist/core/runner/rewind-target.d.ts +28 -0
- package/dist/core/runner/rewind-target.js +58 -0
- package/dist/core/runner/role-resolution-table.d.ts +3 -16
- package/dist/core/runner/role-resolution-table.js +1 -3
- package/dist/core/runner/role-seat-defaulted.d.ts +14 -5
- package/dist/core/runner/role-seat-defaulted.js +17 -13
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -6
- package/dist/core/runner/rule-store-unreadable-notice.js +6 -4
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-harness-handlers.js +43 -11
- package/dist/core/runner/run-identity-wiring.d.ts +2 -0
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +19 -28
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/run-settle-and-teardown.js +32 -17
- package/dist/core/runner/run-stop-and-final-verify.js +66 -69
- package/dist/core/runner/run-telemetry-and-budget-seats.js +14 -8
- package/dist/core/runner/run-turn-boundary.js +3 -6
- package/dist/core/runner/runtask.d.ts +22 -16
- package/dist/core/runner/runtask.js +18 -8
- package/dist/core/runner/sandbox-network-seat.js +1 -1
- package/dist/core/runner/seat-model-doors.d.ts +6 -5
- package/dist/core/runner/seat-model-doors.js +4 -3
- package/dist/core/runner/session-file-state-replay.d.ts +47 -8
- package/dist/core/runner/session-file-state-replay.js +97 -11
- package/dist/core/runner/session-files-open.d.ts +64 -0
- package/dist/core/runner/session-files-open.js +33 -0
- package/dist/core/runner/session-read-file-states.d.ts +37 -41
- package/dist/core/runner/session-read-file-states.js +14 -6
- package/dist/core/runner/session-rule-policy.d.ts +5 -0
- package/dist/core/runner/session-rule-policy.js +16 -9
- package/dist/core/runner/session-verb-doors.d.ts +41 -4
- package/dist/core/runner/session-verb-doors.js +66 -11
- package/dist/core/runner/shared-read-classifier.d.ts +14 -3
- package/dist/core/runner/shared-read-classifier.js +14 -6
- package/dist/core/runner/shell-env-withheld.d.ts +4 -2
- package/dist/core/runner/shell-env-withheld.js +3 -2
- package/dist/core/runner/side-call-account.d.ts +47 -5
- package/dist/core/runner/side-call-account.js +37 -3
- package/dist/core/runner/skipped-rules-notice.d.ts +5 -5
- package/dist/core/runner/skipped-rules-notice.js +3 -3
- package/dist/core/runner/stream-settle-backstop.js +5 -4
- package/dist/core/runner/sub-agent-deny-lists.d.ts +26 -7
- package/dist/core/runner/sub-agent-deny-lists.js +23 -15
- package/dist/core/runner/task-start-doors.d.ts +7 -3
- package/dist/core/runner/task-start-doors.js +72 -31
- package/dist/core/runner/terminal-account.js +14 -8
- package/dist/core/runner/terminal-projection.d.ts +3 -2
- package/dist/core/runner/terminal-projection.js +2 -2
- package/dist/core/runner/tool-defer-gate.d.ts +1 -1
- package/dist/core/runner/tool-end-body.d.ts +8 -1
- package/dist/core/runner/tool-end-body.js +4 -3
- package/dist/core/runner/tool-face-overlay.js +6 -4
- package/dist/core/runner/tool-result-media-seat.d.ts +2 -1
- package/dist/core/runner/tool-table-view.js +1 -1
- package/dist/core/runner/trim-stretch.d.ts +43 -0
- package/dist/core/runner/trim-stretch.js +34 -0
- package/dist/core/runner/turn-attachments.js +7 -2
- package/dist/core/runner/unreadable-person-rows.d.ts +39 -0
- package/dist/core/runner/unreadable-person-rows.js +20 -0
- package/dist/core/runner/verdict-refusal.d.ts +22 -7
- package/dist/core/runner/verdict-refusal.js +35 -3
- package/dist/core/runner/workspace-sync.d.ts +49 -0
- package/dist/core/runner/workspace-sync.js +170 -0
- package/dist/core/runner-deps.d.ts +57 -32
- package/dist/core/scheduler.d.ts +34 -14
- package/dist/core/secret-env.d.ts +168 -18
- package/dist/core/secret-env.js +291 -56
- package/dist/core/sensitive-path-policy.js +3 -2
- package/dist/core/session-changes.d.ts +260 -0
- package/dist/core/session-changes.js +40 -0
- package/dist/core/session-checkout.d.ts +87 -3
- package/dist/core/session-checkout.js +134 -6
- package/dist/core/session-log-transfer.js +13 -7
- package/dist/core/session-policy-store.d.ts +40 -12
- package/dist/core/session-policy-store.js +51 -25
- package/dist/core/session-store.d.ts +23 -10
- package/dist/core/session-store.js +40 -13
- package/dist/core/session.d.ts +56 -9
- package/dist/core/session.js +8 -1
- package/dist/core/shell-read-silence.d.ts +3 -3
- package/dist/core/shell-read-silence.js +3 -1
- package/dist/core/shell-run-candidates.d.ts +23 -6
- package/dist/core/shell-run-candidates.js +34 -11
- package/dist/core/skill-grant.d.ts +11 -6
- package/dist/core/skill-grant.js +23 -15
- package/dist/core/spend-account.d.ts +232 -0
- package/dist/core/spend-account.js +286 -0
- package/dist/core/store-contracts/background-agent-store-contract.js +85 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +60 -6
- package/dist/core/store-contracts/file-history-store-contract.js +4 -4
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +2 -1
- package/dist/core/store-contracts/mailbox-store-contract.js +22 -11
- package/dist/core/store-contracts/peer-directory-contract.js +8 -0
- package/dist/core/store-contracts/permission-rule-sync-contract.js +3 -3
- package/dist/core/store-contracts/session-deletion-cascade-contract.js +23 -4
- package/dist/core/store-contracts/session-policy-store-contract.js +9 -0
- package/dist/core/store-contracts/session-repo-contract.js +38 -1
- package/dist/core/store-contracts/session-store-contract.d.ts +21 -2
- package/dist/core/store-contracts/session-store-contract.js +369 -5
- package/dist/core/store-contracts/tool-result-store-contract.js +8 -7
- package/dist/core/store-contracts/workflow-journal-store-contract.js +33 -0
- package/dist/core/task-event.d.ts +57 -53
- package/dist/core/task-limits.d.ts +15 -8
- package/dist/core/task-notification.d.ts +17 -12
- package/dist/core/task-notification.js +20 -9
- package/dist/core/task-registry-agent.d.ts +35 -30
- package/dist/core/task-registry-agent.js +102 -32
- package/dist/core/task-registry-monitor.js +2 -1
- package/dist/core/task-registry-shared.d.ts +83 -16
- package/dist/core/task-registry-shared.js +26 -7
- package/dist/core/task-registry-workflow.d.ts +9 -1
- package/dist/core/task-registry-workflow.js +11 -3
- package/dist/core/task-registry.d.ts +26 -27
- package/dist/core/task-registry.js +42 -12
- package/dist/core/task-result.d.ts +145 -35
- package/dist/core/task-spec-members.d.ts +21 -3
- package/dist/core/task-spec-members.js +11 -2
- package/dist/core/task-spec.d.ts +42 -45
- package/dist/core/task-start-judge.js +10 -3
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +30 -2
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-errors.js +1 -0
- package/dist/core/tool-face-reader.d.ts +3 -2
- package/dist/core/tool-gate-phase.d.ts +16 -0
- package/dist/core/tool-gate-phase.js +1 -0
- package/dist/core/tool-mount-plan.d.ts +7 -0
- package/dist/core/tool-mount-plan.js +25 -1
- package/dist/core/tool-mount-static.js +3 -2
- package/dist/core/tool-name-aliases.d.ts +81 -106
- package/dist/core/tool-name-aliases.js +60 -155
- package/dist/core/tool-name-readings.d.ts +2 -0
- package/dist/core/tool-name-readings.js +9 -1
- package/dist/core/tool-policy.d.ts +165 -60
- package/dist/core/tool-policy.js +105 -69
- package/dist/core/tool-registry.d.ts +2 -0
- package/dist/core/tool-registry.js +3 -0
- package/dist/core/tool-result-bytes.d.ts +27 -3
- package/dist/core/tool-result-bytes.js +53 -0
- package/dist/core/tool-result-store.d.ts +11 -4
- package/dist/core/tool-result-store.js +6 -2
- package/dist/core/tool-roster.d.ts +33 -22
- package/dist/core/tool-roster.js +28 -18
- package/dist/core/tool-spec-members.d.ts +12 -0
- package/dist/core/tool-spec-members.js +31 -0
- package/dist/core/tool-spec.d.ts +41 -28
- package/dist/core/trace.d.ts +21 -64
- package/dist/core/trace.js +2 -3
- package/dist/core/types.d.ts +7 -7
- package/dist/core/types.js +2 -2
- package/dist/core/unavailable-landing.d.ts +72 -0
- package/dist/core/unavailable-landing.js +18 -0
- package/dist/core/untrusted-egress.d.ts +27 -5
- package/dist/core/untrusted-egress.js +30 -8
- package/dist/core/usage-window-store.d.ts +11 -1
- package/dist/core/usage-window-store.js +5 -0
- package/dist/core/user-attachment.d.ts +74 -48
- package/dist/core/user-attachment.js +137 -69
- package/dist/core/user-row-origin.d.ts +10 -0
- package/dist/core/user-row-origin.js +6 -0
- package/dist/core/wiring-manifest.d.ts +94 -24
- package/dist/core/wiring-manifest.js +65 -13
- package/dist/core/workflow-journal-store.d.ts +16 -7
- package/dist/core/workflow-journal-store.js +34 -6
- package/dist/core/workflow-run-store-contract.js +102 -0
- package/dist/core/workflow-run-store.d.ts +95 -4
- package/dist/core/workflow-run-store.js +74 -11
- package/dist/engine/compaction/compaction.d.ts +15 -3
- package/dist/engine/compaction/compaction.js +29 -10
- package/dist/engine/execution-env/kill-tree.js +44 -49
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -1
- package/dist/engine/execution-env/node-execution-env.js +18 -11
- package/dist/engine/harness/agent-harness.d.ts +13 -0
- package/dist/engine/harness/agent-harness.js +16 -1
- package/dist/engine/harness/types.d.ts +100 -30
- package/dist/engine/harness/types.js +36 -4
- package/dist/engine/llm/rejected-images.js +1 -1
- package/dist/engine/llm/types.d.ts +22 -2
- package/dist/engine/llm/types.js +5 -2
- package/dist/engine/loop/agent-loop.js +43 -11
- package/dist/engine/loop/types.d.ts +11 -0
- package/dist/engine/session/import-validate.d.ts +9 -0
- package/dist/engine/session/import-validate.js +50 -9
- package/dist/engine/session/memory-repo.d.ts +5 -1
- package/dist/engine/session/memory-repo.js +8 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.js +1 -1
- package/dist/engine/session/repo-utils.d.ts +19 -12
- package/dist/engine/session/repo-utils.js +12 -7
- package/dist/engine/session/session.d.ts +30 -10
- package/dist/engine/session/session.js +52 -20
- package/dist/engine/session/storage-base.js +2 -2
- package/dist/fixtures/index.d.ts +3 -1
- package/dist/fixtures/index.js +3 -0
- package/dist/host-env.d.ts +17 -0
- package/dist/host-env.js +1 -0
- package/dist/index.d.ts +83 -41
- package/dist/index.js +64 -30
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +5 -3
- package/dist/internal/harness.js +4 -3
- package/dist/internal/llm.d.ts +1 -1
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +40 -12
- package/dist/orchestration/run-workflow-tool.js +205 -102
- package/dist/orchestration/workflow-catalog.d.ts +254 -0
- package/dist/orchestration/workflow-catalog.js +702 -0
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-meta.d.ts +11 -1
- package/dist/orchestration/workflow-meta.js +48 -0
- package/dist/orchestration/workflow-observe.d.ts +8 -10
- package/dist/orchestration/workflow-observe.js +6 -1
- package/dist/orchestration/workflow-park-adoption.d.ts +71 -33
- package/dist/orchestration/workflow-park-adoption.js +153 -40
- package/dist/orchestration/workflow-requirements.d.ts +51 -0
- package/dist/orchestration/workflow-requirements.js +54 -0
- package/dist/orchestration/workflow-script-runner.d.ts +18 -0
- package/dist/orchestration/workflow-script-store.d.ts +19 -64
- package/dist/orchestration/workflow-script-store.js +1 -24
- package/dist/orchestration/workflow-types.d.ts +173 -41
- package/dist/orchestration/workflow-types.js +22 -4
- package/dist/orchestration/workflow.d.ts +56 -42
- package/dist/orchestration/workflow.js +654 -139
- package/dist/prompt-assembly/catalog/core-behavior.js +6 -2
- package/dist/prompt-assembly/catalog/engine.d.ts +36 -0
- package/dist/prompt-assembly/catalog/engine.js +4 -0
- package/dist/prompt-assembly/catalog/events.d.ts +16 -0
- package/dist/prompt-assembly/catalog/events.js +2 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +4 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +2 -2
- package/dist/prompt-assembly/catalog/mechanism.js +2 -2
- package/dist/prompt-assembly/catalog/schema.d.ts +5 -2
- package/dist/prompt-assembly/catalog/schema.js +1 -0
- package/dist/prompt-assembly/epoch.d.ts +26 -0
- package/dist/prompt-assembly/epoch.js +29 -0
- package/dist/prompt-assembly/event-registry.js +2 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +1 -1
- package/dist/prompt-assembly/turn-snapshot.d.ts +1 -1
- package/dist/prompts/default.d.ts +2 -2
- package/dist/shell/lex.d.ts +10 -7
- package/dist/shell/lex.js +56 -6
- package/dist/stores/file/adoption/adopt.d.ts +12 -0
- package/dist/stores/file/adoption/adopt.js +78 -31
- package/dist/stores/file/adoption/marker.d.ts +48 -26
- package/dist/stores/file/adoption/marker.js +24 -11
- package/dist/stores/file/background-agent-store.d.ts +5 -0
- package/dist/stores/file/background-agent-store.js +26 -5
- package/dist/stores/file/data-root-declaration.js +2 -1
- package/dist/stores/file/descriptor-seat.d.ts +100 -0
- package/dist/stores/file/descriptor-seat.js +150 -0
- package/dist/stores/file/file-history-store.js +2 -1
- package/dist/stores/file/fs-atomic.d.ts +126 -78
- package/dist/stores/file/fs-atomic.js +313 -253
- package/dist/stores/file/index.d.ts +10 -1
- package/dist/stores/file/index.js +28 -16
- package/dist/stores/file/ledger-damage.js +6 -10
- package/dist/stores/file/lock-reading.d.ts +158 -0
- package/dist/stores/file/lock-reading.js +252 -0
- package/dist/stores/file/mailbox-store.d.ts +8 -5
- package/dist/stores/file/mailbox-store.js +23 -14
- package/dist/stores/file/permission-rule-adopt.js +11 -11
- package/dist/stores/file/permission-rule-store.d.ts +14 -3
- package/dist/stores/file/permission-rule-store.js +33 -37
- package/dist/stores/file/process-anchor.d.ts +85 -0
- package/dist/stores/file/process-anchor.js +392 -0
- package/dist/stores/file/session-policy-store.d.ts +18 -2
- package/dist/stores/file/session-policy-store.js +71 -5
- package/dist/stores/file/session-store.d.ts +19 -1
- package/dist/stores/file/session-store.js +51 -19
- package/dist/stores/file/shared-ledger.d.ts +3 -3
- package/dist/stores/file/task-list-store.js +1 -1
- package/dist/stores/file/tool-result-store.js +2 -1
- package/dist/stores/file/usage-window-store.js +1 -1
- package/dist/stores/file/workflow-journal-store.d.ts +5 -2
- package/dist/stores/file/workflow-journal-store.js +12 -25
- package/dist/stores/file/workflow-run-store.d.ts +5 -0
- package/dist/stores/file/workflow-run-store.js +19 -12
- package/dist/tools/artifact/artifact-text.d.ts +29 -11
- package/dist/tools/artifact/artifact-text.js +13 -6
- package/dist/tools/artifact/artifact-tool.d.ts +35 -5
- package/dist/tools/artifact/artifact-tool.js +240 -45
- package/dist/tools/artifact/conformance.d.ts +27 -5
- package/dist/tools/artifact/conformance.js +420 -45
- package/dist/tools/artifact/local-stub.d.ts +2 -2
- package/dist/tools/artifact/local-stub.js +29 -26
- package/dist/tools/fs/bash-failure-output.d.ts +64 -0
- package/dist/tools/fs/bash-failure-output.js +40 -0
- package/dist/tools/fs/bash-program-position.d.ts +7 -3
- package/dist/tools/fs/bash-program-position.js +9 -6
- package/dist/tools/fs/bash-readonly-classifier.d.ts +4 -3
- package/dist/tools/fs/bound-open.d.ts +9 -8
- package/dist/tools/fs/bound-open.js +6 -4
- package/dist/tools/fs/dead-cwd.d.ts +8 -0
- package/dist/tools/fs/dead-cwd.js +7 -7
- package/dist/tools/fs/file-read-check.d.ts +8 -6
- package/dist/tools/fs/file-read-check.js +8 -4
- package/dist/tools/fs/file-write-check.d.ts +14 -0
- package/dist/tools/fs/file-write-check.js +35 -0
- package/dist/tools/fs/find-actions.d.ts +186 -0
- package/dist/tools/fs/find-actions.js +538 -0
- package/dist/tools/fs/fs-bash.d.ts +6 -3
- package/dist/tools/fs/fs-bash.js +67 -60
- package/dist/tools/fs/fs-pdf.js +16 -5
- package/dist/tools/fs/fs-read.js +5 -3
- package/dist/tools/fs/fs-shared.d.ts +67 -3
- package/dist/tools/fs/fs-shared.js +70 -34
- package/dist/tools/fs/fs-write.d.ts +23 -3
- package/dist/tools/fs/fs-write.js +137 -33
- package/dist/tools/fs/index.d.ts +15 -2
- package/dist/tools/fs/index.js +8 -4
- package/dist/tools/fs/program-read-model.d.ts +17 -1
- package/dist/tools/fs/program-read-model.js +7 -2
- package/dist/tools/fs/program-read-model.rows.js +5 -1
- package/dist/tools/fs/read-deny-home.js +12 -5
- package/dist/tools/fs/read-floor.d.ts +16 -0
- package/dist/tools/fs/read-floor.js +10 -5
- package/dist/tools/fs/removal-targets.d.ts +22 -4
- package/dist/tools/fs/removal-targets.js +116 -6
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +9 -2
- package/dist/tools/fs/shell-read-bindings.d.ts +56 -7
- package/dist/tools/fs/shell-read-bindings.js +175 -26
- package/dist/tools/fs/shell-read-check.d.ts +11 -2
- package/dist/tools/fs/shell-read-check.js +31 -5
- package/dist/tools/fs/shell-read-command-environment.d.ts +56 -0
- package/dist/tools/fs/shell-read-command-environment.js +75 -0
- package/dist/tools/fs/shell-read-establish.js +62 -16
- package/dist/tools/fs/shell-read-judge.d.ts +52 -7
- package/dist/tools/fs/shell-read-judge.js +63 -21
- package/dist/tools/fs/shell-read-lost-walk.d.ts +19 -0
- package/dist/tools/fs/shell-read-lost-walk.js +35 -0
- package/dist/tools/fs/shell-read-plan.d.ts +4 -0
- package/dist/tools/fs/shell-read-plan.js +47 -13
- package/dist/tools/fs/shell-read-sourced.d.ts +4 -3
- package/dist/tools/fs/shell-read-sourced.js +28 -3
- package/dist/tools/fs/shell-read-start.d.ts +7 -0
- package/dist/tools/fs/shell-read-word.js +1 -0
- package/dist/tools/fs/shell-read-workdir.d.ts +9 -11
- package/dist/tools/fs/shell-read-workdir.js +20 -26
- package/dist/tools/fs/shell-read-write-targets.d.ts +13 -5
- package/dist/tools/fs/shell-read-write-targets.js +51 -9
- package/dist/tools/monitor.d.ts +2 -1
- package/dist/tools/monitor.js +2 -0
- package/dist/tools/scheduler-tools.d.ts +7 -4
- package/dist/tools/scheduler-tools.js +60 -20
- package/dist/tools/task-list.d.ts +11 -1
- package/dist/tools/task-list.js +187 -134
- package/dist/tools/todo.d.ts +1 -1
- package/dist/tools/worktree.js +10 -9
- package/package.json +6 -2
- package/test/export-surface.snapshot.json +592 -22
- package/wire-changes/core-stores-sql@7.68.7.json +39 -0
- package/wire-changes/core-stores-sql@7.70.0.json +414 -0
- package/wire-changes/core@7.68.7.json +140 -0
- package/wire-changes/core@7.70.0.json +14689 -0
- package/wire-changes/mods-kernel@7.68.7.json +39 -0
- package/wire-changes/mods-kernel@7.70.0.json +75 -0
- package/wire-changes/primitives@7.68.7.json +39 -0
- package/wire-changes/primitives@7.70.0.json +807 -0
- package/wire-changes/wiki-gate@7.68.7.json +39 -0
- package/wire-changes/wiki-gate@7.70.0.json +40 -0
- package/dist/core/cache-break-detector.d.ts +0 -98
- package/dist/core/cache-break-detector.js +0 -146
- package/dist/core/compaction-retired-members.d.ts +0 -12
- package/dist/core/compaction-retired-members.js +0 -22
- package/dist/core/loopback-host.d.ts +0 -18
- package/dist/core/loopback-host.js +0 -40
- package/dist/core/protocol-naming.d.ts +0 -95
- package/dist/core/protocol-naming.js +0 -70
- package/dist/core/protocol-table.d.ts +0 -88
- package/dist/core/protocol-table.js +0 -47
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { presetRoleBaseOf, resolveModelDisplayLabel } from "../core/roles.js";
|
|
2
|
+
import { SPEND_OUTPUT_FLOOR_TOKENS, spendNodeMint } from "../core/spend-account.js";
|
|
3
|
+
import { SPEND_ACCOUNT_CLOSED_CODE } from "../brain/spend-meter.js";
|
|
2
4
|
import { describeRejectedValue } from "../core/tool-search-setting.js";
|
|
3
5
|
import { takeSeat } from "../core/swappable-deps.js";
|
|
4
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -10,6 +12,7 @@ import { thrownFailureOf } from "../core/runner/terminal-account.js";
|
|
|
10
12
|
import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
11
13
|
import { judgeCheckpointRow } from "../core/checkpoint-row-verdict.js";
|
|
12
14
|
import { applyParentSpecSeat } from "../core/parent-spec-seat.js";
|
|
15
|
+
import { ANONYMOUS_SCOPE, callScopeOf, isolationScopeOf } from "../core/isolation-scope.js";
|
|
13
16
|
import { TERMINAL_CAUSE_IS_REPLAYABLE, isTerminalCauseKind } from "../core/terminal-cause.js";
|
|
14
17
|
import { terminalProjection } from "../core/runner/terminal-projection.js";
|
|
15
18
|
import { steeringError } from "../core/runner/steer-admission.js";
|
|
@@ -18,7 +21,7 @@ import { GENERAL_PURPOSE_SUBAGENT_TYPE, markerFragment } from "../agents/subagen
|
|
|
18
21
|
import { runnerRoleMap } from "../agents/child-model-seat.js";
|
|
19
22
|
import { namesRoleBase } from "../prompt-assembly/role-base.js";
|
|
20
23
|
import { createSafeNotifier } from "../core/safe-notify.js";
|
|
21
|
-
import { assertJournalStoreGivesClaimsBack, callKeyOrdinal, clampRunIdText, journalKeepsLaunches, oversizeJournalResult, journalOversizeTombstone, readWorkflowJournalEntry, JOURNAL_OVERSIZE_ERROR_CODE, MAX_JOURNAL_RESULT_BYTES, WorkflowJournalIncompatibleError, } from "../core/workflow-journal-store.js";
|
|
24
|
+
import { assertJournalStoreGivesClaimsBack, callKeyOrdinal, clampRunIdText, journalKeepsLaunches, readWorkflowLaunchRecord, oversizeJournalResult, journalOversizeTombstone, readWorkflowJournalEntry, JOURNAL_OVERSIZE_ERROR_CODE, MAX_JOURNAL_RESULT_BYTES, WorkflowJournalIncompatibleError, } from "../core/workflow-journal-store.js";
|
|
22
25
|
import { isWorkflowRunActive, closeWorkflowChannel, markWorkflowActive, publishWorkflowEvent, readWorkflowParkedDecisions, registerWorkflowParkDelivery } from "./workflow-observe.js";
|
|
23
26
|
import { isDurablePause, resumeNeverStarted } from "../agents/suspend-guard.js";
|
|
24
27
|
import { RUNNING_AGENT_OBSERVE_EVERY_BEATS } from "../config/defaults.js";
|
|
@@ -30,6 +33,8 @@ import { OUTPUT_TOOL_NAME, TOOL_CATALOG_ENTRIES } from "../core/tool-catalog-ent
|
|
|
30
33
|
import { readDelegationReview } from "../core/classifier-unavailable-arm.js";
|
|
31
34
|
import { judgeHostToolCeiling, refuseUnusableDefinition } from "../core/runner/sub-agent-deny-lists.js";
|
|
32
35
|
import { definitionSelectorLayer, withDefinitionServers } from "../agents/inherited-tool-pool.js";
|
|
36
|
+
import { isToolSelectorLayer } from "../agents/tool-filter.js";
|
|
37
|
+
import { legRetiredNameView, selectorLayerUnderView } from "../core/tool-name-aliases.js";
|
|
33
38
|
import { snapshotToolNameList } from "../core/tool-name-list.js";
|
|
34
39
|
import { snapshotDefinitionLists } from "../agents/agent-definition.js";
|
|
35
40
|
import { holdKeeperDeclarations } from "../agents/retain-ledger.js";
|
|
@@ -37,11 +42,12 @@ import { snapshotAndValidateMcpEntries } from "../core/locked-config.js";
|
|
|
37
42
|
import { compileOutputSchema } from "../core/runner/strict-output-schema.js";
|
|
38
43
|
import { callerPlacementSeats } from "../core/runner/child-tree.js";
|
|
39
44
|
import { judgedOwnerSeat } from "../core/runner/delegation-owner.js";
|
|
40
|
-
import { WorkflowBudgetExceededError, WorkflowNestingError, WorkflowAgentBlockedError, WorkflowAgentParkedError, WorkflowAgentSchemaError, WorkflowAgentStalledError, WorkflowMaxAgentsError, WORKFLOW_SPAWN_BLOCKED_ERROR_CODE, PARK_NOT_PENDING_STATUSES, runParkedOf, workflowParkHolderOf } from "./workflow-types.js";
|
|
41
|
-
import {
|
|
45
|
+
import { WorkflowBudgetExceededError, WorkflowNestingError, WorkflowAgentBlockedError, WorkflowAgentParkedError, WorkflowAgentSchemaError, WorkflowAgentStalledError, WorkflowMaxAgentsError, WORKFLOW_SPAWN_BLOCKED_ERROR_CODE, WORKFLOW_AGENT_OUTLIVED_RUN_CODE, PARK_NOT_PENDING_STATUSES, WORKFLOW_STORE_WAIT_BOUND_MS, runParkedOf, workflowParkHolderOf, workflowRowStatusOf } from "./workflow-types.js";
|
|
46
|
+
import { memberOutcomeOf, memberRefusalsOf } from "../core/member-outcome.js";
|
|
47
|
+
import { claimLapseInstant, readWorkflowRunChain, runThatDrove, storeErrorClassOf, workflowParkDecisionOf, workflowRunSuccessors, workflowTreeOf, WORKFLOW_TREE_OVER_BOUND_REASON } from "./workflow-park-adoption.js";
|
|
42
48
|
import { WorkflowScriptError } from "./workflow-meta.js";
|
|
43
49
|
import { firstByteLaneKnobMs, STALL_FIRST_BYTE_MS, STALL_FIRST_TOKEN_MS } from "../brain/timeout.js";
|
|
44
|
-
import { asThrownError, isErrorLike, readMember, thrownIs, thrownName, thrownText } from "../core/thrown-value.js";
|
|
50
|
+
import { asThrownError, codedRefusal, isErrorLike, readMember, thrownIs, thrownName, thrownText } from "../core/thrown-value.js";
|
|
45
51
|
import { bindSettledRun } from "../core/workflow-settled-run.js";
|
|
46
52
|
import { persistTaskArtifact } from "../core/tool-result-store.js";
|
|
47
53
|
import { formatWorkflowRun, WORKFLOW_RECORD_WHOLE } from "../core/task-registry-shared.js";
|
|
@@ -118,10 +124,11 @@ NOTE: You are running inside a workflow script. Your final text response is retu
|
|
|
118
124
|
export const WORKFLOW_SUBAGENT_APPEND_SCHEMA = `---
|
|
119
125
|
|
|
120
126
|
NOTE: You are running inside a workflow script. You MUST return your final answer by calling the ${OUTPUT_TOOL_NAME} tool exactly once — the tool's input schema defines the required shape. Do your work, then call ${OUTPUT_TOOL_NAME}; do NOT put your answer in a text response (the script reads ONLY the tool call). If validation fails, read the error and call ${OUTPUT_TOOL_NAME} again with a corrected shape.`;
|
|
127
|
+
function workflowLaunchTypeWord(agentType, registry) {
|
|
128
|
+
return agentType === undefined || (agentType === GENERAL_PURPOSE_SUBAGENT_TYPE && !registry.some((d) => d.name === agentType)) ? undefined : agentType;
|
|
129
|
+
}
|
|
121
130
|
export function applyWorkflowAgentType(spec, agentType, registry) {
|
|
122
|
-
if (agentType === undefined)
|
|
123
|
-
return { spec };
|
|
124
|
-
if (agentType === GENERAL_PURPOSE_SUBAGENT_TYPE && !registry.some((d) => d.name === agentType))
|
|
131
|
+
if (workflowLaunchTypeWord(agentType, registry) === undefined)
|
|
125
132
|
return { spec };
|
|
126
133
|
const def = registry.find((d) => d.name === agentType);
|
|
127
134
|
if (!def) {
|
|
@@ -149,9 +156,9 @@ export function applyWorkflowAgentType(spec, agentType, registry) {
|
|
|
149
156
|
out.mcp = withDefinitionServers(out.mcp !== undefined ? snapshotAndValidateMcpEntries(out.mcp) : undefined, ownServers);
|
|
150
157
|
const lists = { allowTools: snapshotToolNameList(def.allowTools), denyTools: snapshotToolNameList(def.denyTools) };
|
|
151
158
|
if (lists.allowTools == null && lists.denyTools == null)
|
|
152
|
-
return { spec: out };
|
|
159
|
+
return { spec: out, agentType: def.name };
|
|
153
160
|
refuseUnusableDefinition(def.name, lists);
|
|
154
|
-
return { spec: out, definitionToolLists: { agentType: def.name, layer: definitionSelectorLayer({ ...lists, ...(ownServers !== undefined ? { mcp: ownServers } : {}) }) } };
|
|
161
|
+
return { spec: out, agentType: def.name, definitionToolLists: { agentType: def.name, layer: definitionSelectorLayer({ ...lists, ...(ownServers !== undefined ? { mcp: ownServers } : {}) }) } };
|
|
155
162
|
}
|
|
156
163
|
export function workflowAgentRegistry(opts) {
|
|
157
164
|
const deployment = (opts.agents ?? []).map(snapshotDefinitionLists);
|
|
@@ -184,7 +191,18 @@ function withWorkflowChildSeats(typed, inheritedModelSnap, inheritedThinkingSnap
|
|
|
184
191
|
}
|
|
185
192
|
return { ...seated, ...preset };
|
|
186
193
|
}
|
|
187
|
-
export function workflowAgentCallKey(ordinal, spec, opts) {
|
|
194
|
+
export function workflowAgentCallKey(ordinal, spec, opts, position) {
|
|
195
|
+
return callKeyOf(ordinal, workflowAgentSpecHash(spec, opts), position ?? "");
|
|
196
|
+
}
|
|
197
|
+
function callKeyOf(ordinal, specHash, place) {
|
|
198
|
+
return `${ordinal}:${specHash}${place !== undefined ? `@${place}` : ""}`;
|
|
199
|
+
}
|
|
200
|
+
function callKeySpec(callKey) {
|
|
201
|
+
const colon = callKey.indexOf(":");
|
|
202
|
+
const at = callKey.indexOf("@");
|
|
203
|
+
return callKey.slice(colon + 1, at >= 0 ? at : undefined);
|
|
204
|
+
}
|
|
205
|
+
function workflowAgentSpecHash(spec, opts) {
|
|
188
206
|
const identity = {
|
|
189
207
|
...spec,
|
|
190
208
|
signal: undefined,
|
|
@@ -196,8 +214,19 @@ export function workflowAgentCallKey(ordinal, spec, opts) {
|
|
|
196
214
|
outputSchema: opts.schema ?? spec.outputSchema,
|
|
197
215
|
isolation: opts.isolation ? opts.isolation : undefined,
|
|
198
216
|
};
|
|
199
|
-
return
|
|
217
|
+
return boundInputHashOf(identity);
|
|
200
218
|
}
|
|
219
|
+
function callKeyPosition(callKey) {
|
|
220
|
+
const at = callKey.indexOf("@");
|
|
221
|
+
return at >= 0 && at < callKey.length - 1 ? callKey.slice(at + 1) : undefined;
|
|
222
|
+
}
|
|
223
|
+
function madeAtEvent(position, prefix, n) {
|
|
224
|
+
if (!position.startsWith(prefix))
|
|
225
|
+
return false;
|
|
226
|
+
const segment = position.slice(prefix.length).split(".", 1)[0];
|
|
227
|
+
return (segment[0] === "c" || segment[0] === "p" || segment[0] === "f") && segment.slice(1) === String(n);
|
|
228
|
+
}
|
|
229
|
+
const fanOutScopeStore = new AsyncLocalStorage();
|
|
201
230
|
function resolveChildSessionIdAtSpawn(spec) {
|
|
202
231
|
if (spec.sessionId)
|
|
203
232
|
return spec.sessionId;
|
|
@@ -408,7 +437,16 @@ function readLegApprovalWaitedMs(result, announce) {
|
|
|
408
437
|
}
|
|
409
438
|
return raw;
|
|
410
439
|
}
|
|
411
|
-
export const
|
|
440
|
+
export const TERMINAL_WRITE_RETRY_DELAYS_MS = Object.freeze([1_000, 10_000, 60_000]);
|
|
441
|
+
function terminalWriteCause(o) {
|
|
442
|
+
return o.cause === "threw" ? `the run store refused it: ${storeErrorClassOf(o.err)}`
|
|
443
|
+
: o.cause === "timeout" ? `the run store did not answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms`
|
|
444
|
+
: o.cause === "not_own" ? "the run store holds no row of this run's own under its id"
|
|
445
|
+
: "the run store answered that the row had moved";
|
|
446
|
+
}
|
|
447
|
+
const SETTLE_ROW_READ_FIRST = " A host that settles this row reads it first: a row that reads ended is left as it is; only one that still reads running, and is this run's (an explicit run id may have been reused — docs/KNOWN-LIMITS.md KL-4486-a), is changed, at the rev it read.";
|
|
448
|
+
const WORKFLOW_FAILURE_SETTLE_MS = 5_000;
|
|
449
|
+
const SPEND_STOP_CODES = new Set(["limits.max_tokens_exceeded", "limits.max_cost_exceeded", SPEND_ACCOUNT_CLOSED_CODE]);
|
|
412
450
|
export const WORKFLOW_JOURNAL_APPEND_TIMEOUT_MS = 30_000;
|
|
413
451
|
const REAL_WORKFLOW_TIMERS = {
|
|
414
452
|
setTimeout(fn, ms) {
|
|
@@ -426,15 +464,23 @@ async function finalizeWithin(timers, p, fallback, holdsProcess = false) {
|
|
|
426
464
|
return await Promise.race([
|
|
427
465
|
p,
|
|
428
466
|
new Promise((resolve) => {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
handle.ref
|
|
467
|
+
try {
|
|
468
|
+
handle = timers.setTimeout(() => resolve(fallback), WORKFLOW_STORE_WAIT_BOUND_MS);
|
|
469
|
+
if (holdsProcess && typeof handle === "object" && handle !== null && "ref" in handle && typeof handle.ref === "function")
|
|
470
|
+
handle.ref();
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
}
|
|
432
474
|
}),
|
|
433
475
|
]);
|
|
434
476
|
}
|
|
435
477
|
finally {
|
|
436
|
-
|
|
437
|
-
|
|
478
|
+
try {
|
|
479
|
+
if (handle !== undefined)
|
|
480
|
+
timers.clearTimeout(handle);
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
}
|
|
438
484
|
}
|
|
439
485
|
}
|
|
440
486
|
function defaultConcurrency() {
|
|
@@ -594,7 +640,11 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
594
640
|
throw new Error("runWorkflow: launch is the record a continuation of this run reads back, and requires a journalStore that keeps launch records (recordLaunch and loadLaunch)");
|
|
595
641
|
}
|
|
596
642
|
const now = opts.now ?? (() => Date.now());
|
|
597
|
-
const
|
|
643
|
+
const givenScope = callScopeOf(undefined, { scope: opts.scope }), seatScope = opts.parentSpecSeat !== undefined ? isolationScopeOf(opts.parentSpecSeat) : undefined;
|
|
644
|
+
if (givenScope !== undefined && seatScope !== undefined && givenScope !== seatScope) {
|
|
645
|
+
throw codedRefusal("config.invalid_argument", `runWorkflow: scope ${JSON.stringify(givenScope)} contradicts parentSpecSeat, whose identity files the run under ${JSON.stringify(seatScope)} — hand one of the two, or the same scope in both (\`scope\` speaks only for a run whose agents run as nobody)`);
|
|
646
|
+
}
|
|
647
|
+
const scope = seatScope ?? givenScope ?? ANONYMOUS_SCOPE;
|
|
598
648
|
const parkedResume = opts.parkedResume === undefined ? undefined : readWorkflowParkedDecisions(opts.parkedResume, "runWorkflow: parkedResume"), claimHolder = opts.holder;
|
|
599
649
|
let launchUnkept = false;
|
|
600
650
|
const runId = opts.runId ?? randomUUID();
|
|
@@ -614,6 +664,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
614
664
|
const maxLogChars = normalizeWorkflowHardCap("maxLogChars", opts.maxLogChars);
|
|
615
665
|
const maxResultChars = normalizeWorkflowHardCap("maxResultChars", opts.maxResultChars);
|
|
616
666
|
const budgetCeiling = normalizeWorkflowHardCap("budget", opts.budget);
|
|
667
|
+
const mintWfSpend = spendNodeMint(opts.spendParent, "RunWorkflowOptions.spendParent");
|
|
617
668
|
const totalTimeoutMs = normalizeWorkflowTimerCap("totalTimeoutMs", opts.totalTimeoutMs);
|
|
618
669
|
const stallMs = normalizeWorkflowStallMs(opts.stallMs);
|
|
619
670
|
const agentMaxRetries = normalizeWorkflowHardCap("agentMaxRetries", opts.agentMaxRetries) ?? WORKFLOW_AGENT_MAX_RETRIES;
|
|
@@ -638,36 +689,71 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
638
689
|
notifier.notify(() => opts.onEvent?.(e), "workflow.onEvent");
|
|
639
690
|
};
|
|
640
691
|
let persistTail = Promise.resolve();
|
|
641
|
-
|
|
692
|
+
let persistEpoch = 0;
|
|
693
|
+
let vouched = true;
|
|
694
|
+
let createAnswer;
|
|
695
|
+
const ownRow = (row) => row != null && row.id === runId && row.scope === scope && row.createdAt === t0;
|
|
696
|
+
const writeOwnRow = async (s, snapshot) => {
|
|
697
|
+
const row = await s.get(runId);
|
|
698
|
+
if (!ownRow(row))
|
|
699
|
+
return { ok: false, cause: "not_own" };
|
|
700
|
+
if (row.status !== "running")
|
|
701
|
+
return { ok: true };
|
|
702
|
+
const rev = typeof row.rev === "number" ? row.rev : 0;
|
|
703
|
+
snapshot.rev = rev;
|
|
704
|
+
return (await s.update(runId, scope, snapshot, { rev })) ? { ok: true } : { ok: false, cause: "cas_lost" };
|
|
705
|
+
};
|
|
706
|
+
const persist = (mode, given) => {
|
|
642
707
|
if (!store)
|
|
643
708
|
return Promise.resolve({ ok: true });
|
|
644
|
-
const snapshot = structuredClone(run);
|
|
709
|
+
const snapshot = given ?? structuredClone(run);
|
|
710
|
+
const epoch = persistEpoch;
|
|
645
711
|
const next = persistTail.then(async () => {
|
|
712
|
+
if (epoch !== persistEpoch)
|
|
713
|
+
return { ok: false, cause: "cas_lost" };
|
|
646
714
|
try {
|
|
647
715
|
if (mode === "create") {
|
|
648
716
|
snapshot.rev = storeRev;
|
|
649
|
-
await
|
|
717
|
+
const created = await Promise.resolve()
|
|
718
|
+
.then(() => store.put(runId, snapshot))
|
|
719
|
+
.then(() => undefined, (err) => ({ err }));
|
|
720
|
+
createAnswer = created === undefined ? { ok: true } : { ok: false, err: created.err };
|
|
721
|
+
if (epoch !== persistEpoch)
|
|
722
|
+
createLandedLate();
|
|
723
|
+
if (created !== undefined)
|
|
724
|
+
throw created.err;
|
|
650
725
|
return { ok: true };
|
|
651
726
|
}
|
|
727
|
+
if (!vouched)
|
|
728
|
+
return await writeOwnRow(store, snapshot);
|
|
652
729
|
snapshot.rev = storeRev;
|
|
653
730
|
const won = await store.update(runId, scope, snapshot, { rev: storeRev });
|
|
654
731
|
if (won)
|
|
655
732
|
storeRev += 1;
|
|
733
|
+
else
|
|
734
|
+
vouched = false;
|
|
656
735
|
return won ? { ok: true } : { ok: false, cause: "cas_lost" };
|
|
657
736
|
}
|
|
658
|
-
catch {
|
|
659
|
-
|
|
737
|
+
catch (err) {
|
|
738
|
+
vouched = false;
|
|
739
|
+
return { ok: false, cause: "threw", err };
|
|
660
740
|
}
|
|
661
741
|
});
|
|
662
742
|
persistTail = next;
|
|
663
743
|
return next;
|
|
664
744
|
};
|
|
745
|
+
const restartPersistTail = () => {
|
|
746
|
+
persistEpoch += 1;
|
|
747
|
+
persistTail = Promise.resolve();
|
|
748
|
+
vouched = false;
|
|
749
|
+
};
|
|
665
750
|
const t0 = now();
|
|
666
751
|
const run = {
|
|
667
752
|
id: runId,
|
|
668
753
|
scope,
|
|
669
754
|
...(opts.name !== undefined ? { name: opts.name } : {}),
|
|
670
755
|
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
756
|
+
...(opts.editedFrom !== undefined ? { editedFrom: { name: opts.editedFrom.name, contentHash: opts.editedFrom.contentHash } } : {}),
|
|
671
757
|
...(opts.sourceTaskId !== undefined ? { sourceTaskId: opts.sourceTaskId } : {}),
|
|
672
758
|
...(opts.originatingSessionId !== undefined ? { originatingSessionId: opts.originatingSessionId } : {}),
|
|
673
759
|
status: "running",
|
|
@@ -691,7 +777,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
691
777
|
timeoutTimer.unref?.();
|
|
692
778
|
}
|
|
693
779
|
emit({ type: "run_start", runId, scope, ts: t0 });
|
|
694
|
-
|
|
780
|
+
const recordLanded = store === undefined ? Promise.resolve({ ok: true }) : finalizeWithin(timers, persist("create"), { ok: false, cause: "timeout" }, true);
|
|
695
781
|
let openOrdinal = 0;
|
|
696
782
|
const openOrder = new Map();
|
|
697
783
|
const agentPhaseOf = new Map();
|
|
@@ -710,6 +796,14 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
710
796
|
}
|
|
711
797
|
return undefined;
|
|
712
798
|
};
|
|
799
|
+
const settleRowOutcome = (rec, facts) => {
|
|
800
|
+
const outcome = memberOutcomeOf("workflow_member", rec.replayed === true ? "replayed" : "live", facts);
|
|
801
|
+
rec.outcome = outcome;
|
|
802
|
+
rec.status = workflowRowStatusOf(outcome.outcome);
|
|
803
|
+
return outcome;
|
|
804
|
+
};
|
|
805
|
+
const withMember = (result, member) => ({ ...result, member });
|
|
806
|
+
const lateMember = (rec, result, provenance, facts) => withMember(result, rec?.outcome ?? memberOutcomeOf("workflow_member", provenance, facts));
|
|
713
807
|
const countAgentFailures = (phase) => run.agents.reduce((n, a) => n + (a.status === "failed" && (phase === undefined || agentPhaseOf.get(a) === phase) ? 1 : 0), 0);
|
|
714
808
|
const phaseFailureExtra = (p) => {
|
|
715
809
|
const n = countAgentFailures(p);
|
|
@@ -726,10 +820,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
726
820
|
delete p.agentFailures;
|
|
727
821
|
}
|
|
728
822
|
};
|
|
823
|
+
const runStopper = () => !workflowSignal.aborted ? undefined : timeoutController !== undefined && timeoutController.signal.aborted && workflowSignal.reason === timeoutController.signal.reason ? "system" : "parent";
|
|
729
824
|
const closeAbandonedAgents = (endedAt) => {
|
|
825
|
+
const stopper = runStopper();
|
|
730
826
|
for (const a of run.agents) {
|
|
731
827
|
if (a.status === "running") {
|
|
732
|
-
a
|
|
828
|
+
settleRowOutcome(a, stopper !== undefined ? { from: "ended", status: "killed", stoppedBy: stopper } : { from: "ended", status: "failed", code: WORKFLOW_AGENT_OUTLIVED_RUN_CODE });
|
|
733
829
|
a.endedAt = endedAt;
|
|
734
830
|
emit({ type: "agent_end", runId, label: a.label, ...(a.phase !== undefined ? { phase: a.phase } : {}), ...(a.groupId !== undefined ? { groupId: a.groupId } : {}), status: "failed", ts: endedAt });
|
|
735
831
|
}
|
|
@@ -776,12 +872,24 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
776
872
|
const sem = createSemaphore(concurrency);
|
|
777
873
|
const launchingCeiling = internals?.toolCeiling ?? undefined;
|
|
778
874
|
const hostCeiling = opts.toolCeiling ?? undefined;
|
|
779
|
-
const agentCeiling = launchingCeiling === undefined ? hostCeiling : hostCeiling === undefined ? launchingCeiling : [...launchingCeiling, ...hostCeiling];
|
|
780
875
|
const judgeHostCeiling = (spec) => {
|
|
781
876
|
if (hostCeiling !== undefined)
|
|
782
877
|
judgeHostToolCeiling(hostCeiling, spec, launchingCeiling);
|
|
783
878
|
};
|
|
784
|
-
const
|
|
879
|
+
const ceilingOf = (spec) => {
|
|
880
|
+
if (hostCeiling === undefined)
|
|
881
|
+
return launchingCeiling;
|
|
882
|
+
const view = legRetiredNameView(spec.tools ?? []);
|
|
883
|
+
const host = hostCeiling.map((l) => (isToolSelectorLayer(l) ? selectorLayerUnderView(l, view) : l));
|
|
884
|
+
return launchingCeiling === undefined ? host : [...launchingCeiling, ...host];
|
|
885
|
+
};
|
|
886
|
+
const definitionSeats = (launch) => {
|
|
887
|
+
const ceiling = ceilingOf(launch.spec);
|
|
888
|
+
return {
|
|
889
|
+
...(launch.definitionToolLists !== undefined ? { definitionToolLists: launch.definitionToolLists, toolCeiling: ceiling ?? [] } : ceiling !== undefined ? { toolCeiling: ceiling } : {}),
|
|
890
|
+
...(launch.agentType !== undefined ? { spawnAgentType: launch.agentType } : {}),
|
|
891
|
+
};
|
|
892
|
+
};
|
|
785
893
|
const spawnAttribution = {
|
|
786
894
|
isDelegatedChild: true,
|
|
787
895
|
...(parkLaneArmed(opts) ? { parkLaneHeld: true } : {}),
|
|
@@ -794,7 +902,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
794
902
|
...(opts.parentCenterSourceRevision !== undefined ? { parentCenterSourceRevision: opts.parentCenterSourceRevision } : {}),
|
|
795
903
|
...(opts.onForwardEvent ? { onForwardEvent: opts.onForwardEvent } : {}),
|
|
796
904
|
...(opts.inheritedGate !== undefined ? { inheritedGate: opts.inheritedGate } : {}),
|
|
797
|
-
...(agentCeiling !== undefined ? { toolCeiling: agentCeiling } : {}),
|
|
798
905
|
...((opts.rootSessionId ?? opts.originatingSessionId) !== undefined ? { rootSessionId: opts.rootSessionId ?? opts.originatingSessionId } : {}),
|
|
799
906
|
...(opts.rootSessionId !== undefined && opts.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: opts.rootSessionIncarnation } : {}),
|
|
800
907
|
...(opts.rootSessionId !== undefined && opts.rootSessionScope !== undefined ? { rootSessionScope: opts.rootSessionScope } : {}),
|
|
@@ -822,9 +929,10 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
822
929
|
const bceParentToolCall = opts.parentToolCallId !== undefined ? { parentToolCallId: opts.parentToolCallId } : {};
|
|
823
930
|
const waIdOf = (callKey) => `wa${createHash("sha256").update(`${runId}:${callKey}`).digest("hex").slice(0, 16)}`;
|
|
824
931
|
const bceLive = new Map();
|
|
825
|
-
const bceSpawn = (callKey, label,
|
|
932
|
+
const bceSpawn = (callKey, label, asked, replayed, sessionId, model) => {
|
|
826
933
|
if (!bceSink)
|
|
827
934
|
return;
|
|
935
|
+
const agentType = workflowLaunchTypeWord(asked, agentRegistry);
|
|
828
936
|
const id = waIdOf(callKey);
|
|
829
937
|
bceLive.set(id, { callKey, label, ...(agentType !== undefined ? { agentType } : {}), ...(sessionId !== undefined ? { sessionId } : {}), ...(sessionId !== undefined && judgedOwnerSeat({}, opts) === undefined ? { verified: true } : {}), ...(model !== undefined ? { model } : {}), generation: 1 });
|
|
830
938
|
bceEmit({
|
|
@@ -926,15 +1034,31 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
926
1034
|
});
|
|
927
1035
|
};
|
|
928
1036
|
const budgetTotal = budgetCeiling ?? null;
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1037
|
+
const wfSpend = mintWfSpend();
|
|
1038
|
+
if (budgetTotal !== null)
|
|
1039
|
+
wfSpend.setCeiling({ tokens: budgetTotal });
|
|
1040
|
+
const spent = () => wfSpend.subtreeSettled.tokens;
|
|
932
1041
|
const budget = {
|
|
933
1042
|
total: budgetTotal,
|
|
934
1043
|
spent,
|
|
935
|
-
remaining: () => (
|
|
1044
|
+
remaining: () => wfSpend.remaining("tokens") ?? Infinity,
|
|
1045
|
+
};
|
|
1046
|
+
const memberSpendParent = { seat: wfSpend, link: "task" };
|
|
1047
|
+
const budgetGate = () => {
|
|
1048
|
+
if (budgetTotal !== null && budgetTotal - spent() < SPEND_OUTPUT_FLOOR_TOKENS)
|
|
1049
|
+
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
1050
|
+
};
|
|
1051
|
+
const ownBooked = { tokens: 0, costMicroUsd: 0 };
|
|
1052
|
+
const bookOwnSpend = () => {
|
|
1053
|
+
if (finalized)
|
|
1054
|
+
return;
|
|
1055
|
+
const own = wfSpend.ownSettled;
|
|
1056
|
+
run.stats.tokens += own.tokens - ownBooked.tokens;
|
|
1057
|
+
run.stats.costMicroUsd += own.costMicroUsd - ownBooked.costMicroUsd;
|
|
1058
|
+
ownBooked.tokens = own.tokens;
|
|
1059
|
+
ownBooked.costMicroUsd = own.costMicroUsd;
|
|
936
1060
|
};
|
|
937
|
-
const accumulateStats = (result
|
|
1061
|
+
const accumulateStats = (result) => {
|
|
938
1062
|
const s = result.stats;
|
|
939
1063
|
run.stats.tokens += s.tokens ?? 0;
|
|
940
1064
|
run.stats.turns += s.turns ?? 0;
|
|
@@ -945,10 +1069,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
945
1069
|
run.stats.nested.tasks += s.nested.tasks ?? 0;
|
|
946
1070
|
run.stats.nested.costMicroUsd += s.nested.costMicroUsd ?? 0;
|
|
947
1071
|
}
|
|
948
|
-
if (live) {
|
|
949
|
-
liveTokens += s.tokens ?? 0;
|
|
950
|
-
liveNestedTokens += s.nested?.tokens ?? 0;
|
|
951
|
-
}
|
|
952
1072
|
};
|
|
953
1073
|
const activeUsageBeats = new Set();
|
|
954
1074
|
const settleActiveUsageBeats = () => {
|
|
@@ -964,6 +1084,72 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
964
1084
|
let resumeClaim;
|
|
965
1085
|
const replayByOrdinal = [];
|
|
966
1086
|
let divergence;
|
|
1087
|
+
const recordedOrdinalOfPosition = new Map();
|
|
1088
|
+
const recordedOrdinals = new Set();
|
|
1089
|
+
let priorRecordUnpositioned = false;
|
|
1090
|
+
const recordedOrdinalsOfSpec = new Map();
|
|
1091
|
+
const heldOrdinals = new Set();
|
|
1092
|
+
const startingOrdinals = new Set();
|
|
1093
|
+
const reachedPositions = new Set();
|
|
1094
|
+
const scopeOwner = {};
|
|
1095
|
+
const rootChain = { n: 0 };
|
|
1096
|
+
let pipelinesRunning = 0;
|
|
1097
|
+
const scopeHere = () => {
|
|
1098
|
+
const scope = fanOutScopeStore.getStore();
|
|
1099
|
+
return scope !== undefined && scope.owner === scopeOwner ? scope : undefined;
|
|
1100
|
+
};
|
|
1101
|
+
const ordinalFor = (position, inItem, spec) => {
|
|
1102
|
+
const taken = (o) => heldOrdinals.has(o) || startingOrdinals.has(o);
|
|
1103
|
+
const recorded = priorRecordUnpositioned ? (inItem ? recordedOrdinalsOfSpec.get(spec)?.find((o) => !taken(o)) : undefined) : recordedOrdinalOfPosition.get(position);
|
|
1104
|
+
let picked;
|
|
1105
|
+
if (recorded !== undefined && !taken(recorded))
|
|
1106
|
+
picked = { ordinal: recorded, adopted: true };
|
|
1107
|
+
else {
|
|
1108
|
+
let o = 0;
|
|
1109
|
+
while (taken(o) || (priorRecordUnpositioned ? inItem && parkedByOrdinal[o] !== undefined : recordedOrdinals.has(o)))
|
|
1110
|
+
o++;
|
|
1111
|
+
picked = { ordinal: o, adopted: false };
|
|
1112
|
+
}
|
|
1113
|
+
const ordinal = picked.ordinal;
|
|
1114
|
+
startingOrdinals.add(ordinal);
|
|
1115
|
+
queueMicrotask(() => startingOrdinals.delete(ordinal));
|
|
1116
|
+
return picked;
|
|
1117
|
+
};
|
|
1118
|
+
const fanOutSite = (kind) => {
|
|
1119
|
+
const enclosing = scopeHere();
|
|
1120
|
+
const prefix = enclosing !== undefined ? `${enclosing.path}.` : "";
|
|
1121
|
+
const n = (enclosing?.chain ?? rootChain).n++;
|
|
1122
|
+
return { site: `${prefix}${kind}${n}`, enclosing, prefix, n };
|
|
1123
|
+
};
|
|
1124
|
+
const notMadeAt = (what, at) => {
|
|
1125
|
+
if (opts.resumeFromRunId === undefined || parkedLeg !== undefined || resumeRefusal !== undefined || finalized)
|
|
1126
|
+
return undefined;
|
|
1127
|
+
let missing;
|
|
1128
|
+
let waiting;
|
|
1129
|
+
for (const [position, ordinal] of recordedOrdinalOfPosition) {
|
|
1130
|
+
if (reachedPositions.has(position) || !madeAtEvent(position, at.prefix, at.n))
|
|
1131
|
+
continue;
|
|
1132
|
+
if (missing === undefined || ordinal < missing.ordinal)
|
|
1133
|
+
missing = { position, ordinal };
|
|
1134
|
+
if (parkedByOrdinal[ordinal]?.kind === "pending" && (waiting === undefined || ordinal < waiting.ordinal))
|
|
1135
|
+
waiting = { position, ordinal };
|
|
1136
|
+
}
|
|
1137
|
+
if (waiting !== undefined) {
|
|
1138
|
+
const refusal = parkedCallNotMadeError(waiting.ordinal, waiting.position, what);
|
|
1139
|
+
resumeRefusal ??= refusal;
|
|
1140
|
+
throw refusal;
|
|
1141
|
+
}
|
|
1142
|
+
return missing;
|
|
1143
|
+
};
|
|
1144
|
+
const joinFanOut = (kind, at) => {
|
|
1145
|
+
const missing = notMadeAt(kind, at);
|
|
1146
|
+
if (missing !== undefined)
|
|
1147
|
+
noteDivergence(missing.ordinal, `the ${kind} ended without the call the resumed run made at ${missing.position} — an item, a stage, a thunk or a call the script no longer reaches`);
|
|
1148
|
+
};
|
|
1149
|
+
const admitRecord = (rec) => {
|
|
1150
|
+
run.agents.push(rec);
|
|
1151
|
+
heldOrdinals.add(callKeyOrdinal(rec.callKey));
|
|
1152
|
+
};
|
|
967
1153
|
let resumeRefusal;
|
|
968
1154
|
const refusalTerminal = (thrown) => (workflowSignal?.aborted !== true ? resumeRefusal : thrown === resumeRefusal ? (workflowSignal.reason ?? new Error("workflow aborted")) : thrown);
|
|
969
1155
|
let parkedLeg;
|
|
@@ -976,9 +1162,10 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
976
1162
|
const status = t.detail?.kind === "coded" ? t.detail.detail.status : undefined;
|
|
977
1163
|
return PARK_NOT_PENDING_STATUSES.find((s) => s === status);
|
|
978
1164
|
};
|
|
1165
|
+
const completedRunsAgain = new Set();
|
|
979
1166
|
const askedAgainBit = (callKey) => {
|
|
980
1167
|
const status = stepAskedAgainAfter(callKey);
|
|
981
|
-
return status === "expired" || status === "absent" ? { workflowStepAskedAgain: true } : {};
|
|
1168
|
+
return status === "expired" || status === "absent" || completedRunsAgain.has(callKey) ? { workflowStepAskedAgain: true } : {};
|
|
982
1169
|
};
|
|
983
1170
|
const memberAt = (callKey, label) => ({ runId, label, ...(askedAgainBit(callKey).workflowStepAskedAgain === true ? { askedAgain: true } : {}) });
|
|
984
1171
|
const memberSeat = (callKey, label) => ({ workflowMember: memberAt(callKey, label) });
|
|
@@ -1052,7 +1239,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1052
1239
|
const parkedError = () => {
|
|
1053
1240
|
const p = parkedLeg;
|
|
1054
1241
|
const gate = p.paused.terminal.gate;
|
|
1055
|
-
return new WorkflowAgentParkedError(p.label, gate.kind, p.paused.terminal.checkpointId, gate.kind === "resource_limit" ? gate.reason : undefined,
|
|
1242
|
+
return new WorkflowAgentParkedError(p.label, gate.kind, p.paused.terminal.checkpointId, gate.kind === "resource_limit" ? gate.reason : undefined, askedAgainBit(p.callKey).workflowStepAskedAgain === true);
|
|
1056
1243
|
};
|
|
1057
1244
|
const parkWaits = new Map();
|
|
1058
1245
|
const takenParkTokens = new Set();
|
|
@@ -1159,6 +1346,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1159
1346
|
: `after replay stopped at agent #${divergence.ordinal} (${divergence.reason}) — the calls from there on ran live, so this call may have been built from a live result rather than the recorded one. `) +
|
|
1160
1347
|
"A fresh spawn there would run beside the pinned child. Resume with the calls up to it unchanged, or decide the checkpoint " +
|
|
1161
1348
|
"through the deployment's approval channel and start a fresh run."), { code: "workflow.parked_call_changed" });
|
|
1349
|
+
const parkedCallNotMadeError = (ordinal, position, what) => Object.assign(new Error(`workflow resume: ordinal ${ordinal} is PARKED on a checkpoint (recorded at ${position}), but ${what === "call" ? "a call now stands where the fan-out it was made under stood" : `the ${what} at its place ended without that call`} — ` +
|
|
1350
|
+
"the script no longer makes it there, or it was refused before its record. Resume with a script that makes the parked call where it was, " +
|
|
1351
|
+
"or decide the checkpoint through the deployment's approval channel and start a fresh run."), { code: "workflow.parked_call_changed" });
|
|
1162
1352
|
let inFlightLegs = 0;
|
|
1163
1353
|
let legsIdleResolve;
|
|
1164
1354
|
let retired = false;
|
|
@@ -1192,6 +1382,23 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1192
1382
|
});
|
|
1193
1383
|
}
|
|
1194
1384
|
};
|
|
1385
|
+
const membersStop = new AbortController();
|
|
1386
|
+
const stopAndSettleMembers = async () => {
|
|
1387
|
+
if (inFlightLegs === 0 || workflowSignal.aborted)
|
|
1388
|
+
return;
|
|
1389
|
+
membersStop.abort(new Error("workflow failed"));
|
|
1390
|
+
const bound = new AbortController();
|
|
1391
|
+
const timer = timers.setTimeout(() => bound.abort(), WORKFLOW_FAILURE_SETTLE_MS);
|
|
1392
|
+
const onRunAbort = () => bound.abort();
|
|
1393
|
+
workflowSignal.addEventListener("abort", onRunAbort, { once: true });
|
|
1394
|
+
try {
|
|
1395
|
+
await awaitLegsIdle(bound.signal);
|
|
1396
|
+
}
|
|
1397
|
+
finally {
|
|
1398
|
+
timers.clearTimeout(timer);
|
|
1399
|
+
workflowSignal.removeEventListener("abort", onRunAbort);
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1195
1402
|
const parkSeat = opts.checkpointStore;
|
|
1196
1403
|
const parkedByOrdinal = [];
|
|
1197
1404
|
const errText = (err) => (thrownText(err));
|
|
@@ -1266,12 +1473,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1266
1473
|
return claimHolder === undefined || claimHolder === "" ? text : text.split(claimHolder).join("<holder>");
|
|
1267
1474
|
};
|
|
1268
1475
|
const noteDecision = (drive, callKey, result, code) => {
|
|
1269
|
-
if (drive.decisionId === undefined ||
|
|
1476
|
+
if (drive.decisionId === undefined || finalized)
|
|
1270
1477
|
return;
|
|
1271
|
-
const decisions = (run.
|
|
1478
|
+
const decisions = (run.decisions ??= []);
|
|
1272
1479
|
if (decisions.some((d) => d.decisionId === drive.decisionId && d.callKey === callKey))
|
|
1273
1480
|
return;
|
|
1274
|
-
decisions.push({ ordinal: callKeyOrdinal(callKey), callKey, decisionId: drive.decisionId, result, ...(code !== undefined && code !== "" ? { code } : {}) });
|
|
1481
|
+
decisions.push({ ordinal: callKeyOrdinal(callKey), callKey, decisionId: drive.decisionId, result, ...(code !== undefined && code !== "" ? { code: withoutToken(code, drive.token) } : {}) });
|
|
1275
1482
|
};
|
|
1276
1483
|
const codeOf = (err) => {
|
|
1277
1484
|
const c = readMember(err, "code");
|
|
@@ -1308,7 +1515,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1308
1515
|
const gate = truth.cp.gate;
|
|
1309
1516
|
const outcome = entry !== undefined ? entry.outcome : gate.kind === "resource_limit" && gate.reason === "preempt" ? { gate: "resource_limit", decision: "continue" } : undefined;
|
|
1310
1517
|
if (outcome !== undefined) {
|
|
1311
|
-
const accounted = entry?.decisionId !== undefined
|
|
1518
|
+
const accounted = entry?.decisionId !== undefined ? { decisionId: entry.decisionId } : {};
|
|
1312
1519
|
return { kind: "drive", drive: { token: truth.key.token, outcome, ...(entry?.inheritedGate !== undefined ? { inheritedGate: entry.inheritedGate } : {}), sessionId: paused.sessionId || undefined, paused, row: judgeCheckpointRow(truth.cp), ...accounted } };
|
|
1313
1520
|
}
|
|
1314
1521
|
return { kind: "repark", paused };
|
|
@@ -1328,6 +1535,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1328
1535
|
results[at] = takenParkTokens.has(d.token) ? "already_taken" : "not_parked_here";
|
|
1329
1536
|
return;
|
|
1330
1537
|
}
|
|
1538
|
+
const was = d.decisionId === undefined ? undefined : workflowParkDecisionOf(d.token, d.decisionId, [run]);
|
|
1539
|
+
if (was?.kind === "spent") {
|
|
1540
|
+
emitRunLog(`[park] a decision for the parked leg "${w.rec.label.slice(0, 80)}" was not applied — it was already refused${was.code !== undefined ? ` (${withoutToken(was.code, w.key.token)})` : ""}; the park stands and needs a new decision.`);
|
|
1541
|
+
results[at] = "spent";
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1331
1544
|
takeParkWait(w);
|
|
1332
1545
|
taken.push({ at, w, d });
|
|
1333
1546
|
});
|
|
@@ -1428,6 +1641,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1428
1641
|
return written;
|
|
1429
1642
|
};
|
|
1430
1643
|
const durableApprovalInherit = (s) => s.durableApproval === undefined && opts.defaultDurableApproval !== undefined && !launchUnkept ? { durableApproval: { ...opts.defaultDurableApproval } } : {};
|
|
1644
|
+
const parkGapInherit = (s) => s.durableApproval === undefined && opts.durableApprovalWithheld !== undefined && opts.durableApprovalWithheld.length > 0 ? { workflowParkGap: opts.durableApprovalWithheld } : {};
|
|
1431
1645
|
const journalDurableResult = (result) => {
|
|
1432
1646
|
const t = result.terminal;
|
|
1433
1647
|
if (t === undefined || t.kind !== "failed" || typeof t.message !== "string" || t.message === "")
|
|
@@ -1485,13 +1699,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1485
1699
|
return true;
|
|
1486
1700
|
};
|
|
1487
1701
|
const pausesCounted = new WeakSet();
|
|
1488
|
-
const parkAgentLeg = async (rec, paused, activityTail
|
|
1702
|
+
const parkAgentLeg = async (rec, paused, activityTail) => {
|
|
1489
1703
|
const s = paused.stats;
|
|
1490
1704
|
if (!pausesCounted.has(paused)) {
|
|
1491
1705
|
pausesCounted.add(paused);
|
|
1492
|
-
accumulateStats(paused
|
|
1706
|
+
accumulateStats(paused);
|
|
1493
1707
|
}
|
|
1494
|
-
rec
|
|
1708
|
+
settleRowOutcome(rec, { from: "result", result: paused });
|
|
1495
1709
|
rec.parkedCheckpointToken = paused.terminal.token;
|
|
1496
1710
|
rec.taskStatus = terminalProjection(paused.terminal).status;
|
|
1497
1711
|
foldAgentSession(rec, paused);
|
|
@@ -1541,6 +1755,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1541
1755
|
};
|
|
1542
1756
|
const reviveParkedRecord = (rec) => {
|
|
1543
1757
|
rec.status = "running";
|
|
1758
|
+
delete rec.outcome;
|
|
1544
1759
|
delete rec.parkedCheckpointToken;
|
|
1545
1760
|
delete rec.endedAt;
|
|
1546
1761
|
delete rec.taskStatus;
|
|
@@ -1556,7 +1771,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1556
1771
|
const rec = { label, callKey, ...(groupId !== undefined ? { groupId } : {}), phase, prompt, ...(model !== undefined ? { model } : {}), ...(d.kind === "repark" ? { replayed: true } : {}), status: "running", queuedAt: at, startedAt: at };
|
|
1557
1772
|
if (d.kind === "repark" && run.resume)
|
|
1558
1773
|
run.resume.replayed += 1;
|
|
1559
|
-
|
|
1774
|
+
admitRecord(rec);
|
|
1560
1775
|
if (phaseInstance)
|
|
1561
1776
|
agentPhaseOf.set(rec, phaseInstance);
|
|
1562
1777
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(model !== undefined ? { model } : {}), ...(d.kind === "repark" ? { replayed: true } : {}), ts: at });
|
|
@@ -1567,9 +1782,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1567
1782
|
};
|
|
1568
1783
|
const settleParkedCall = async (rec, result, activityTail, agentOpts) => {
|
|
1569
1784
|
if (finalized)
|
|
1570
|
-
return result;
|
|
1571
|
-
await settleAgentResult(rec, result, activityTail, agentOpts);
|
|
1572
|
-
return result;
|
|
1785
|
+
return lateMember(rec, result, rec.replayed === true ? "replayed" : "live", { from: "result", result, schemaRequested: Boolean(agentOpts.schema), parked: false });
|
|
1786
|
+
return await settleAgentResult(rec, result, activityTail, agentOpts);
|
|
1573
1787
|
};
|
|
1574
1788
|
const createActivityCapture = (callKey, label, groupId, rec) => {
|
|
1575
1789
|
const tail = [];
|
|
@@ -1627,7 +1841,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1627
1841
|
const MAX_GROUP_DEPTH = 32;
|
|
1628
1842
|
let finalized = false;
|
|
1629
1843
|
const latchFinalized = () => {
|
|
1844
|
+
bookOwnSpend();
|
|
1630
1845
|
finalized = true;
|
|
1846
|
+
wfSpend.close();
|
|
1631
1847
|
if (inFlightLegs === 0)
|
|
1632
1848
|
retire();
|
|
1633
1849
|
};
|
|
@@ -1654,6 +1870,144 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1654
1870
|
return;
|
|
1655
1871
|
emitLogLine(message);
|
|
1656
1872
|
};
|
|
1873
|
+
const afterAnswer = [];
|
|
1874
|
+
const persistTerminal = async (ending) => {
|
|
1875
|
+
if (!store)
|
|
1876
|
+
return;
|
|
1877
|
+
const terminal = structuredClone(run);
|
|
1878
|
+
const first = await finalizeWithin(timers, persist("update", structuredClone(terminal)), { ok: false, cause: "timeout" }, true);
|
|
1879
|
+
if (first.ok)
|
|
1880
|
+
return;
|
|
1881
|
+
if (first.cause === "timeout")
|
|
1882
|
+
restartPersistTail();
|
|
1883
|
+
if (first.cause === "not_own") {
|
|
1884
|
+
emitLogLine(`record: this run's ${ending} record was not written — the run store holds no row of this run's own under its id (gone, or another run's), and none is written.`);
|
|
1885
|
+
afterAnswer.push(() => noOwnRow(ending));
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
terminalTries = { ending, terminal, state: "trying" };
|
|
1889
|
+
emitLogLine(first.cause === "timeout"
|
|
1890
|
+
? `record: this run's ${ending} record was not confirmed written (${terminalWriteCause(first)}) — the write is tried again after the run has answered.`
|
|
1891
|
+
: `record: this run's ${ending} record was not written (${terminalWriteCause(first)}) — its record reads running until a later write lands; the write is tried again after the run has answered.`);
|
|
1892
|
+
const tries = terminalTries;
|
|
1893
|
+
afterAnswer.push(() => continueTerminalWrite(tries, first, 0));
|
|
1894
|
+
};
|
|
1895
|
+
let terminalTries;
|
|
1896
|
+
let toldUnwritten = false;
|
|
1897
|
+
let catchingUp = false;
|
|
1898
|
+
const tellUnwritten = (message, detail) => {
|
|
1899
|
+
if (toldUnwritten || catchingUp)
|
|
1900
|
+
return;
|
|
1901
|
+
toldUnwritten = true;
|
|
1902
|
+
deliverEngineNotice(undefined, { code: "workflow.record_unwritten", message: `${message}${SETTLE_ROW_READ_FIRST}`, detail });
|
|
1903
|
+
};
|
|
1904
|
+
const createLandedLate = () => {
|
|
1905
|
+
const tries = terminalTries;
|
|
1906
|
+
if (tries === undefined)
|
|
1907
|
+
return;
|
|
1908
|
+
const unanswered = { ok: false, cause: "timeout" };
|
|
1909
|
+
catchingUp = true;
|
|
1910
|
+
void answeredWithin(() => persist("update", structuredClone(tries.terminal)), unanswered, unanswered)
|
|
1911
|
+
.then((out) => {
|
|
1912
|
+
catchingUp = false;
|
|
1913
|
+
if (out.ok)
|
|
1914
|
+
tries.state = "written";
|
|
1915
|
+
else if (out.cause === "timeout")
|
|
1916
|
+
restartPersistTail();
|
|
1917
|
+
if (tries.state !== "stopped" || out.ok)
|
|
1918
|
+
return;
|
|
1919
|
+
if (out.cause === "not_own")
|
|
1920
|
+
noOwnRow(tries.ending);
|
|
1921
|
+
else
|
|
1922
|
+
readBackAndTell(tries, out);
|
|
1923
|
+
})
|
|
1924
|
+
.catch(() => undefined);
|
|
1925
|
+
};
|
|
1926
|
+
const noOwnRow = (ending) => {
|
|
1927
|
+
const answer = createAnswer;
|
|
1928
|
+
if (answer === undefined || answer.ok)
|
|
1929
|
+
return;
|
|
1930
|
+
tellUnwritten(`workflow run "${runId}": its ${ending} record was not written — the run store did not confirm creating its row (${terminalWriteCause({ cause: "threw", err: answer.err })}) and holds no row of this run's own; the run has ended, and its row may still appear and read running.`, { runId, ending, cause: "create_unconfirmed", storeErrorClass: storeErrorClassOf(answer.err) });
|
|
1931
|
+
};
|
|
1932
|
+
const letGo = (h) => h?.unref?.();
|
|
1933
|
+
const answeredWithin = (ask, unanswered, threw) => new Promise((resolve) => {
|
|
1934
|
+
let bound;
|
|
1935
|
+
try {
|
|
1936
|
+
bound = timers.setTimeout(() => resolve(unanswered), WORKFLOW_STORE_WAIT_BOUND_MS);
|
|
1937
|
+
letGo(bound);
|
|
1938
|
+
}
|
|
1939
|
+
catch {
|
|
1940
|
+
}
|
|
1941
|
+
Promise.resolve()
|
|
1942
|
+
.then(ask)
|
|
1943
|
+
.then(resolve, () => resolve(threw))
|
|
1944
|
+
.then(() => {
|
|
1945
|
+
try {
|
|
1946
|
+
if (bound !== undefined)
|
|
1947
|
+
timers.clearTimeout(bound);
|
|
1948
|
+
}
|
|
1949
|
+
catch {
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
const continueTerminalWrite = (tries, last, tried) => {
|
|
1954
|
+
if (tries.state === "written")
|
|
1955
|
+
return;
|
|
1956
|
+
if (last.ok) {
|
|
1957
|
+
tries.state = "written";
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
if (last.cause === "not_own") {
|
|
1961
|
+
tries.state = "stopped";
|
|
1962
|
+
noOwnRow(tries.ending);
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
const delay = TERMINAL_WRITE_RETRY_DELAYS_MS[tried];
|
|
1966
|
+
if (delay !== undefined) {
|
|
1967
|
+
const unanswered = { ok: false, cause: "timeout" };
|
|
1968
|
+
const tryAgain = () => {
|
|
1969
|
+
if (tries.state === "written")
|
|
1970
|
+
return;
|
|
1971
|
+
void answeredWithin(() => persist("update", structuredClone(tries.terminal)), unanswered, unanswered)
|
|
1972
|
+
.then((next) => {
|
|
1973
|
+
if (!next.ok && next.cause === "timeout")
|
|
1974
|
+
restartPersistTail();
|
|
1975
|
+
continueTerminalWrite(tries, next, tried + 1);
|
|
1976
|
+
})
|
|
1977
|
+
.catch(() => undefined);
|
|
1978
|
+
};
|
|
1979
|
+
try {
|
|
1980
|
+
letGo(timers.setTimeout(tryAgain, delay));
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
catch {
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
tries.state = "stopped";
|
|
1987
|
+
readBackAndTell(tries, last);
|
|
1988
|
+
};
|
|
1989
|
+
const readBackAndTell = (tries, answered) => {
|
|
1990
|
+
if (answered.cause === "not_own")
|
|
1991
|
+
return;
|
|
1992
|
+
const last = answered;
|
|
1993
|
+
const cause = answered.cause;
|
|
1994
|
+
void answeredWithin(async () => {
|
|
1995
|
+
const row = await store?.get(runId);
|
|
1996
|
+
return ownRow(row) ? { read: true, own: true, running: row.status === "running" } : { read: true, own: false, running: false };
|
|
1997
|
+
}, { read: false }, { read: false })
|
|
1998
|
+
.then((back) => {
|
|
1999
|
+
if (tries.state === "written")
|
|
2000
|
+
return;
|
|
2001
|
+
if (back.read && !back.own)
|
|
2002
|
+
return noOwnRow(tries.ending);
|
|
2003
|
+
if (back.read && !back.running)
|
|
2004
|
+
return;
|
|
2005
|
+
tellUnwritten(back.read
|
|
2006
|
+
? `workflow run "${runId}": its ${tries.ending} record was not written (${terminalWriteCause(last)}) — the run has ended and its record still reads running.`
|
|
2007
|
+
: `workflow run "${runId}": its ${tries.ending} record was not confirmed written (${terminalWriteCause(last)}) — the run has ended and its record could not be read back.`, { runId, ending: tries.ending, cause, ...(last.cause === "threw" ? { storeErrorClass: storeErrorClassOf(last.err) } : {}) });
|
|
2008
|
+
})
|
|
2009
|
+
.catch(() => undefined);
|
|
2010
|
+
};
|
|
1657
2011
|
const yieldIntent = opts.preemptSignal;
|
|
1658
2012
|
const yieldLegs = new Set();
|
|
1659
2013
|
const onYieldIntent = () => {
|
|
@@ -1801,6 +2155,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1801
2155
|
if (effectiveSignal?.aborted)
|
|
1802
2156
|
throw new Error("workflow aborted");
|
|
1803
2157
|
if (maxAgents !== undefined && run.agents.length >= maxAgents) {
|
|
2158
|
+
run.refusedAtMemberCap = (run.refusedAtMemberCap ?? 0) + 1;
|
|
1804
2159
|
throw new WorkflowMaxAgentsError(maxAgents, budgetTotal, spent());
|
|
1805
2160
|
}
|
|
1806
2161
|
return effectiveSignal;
|
|
@@ -1812,7 +2167,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1812
2167
|
throw new TypeError(`agent({schema}) received an invalid JSON Schema: ${compiled.error}`);
|
|
1813
2168
|
}
|
|
1814
2169
|
assertSupportedAgentIsolation(agentOpts.isolation);
|
|
1815
|
-
const
|
|
2170
|
+
const statedLabel = agentOpts.label;
|
|
1816
2171
|
const phase = agentOpts.phase ?? currentPhase?.title;
|
|
1817
2172
|
const phaseInstance = resolveAgentPhase(agentOpts.phase);
|
|
1818
2173
|
const groupId = currentGroup;
|
|
@@ -1839,11 +2194,20 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1839
2194
|
...(inheritedPrincipal !== undefined ? { principal: inheritedPrincipal } : {}),
|
|
1840
2195
|
...(inheritedIsolationScope !== undefined ? { isolationScope: inheritedIsolationScope } : {}),
|
|
1841
2196
|
};
|
|
1842
|
-
const
|
|
2197
|
+
const specHash = workflowAgentSpecHash(specForIdentity, agentOpts);
|
|
1843
2198
|
const prompt = boundedRedactedSummary(spec.systemPrompt ? `${spec.systemPrompt}\n\n${spec.objective}` : spec.objective, MAX_TRANSCRIPT_CHARS);
|
|
1844
2199
|
const specForLabel = spec.model === undefined && typeDefModel !== undefined ? { ...spec, model: typeDefModel } : specForIdentity;
|
|
1845
2200
|
const model = workflowModelLabel(specForLabel, modelCatalog);
|
|
1846
|
-
|
|
2201
|
+
const scope = scopeHere();
|
|
2202
|
+
const inItem = scope?.item !== undefined;
|
|
2203
|
+
const event = { prefix: scope !== undefined ? `${scope.path}.` : "", n: (scope?.chain ?? rootChain).n++ };
|
|
2204
|
+
const position = `${event.prefix}c${event.n}`;
|
|
2205
|
+
const { ordinal, adopted } = ordinalFor(position, inItem, specHash);
|
|
2206
|
+
reachedPositions.add(position);
|
|
2207
|
+
const label = statedLabel ?? `agent-${ordinal + 1}`;
|
|
2208
|
+
const callKey = callKeyOf(ordinal, specHash, priorRecordUnpositioned ? undefined : position);
|
|
2209
|
+
const place = { ordinal, position, event, adopted, inItem, besidePipeline: (priorRecordUnpositioned ? !inItem : scope === undefined) && pipelinesRunning > 0 };
|
|
2210
|
+
return { label, phase, phaseInstance, groupId, inheritedModelSnap, inheritedModelRef: inheritedModelPick?.modelRef, inheritedModelError, inheritedThinkingSnap, callKey, place, prompt, model };
|
|
1847
2211
|
};
|
|
1848
2212
|
const reviewSpawnBeforeLaunch = async (lane, label, callKey, runSpec, effectiveSignal, agentType, driven) => {
|
|
1849
2213
|
if (opts.agentStations?.listens("agent.spawn") === true && !driven) {
|
|
@@ -1926,8 +2290,10 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1926
2290
|
},
|
|
1927
2291
|
askMessage: `Reviewing a workflow-spawned sub-agent ("${labelForReview}", ${lane}) about to be started. ` +
|
|
1928
2292
|
`Objective: ${objective}\nTools available to it: ${toolsNote}${remoteNote}${imagesNote}`,
|
|
2293
|
+
spendSeat: wfSpend,
|
|
1929
2294
|
}, effectiveSignal)
|
|
1930
2295
|
.catch(() => ({ kind: "unavailable", cause: "error" }));
|
|
2296
|
+
bookOwnSpend();
|
|
1931
2297
|
if (effectiveSignal?.aborted)
|
|
1932
2298
|
throw new Error("workflow aborted");
|
|
1933
2299
|
if (finalized)
|
|
@@ -1969,16 +2335,23 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1969
2335
|
};
|
|
1970
2336
|
return { onTurnEndUsage, rollbackUsageBeat, observedTokens: () => beatTokens };
|
|
1971
2337
|
};
|
|
1972
|
-
const settleAgentResult = async (rec, result, activityTail, agentOpts) => {
|
|
2338
|
+
const settleAgentResult = async (rec, result, activityTail, agentOpts, counted = false) => {
|
|
1973
2339
|
const s = result.stats;
|
|
1974
|
-
|
|
1975
|
-
|
|
2340
|
+
if (!counted)
|
|
2341
|
+
accumulateStats(result);
|
|
2342
|
+
const stopper = result.terminal.kind === "failed" ? runStopper() : undefined;
|
|
2343
|
+
const outcome = settleRowOutcome(rec, { from: "result", result, schemaRequested: Boolean(agentOpts.schema), parked: false, ...(stopper !== undefined ? { settled: { status: "killed", stoppedBy: stopper } } : {}) });
|
|
1976
2344
|
rec.taskStatus = terminalProjection(result.terminal).status;
|
|
1977
2345
|
foldAgentSession(rec, result);
|
|
1978
2346
|
setLegRunId(rec, result);
|
|
1979
2347
|
rec.endedAt = now();
|
|
1980
2348
|
rec.stats = { tokens: s.tokens ?? 0, turns: s.turns ?? 0, costMicroUsd: s.costMicroUsd };
|
|
1981
2349
|
const output = settleAgentError(rec, result.terminal, rec.label, boundedRedactedSummary(result.structuredOutput ?? result.result, MAX_TRANSCRIPT_CHARS));
|
|
2350
|
+
const schemaUnmet = outcome.outcome === "schema_unmet" ? new WorkflowAgentSchemaError(rec.label, result, outcome) : undefined;
|
|
2351
|
+
if (schemaUnmet !== undefined) {
|
|
2352
|
+
rec.errorCode = schemaUnmet.code;
|
|
2353
|
+
rec.errorMessage = boundedRedactedSummary(schemaUnmet.message, MAX_TRANSCRIPT_CHARS);
|
|
2354
|
+
}
|
|
1982
2355
|
if (result.stats.toolCalls !== undefined)
|
|
1983
2356
|
rec.toolCalls = result.stats.toolCalls;
|
|
1984
2357
|
if (activityTail.length > 0)
|
|
@@ -1988,12 +2361,14 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1988
2361
|
void persist("update");
|
|
1989
2362
|
bceTerminal(rec.callKey, rec.status === "completed" ? "completed" : "failed", output, rec.stats);
|
|
1990
2363
|
await journalAppend(rec.callKey, result, rec.label);
|
|
1991
|
-
if (
|
|
1992
|
-
throw
|
|
1993
|
-
|
|
1994
|
-
};
|
|
1995
|
-
const resumeArmOf = (callKey) => {
|
|
1996
|
-
const ordinal =
|
|
2364
|
+
if (schemaUnmet !== undefined)
|
|
2365
|
+
throw schemaUnmet;
|
|
2366
|
+
return withMember(result, outcome);
|
|
2367
|
+
};
|
|
2368
|
+
const resumeArmOf = (callKey, place) => {
|
|
2369
|
+
const ordinal = place.ordinal;
|
|
2370
|
+
const newPosition = place.inItem && !place.adopted;
|
|
2371
|
+
notMadeAt("call", place.event);
|
|
1997
2372
|
let drive;
|
|
1998
2373
|
const truth = opts.resumeFromRunId !== undefined ? parkedByOrdinal[ordinal] : undefined;
|
|
1999
2374
|
if (truth !== undefined) {
|
|
@@ -2011,8 +2386,30 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2011
2386
|
}
|
|
2012
2387
|
if (parkedLeg !== undefined && drive === undefined)
|
|
2013
2388
|
throw parkedError();
|
|
2014
|
-
if (drive !== undefined || opts.resumeFromRunId === undefined
|
|
2389
|
+
if (drive !== undefined || opts.resumeFromRunId === undefined)
|
|
2015
2390
|
return { kind: "live", drive };
|
|
2391
|
+
const runAgain = () => {
|
|
2392
|
+
const prior = replayByOrdinal[ordinal];
|
|
2393
|
+
if (prior?.callKey === callKey && prior.result !== undefined && TERMINAL_CAUSE_IS_REPLAYABLE[prior.result.terminal.kind])
|
|
2394
|
+
completedRunsAgain.add(callKey);
|
|
2395
|
+
return { kind: "live", drive: undefined };
|
|
2396
|
+
};
|
|
2397
|
+
if (divergence !== undefined)
|
|
2398
|
+
return runAgain();
|
|
2399
|
+
if (newPosition) {
|
|
2400
|
+
noteDivergence(ordinal, priorRecordUnpositioned
|
|
2401
|
+
? "a pipeline call the resumed run's record holds no call for — the record was written before pipeline calls had positions, and no call in it has this call's spec"
|
|
2402
|
+
: `a call at a pipeline position the resumed run never recorded (${place.position}) — an item, a stage or a call it did not reach, or one the script added`);
|
|
2403
|
+
return runAgain();
|
|
2404
|
+
}
|
|
2405
|
+
if (place.besidePipeline) {
|
|
2406
|
+
noteDivergence(ordinal, "a call outside the pipeline made while a pipeline of this run was running (written beside it, or the script runner did not carry the engine's context into the call) — its ordinal depends on how far the pipeline had got");
|
|
2407
|
+
return runAgain();
|
|
2408
|
+
}
|
|
2409
|
+
if (place.inItem && priorRecordUnpositioned) {
|
|
2410
|
+
noteDivergence(ordinal, "a pipeline call while the resumed run's record was written before pipeline calls had positions — its pipeline calls run live, as they did then (each on the ordinal of the recorded call with its spec, so a parked one is driven where it was)");
|
|
2411
|
+
return runAgain();
|
|
2412
|
+
}
|
|
2016
2413
|
const cached = replayByOrdinal[ordinal];
|
|
2017
2414
|
if (cached && cached.callKey === callKey && cached.result !== undefined && TERMINAL_CAUSE_IS_REPLAYABLE[cached.result.terminal.kind]) {
|
|
2018
2415
|
return { kind: "replay", result: cached.result };
|
|
@@ -2032,8 +2429,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2032
2429
|
};
|
|
2033
2430
|
const replayAgent = async (call, r, agentOpts) => {
|
|
2034
2431
|
const { label, callKey, groupId, phase, phaseInstance, prompt } = call;
|
|
2432
|
+
const replayFacts = { from: "result", result: r, schemaRequested: Boolean(agentOpts.schema), parked: false };
|
|
2035
2433
|
if (finalized)
|
|
2036
|
-
return r;
|
|
2434
|
+
return lateMember(undefined, r, "replayed", replayFacts);
|
|
2037
2435
|
const rs = r.stats;
|
|
2038
2436
|
const cachedOutput = boundedRedactedSummary(r.structuredOutput ?? r.result, MAX_TRANSCRIPT_CHARS);
|
|
2039
2437
|
const at = now();
|
|
@@ -2046,7 +2444,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2046
2444
|
prompt,
|
|
2047
2445
|
...(replayModel !== undefined ? { model: replayModel } : {}),
|
|
2048
2446
|
replayed: true,
|
|
2049
|
-
status:
|
|
2447
|
+
status: "running",
|
|
2050
2448
|
taskStatus: terminalProjection(r.terminal).status,
|
|
2051
2449
|
...(r.sessionId ? { sessionId: r.sessionId } : {}),
|
|
2052
2450
|
...(r.runId ? { taskRunId: r.runId } : {}),
|
|
@@ -2059,21 +2457,26 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2059
2457
|
};
|
|
2060
2458
|
if (run.resume)
|
|
2061
2459
|
run.resume.replayed += 1;
|
|
2062
|
-
|
|
2460
|
+
const replayOutcome = settleRowOutcome(replayRec, replayFacts);
|
|
2461
|
+
const schemaUnmet = replayOutcome.outcome === "schema_unmet" ? new WorkflowAgentSchemaError(label, r, replayOutcome) : undefined;
|
|
2462
|
+
if (schemaUnmet !== undefined) {
|
|
2463
|
+
replayRec.errorCode = schemaUnmet.code;
|
|
2464
|
+
replayRec.errorMessage = boundedRedactedSummary(schemaUnmet.message, MAX_TRANSCRIPT_CHARS);
|
|
2465
|
+
}
|
|
2466
|
+
admitRecord(replayRec);
|
|
2063
2467
|
if (phaseInstance)
|
|
2064
2468
|
agentPhaseOf.set(replayRec, phaseInstance);
|
|
2065
2469
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(replayModel !== undefined ? { model: replayModel } : {}), replayed: true, ts: at });
|
|
2066
|
-
emit({ type: "agent_end", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), status: replayRec.status, output: cachedOutput, ...(rs.toolCalls !== undefined ? { toolCalls: rs.toolCalls } : {}), replayed: true, ts: at });
|
|
2470
|
+
emit({ type: "agent_end", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), status: replayRec.status, output: cachedOutput, ...(replayRec.errorCode !== undefined ? { errorCode: replayRec.errorCode } : {}), ...(rs.toolCalls !== undefined ? { toolCalls: rs.toolCalls } : {}), replayed: true, ts: at });
|
|
2067
2471
|
bceSpawn(callKey, label, agentOpts.agentType, true, r.sessionId || undefined, replayModel);
|
|
2068
2472
|
foldAgentSession(replayRec, r);
|
|
2069
2473
|
bceTerminal(callKey, replayRec.status === "completed" ? "completed" : "failed", cachedOutput, replayRec.stats);
|
|
2070
|
-
accumulateStats(r
|
|
2474
|
+
accumulateStats(r);
|
|
2071
2475
|
void persist("update");
|
|
2072
2476
|
await journalAppend(callKey, r);
|
|
2073
|
-
if (
|
|
2074
|
-
throw
|
|
2075
|
-
|
|
2076
|
-
return r;
|
|
2477
|
+
if (schemaUnmet !== undefined)
|
|
2478
|
+
throw schemaUnmet;
|
|
2479
|
+
return withMember(r, replayOutcome);
|
|
2077
2480
|
};
|
|
2078
2481
|
const settledHandle = (label, callKey, settled) => {
|
|
2079
2482
|
settled.catch(() => undefined);
|
|
@@ -2096,9 +2499,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2096
2499
|
},
|
|
2097
2500
|
async agent(spec, agentOpts = {}) {
|
|
2098
2501
|
const effectiveSignal = assertAgentSpawnAllowed("ctx.agent", spec, agentOpts);
|
|
2099
|
-
const { label, phase, phaseInstance, groupId, inheritedModelSnap, inheritedModelRef, inheritedModelError, inheritedThinkingSnap, callKey, prompt, model } = prepareAgentCall(spec, agentOpts);
|
|
2502
|
+
const { label, phase, phaseInstance, groupId, inheritedModelSnap, inheritedModelRef, inheritedModelError, inheritedThinkingSnap, callKey, place, prompt, model } = prepareAgentCall(spec, agentOpts);
|
|
2100
2503
|
const call = { label, callKey, groupId, phase, phaseInstance, prompt };
|
|
2101
|
-
const arm = resumeArmOf(callKey);
|
|
2504
|
+
const arm = resumeArmOf(callKey, place);
|
|
2102
2505
|
const disposition = arm.kind === "dispose" ? arm.d : undefined;
|
|
2103
2506
|
if (disposition?.kind === "settle")
|
|
2104
2507
|
return await settleParkedCall(openDispositionRecord(disposition, call, agentOpts), disposition.result, [], agentOpts);
|
|
@@ -2110,11 +2513,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2110
2513
|
rec = openDispositionRecord(disposition, call, agentOpts);
|
|
2111
2514
|
}
|
|
2112
2515
|
else {
|
|
2113
|
-
if (budgetTotal !== null && spent() >= budgetTotal) {
|
|
2114
|
-
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
2115
|
-
}
|
|
2116
2516
|
rec = { label, callKey, ...(groupId !== undefined ? { groupId } : {}), phase, prompt, ...(model !== undefined ? { model } : {}), status: "running", queuedAt: now() };
|
|
2117
|
-
|
|
2517
|
+
admitRecord(rec);
|
|
2118
2518
|
if (phaseInstance)
|
|
2119
2519
|
agentPhaseOf.set(rec, phaseInstance);
|
|
2120
2520
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(model !== undefined ? { model } : {}), queuedAt: rec.queuedAt, ts: rec.queuedAt });
|
|
@@ -2122,7 +2522,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2122
2522
|
}
|
|
2123
2523
|
const { tail: activityTail, onActivity } = createActivityCapture(callKey, label, groupId, rec);
|
|
2124
2524
|
if (disposition !== undefined) {
|
|
2125
|
-
const answer = await parkAgentLeg(rec, disposition.paused, []
|
|
2525
|
+
const answer = await parkAgentLeg(rec, disposition.paused, []);
|
|
2126
2526
|
if (answer.kind === "settle")
|
|
2127
2527
|
return await settleParkedCall(rec, answer.result, activityTail, agentOpts);
|
|
2128
2528
|
nextDrive = answer.drive;
|
|
@@ -2132,6 +2532,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2132
2532
|
legStart();
|
|
2133
2533
|
const release = await sem.acquire();
|
|
2134
2534
|
let result;
|
|
2535
|
+
let keptFirstAnswer = false;
|
|
2135
2536
|
try {
|
|
2136
2537
|
adviseIsolationIfConcurrent(agentOpts);
|
|
2137
2538
|
if (effectiveSignal?.aborted)
|
|
@@ -2140,9 +2541,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2140
2541
|
throw new Error("workflow run already finalized — ctx.agent cannot spawn after the run ended");
|
|
2141
2542
|
if (parkedLeg !== undefined && drive === undefined)
|
|
2142
2543
|
throw parkedError();
|
|
2143
|
-
|
|
2144
|
-
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
2145
|
-
}
|
|
2544
|
+
budgetGate();
|
|
2146
2545
|
rec.startedAt = now();
|
|
2147
2546
|
const bornChildSessionId = drive !== undefined ? drive.sessionId : resolveChildSessionIdAtSpawn(spec);
|
|
2148
2547
|
bceSpawn(callKey, label, agentOpts.agentType, false, bornChildSessionId, model);
|
|
@@ -2168,9 +2567,10 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2168
2567
|
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ? memberStamp(e, callKey, label) : e);
|
|
2169
2568
|
}
|
|
2170
2569
|
: undefined;
|
|
2171
|
-
const baseInternals = { ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...callerPlacementSeats(opts.parentCwd, opts.callerRoot), ...spawnAttribution, ...definitionSeats(typed), ...(await captureFloorSeatsNow()), ...(enrichedForward !== undefined ? { onForwardEvent: enrichedForward } : {}), delegationTaskType: "workflow", agentName: label, ...memberSeat(callKey, label), onWorkspaceResolved: createWorkspaceObserver(rec) };
|
|
2570
|
+
const baseInternals = { ...parkGapInherit(seatedSpec), ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...callerPlacementSeats(opts.parentCwd, opts.callerRoot), ...spawnAttribution, ...definitionSeats(typed), ...(await captureFloorSeatsNow()), ...(enrichedForward !== undefined ? { onForwardEvent: enrichedForward } : {}), delegationTaskType: "workflow", spendParent: memberSpendParent, agentName: label, ...memberSeat(callKey, label), onWorkspaceResolved: createWorkspaceObserver(rec) };
|
|
2172
2571
|
let attempts = 0;
|
|
2173
2572
|
let throttleRetried = false;
|
|
2573
|
+
let throttleFirst;
|
|
2174
2574
|
let lastAttemptReason;
|
|
2175
2575
|
let approvalWaivedAttempts = 0;
|
|
2176
2576
|
for (;;) {
|
|
@@ -2197,10 +2597,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2197
2597
|
}
|
|
2198
2598
|
};
|
|
2199
2599
|
const onCallerAbort = () => attemptCtl.abort(new Error("workflow aborted"));
|
|
2200
|
-
if (effectiveSignal?.aborted === true)
|
|
2600
|
+
if (effectiveSignal?.aborted === true || membersStop.signal.aborted)
|
|
2201
2601
|
onCallerAbort();
|
|
2202
|
-
else
|
|
2602
|
+
else {
|
|
2203
2603
|
effectiveSignal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
2604
|
+
membersStop.signal.addEventListener("abort", onCallerAbort, { once: true });
|
|
2605
|
+
}
|
|
2204
2606
|
armWatchdog();
|
|
2205
2607
|
const attemptSessionId = drive !== undefined ? drive.sessionId : attempts === 1 ? bornChildSessionId : resolveChildSessionIdAtSpawn(runSpec);
|
|
2206
2608
|
const attemptYield = legYieldSeats();
|
|
@@ -2291,12 +2693,20 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2291
2693
|
const attemptHadSpend = rollbackUsageBeat();
|
|
2292
2694
|
activeUsageBeats.delete(activeBeat);
|
|
2293
2695
|
if (attemptError !== undefined && attemptHadSpend && !finalized && rec.stats !== undefined) {
|
|
2294
|
-
accumulateStats({ stats: rec.stats }
|
|
2696
|
+
accumulateStats({ stats: rec.stats });
|
|
2295
2697
|
}
|
|
2296
2698
|
disarmWatchdog();
|
|
2297
2699
|
effectiveSignal?.removeEventListener("abort", onCallerAbort);
|
|
2700
|
+
membersStop.signal.removeEventListener("abort", onCallerAbort);
|
|
2298
2701
|
}
|
|
2299
|
-
if (effectiveSignal?.aborted) {
|
|
2702
|
+
if (effectiveSignal?.aborted || membersStop.signal.aborted) {
|
|
2703
|
+
if (throttleFirst !== undefined && attemptResult?.terminal.kind !== "completed") {
|
|
2704
|
+
if (attemptResult !== undefined && !finalized)
|
|
2705
|
+
accumulateStats(attemptResult);
|
|
2706
|
+
result = throttleFirst;
|
|
2707
|
+
keptFirstAnswer = true;
|
|
2708
|
+
break;
|
|
2709
|
+
}
|
|
2300
2710
|
if (attemptError !== undefined)
|
|
2301
2711
|
throw attemptError;
|
|
2302
2712
|
if (attemptResult !== undefined) {
|
|
@@ -2307,7 +2717,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2307
2717
|
}
|
|
2308
2718
|
if (drive === undefined && stallFired && attemptResult?.terminal.kind !== "completed") {
|
|
2309
2719
|
if (attemptResult !== undefined && !finalized)
|
|
2310
|
-
accumulateStats(attemptResult
|
|
2720
|
+
accumulateStats(attemptResult);
|
|
2311
2721
|
if (attemptResult !== undefined && !finalized)
|
|
2312
2722
|
setLegRunId(rec, attemptResult);
|
|
2313
2723
|
const reported = attemptResult !== undefined && !finalized ? foldLegApprovalReport(rec, attemptResult) : undefined;
|
|
@@ -2328,6 +2738,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2328
2738
|
if (attemptError !== undefined)
|
|
2329
2739
|
throw attemptError;
|
|
2330
2740
|
result = attemptResult;
|
|
2741
|
+
if (throttleFirst !== undefined && result.terminal.kind === "failed" && SPEND_STOP_CODES.has(result.terminal.code ?? "")) {
|
|
2742
|
+
if (!finalized)
|
|
2743
|
+
accumulateStats(result);
|
|
2744
|
+
result = throttleFirst;
|
|
2745
|
+
keptFirstAnswer = true;
|
|
2746
|
+
break;
|
|
2747
|
+
}
|
|
2331
2748
|
const durationMs = now() - attemptStart;
|
|
2332
2749
|
const degraded = result.terminal.kind === "completed" &&
|
|
2333
2750
|
result.structuredOutput === undefined &&
|
|
@@ -2338,24 +2755,31 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2338
2755
|
throttleRetried = true;
|
|
2339
2756
|
lastAttemptReason = "throttled";
|
|
2340
2757
|
emitRunLog(`[${label}] throttled response (${(result.result ?? "").trim().length} chars in ${Math.round(durationMs / 1000)}s) — sleeping ${Math.round(throttleBackoffMs / 1000)}s before retry`);
|
|
2758
|
+
throttleFirst = result;
|
|
2341
2759
|
if (!finalized) {
|
|
2342
2760
|
setLegRunId(rec, result);
|
|
2343
|
-
accumulateStats(result
|
|
2761
|
+
accumulateStats(result);
|
|
2344
2762
|
void persist("update");
|
|
2345
2763
|
}
|
|
2346
2764
|
await new Promise((resolve) => {
|
|
2347
2765
|
const onAbort = () => {
|
|
2348
2766
|
timers.clearTimeout(t);
|
|
2767
|
+
effectiveSignal?.removeEventListener("abort", onAbort);
|
|
2768
|
+
membersStop.signal.removeEventListener("abort", onAbort);
|
|
2349
2769
|
resolve();
|
|
2350
2770
|
};
|
|
2351
2771
|
const t = timers.setTimeout(() => {
|
|
2352
2772
|
effectiveSignal?.removeEventListener("abort", onAbort);
|
|
2773
|
+
membersStop.signal.removeEventListener("abort", onAbort);
|
|
2353
2774
|
resolve();
|
|
2354
2775
|
}, throttleBackoffMs);
|
|
2355
2776
|
effectiveSignal?.addEventListener("abort", onAbort, { once: true });
|
|
2777
|
+
membersStop.signal.addEventListener("abort", onAbort, { once: true });
|
|
2356
2778
|
});
|
|
2357
|
-
if (effectiveSignal?.aborted)
|
|
2358
|
-
|
|
2779
|
+
if (effectiveSignal?.aborted || membersStop.signal.aborted) {
|
|
2780
|
+
keptFirstAnswer = true;
|
|
2781
|
+
break;
|
|
2782
|
+
}
|
|
2359
2783
|
continue;
|
|
2360
2784
|
}
|
|
2361
2785
|
if (degraded && throttleRetried) {
|
|
@@ -2377,14 +2801,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2377
2801
|
const unresumable = unresumableRowResult(drive, rec.callKey, err);
|
|
2378
2802
|
if (unresumable !== undefined)
|
|
2379
2803
|
return await settleParkedCall(rec, unresumable, activityTail, agentOpts);
|
|
2380
|
-
const answer = await parkAgentLeg(rec, drive.paused, activityTail
|
|
2804
|
+
const answer = await parkAgentLeg(rec, drive.paused, activityTail);
|
|
2381
2805
|
if (answer.kind === "settle")
|
|
2382
2806
|
return await settleParkedCall(rec, answer.result, activityTail, agentOpts);
|
|
2383
2807
|
nextDrive = answer.drive;
|
|
2384
2808
|
continue;
|
|
2385
2809
|
}
|
|
2386
2810
|
if (!finalized) {
|
|
2387
|
-
rec.status = "failed";
|
|
2388
2811
|
rec.endedAt = now();
|
|
2389
2812
|
const salvaged = thrownIs(err, WorkflowAgentStalledError) ? err.lastResult : undefined;
|
|
2390
2813
|
if (salvaged?.runId === undefined)
|
|
@@ -2416,6 +2839,18 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2416
2839
|
rec.attempts = err.attempts;
|
|
2417
2840
|
rec.lastAttemptReason = "stalled";
|
|
2418
2841
|
}
|
|
2842
|
+
const stopper = thrownIs(err, WorkflowBudgetExceededError) ? undefined : runStopper();
|
|
2843
|
+
const thrownOutcome = settleRowOutcome(rec, thrownIs(err, WorkflowBudgetExceededError)
|
|
2844
|
+
? { from: "refused", budget: true }
|
|
2845
|
+
: (() => {
|
|
2846
|
+
const refused = salvaged !== undefined ? memberRefusalsOf(salvaged) : undefined;
|
|
2847
|
+
if (stopper !== undefined)
|
|
2848
|
+
return { from: "ended", status: "killed", stoppedBy: stopper, ...(refused !== undefined ? { refused } : {}) };
|
|
2849
|
+
const code = rec.errorCode ?? codeOf(err);
|
|
2850
|
+
return { from: "ended", status: "failed", ...(code !== undefined ? { code } : {}), ...(refused !== undefined ? { refused } : {}) };
|
|
2851
|
+
})());
|
|
2852
|
+
if (thrownIs(err, WorkflowBudgetExceededError))
|
|
2853
|
+
err.member = thrownOutcome;
|
|
2419
2854
|
emit({ type: "agent_end", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), status: "failed", ...(rec.output !== undefined ? { output: rec.output } : {}), ...(rec.errorCode !== undefined ? { errorCode: rec.errorCode } : {}), ts: rec.endedAt });
|
|
2420
2855
|
void persist("update");
|
|
2421
2856
|
release();
|
|
@@ -2442,29 +2877,28 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2442
2877
|
legEnd();
|
|
2443
2878
|
}
|
|
2444
2879
|
if (finalized)
|
|
2445
|
-
return result;
|
|
2880
|
+
return lateMember(rec, result, "live", { from: "result", result, schemaRequested: Boolean(agentOpts.schema) });
|
|
2446
2881
|
const unstartedDrive = drive !== undefined && resumeNeverStarted(result) ? drive : undefined;
|
|
2447
2882
|
if (unstartedDrive !== undefined)
|
|
2448
2883
|
emitRunLog(`[park] the parked leg "${label}" was driven but the approved action never started (${result.terminal.kind === "failed" ? result.terminal.code : ""}); the park stands.`);
|
|
2449
2884
|
if (drive !== undefined)
|
|
2450
2885
|
noteDecision(drive, rec.callKey, unstartedDrive !== undefined ? "refused" : "driven", unstartedDrive !== undefined && result.terminal.kind === "failed" ? result.terminal.code : undefined);
|
|
2451
|
-
const parkOn = isPausedResult(result) ?
|
|
2886
|
+
const parkOn = isPausedResult(result) ? result : unstartedDrive?.paused;
|
|
2452
2887
|
if (parkOn !== undefined) {
|
|
2453
|
-
const answer = await parkAgentLeg(rec, parkOn
|
|
2888
|
+
const answer = await parkAgentLeg(rec, parkOn, activityTail);
|
|
2454
2889
|
if (answer.kind === "settle")
|
|
2455
2890
|
return await settleParkedCall(rec, answer.result, activityTail, agentOpts);
|
|
2456
2891
|
nextDrive = answer.drive;
|
|
2457
2892
|
continue;
|
|
2458
2893
|
}
|
|
2459
|
-
await settleAgentResult(rec, result, activityTail, agentOpts);
|
|
2460
|
-
return result;
|
|
2894
|
+
return await settleAgentResult(rec, result, activityTail, agentOpts, keptFirstAnswer);
|
|
2461
2895
|
}
|
|
2462
2896
|
},
|
|
2463
2897
|
async agentStream(spec, agentOpts = {}) {
|
|
2464
2898
|
const effectiveSignal = assertAgentSpawnAllowed("ctx.agentStream", spec, agentOpts);
|
|
2465
|
-
const { label, phase, phaseInstance, groupId, inheritedModelSnap, inheritedModelRef, inheritedModelError, inheritedThinkingSnap, callKey, prompt, model } = prepareAgentCall(spec, agentOpts);
|
|
2899
|
+
const { label, phase, phaseInstance, groupId, inheritedModelSnap, inheritedModelRef, inheritedModelError, inheritedThinkingSnap, callKey, place, prompt, model } = prepareAgentCall(spec, agentOpts);
|
|
2466
2900
|
const call = { label, callKey, groupId, phase, phaseInstance, prompt };
|
|
2467
|
-
const arm = resumeArmOf(callKey);
|
|
2901
|
+
const arm = resumeArmOf(callKey, place);
|
|
2468
2902
|
const disposition = arm.kind === "dispose" ? arm.d : undefined;
|
|
2469
2903
|
if (disposition?.kind === "settle")
|
|
2470
2904
|
return settledHandle(label, callKey, Promise.resolve(await settleParkedCall(openDispositionRecord(disposition, call, agentOpts), disposition.result, [], agentOpts)));
|
|
@@ -2475,19 +2909,16 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2475
2909
|
rec = openDispositionRecord(disposition, call, agentOpts);
|
|
2476
2910
|
}
|
|
2477
2911
|
else {
|
|
2478
|
-
if (budgetTotal !== null && spent() >= budgetTotal) {
|
|
2479
|
-
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
2480
|
-
}
|
|
2481
2912
|
rec = { label, callKey, ...(groupId !== undefined ? { groupId } : {}), phase, prompt, ...(model !== undefined ? { model } : {}), status: "running", queuedAt: now() };
|
|
2482
|
-
|
|
2913
|
+
admitRecord(rec);
|
|
2483
2914
|
if (phaseInstance)
|
|
2484
2915
|
agentPhaseOf.set(rec, phaseInstance);
|
|
2485
2916
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(model !== undefined ? { model } : {}), queuedAt: rec.queuedAt, ts: rec.queuedAt });
|
|
2486
2917
|
void persist("update");
|
|
2487
2918
|
}
|
|
2488
2919
|
const { tail: activityTail, onActivity } = createActivityCapture(callKey, label, groupId, rec);
|
|
2489
|
-
const legAfterPark = async (paused, tail
|
|
2490
|
-
const answer = await parkAgentLeg(rec, paused, tail
|
|
2920
|
+
const legAfterPark = async (paused, tail) => {
|
|
2921
|
+
const answer = await parkAgentLeg(rec, paused, tail);
|
|
2491
2922
|
if (answer.kind === "settle")
|
|
2492
2923
|
return { kind: "settled", result: await settleParkedCall(rec, answer.result, tail, agentOpts) };
|
|
2493
2924
|
return await launch(answer.drive);
|
|
@@ -2502,13 +2933,16 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2502
2933
|
release();
|
|
2503
2934
|
}
|
|
2504
2935
|
};
|
|
2505
|
-
const recordFailed = () => {
|
|
2936
|
+
const recordFailed = (facts) => {
|
|
2506
2937
|
if (!finalized) {
|
|
2507
|
-
|
|
2938
|
+
const stopper = runStopper();
|
|
2939
|
+
const outcome = settleRowOutcome(rec, facts ?? (stopper !== undefined ? { from: "ended", status: "killed", stoppedBy: stopper } : { from: "ended", status: "failed", ...(rec.errorCode !== undefined ? { code: rec.errorCode } : {}) }));
|
|
2508
2940
|
rec.endedAt = now();
|
|
2509
2941
|
emit({ type: "agent_end", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), status: "failed", ...(rec.errorCode !== undefined ? { errorCode: rec.errorCode } : {}), ts: rec.endedAt });
|
|
2510
2942
|
void persist("update");
|
|
2943
|
+
return outcome;
|
|
2511
2944
|
}
|
|
2945
|
+
return undefined;
|
|
2512
2946
|
};
|
|
2513
2947
|
const releaseLeg = () => {
|
|
2514
2948
|
if (!released)
|
|
@@ -2528,16 +2962,19 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2528
2962
|
releaseLeg();
|
|
2529
2963
|
throw parked;
|
|
2530
2964
|
}
|
|
2531
|
-
if (budgetTotal !== null && spent()
|
|
2965
|
+
if (budgetTotal !== null && budgetTotal - spent() < SPEND_OUTPUT_FLOOR_TOKENS) {
|
|
2532
2966
|
if (drive !== undefined) {
|
|
2533
2967
|
emitRunLog(`[park] the parked leg "${label}" could not be driven — the run's token ceiling was reached before its turn; the park stands.`);
|
|
2968
|
+
noteDecision(drive, rec.callKey, "refused", "workflow.budget_exceeded");
|
|
2534
2969
|
releaseLeg();
|
|
2535
|
-
return await legAfterPark(drive.paused, []
|
|
2970
|
+
return await legAfterPark(drive.paused, []);
|
|
2536
2971
|
}
|
|
2537
2972
|
const refusal = new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
2538
2973
|
rec.errorCode = refusal.code;
|
|
2539
2974
|
rec.errorMessage = boundedRedactedSummary(refusal.message, MAX_TRANSCRIPT_CHARS);
|
|
2540
|
-
recordFailed();
|
|
2975
|
+
const refusedOutcome = recordFailed({ from: "refused", budget: true });
|
|
2976
|
+
if (refusedOutcome !== undefined)
|
|
2977
|
+
refusal.member = refusedOutcome;
|
|
2541
2978
|
releaseLeg();
|
|
2542
2979
|
void journalAppend(callKey, {
|
|
2543
2980
|
taskId: callKey,
|
|
@@ -2581,6 +3018,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2581
3018
|
const streamYield = legYieldSeats();
|
|
2582
3019
|
const runInternals = {
|
|
2583
3020
|
...streamYield?.internals,
|
|
3021
|
+
...parkGapInherit(seatedSpec),
|
|
2584
3022
|
onSessionVerified: (id) => void (verifyAgentSession(rec, id) && persist("update")),
|
|
2585
3023
|
...(inheritedModelRef !== undefined ? { inheritedModelRef } : {}),
|
|
2586
3024
|
...(drive === undefined && !spec.sessionId && childSessionId !== undefined ? { sessionIdMintedBySpawner: true } : {}),
|
|
@@ -2592,6 +3030,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2592
3030
|
...(await captureFloorSeatsNow()),
|
|
2593
3031
|
...(enrichedForwardS !== undefined ? { onForwardEvent: enrichedForwardS } : {}),
|
|
2594
3032
|
delegationTaskType: "workflow",
|
|
3033
|
+
spendParent: memberSpendParent,
|
|
2595
3034
|
agentName: label,
|
|
2596
3035
|
...memberSeat(callKey, label),
|
|
2597
3036
|
onActivity,
|
|
@@ -2610,7 +3049,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2610
3049
|
}
|
|
2611
3050
|
: {}),
|
|
2612
3051
|
};
|
|
2613
|
-
const legSpec = { ...runSpec, ...streamYield?.spec };
|
|
3052
|
+
const legSpec = { ...runSpec, ...streamYield?.spec, signal: runSpec.signal !== undefined ? AbortSignal.any([runSpec.signal, membersStop.signal]) : membersStop.signal };
|
|
2614
3053
|
stream = drive === undefined
|
|
2615
3054
|
? workflowDepthStore.run({ depth: depth + 1 }, () => runner.runTaskStream(legSpec, undefined, runInternals))
|
|
2616
3055
|
: await workflowDepthStore.run({ depth: depth + 1 }, () => {
|
|
@@ -2627,7 +3066,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2627
3066
|
const unresumable = unresumableRowResult(drive, rec.callKey, err);
|
|
2628
3067
|
if (unresumable !== undefined)
|
|
2629
3068
|
return { kind: "settled", result: await settleParkedCall(rec, unresumable, [], agentOpts) };
|
|
2630
|
-
return await legAfterPark(drive.paused, []
|
|
3069
|
+
return await legAfterPark(drive.paused, []);
|
|
2631
3070
|
}
|
|
2632
3071
|
const spawnMessage = thrownMessageOf(err);
|
|
2633
3072
|
if (!finalized && rec.errorMessage === undefined && spawnMessage !== undefined)
|
|
@@ -2663,7 +3102,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2663
3102
|
throw err;
|
|
2664
3103
|
}
|
|
2665
3104
|
};
|
|
2666
|
-
const firstLeg = disposition !== undefined ? await legAfterPark(disposition.paused, []
|
|
3105
|
+
const firstLeg = disposition !== undefined ? await legAfterPark(disposition.paused, []) : await launch(arm.kind === "live" ? arm.drive : undefined);
|
|
2667
3106
|
if (firstLeg.kind === "settled")
|
|
2668
3107
|
return settledHandle(label, callKey, Promise.resolve(firstLeg.result));
|
|
2669
3108
|
let leg = firstLeg;
|
|
@@ -2698,7 +3137,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2698
3137
|
activeUsageBeats.delete(activeBeat);
|
|
2699
3138
|
const partialSpend = rec.stats;
|
|
2700
3139
|
if (!finalized && partialSpend !== undefined && (partialSpend.tokens > 0 || partialSpend.turns > 0 || (partialSpend.costMicroUsd ?? 0) > 0)) {
|
|
2701
|
-
accumulateStats({ stats: partialSpend }
|
|
3140
|
+
accumulateStats({ stats: partialSpend });
|
|
2702
3141
|
}
|
|
2703
3142
|
try {
|
|
2704
3143
|
recordFailed();
|
|
@@ -2721,22 +3160,21 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2721
3160
|
activeUsageBeats.delete(activeBeat);
|
|
2722
3161
|
releaseLeg();
|
|
2723
3162
|
if (finalized)
|
|
2724
|
-
return result;
|
|
3163
|
+
return lateMember(rec, result, "live", { from: "result", result, schemaRequested: Boolean(agentOpts.schema) });
|
|
2725
3164
|
const unstartedDrive = drive !== undefined && resumeNeverStarted(result) ? drive : undefined;
|
|
2726
3165
|
if (unstartedDrive !== undefined)
|
|
2727
3166
|
emitRunLog(`[park] the parked leg "${label}" was driven but the approved action never started (${result.terminal.kind === "failed" ? result.terminal.code : ""}); the park stands.`);
|
|
2728
3167
|
if (drive !== undefined)
|
|
2729
3168
|
noteDecision(drive, rec.callKey, unstartedDrive !== undefined ? "refused" : "driven", unstartedDrive !== undefined && result.terminal.kind === "failed" ? result.terminal.code : undefined);
|
|
2730
|
-
const parkOn = isPausedResult(result) ?
|
|
3169
|
+
const parkOn = isPausedResult(result) ? result : unstartedDrive?.paused;
|
|
2731
3170
|
if (parkOn !== undefined) {
|
|
2732
|
-
const next = await legAfterPark(parkOn
|
|
3171
|
+
const next = await legAfterPark(parkOn, activityTail);
|
|
2733
3172
|
if (next.kind === "settled")
|
|
2734
3173
|
return next.result;
|
|
2735
3174
|
leg = next;
|
|
2736
3175
|
continue;
|
|
2737
3176
|
}
|
|
2738
|
-
await settleAgentResult(rec, result, activityTail, agentOpts);
|
|
2739
|
-
return result;
|
|
3177
|
+
return await settleAgentResult(rec, result, activityTail, agentOpts);
|
|
2740
3178
|
}
|
|
2741
3179
|
})();
|
|
2742
3180
|
completion.catch(() => undefined);
|
|
@@ -2746,9 +3184,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2746
3184
|
const list = snapshotFanOutList("parallel", "the thunk list", thunks);
|
|
2747
3185
|
assertFanOutCallables("parallel", "item", list);
|
|
2748
3186
|
const errorsOut = fanOutOpts?.errors;
|
|
3187
|
+
const placed = list.length > 0 ? fanOutSite("f") : undefined;
|
|
2749
3188
|
const settled = await Promise.all(list.map((t, i) => Promise.resolve()
|
|
2750
|
-
.then(t)
|
|
3189
|
+
.then((v) => fanOutScopeStore.run({ owner: scopeOwner, path: `${placed.site}.t${i}`, item: placed.enclosing?.item, chain: { n: 0 } }, () => t(v)))
|
|
2751
3190
|
.then((v) => ({ ok: true, v }), (e) => ({ ok: false, e, i }))));
|
|
3191
|
+
if (placed !== undefined)
|
|
3192
|
+
joinFanOut("parallel", placed);
|
|
2752
3193
|
return foldFanOutSettled(settled, "parallel", errorsOut, emitRunLog, resumeRefusal);
|
|
2753
3194
|
},
|
|
2754
3195
|
async pipeline(items, ...stagesAndOpts) {
|
|
@@ -2765,10 +3206,22 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2765
3206
|
const stages = (fanOutOpts !== undefined ? stagesAndOpts.slice(0, -1) : stagesAndOpts);
|
|
2766
3207
|
assertFanOutCallables("pipeline", "stage", stages);
|
|
2767
3208
|
const errorsOut = fanOutOpts?.errors;
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
3209
|
+
const placed = itemList.length > 0 ? fanOutSite("p") : undefined;
|
|
3210
|
+
pipelinesRunning += 1;
|
|
3211
|
+
let settled;
|
|
3212
|
+
try {
|
|
3213
|
+
settled = await Promise.all(itemList.map((item, index) => {
|
|
3214
|
+
const itemScope = { owner: scopeOwner, path: `${placed.site}.i${index}`, item: `${placed.site}.i${index}`, chain: { n: 0 } };
|
|
3215
|
+
return stages
|
|
3216
|
+
.reduce((acc, stage) => acc.then((prev) => fanOutScopeStore.run(itemScope, () => stage(prev, item, index))), Promise.resolve(item))
|
|
3217
|
+
.then((v) => ({ ok: true, v }), (e) => ({ ok: false, e, i: index }));
|
|
3218
|
+
}));
|
|
3219
|
+
}
|
|
3220
|
+
finally {
|
|
3221
|
+
pipelinesRunning -= 1;
|
|
3222
|
+
}
|
|
3223
|
+
if (placed !== undefined)
|
|
3224
|
+
joinFanOut("pipeline", placed);
|
|
2772
3225
|
return foldFanOutSettled(settled, "pipeline", errorsOut, emitRunLog, resumeRefusal);
|
|
2773
3226
|
},
|
|
2774
3227
|
async phase(title, body) {
|
|
@@ -2903,21 +3356,36 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2903
3356
|
if (entry.decisionId === undefined)
|
|
2904
3357
|
continue;
|
|
2905
3358
|
const key = run.parks?.find((p) => p.token === entry.token);
|
|
2906
|
-
if (key === undefined || run.
|
|
3359
|
+
if (key === undefined || run.decisions?.some((d) => d.decisionId === entry.decisionId && d.callKey === key.callKey) === true)
|
|
2907
3360
|
continue;
|
|
2908
|
-
(run.
|
|
3361
|
+
(run.decisions ??= []).push({ ordinal: callKeyOrdinal(key.callKey), callKey: key.callKey, decisionId: entry.decisionId, result: "not_reached", ...(run.errorCode !== undefined ? { code: run.errorCode } : {}) });
|
|
2909
3362
|
}
|
|
2910
3363
|
};
|
|
2911
3364
|
const done = (async () => {
|
|
2912
3365
|
try {
|
|
2913
3366
|
keeperHold = holdKeeper({ agents: agentRegistry, tools: [launchingTool] });
|
|
2914
3367
|
const runBody = async () => {
|
|
2915
|
-
|
|
3368
|
+
let launch;
|
|
3369
|
+
try {
|
|
3370
|
+
launch = opts.launch === undefined ? undefined : (readWorkflowLaunchRecord(opts.launch) ?? "unkeepable");
|
|
3371
|
+
}
|
|
3372
|
+
catch {
|
|
3373
|
+
launch = "unkeepable";
|
|
3374
|
+
}
|
|
2916
3375
|
if (launch !== undefined && journalKeepsLaunches(journalStore)) {
|
|
2917
|
-
const
|
|
3376
|
+
const record = launch;
|
|
3377
|
+
const landed = record === "unkeepable" ? undefined : await recordLanded;
|
|
3378
|
+
const kept = record === "unkeepable" ? "unkeepable"
|
|
3379
|
+
: !landed.ok ? `record_${landed.cause}`
|
|
3380
|
+
: await finalizeWithin(timers, new Promise((resolve) => resolve(journalStore.recordLaunch(runId, scope, record))).then(() => "kept", () => "threw"), "timeout", true);
|
|
2918
3381
|
if (kept !== "kept") {
|
|
2919
3382
|
launchUnkept = true;
|
|
2920
|
-
|
|
3383
|
+
const why = kept === "unkeepable" ? "it is not a record a store keeps"
|
|
3384
|
+
: kept === "timeout" ? `the journal store did not answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms`
|
|
3385
|
+
: kept === "threw" ? "the journal store refused it"
|
|
3386
|
+
: kept === "record_timeout" ? `the run's record was not written first: the run store did not answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms`
|
|
3387
|
+
: "the run's record was not written first: the run store refused it";
|
|
3388
|
+
emitRunLog(`launch: this run's launch record was not kept (${why}) — nothing could continue a card this run parked on, so its agents do not park on approvals.`);
|
|
2921
3389
|
}
|
|
2922
3390
|
}
|
|
2923
3391
|
if (opts.resumeFromRunId !== undefined && journalStore) {
|
|
@@ -3021,6 +3489,38 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3021
3489
|
continue;
|
|
3022
3490
|
inherited.push(key);
|
|
3023
3491
|
}
|
|
3492
|
+
const placeAtOrdinal = new Map();
|
|
3493
|
+
const specsAtOrdinal = new Map();
|
|
3494
|
+
let marked = false;
|
|
3495
|
+
const notePlace = (callKey) => {
|
|
3496
|
+
const ord = callKeyOrdinal(callKey);
|
|
3497
|
+
const position = callKeyPosition(callKey) ?? null;
|
|
3498
|
+
const seen = placeAtOrdinal.get(ord);
|
|
3499
|
+
const recordedAt = position === null ? undefined : recordedOrdinalOfPosition.get(position);
|
|
3500
|
+
if ((seen !== undefined && seen !== position) || (recordedAt !== undefined && recordedAt !== ord))
|
|
3501
|
+
throw new WorkflowJournalIncompatibleError(opts.resumeFromRunId, ord);
|
|
3502
|
+
placeAtOrdinal.set(ord, position);
|
|
3503
|
+
recordedOrdinals.add(ord);
|
|
3504
|
+
marked ||= callKey.includes("@");
|
|
3505
|
+
specsAtOrdinal.set(ord, (specsAtOrdinal.get(ord) ?? new Set()).add(callKeySpec(callKey)));
|
|
3506
|
+
if (position !== null)
|
|
3507
|
+
recordedOrdinalOfPosition.set(position, ord);
|
|
3508
|
+
};
|
|
3509
|
+
for (const e of entries)
|
|
3510
|
+
notePlace(e.callKey);
|
|
3511
|
+
for (const key of candidates.values())
|
|
3512
|
+
notePlace(key.callKey);
|
|
3513
|
+
for (const rec of Array.isArray(prior?.agents) ? prior.agents : []) {
|
|
3514
|
+
if (rec === null || typeof rec !== "object" || typeof rec.callKey !== "string" || !/^\d+:/.test(rec.callKey))
|
|
3515
|
+
continue;
|
|
3516
|
+
notePlace(rec.callKey);
|
|
3517
|
+
}
|
|
3518
|
+
priorRecordUnpositioned = recordedOrdinals.size > 0 && !marked;
|
|
3519
|
+
if (priorRecordUnpositioned) {
|
|
3520
|
+
for (const [ord, specs] of [...specsAtOrdinal].sort(([a], [b]) => a - b))
|
|
3521
|
+
for (const s of specs)
|
|
3522
|
+
recordedOrdinalsOfSpec.set(s, [...(recordedOrdinalsOfSpec.get(s) ?? []), ord]);
|
|
3523
|
+
}
|
|
3024
3524
|
if (parkSeat === undefined) {
|
|
3025
3525
|
if (inherited.length > 0) {
|
|
3026
3526
|
throw new WorkflowParkRefusal("workflow.park_truth_unreadable", `startWorkflow: resume from "${fromRunId}" was REFUSED — it is responsible for ${inherited.length} recorded park(s) and this workflow holds no checkpoint store to prove them against (RunWorkflowOptions.checkpointStore); without the seat a parked call would run live beside its pinned child.`, { reason: "capability_not_armed" });
|
|
@@ -3051,14 +3551,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3051
3551
|
key.generation += 1;
|
|
3052
3552
|
run.parks = inherited;
|
|
3053
3553
|
delete run.resumeAdmissionIncomplete;
|
|
3554
|
+
run.resume = { fromRunId, journalEntries: entries.length, replayed: 0 };
|
|
3054
3555
|
}
|
|
3055
3556
|
const continuedBefore = await continuedBeforeOf(opts.resumeFromRunId);
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
replayed: 0,
|
|
3060
|
-
...(continuedBefore !== undefined ? { continuedBefore } : {}),
|
|
3061
|
-
};
|
|
3557
|
+
workflowSignal.throwIfAborted();
|
|
3558
|
+
if (continuedBefore !== undefined && run.resume !== undefined)
|
|
3559
|
+
run.resume = { ...run.resume, continuedBefore };
|
|
3062
3560
|
if (entries.length === 0) {
|
|
3063
3561
|
emitRunLog("resume: the prior run's journal yielded NO entries under this run's scope — nothing will replay; the entire script runs live. " +
|
|
3064
3562
|
"The prior run id may be unknown or pruned, recorded under a different scope, or its journal unreadable.");
|
|
@@ -3068,6 +3566,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3068
3566
|
}
|
|
3069
3567
|
void persist("update");
|
|
3070
3568
|
}
|
|
3569
|
+
workflowSignal.throwIfAborted();
|
|
3071
3570
|
return fn(ctx);
|
|
3072
3571
|
};
|
|
3073
3572
|
const bodyPromise = workflowDepthStore.run({ depth: depth + 1 }, runBody);
|
|
@@ -3133,13 +3632,15 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3133
3632
|
settleUnreachedDecisions();
|
|
3134
3633
|
await settleRecordArtifact();
|
|
3135
3634
|
emit({ type: "run_end", runId, status: "completed", ...(completedRunFailures > 0 ? { agentFailures: completedRunFailures } : {}), ts: run.endedAt });
|
|
3136
|
-
await
|
|
3635
|
+
await persistTerminal("completed");
|
|
3137
3636
|
return { result, runId, run };
|
|
3138
3637
|
}
|
|
3139
3638
|
catch (err) {
|
|
3140
3639
|
await awaitParksSettled();
|
|
3141
3640
|
if (parkedLeg !== undefined)
|
|
3142
3641
|
await awaitLegsIdle(workflowSignal);
|
|
3642
|
+
else
|
|
3643
|
+
await stopAndSettleMembers();
|
|
3143
3644
|
latchFinalized();
|
|
3144
3645
|
const unsettledOnFailure = settleActiveUsageBeats();
|
|
3145
3646
|
stampBudgetOvershoot(unsettledOnFailure);
|
|
@@ -3173,7 +3674,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3173
3674
|
settleUnreachedDecisions();
|
|
3174
3675
|
await settleRecordArtifact();
|
|
3175
3676
|
emit({ type: "run_end", runId, status: "failed", ...(failedRunFailures > 0 ? { agentFailures: failedRunFailures } : {}), ts: run.endedAt });
|
|
3176
|
-
await
|
|
3677
|
+
await persistTerminal("failed");
|
|
3177
3678
|
if (err !== null && (typeof err === "object" || typeof err === "function")) {
|
|
3178
3679
|
try {
|
|
3179
3680
|
Object.defineProperty(err, "workflowRun", { value: run, enumerable: false, configurable: true });
|
|
@@ -3224,6 +3725,19 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3224
3725
|
}
|
|
3225
3726
|
workflowSignal?.removeEventListener("abort", suspendOnParks);
|
|
3226
3727
|
closeWorkflowChannel(runId);
|
|
3728
|
+
for (const go of afterAnswer.splice(0)) {
|
|
3729
|
+
try {
|
|
3730
|
+
letGo(timers.setTimeout(go, 0));
|
|
3731
|
+
}
|
|
3732
|
+
catch {
|
|
3733
|
+
try {
|
|
3734
|
+
letGo(setTimeout(go, 0));
|
|
3735
|
+
}
|
|
3736
|
+
catch {
|
|
3737
|
+
void Promise.resolve().then(go).catch(() => undefined);
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3227
3741
|
}
|
|
3228
3742
|
})();
|
|
3229
3743
|
bindSettledRun(done, run);
|
|
@@ -3232,6 +3746,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3232
3746
|
done,
|
|
3233
3747
|
cancel: (reason) => cancelController.abort(reason ? new Error(reason) : undefined),
|
|
3234
3748
|
parked: () => runParkedOf(run),
|
|
3749
|
+
recordLanded: () => recordLanded.then((o) => o.ok),
|
|
3235
3750
|
};
|
|
3236
3751
|
}
|
|
3237
3752
|
export async function runWorkflow(runner, fn, opts = {}, internals) {
|