@sema-agent/server 7.131.0 → 7.133.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/MIGRATION.md +575 -0
- package/README.md +12 -9
- package/README.zh-CN.md +9 -6
- package/USAGE.md +326 -98
- package/deploy/sema-up/README.md +19 -1
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +5 -2
- package/deploy/sema-up/chart/templates/server.yaml +5 -2
- package/deploy/sema-up/stack/compose.yaml +3 -0
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +4 -2
- package/dist/adoption/plan.d.ts +3 -2
- package/dist/adoption/plan.js +7 -5
- package/dist/adoption/runner.js +3 -10
- package/dist/adoption/sql.d.ts +3 -2
- package/dist/adoption/sql.js +3 -5
- package/dist/adoption/wire.d.ts +4 -1
- package/dist/adoption/wire.js +1 -0
- package/dist/approval-ask-audit-store.d.ts +31 -13
- package/dist/approval-ask-audit-store.js +272 -74
- package/dist/approval-ask-machine.d.ts +15 -0
- package/dist/approval-ask-machine.js +6 -0
- package/dist/approval-ask-retention.d.ts +136 -0
- package/dist/approval-ask-retention.js +102 -0
- package/dist/approval-card.d.ts +82 -20
- package/dist/approval-card.js +46 -16
- package/dist/approval-deny-reasons.d.ts +1 -1
- package/dist/approval.d.ts +9 -0
- package/dist/approval.js +24 -3
- package/dist/audit.d.ts +33 -19
- package/dist/audit.js +12 -16
- package/dist/auth-bridge.d.ts +4 -0
- package/dist/auth-bridge.js +10 -11
- package/dist/bake-runner/main.js +3 -2
- package/dist/boot/deferred-sandbox-path-env.js +1 -1
- package/dist/boot/deployment-mods.d.ts +31 -0
- package/dist/boot/deployment-mods.js +26 -0
- package/dist/boot/execution-env.d.ts +1 -1
- package/dist/boot/execution-env.js +27 -12
- package/dist/boot/execution-lane.js +11 -0
- package/dist/boot/leader.js +2 -0
- package/dist/boot/memory-boundary.d.ts +2 -2
- package/dist/boot/memory-boundary.js +2 -2
- package/dist/boot/memory-consolidation.d.ts +5 -4
- package/dist/boot/memory-consolidation.js +7 -6
- package/dist/boot/org-delivery.d.ts +28 -0
- package/dist/boot/org-delivery.js +20 -0
- package/dist/boot/read-deny-anchor-audit.d.ts +17 -0
- package/dist/boot/read-deny-anchor-audit.js +36 -0
- package/dist/boot/reapers.d.ts +3 -0
- package/dist/boot/reapers.js +21 -1
- package/dist/boot/resolve-spec.d.ts +4 -5
- package/dist/boot/resolve-spec.js +74 -123
- package/dist/boot/runner-deps.d.ts +19 -8
- package/dist/boot/runner-deps.js +15 -2
- package/dist/boot/session-faces.d.ts +2 -7
- package/dist/boot/session-faces.js +4 -2
- package/dist/boot/stage-02-web-admin-pull.js +4 -1
- package/dist/boot/stage-03-store-backend.d.ts +1 -1
- package/dist/boot/stage-03-store-backend.js +2 -2
- package/dist/boot/stage-04-stores.d.ts +1 -1
- package/dist/boot/stage-05-execution-env.d.ts +4 -4
- package/dist/boot/stage-05-execution-env.js +7 -10
- package/dist/boot/stage-06-runners.d.ts +4 -2
- package/dist/boot/stage-06-runners.js +11 -7
- package/dist/boot/stage-07-capability-layer.d.ts +4 -2
- package/dist/boot/stage-07-capability-layer.js +27 -6
- package/dist/boot/stage-08-reapers.d.ts +4 -2
- package/dist/boot/stage-08-reapers.js +2 -2
- package/dist/boot/stage-09-leader.d.ts +6 -9
- package/dist/boot/stage-10-http-server.d.ts +6 -9
- package/dist/boot/stage-10-http-server.js +7 -9
- package/dist/boot/stores.d.ts +1 -1
- package/dist/boot/stores.js +7 -8
- package/dist/boot/web-admin.d.ts +4 -3
- package/dist/boot/web-admin.js +186 -98
- package/dist/boot/workflow-orchestration.d.ts +2 -0
- package/dist/boot/workflow-orchestration.js +2 -1
- package/dist/brain.js +25 -25
- package/dist/breaker-key.d.ts +6 -0
- package/dist/breaker-key.js +29 -0
- package/dist/budget.js +5 -4
- package/dist/caller-text-echo.d.ts +23 -0
- package/dist/caller-text-echo.js +21 -0
- package/dist/capabilities/brand-identity.d.ts +26 -0
- package/dist/capabilities/brand-identity.js +27 -0
- package/dist/capabilities/center-plugins.d.ts +7 -0
- package/dist/capabilities/center-plugins.js +1 -1
- package/dist/capabilities/center-prompts.d.ts +32 -59
- package/dist/capabilities/center-prompts.js +18 -32
- package/dist/capabilities/composite-members.d.ts +1 -1
- package/dist/capabilities/composite-members.js +1 -1
- package/dist/capabilities/engine-capabilities.js +2 -1
- package/dist/capabilities/execution-lane.js +2 -2
- package/dist/capabilities/hands-lane.d.ts +30 -6
- package/dist/capabilities/hands-lane.js +11 -1
- package/dist/capabilities/mcp-probe.d.ts +48 -3
- package/dist/capabilities/mcp-probe.js +47 -135
- package/dist/capabilities/scenarios.d.ts +95 -45
- package/dist/capabilities/scenarios.js +53 -38
- package/dist/capabilities/skills.d.ts +19 -4
- package/dist/capabilities/skills.js +30 -10
- package/dist/capability-facts.d.ts +34 -4
- package/dist/capability-facts.js +28 -2
- package/dist/center-config-tier.d.ts +69 -0
- package/dist/center-config-tier.js +42 -0
- package/dist/checkpoint-identity.d.ts +16 -0
- package/dist/checkpoint-identity.js +19 -0
- package/dist/config-catalog.d.ts +17 -10
- package/dist/config-catalog.js +47 -32
- package/dist/config-d-migration.d.ts +3 -1
- package/dist/config-d-migration.js +2 -2
- package/dist/config-dir-trust.d.ts +114 -0
- package/dist/config-dir-trust.js +388 -0
- package/dist/config-invariants.d.ts +18 -5
- package/dist/config-invariants.js +35 -3
- package/dist/config-lkg.d.ts +9 -9
- package/dist/config-lkg.js +20 -4
- package/dist/config-provider.d.ts +9 -2
- package/dist/config-provider.js +18 -6
- package/dist/config-types.d.ts +75 -20
- package/dist/config-types.js +8 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +137 -62
- package/dist/delegated-session-owner.d.ts +185 -0
- package/dist/delegated-session-owner.js +119 -0
- package/dist/device-protocol.d.ts +5 -3
- package/dist/device-protocol.js +1 -1
- package/dist/device-ws-hub.js +21 -2
- package/dist/device-ws-protocol.d.ts +70 -6
- package/dist/device-ws-protocol.js +50 -22
- package/dist/elicitation.js +3 -2
- package/dist/entry-problems.d.ts +34 -0
- package/dist/entry-problems.js +14 -0
- package/dist/env-name-allowlist-knobs.d.ts +12 -2
- package/dist/env-name-allowlist-knobs.js +5 -4
- package/dist/exec-bounds.d.ts +15 -3
- package/dist/exec-bounds.js +4 -0
- package/dist/execution-lane-caps.d.ts +56 -10
- package/dist/execution-lane-caps.js +50 -0
- package/dist/field-conflict.d.ts +43 -0
- package/dist/field-conflict.js +20 -0
- package/dist/fleet/fleet-bus.d.ts +80 -6
- package/dist/fleet/fleet-bus.js +41 -9
- package/dist/hooks/classic-stations.d.ts +91 -0
- package/dist/hooks/classic-stations.js +27 -0
- package/dist/hooks/command-spawn.d.ts +57 -0
- package/dist/hooks/command-spawn.js +139 -0
- package/dist/hooks/hook-llm.d.ts +8 -5
- package/dist/hooks/hook-llm.js +79 -36
- package/dist/hooks/hook-runner.d.ts +349 -95
- package/dist/hooks/hook-runner.js +855 -568
- package/dist/hooks/hook-source.d.ts +44 -0
- package/dist/hooks/hook-source.js +40 -0
- package/dist/http/active-run-conflict.d.ts +5 -13
- package/dist/http/active-run-conflict.js +17 -27
- package/dist/http/admission.d.ts +8 -2
- package/dist/http/admission.js +188 -101
- package/dist/http/approval-sweeps.js +99 -21
- package/dist/http/caller-trust.d.ts +77 -0
- package/dist/http/caller-trust.js +143 -0
- package/dist/http/checkpoint-ctx.d.ts +41 -24
- package/dist/http/checkpoint-ctx.js +23 -16
- package/dist/http/claimed-run.d.ts +14 -0
- package/dist/http/claimed-run.js +15 -0
- package/dist/http/device-placement.d.ts +2 -4
- package/dist/http/device-placement.js +7 -11
- package/dist/http/dispatch.d.ts +0 -4
- package/dist/http/dispatch.js +15 -13
- package/dist/http/durable-run-leg.d.ts +6 -33
- package/dist/http/durable-run-leg.js +36 -10
- package/dist/http/health-self-report.d.ts +7 -5
- package/dist/http/health-self-report.js +4 -18
- package/dist/http/owner-access.d.ts +56 -0
- package/dist/http/owner-access.js +42 -0
- package/dist/http/principal-gate.d.ts +70 -28
- package/dist/http/principal-gate.js +61 -15
- package/dist/http/readiness.d.ts +11 -5
- package/dist/http/readiness.js +10 -3
- package/dist/http/refusal-body.d.ts +21 -0
- package/dist/http/refusal-body.js +4 -0
- package/dist/http/request-guards.d.ts +43 -23
- package/dist/http/request-guards.js +53 -17
- package/dist/http/resume-ctx-read.d.ts +2 -5
- package/dist/http/resume-ctx-read.js +7 -4
- package/dist/http/resume-legs.d.ts +28 -4
- package/dist/http/resume-legs.js +169 -91
- package/dist/http/retired-service-deps.d.ts +43 -0
- package/dist/http/retired-service-deps.js +18 -0
- package/dist/http/route-ctx.d.ts +44 -28
- package/dist/http/route-ctx.js +4 -0
- package/dist/http/route-table.js +2 -0
- package/dist/http/routes/a2a-serve.js +3 -4
- package/dist/http/routes/admin-config-refresh.js +1 -1
- package/dist/http/routes/admin-drain.js +1 -1
- package/dist/http/routes/admin-memory-optout.js +5 -1
- package/dist/http/routes/adoption.js +2 -9
- package/dist/http/routes/approvals-assistant.js +49 -48
- package/dist/http/routes/background.js +3 -2
- package/dist/http/routes/capabilities.js +21 -5
- package/dist/http/routes/config-catalog.d.ts +3 -3
- package/dist/http/routes/config-catalog.js +1 -1
- package/dist/http/routes/devices.js +3 -17
- package/dist/http/routes/diagnostics.js +6 -2
- package/dist/http/routes/images.js +6 -7
- package/dist/http/routes/leader.js +1 -8
- package/dist/http/routes/mcp-reconnect.d.ts +1 -1
- package/dist/http/routes/mcp-reconnect.js +3 -2
- package/dist/http/routes/memory-bundle.js +1 -1
- package/dist/http/routes/memory-compliance.js +1 -1
- package/dist/http/routes/memory-consolidation.js +1 -1
- package/dist/http/routes/memory-origin.js +1 -1
- package/dist/http/routes/memory-policy.d.ts +1 -1
- package/dist/http/routes/memory-policy.js +3 -2
- package/dist/http/routes/notify-wake.js +8 -21
- package/dist/http/routes/observability.js +2 -2
- package/dist/http/routes/principal-inbox.d.ts +39 -0
- package/dist/http/routes/principal-inbox.js +76 -0
- package/dist/http/routes/retention-ops.js +2 -9
- package/dist/http/routes/rules.js +5 -18
- package/dist/http/routes/runs.d.ts +5 -0
- package/dist/http/routes/runs.js +34 -107
- package/dist/http/routes/session-sync.js +15 -26
- package/dist/http/routes/sessions.js +30 -40
- package/dist/http/routes/shared-memory.js +2 -13
- package/dist/http/routes/side-query.js +8 -7
- package/dist/http/routes/tasks.js +67 -21
- package/dist/http/routes/workflows.d.ts +351 -0
- package/dist/http/routes/workflows.js +153 -119
- package/dist/http/send.d.ts +33 -10
- package/dist/http/send.js +21 -4
- package/dist/http/server.d.ts +27 -18
- package/dist/http/server.js +34 -6
- package/dist/http/stored-body-replay.js +17 -4
- package/dist/http/submit-ctx.d.ts +25 -0
- package/dist/http/submit-ctx.js +40 -0
- package/dist/http/submit-replay.d.ts +4 -3
- package/dist/http/submit-replay.js +5 -4
- package/dist/http/wire-types.d.ts +11 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/lane-home-probe.d.ts +112 -0
- package/dist/lane-home-probe.js +101 -0
- package/dist/leader/endpoint.d.ts +4 -1
- package/dist/leader/endpoint.js +11 -10
- package/dist/limit-refusal.d.ts +59 -0
- package/dist/limit-refusal.js +15 -0
- package/dist/main.js +1 -1
- package/dist/mcp-assertion-header.d.ts +32 -19
- package/dist/mcp-assertion-header.js +10 -9
- package/dist/mcp-tool-faces.d.ts +5 -0
- package/dist/mcp-tool-faces.js +6 -4
- package/dist/memory-project-layer.d.ts +37 -0
- package/dist/memory-project-layer.js +46 -0
- package/dist/memory-scope.d.ts +24 -17
- package/dist/memory-scope.js +24 -8
- package/dist/memory-sync-client.d.ts +27 -13
- package/dist/memory-sync-client.js +107 -18
- package/dist/model-entry-refusal.d.ts +9 -1
- package/dist/model-entry-refusal.js +6 -1
- package/dist/model-plane-face.d.ts +51 -0
- package/dist/model-plane-face.js +24 -0
- package/dist/model-provider.d.ts +44 -12
- package/dist/model-provider.js +21 -2
- package/dist/model-route-endpoint.d.ts +9 -12
- package/dist/model-route-endpoint.js +8 -11
- package/dist/model-route-env.d.ts +22 -0
- package/dist/model-route-env.js +2 -0
- package/dist/model-route-gap.d.ts +60 -30
- package/dist/model-route-gap.js +21 -15
- package/dist/observability/corrupt-read-seat.d.ts +7 -0
- package/dist/observability/corrupt-read-seat.js +9 -0
- package/dist/observability/cost-taxonomy.d.ts +7 -7
- package/dist/observability/err-text.d.ts +6 -0
- package/dist/observability/err-text.js +18 -4
- package/dist/observability/fail-open.d.ts +76 -14
- package/dist/observability/fail-open.js +76 -14
- package/dist/observability/metrics.js +4 -1
- package/dist/observability/prompt-manifest.d.ts +33 -82
- package/dist/observability/prompt-manifest.js +122 -17
- package/dist/observability/run-terminal.js +14 -6
- package/dist/observability/secret-env-scrub.d.ts +13 -1
- package/dist/observability/secret-env-scrub.js +13 -1
- package/dist/observability/tool-trace.d.ts +16 -21
- package/dist/observability/tool-trace.js +58 -49
- package/dist/operator-ask.d.ts +10 -0
- package/dist/operator-ask.js +3 -0
- package/dist/orchestration/workflow-agent-session-index.d.ts +12 -12
- package/dist/orchestration/workflow-agent-session-index.js +9 -13
- package/dist/orchestration/workflow-completion-inbox.d.ts +42 -15
- package/dist/orchestration/workflow-completion-inbox.js +13 -0
- package/dist/orchestration/workflow-notify-journal.d.ts +13 -32
- package/dist/orchestration/workflow-notify-journal.js +27 -34
- package/dist/orchestration/workflow-park-decision.d.ts +89 -0
- package/dist/orchestration/workflow-park-decision.js +118 -0
- package/dist/org-delivery-gate.d.ts +81 -0
- package/dist/org-delivery-gate.js +59 -0
- package/dist/panel-tool-names.d.ts +23 -0
- package/dist/panel-tool-names.js +8 -0
- package/dist/parked-decide.d.ts +39 -6
- package/dist/parked-decide.js +98 -51
- package/dist/parked-revive-surface.d.ts +9 -2
- package/dist/parked-revive-surface.js +11 -8
- package/dist/per-task-image.d.ts +7 -1
- package/dist/per-task-image.js +3 -3
- package/dist/permission-rule-list.d.ts +1 -1
- package/dist/permission-rule-list.js +2 -2
- package/dist/plain-string-record.d.ts +25 -0
- package/dist/plain-string-record.js +32 -0
- package/dist/plugins/approval-ask-store-file.d.ts +16 -1
- package/dist/plugins/approval-ask-store-file.js +21 -0
- package/dist/plugins/approval-ask-store-memory.d.ts +18 -1
- package/dist/plugins/approval-ask-store-memory.js +34 -2
- package/dist/plugins/approval-ask-store-sql.d.ts +25 -0
- package/dist/plugins/approval-ask-store-sql.js +37 -1
- package/dist/plugins/blob-backend.d.ts +83 -15
- package/dist/plugins/blob-backend.js +68 -15
- package/dist/plugins/breaker-state-sql.d.ts +2 -2
- package/dist/plugins/breaker-state-sql.js +4 -4
- package/dist/plugins/caching-session-store.d.ts +3 -0
- package/dist/plugins/caching-session-store.js +3 -0
- package/dist/plugins/checkpoint-store-sql.d.ts +28 -4
- package/dist/plugins/checkpoint-store-sql.js +59 -28
- package/dist/plugins/file-history-store-sql.d.ts +5 -2
- package/dist/plugins/file-history-store-sql.js +3 -1
- package/dist/plugins/file-run-store.d.ts +5 -13
- package/dist/plugins/file-run-store.js +9 -0
- package/dist/plugins/fork-routing-session-store.d.ts +9 -1
- package/dist/plugins/fork-routing-session-store.js +12 -1
- package/dist/plugins/host-platform.d.ts +2 -0
- package/dist/plugins/host-platform.js +2 -1
- package/dist/plugins/k8s-bg-scripts.d.ts +11 -0
- package/dist/plugins/k8s-bg-scripts.js +22 -0
- package/dist/plugins/local-checkpoint-store.d.ts +2 -0
- package/dist/plugins/local-checkpoint-store.js +11 -3
- package/dist/plugins/local-session-store.d.ts +1 -1
- package/dist/plugins/local-session-store.js +1 -1
- package/dist/plugins/local-session-window.d.ts +39 -0
- package/dist/plugins/local-session-window.js +54 -0
- package/dist/plugins/mailbox-recipient-lifecycle.d.ts +3 -2
- package/dist/plugins/mailbox-store-sql.d.ts +30 -48
- package/dist/plugins/mailbox-store-sql.js +77 -52
- package/dist/plugins/memory-embedder-fingerprint.js +2 -1
- package/dist/plugins/memory-run-store.d.ts +5 -13
- package/dist/plugins/memory-run-store.js +8 -0
- package/dist/plugins/one-time-migrations.d.ts +245 -93
- package/dist/plugins/one-time-migrations.js +668 -207
- package/dist/plugins/org-delivery-quota-store.d.ts +123 -0
- package/dist/plugins/org-delivery-quota-store.js +228 -0
- package/dist/plugins/permission-rule-store-sql.d.ts +13 -7
- package/dist/plugins/permission-rule-store-sql.js +4 -18
- package/dist/plugins/pg-pool.js +39 -7
- package/dist/plugins/pg-session-storage.d.ts +20 -8
- package/dist/plugins/pg-session-storage.js +34 -21
- package/dist/plugins/remote-env-adb.d.ts +12 -12
- package/dist/plugins/remote-env-adb.js +21 -6
- package/dist/plugins/remote-env-device.js +3 -0
- package/dist/plugins/remote-env-e2b.d.ts +1 -1
- package/dist/plugins/remote-env-e2b.js +21 -9
- package/dist/plugins/remote-env-host.d.ts +9 -9
- package/dist/plugins/remote-env-host.js +10 -32
- package/dist/plugins/remote-env-k8s.d.ts +103 -38
- package/dist/plugins/remote-env-k8s.js +288 -95
- package/dist/plugins/remote-env-local-docker.d.ts +27 -13
- package/dist/plugins/remote-env-local-docker.js +82 -11
- package/dist/plugins/remote-env-ssh.d.ts +21 -12
- package/dist/plugins/remote-env-ssh.js +117 -5
- package/dist/plugins/remote-shell.d.ts +0 -1
- package/dist/plugins/remote-shell.js +1 -2
- package/dist/plugins/retention-store-sql.js +6 -2
- package/dist/plugins/run-store-sql.d.ts +16 -14
- package/dist/plugins/run-store-sql.js +22 -2
- package/dist/plugins/schema-consistency.d.ts +54 -0
- package/dist/plugins/schema-consistency.js +52 -0
- package/dist/plugins/schema-indexes.js +2 -0
- package/dist/plugins/send-user-file.js +2 -2
- package/dist/plugins/session-epoch-anchor.d.ts +39 -0
- package/dist/plugins/session-epoch-anchor.js +22 -0
- package/dist/plugins/session-store.d.ts +18 -8
- package/dist/plugins/session-store.js +15 -4
- package/dist/plugins/shared-memory-store-sql.d.ts +9 -3
- package/dist/plugins/shared-memory-store-sql.js +5 -16
- package/dist/plugins/sql-driver.d.ts +205 -1
- package/dist/plugins/sql-driver.js +325 -13
- package/dist/plugins/sql-errors.d.ts +64 -0
- package/dist/plugins/sql-errors.js +57 -0
- package/dist/plugins/store-backend.d.ts +36 -1
- package/dist/plugins/store-backend.js +42 -15
- package/dist/plugins/store-contracts.d.ts +42 -0
- package/dist/plugins/store-contracts.js +1 -0
- package/dist/plugins/tidb-pool.d.ts +6 -1
- package/dist/plugins/tidb-pool.js +44 -10
- package/dist/plugins/tidb-session-storage.d.ts +8 -11
- package/dist/plugins/tidb-session-storage.js +6 -16
- package/dist/plugins/tidb-session-store.d.ts +24 -4
- package/dist/plugins/tidb-session-store.js +29 -5
- package/dist/plugins/workflow-journal-store-sql.d.ts +73 -19
- package/dist/plugins/workflow-journal-store-sql.js +19 -6
- package/dist/plugins/workflow-run-store-sql.d.ts +30 -8
- package/dist/plugins/workflow-run-store-sql.js +50 -9
- package/dist/posture-source.d.ts +18 -10
- package/dist/posture-source.js +4 -1
- package/dist/project-identity.d.ts +45 -6
- package/dist/project-identity.js +162 -8
- package/dist/project-layer-key.d.ts +28 -0
- package/dist/project-layer-key.js +29 -0
- package/dist/prompts-domain-validate.d.ts +17 -61
- package/dist/prompts-domain-validate.js +9 -119
- package/dist/question.js +3 -2
- package/dist/read-deny-entry.d.ts +25 -0
- package/dist/read-deny-entry.js +12 -0
- package/dist/read-face-posture.d.ts +37 -11
- package/dist/read-face-posture.js +32 -3
- package/dist/request-key-closure.d.ts +9 -2
- package/dist/request-key-closure.js +11 -5
- package/dist/request-value-closure.d.ts +5 -0
- package/dist/request-value-closure.js +11 -3
- package/dist/rule-entry-list.d.ts +38 -11
- package/dist/rule-entry-list.js +106 -30
- package/dist/rules-consent.js +3 -4
- package/dist/run-acceptance.d.ts +19 -3
- package/dist/run-acceptance.js +13 -1
- package/dist/run-local.js +54 -24
- package/dist/runs.d.ts +15 -8
- package/dist/runs.js +35 -1
- package/dist/runtime-caps-resolver.d.ts +16 -6
- package/dist/runtime-caps-resolver.js +18 -5
- package/dist/sandbox-pkg-source.d.ts +19 -1
- package/dist/sandbox-pkg-source.js +29 -7
- package/dist/security.d.ts +87 -9
- package/dist/security.js +52 -9
- package/dist/server-secret-env.d.ts +44 -18
- package/dist/server-secret-env.js +49 -8
- package/dist/session-error-wire.d.ts +19 -2
- package/dist/session-error-wire.js +5 -1
- package/dist/session-incarnation.d.ts +15 -5
- package/dist/session-incarnation.js +16 -9
- package/dist/session-titled-frame.d.ts +33 -0
- package/dist/session-titled-frame.js +4 -0
- package/dist/session-titler.d.ts +9 -1
- package/dist/session-titler.js +27 -6
- package/dist/spec-fields.d.ts +28 -16
- package/dist/spec-fields.js +66 -54
- package/dist/sql-engine-posture.d.ts +31 -4
- package/dist/sql-engine-posture.js +36 -1
- package/dist/stored-request-tool-axes-m19.d.ts +19 -4
- package/dist/stored-request-tool-axes-m19.js +30 -2
- package/dist/task-a2a.d.ts +9 -1
- package/dist/task-a2a.js +73 -47
- package/dist/task-cwd.d.ts +1 -1
- package/dist/task-mcp.d.ts +46 -58
- package/dist/task-mcp.js +82 -107
- package/dist/task-settings.d.ts +95 -108
- package/dist/task-settings.js +77 -98
- package/dist/text-bidi.d.ts +1 -48
- package/dist/text-bidi.js +3 -5
- package/dist/tighten-only-seats.d.ts +150 -0
- package/dist/tighten-only-seats.js +196 -0
- package/dist/tool-approval.d.ts +304 -88
- package/dist/tool-approval.js +623 -239
- package/dist/trace/core-keyset-guard.d.ts +122 -20
- package/dist/trace/engine-notice-wire.d.ts +11 -3
- package/dist/trace/engine-notice-wire.js +8 -1
- package/dist/trace/exit-seat.d.ts +28 -0
- package/dist/trace/exit-seat.js +76 -0
- package/dist/trace/ledger-events.d.ts +6 -3
- package/dist/trace/ledger-sink.js +4 -1
- package/dist/trace/model-segment.js +1 -1
- package/dist/trace/project.d.ts +98 -17
- package/dist/trace/project.js +98 -50
- package/dist/trace/projection-table.d.ts +100 -0
- package/dist/trace/projection-table.js +130 -0
- package/dist/trace/redact.d.ts +54 -0
- package/dist/trace/redact.js +778 -152
- package/dist/trace/self-minted-wire.d.ts +345 -1
- package/dist/trace/self-minted-wire.js +117 -1
- package/dist/trace/wire-projection-faces.d.ts +377 -3
- package/dist/trace/wire-projection-faces.js +164 -1
- package/dist/url-refusal.js +2 -0
- package/dist/web-admin-client/apply-effective.d.ts +12 -0
- package/dist/web-admin-client/apply-effective.js +56 -5
- package/dist/web-admin-client/candidate-gate.d.ts +6 -6
- package/dist/web-admin-client/candidate-gate.js +3 -3
- package/dist/web-admin-client/facade.d.ts +1 -1
- package/dist/web-admin-client/facade.js +1 -1
- package/dist/web-admin-client/http-client.js +0 -6
- package/dist/web-admin-client/read-face.js +5 -9
- package/dist/web-admin-client/read-warnings.d.ts +13 -0
- package/dist/web-admin-client/read-warnings.js +10 -0
- package/dist/web-admin-client/skills-mcp.d.ts +3 -0
- package/dist/web-admin-client/skills-mcp.js +11 -9
- package/dist/web-admin-client/types.d.ts +2 -3
- package/dist/workspace-cache.d.ts +35 -0
- package/dist/workspace-cache.js +36 -0
- package/dist/workspace-space.d.ts +3 -2
- package/dist/workspace-space.js +2 -0
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +65 -10
- package/package.json +8 -4
- package/scripts/drain-check-local.mjs +34 -1
- package/scripts/drain-check.mysql.sql +30 -2
- package/scripts/drain-check.pg.sql +29 -2
- package/dist/capabilities/memory-notice.d.ts +0 -138
- package/dist/capabilities/memory-notice.js +0 -64
- package/dist/capabilities/prompt.d.ts +0 -17
- package/dist/capabilities/prompt.js +0 -6
- package/dist/mcp-content-origin.d.ts +0 -34
- package/dist/mcp-content-origin.js +0 -10
- package/dist/tool-axis-words.d.ts +0 -27
- package/dist/tool-axis-words.js +0 -9
- package/dist/wire-name-bound.d.ts +0 -14
- package/dist/wire-name-bound.js +0 -13
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* 于是一次 dup 变成一个裸驱动对象漏给调用方。`Reflect.get` 与属性访问一样走原型链,写成 `Reflect.get`
|
|
21
21
|
* 是把"必须走原型链"这件事写在码面上(收编前唯一的硬化形 `shared-memory-store-sql.ts` 即此形)。
|
|
22
22
|
*
|
|
23
|
+
* 例外只有一只**类**:{@link StoreRowTooLargeError} —— 「一行装不下」这条判据的带码产物,与它的谓词住在一起
|
|
24
|
+
* (判据与产物分家 = 两处各写一份「哪些驱动错算这一类」)。
|
|
25
|
+
*
|
|
23
26
|
* ## 本模块**不**管的事(与 `sql-driver.ts` 头注的分工一致)
|
|
24
27
|
* 「撞的是**哪一个** UNIQUE 键」留在店内:mysql2 把键名写进 `sqlMessage` 文本、node-pg 写进
|
|
25
28
|
* `err.constraint`,而怎么按键名分诊(良性重发 vs 必须重试的竞态)是 store-specific 的判别规则,
|
|
@@ -93,4 +96,65 @@ export declare const PG_DEADLOCK_DETECTED_SQLSTATE = "40P01";
|
|
|
93
96
|
* **MySQL 协议腿**,两方言都认只是为了让店不必自己判引擎。
|
|
94
97
|
*/
|
|
95
98
|
export declare function isDeadlockError(dialect: SqlDialect, err: unknown): boolean;
|
|
99
|
+
/** TiDB `ErrEntryTooLarge` (one row's key + value over `txn-entry-size-limit`, 6 MiB by default) — TiDB's own
|
|
100
|
+
* errno, which mysql2 carries without a symbolic name. */
|
|
101
|
+
export declare const TIDB_ER_ENTRY_TOO_LARGE_ERRNO = 8025;
|
|
102
|
+
/** MySQL/MariaDB `ER_NET_PACKET_TOO_LARGE` (one statement over `max_allowed_packet`). */
|
|
103
|
+
export declare const MYSQL_ER_NET_PACKET_TOO_LARGE_ERRNO = 1153;
|
|
104
|
+
/** MySQL/MariaDB `ER_NET_PACKET_TOO_LARGE`'s symbolic code (mysql2 `code`). */
|
|
105
|
+
export declare const MYSQL_ER_NET_PACKET_TOO_LARGE_CODE = "ER_NET_PACKET_TOO_LARGE";
|
|
106
|
+
/** PostgreSQL `program_limit_exceeded` — a value or row over one of the engine's hard size limits (e.g. a `jsonb`
|
|
107
|
+
* value over 255 MiB, an index row over its page budget). */
|
|
108
|
+
export declare const PG_PROGRAM_LIMIT_EXCEEDED_SQLSTATE = "54000";
|
|
109
|
+
/**
|
|
110
|
+
* 「一行装不下」是被哪一堵墙拒的(闭集;加一堵 ⇒ 读它的 switch 编译红)—— 出路随墙不同,所以墙是这类拒的一位事实:
|
|
111
|
+
* · `row` —— TiDB 的单行墙(`txn-entry-size-limit`,errno 8025;出路:抬它);
|
|
112
|
+
* · `statement` —— MySQL 协议的语句墙(`max_allowed_packet`,errno 1153 / `ER_NET_PACKET_TOO_LARGE`;InnoDB 与 TiDB 都有;出路:抬它);
|
|
113
|
+
* · `value` —— PostgreSQL 的硬上限(SQLSTATE `54000`,如一只 `jsonb` 值超 255 MiB;没有可调的墙,出路只有缩小)。
|
|
114
|
+
*/
|
|
115
|
+
export type RowTooLargeWall = "row" | "statement" | "value";
|
|
116
|
+
/**
|
|
117
|
+
* 「这个写**是**被引擎以『一行装不下』拒的吗、被哪堵墙」—— 单一判据(与本文件其余谓词同一条 single-semantic-multi-site-drift 纪律)。
|
|
118
|
+
* MySQL 协议两条墙都认 —— 两条墙对**一条单行 INSERT** 说的是同一件事(这一行写不进),出路不同;PG 认 `54000`。认不出的一律 `undefined`(原始错误原样上抛)。
|
|
119
|
+
*/
|
|
120
|
+
export declare function rowTooLargeWallOf(dialect: SqlDialect, err: unknown): RowTooLargeWall | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* **这条连接不许再回池**的 MySQL 协议错误 —— 闭集,逐码登记「为什么」。两类原因:
|
|
123
|
+
* · **库发完这个错误包之后自己关掉这条连接**(或随后必关):客户端的池只看见「这条语句完了」,连接照常归还,库的 FIN / RST 晚一拍才到 ——
|
|
124
|
+
* 池上紧接着的下一笔借到这条半死的连接,答 `write ECONNRESET`。1153 是真库读数(k3s8 TiDB v7.5.1:超墙的续跑输入写,首笔答 1153 + 带库原句,
|
|
125
|
+
* 同池下一笔 `getCtx` 答 `write ECONNRESET`);其余按各引擎的服务端行为文档登记(**未在真库上逐码复现**,收车档如实标注),错放进来的代价只是一次重连;
|
|
126
|
+
* · **只读类**(只读模式 / 故障切换之后连接落在只读节点上):mysql2 自己的 `pool.query` 对这三个错误号同样销毁连接(`lib/base/pool.js` `isReadOnlyError`)——
|
|
127
|
+
* 本仓的池上裸语句改走租来的连接(`createCloseAwarePool`),不收进来就丢了这条既有行为;归因取 mysql2 的,不另作更窄的断言。
|
|
128
|
+
* **不在表里**的(连接仍可用,语句级错误):唯一键冲突 1062、死锁 1213、锁等待超时 1205、`KILL QUERY` 的 1317、缺表 1146、CHECK 被拒 3819,以及 **TiDB 的单行墙 8025**
|
|
129
|
+
* (`ErrEntryTooLarge`,事务层的语句错;真库读数:同池上 8025 写之后的读照常 —— `checkpoint-row-size-db-integration` ②③④)。
|
|
130
|
+
* 断连形(`ECONNRESET` / `EPIPE` / `PROTOCOL_CONNECTION_LOST`)也不在表里:那是 mysql2 的**致命错误**,连接对象自己已经 `_removeFromPool`。
|
|
131
|
+
* PostgreSQL 没有对应面:node-pg 的 `pool.query` 对任何错误都丢弃那条 client。
|
|
132
|
+
* 新增一行 = 改表 + 在 `test/db-closed-connection-never-pooled.test.ts` 的码表里加一格。
|
|
133
|
+
*/
|
|
134
|
+
export declare const MYSQL_CONNECTION_UNUSABLE_ERRORS: ReadonlyArray<{
|
|
135
|
+
readonly errno: number;
|
|
136
|
+
readonly code: string;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* 「抛出这个错误的那条连接还能不能回池」的单一判据:{@link MYSQL_CONNECTION_UNUSABLE_ERRORS} 里的错 ⇒ **不能** —— 持连接的一方(`sql-driver.ts` 的 `leaseOf`)
|
|
140
|
+
* 先销毁它、再让错误出去。两个归因键任一在场即认(同本文件其余谓词的姿势:`errno` 与 `code` 是同一件事的两种写法,代理 / 序列化往返可能只留一个)。
|
|
141
|
+
* 认不出的一律不是(连接照常归还;断连形由 mysql2 自己清出池)。只管 MySQL 协议的错误形:PG 的错误没有这两个键,恒 false。
|
|
142
|
+
*/
|
|
143
|
+
export declare function isConnectionUnusableError(err: unknown): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* 检查点店的两笔写(续跑输入 `putCtx` / 停驻行 `put`)被引擎以「一行装不下」拒 ⇒ **这一只**带码错误(码 `store.row_too_large`),不以裸驱动错上抛
|
|
146
|
+
* (其余店写今天仍是各自的驱动错 —— 未收,登记在案)。
|
|
147
|
+
* `row` = 哪一张表的哪一格、为谁写(进句子与运维日志);`wall` = 拒它的那堵墙({@link rowTooLargeWallOf} 的读数;提交腿按它选 413 的出路);
|
|
148
|
+
* `dbMessage` = 引擎自己的那句(TiDB 的句子带着上限与这一行的实际字节数),截到 200 字符。
|
|
149
|
+
* 提交腿把它答成 413 `request.payload_too_large`(`http/submit-ctx.ts`);停驻那一拍它经引擎的错误座落进运维日志。
|
|
150
|
+
*/
|
|
151
|
+
export declare class StoreRowTooLargeError extends Error {
|
|
152
|
+
readonly row: string;
|
|
153
|
+
readonly wall: RowTooLargeWall;
|
|
154
|
+
readonly code: "store.row_too_large";
|
|
155
|
+
readonly dbMessage: string;
|
|
156
|
+
constructor(row: string, cause: unknown, wall: RowTooLargeWall);
|
|
157
|
+
}
|
|
158
|
+
/** 店写口的翻译:{@link rowTooLargeWallOf} 认得出 ⇒ {@link StoreRowTooLargeError}(带那堵墙);其余原样交回(调用方 `throw` 它)。 */
|
|
159
|
+
export declare function rowTooLargeOrSelf(dialect: SqlDialect, err: unknown, row: string): unknown;
|
|
96
160
|
//# sourceMappingURL=sql-errors.d.ts.map
|
|
@@ -45,4 +45,61 @@ export function isDeadlockError(dialect, err) {
|
|
|
45
45
|
return keyOf(err, "code") === PG_DEADLOCK_DETECTED_SQLSTATE;
|
|
46
46
|
return keyOf(err, "errno") === MYSQL_ER_LOCK_DEADLOCK_ERRNO || keyOf(err, "code") === MYSQL_ER_LOCK_DEADLOCK_CODE;
|
|
47
47
|
}
|
|
48
|
+
export const TIDB_ER_ENTRY_TOO_LARGE_ERRNO = 8025;
|
|
49
|
+
export const MYSQL_ER_NET_PACKET_TOO_LARGE_ERRNO = 1153;
|
|
50
|
+
export const MYSQL_ER_NET_PACKET_TOO_LARGE_CODE = "ER_NET_PACKET_TOO_LARGE";
|
|
51
|
+
export const PG_PROGRAM_LIMIT_EXCEEDED_SQLSTATE = "54000";
|
|
52
|
+
export function rowTooLargeWallOf(dialect, err) {
|
|
53
|
+
if (err === null || typeof err !== "object")
|
|
54
|
+
return undefined;
|
|
55
|
+
if (dialect === "pg")
|
|
56
|
+
return keyOf(err, "code") === PG_PROGRAM_LIMIT_EXCEEDED_SQLSTATE ? "value" : undefined;
|
|
57
|
+
const errno = keyOf(err, "errno");
|
|
58
|
+
if (errno === TIDB_ER_ENTRY_TOO_LARGE_ERRNO)
|
|
59
|
+
return "row";
|
|
60
|
+
if (errno === MYSQL_ER_NET_PACKET_TOO_LARGE_ERRNO || keyOf(err, "code") === MYSQL_ER_NET_PACKET_TOO_LARGE_CODE)
|
|
61
|
+
return "statement";
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
export const MYSQL_CONNECTION_UNUSABLE_ERRORS = [
|
|
65
|
+
{ errno: 1053, code: "ER_SERVER_SHUTDOWN" },
|
|
66
|
+
{ errno: 1152, code: "ER_ABORTING_CONNECTION" },
|
|
67
|
+
{ errno: 1153, code: "ER_NET_PACKET_TOO_LARGE" },
|
|
68
|
+
{ errno: 1158, code: "ER_NET_READ_ERROR" },
|
|
69
|
+
{ errno: 1159, code: "ER_NET_READ_INTERRUPTED" },
|
|
70
|
+
{ errno: 1160, code: "ER_NET_ERROR_ON_WRITE" },
|
|
71
|
+
{ errno: 1161, code: "ER_NET_WRITE_INTERRUPTED" },
|
|
72
|
+
{ errno: 1927, code: "ER_CONNECTION_KILLED" },
|
|
73
|
+
{ errno: 4031, code: "ER_CLIENT_INTERACTION_TIMEOUT" },
|
|
74
|
+
{ errno: 1290, code: "ER_OPTION_PREVENTS_STATEMENT" },
|
|
75
|
+
{ errno: 1792, code: "ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION" },
|
|
76
|
+
{ errno: 1836, code: "ER_READ_ONLY_MODE" },
|
|
77
|
+
];
|
|
78
|
+
const UNUSABLE_ERRNOS = new Set(MYSQL_CONNECTION_UNUSABLE_ERRORS.map((e) => e.errno));
|
|
79
|
+
const UNUSABLE_CODES = new Set(MYSQL_CONNECTION_UNUSABLE_ERRORS.map((e) => e.code));
|
|
80
|
+
export function isConnectionUnusableError(err) {
|
|
81
|
+
const errno = keyOf(err, "errno");
|
|
82
|
+
const code = keyOf(err, "code");
|
|
83
|
+
return (typeof errno === "number" && UNUSABLE_ERRNOS.has(errno)) || (typeof code === "string" && UNUSABLE_CODES.has(code));
|
|
84
|
+
}
|
|
85
|
+
export class StoreRowTooLargeError extends Error {
|
|
86
|
+
row;
|
|
87
|
+
wall;
|
|
88
|
+
code = "store.row_too_large";
|
|
89
|
+
dbMessage;
|
|
90
|
+
constructor(row, cause, wall) {
|
|
91
|
+
const dbMessage = (cause instanceof Error ? cause.message : String(cause)).replace(/[\u0000-\u001f\u007f]+/g, " ").slice(0, 200);
|
|
92
|
+
super(`${row} was refused by the database: the row is larger than the database stores in one row (${dbMessage}). ` +
|
|
93
|
+
"Shrink what the request carries inline (images / userAttachments), or raise the database's single-row limit " +
|
|
94
|
+
"(TiDB: performance.txn-entry-size-limit, or the tidb_txn_entry_size_limit variable on TiDB 7.6+; MySQL / MariaDB: max_allowed_packet)");
|
|
95
|
+
this.row = row;
|
|
96
|
+
this.wall = wall;
|
|
97
|
+
this.name = "StoreRowTooLargeError";
|
|
98
|
+
this.dbMessage = dbMessage;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function rowTooLargeOrSelf(dialect, err, row) {
|
|
102
|
+
const wall = rowTooLargeWallOf(dialect, err);
|
|
103
|
+
return wall !== undefined ? new StoreRowTooLargeError(row, err, wall) : err;
|
|
104
|
+
}
|
|
48
105
|
//# sourceMappingURL=sql-errors.js.map
|
|
@@ -10,6 +10,7 @@ import { LocalCheckpointStore } from "./local-checkpoint-store.js";
|
|
|
10
10
|
import { FileResumeAnchorStore } from "./file-resume-anchor-store.js";
|
|
11
11
|
import { type ApprovalExemptionStore } from "./approval-exemption-store.js";
|
|
12
12
|
import { type ApprovalNonceStore } from "./approval-nonce-store.js";
|
|
13
|
+
import { type OrgDeliveryQuotaStore } from "./org-delivery-quota-store.js";
|
|
13
14
|
import { type ApprovalAskStore as ApprovalAskStoreType } from "./approval-ask-store-sql.js";
|
|
14
15
|
import { type MemoryOptOutGrantStore } from "./memory-optout-grant-store-sql.js";
|
|
15
16
|
import { type SendFileLedger } from "./send-file-ledger.js";
|
|
@@ -59,6 +60,19 @@ export type ServiceSessionPolicyStore = SessionPolicyStore;
|
|
|
59
60
|
* whole-tree `ServiceFileSnapshotStore` ([ref]: the boundary covers the TRACKED set only — files this
|
|
60
61
|
* session edited; there is no whole-tree manifest anymore). Also the 2c history-transfer store
|
|
61
62
|
* (exportHistory/importHistory + the blob negotiation faces below). */
|
|
63
|
+
/**
|
|
64
|
+
* The 2c `putBlob` answer: core's `FileHistoryResult` plus ONE arm — the SQL blob judge refused the blob on the connection that
|
|
65
|
+
* would have written it ({@link import("./blob-backend.js").BlobTooLargeError}, code `blob_too_large_for_sql`). `PUT /sync/blobs`
|
|
66
|
+
* answers that arm 413 (the store's sentence, plus the machine-readable `wallSource` = where the cap came from) and every other failure 502 (retryable).
|
|
67
|
+
*/
|
|
68
|
+
export type SyncBlobPutResult = import("@sema-agent/core").FileHistoryResult | {
|
|
69
|
+
readonly ok: false;
|
|
70
|
+
readonly error: {
|
|
71
|
+
readonly code: import("./blob-backend.js").BlobTooLargeError["code"];
|
|
72
|
+
readonly message: string;
|
|
73
|
+
readonly wallSource: import("./blob-backend.js").SqlBlobCapReading["source"];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
62
76
|
export type ServiceFileHistoryStore = FileHistoryStore & {
|
|
63
77
|
/** 2c sync blob-face marker — see SqlFileHistoryStore.syncBlobFaces (codex R2-high: name-probing
|
|
64
78
|
* `putBlob` on an arbitrary store collides with the local core store's PRIVATE void helper). */
|
|
@@ -70,7 +84,7 @@ export type ServiceFileHistoryStore = FileHistoryStore & {
|
|
|
70
84
|
* protected — never a synchronous external-store delete). Reaper-driven; SQL twins only. */
|
|
71
85
|
sweepOrphanBlobs?(): Promise<number>;
|
|
72
86
|
/** 2c blob negotiation: upload one content-addressed blob ahead of importHistory. SQL twins only. */
|
|
73
|
-
putBlob?(hash: string, bytes: Uint8Array): Promise<
|
|
87
|
+
putBlob?(hash: string, bytes: Uint8Array): Promise<SyncBlobPutResult>;
|
|
74
88
|
/** 2c blob read face (scope-checked by the route against the session's history graph). SQL twins only. */
|
|
75
89
|
getBlob?(hash: string): Promise<Uint8Array | undefined>;
|
|
76
90
|
/** The subset of `hashes` already present — a cheap SQL INDEX probe (the import presence pre-check,
|
|
@@ -163,6 +177,11 @@ export interface StoreBackend {
|
|
|
163
177
|
* `approvalExemption` 同姿势:tidb/pg = SQL 双方言(单类双语句),local = File 追加日志 + 压实。
|
|
164
178
|
* **不能**退化成进程内易失形:一次重启若把记录抹掉,JWT TTL 窗内的重放就复活了,而那正是本店要关的洞。 */
|
|
165
179
|
approvalNonce(): ApprovalNonceStore;
|
|
180
|
+
/** [ref] §10.2 —— 跨主体投递门的配额店(`org-delivery-quota-store.ts`:一次 take 在同一把锁下判并记对偶界与收件人
|
|
181
|
+
* 聚合界)。REQUIRED on all backends —— tidb/pg = SQL 双方言(单类双语句,窗按库钟),local = File 整份快照(本进程墙钟;
|
|
182
|
+
* 数据根锁保证一个进程)。门装配时才取(`PRINCIPAL_INBOX_ASSISTANT` 在场);**不能**退化成进程内易失形:多副本各数各的
|
|
183
|
+
* = 额度 × 副本数,一次重启清零 = 窗内额度复活。 */
|
|
184
|
+
orgDeliveryQuota(): OrgDeliveryQuotaStore;
|
|
166
185
|
/** [ref]([ref] §3.0-§3.2)流内审批协议持久层:每个流内工具调用一行的 ask 状态机 + 批行。
|
|
167
186
|
* REQUIRED **且持久** on all backends — tidb/pg = SQL 双方言 twin;local = {@link FileApprovalAskStore}。
|
|
168
187
|
*
|
|
@@ -287,6 +306,11 @@ export interface StoreBackend {
|
|
|
287
306
|
* 缺席**是一个真答案**:那里的索引家在 run 店同一间屋子里(`LocalWorkflowAgentSessionIndex`,文件账本
|
|
288
307
|
* 或纯内存),不需要经过 backend。契约与单写者纪律的属主 = orchestration/workflow-agent-session-index.ts。 */
|
|
289
308
|
workflowAgentSessionIndex?(): import("../orchestration/workflow-agent-session-index.js").WorkflowAgentSessionIndex;
|
|
309
|
+
/** workflow 子代停驻卡的耐久决定行(一张卡一行,键 = 子代 checkpoint 的 token),**绑在本后端的 {@link run} 那只 run 店上**(每一笔写都在它的会话认领栅栏里落)。
|
|
310
|
+
* 与 `run()` 同形:无参、恒交同一只(三孪生同),所以这只决定店绑的就是部署的 run 店。SQL 后端 = 跨副本表,读写走 run 店的池;`local` 后端 = 进程内,
|
|
311
|
+
* 账本位置由后端按自己的数据根与 `WORKFLOW_RUN_STORE` 定(`<数据根>/workflows/workflow-park-decisions/decisions.jsonl`;`memory` ⇒ 纯内存)。
|
|
312
|
+
* 契约与律的属主 = orchestration/workflow-park-decision.ts。 */
|
|
313
|
+
workflowParkDecisions?(): import("../orchestration/workflow-park-decision.js").WorkflowParkDecisionStore;
|
|
290
314
|
/** Cloud-only stores below are OPTIONAL: the `local` (in-memory/file) backend omits them (it has no core
|
|
291
315
|
* in-memory twin carrying the service extras, and these are fleet/multi-replica concepts), so a local HTTP
|
|
292
316
|
* service degrades EXACTLY like today's no-DB env (the consumers gate on `backend?.X?.()`). TiDB/PG provide all. */
|
|
@@ -301,6 +325,17 @@ export interface StoreBackend {
|
|
|
301
325
|
checkpoint?(logger?: {
|
|
302
326
|
info?(msg: string, meta?: unknown): void;
|
|
303
327
|
}): CheckpointStoreFull;
|
|
328
|
+
/**
|
|
329
|
+
* 待决 checkpoint 的**只读**读口(**必选**成员)—— 审批账本留存律(`approval-ask-retention.ts` 的挂靠集)读「还有哪些会话停驻着」就走这一口,不走 {@link checkpoint}。
|
|
330
|
+
* 区别只有一条:这一口**不牵动任何别的店**。local 车道的 `checkpoint()` 是 durable 停驻面的装配点 —— 它给 run 店接上 [ref] 的收割探针(停驻行的收割从 no-op 变生效),
|
|
331
|
+
* 那是开了 `DURABLE_APPROVAL` 的部署才该发生的事;留存腿在没开它的部署上同样要读(前世 / 别的副本留下的停驻不因这一世的开关消失,看不见就会把还能被决的停驻的问删掉),
|
|
332
|
+
* 所以读和接线必须分口。SQL 孪生本来无状态(接线靠 JOIN),两口同一只。
|
|
333
|
+
*
|
|
334
|
+
* 🔴 为什么必选而不是跟着 {@link checkpoint} 一起可选:留存腿读不到这一口的后果在**删除方向**(挂靠集里少了待决停驻 ⇒ 还能被决的停驻的问按龄被删),
|
|
335
|
+
* 「有 checkpoint 店却没交读口」若只是运行期的 `undefined`,就是一次静默少保护;必选 ⇒ 漏实现是**编译红**。没有 checkpoint 店的后端(`checkpoint` 缺席)交一只恒空的读口
|
|
336
|
+
* (`{ listPendingSessionIds: async () => [] }` —— 没有店 ⇒ 没有停驻,这是事实不是缺省)。
|
|
337
|
+
*/
|
|
338
|
+
checkpointReadView(): Pick<CheckpointStoreFull, "listPendingSessionIds">;
|
|
304
339
|
toolResult?(): ToolResultStoreFull;
|
|
305
340
|
imageIndex?(): ImageIndex;
|
|
306
341
|
imageBake?(): ImageBake;
|
|
@@ -7,17 +7,20 @@ import { FileWorkflowJournalStore } from "@sema-agent/core";
|
|
|
7
7
|
import { fileSessionCaptureRecordStore } from "@sema-agent/core";
|
|
8
8
|
import { TiDBOutcomeLedger, PgOutcomeLedger } from "./outcome-ledger-sql.js";
|
|
9
9
|
import { FileOutcomeSink } from "./file-outcome-sink.js";
|
|
10
|
-
import { TiDBWorkflowRunStore, TiDBWorkflowCompletionInbox, TiDBWorkflowNotifyJournalStore, TiDBWorkflowAgentSessionIndex, PgWorkflowRunStore, PgWorkflowCompletionInbox, PgWorkflowNotifyJournalStore, PgWorkflowAgentSessionIndex } from "./workflow-run-store-sql.js";
|
|
10
|
+
import { TiDBWorkflowRunStore, TiDBWorkflowCompletionInbox, TiDBWorkflowNotifyJournalStore, TiDBWorkflowAgentSessionIndex, SqlWorkflowParkDecisionStore, PgWorkflowRunStore, PgWorkflowCompletionInbox, PgWorkflowNotifyJournalStore, PgWorkflowAgentSessionIndex } from "./workflow-run-store-sql.js";
|
|
11
11
|
import { FileRunStore } from "./file-run-store.js";
|
|
12
|
+
import { LocalWorkflowParkDecisionStore } from "../orchestration/workflow-park-decision.js";
|
|
12
13
|
import { StoreBootRefusalError } from "./store-contracts.js";
|
|
13
14
|
import { buildStoreOpenRefusalTail } from "./store-open-refusal.js";
|
|
14
15
|
import { acquireLocalBackendWithWait } from "./store-lock-wait.js";
|
|
15
|
-
import { NO_SQL_MIGRATIONS,
|
|
16
|
+
import { NO_SQL_MIGRATIONS, runSqlOneTimeMigrations } from "./one-time-migrations.js";
|
|
17
|
+
import { assertRetiredSchemaAbsentOnPool } from "./schema-consistency.js";
|
|
16
18
|
import { LocalSessionStore, createLocalSessionRepo } from "./local-session-store.js";
|
|
17
19
|
import { LocalCheckpointStore } from "./local-checkpoint-store.js";
|
|
18
20
|
import { FileResumeAnchorStore } from "./file-resume-anchor-store.js";
|
|
19
21
|
import { TiDBApprovalExemptionStore, PgApprovalExemptionStore, FileApprovalExemptionStore } from "./approval-exemption-store.js";
|
|
20
22
|
import { TiDBApprovalNonceStore, PgApprovalNonceStore, FileApprovalNonceStore } from "./approval-nonce-store.js";
|
|
23
|
+
import { TiDBOrgDeliveryQuotaStore, PgOrgDeliveryQuotaStore, FileOrgDeliveryQuotaStore } from "./org-delivery-quota-store.js";
|
|
21
24
|
import { TiDBApprovalAskStore, PgApprovalAskStore } from "./approval-ask-store-sql.js";
|
|
22
25
|
import { FileApprovalAskStore } from "./approval-ask-store-file.js";
|
|
23
26
|
import { TiDBMemoryOptOutGrantStore, PgMemoryOptOutGrantStore } from "./memory-optout-grant-store-sql.js";
|
|
@@ -60,7 +63,7 @@ import { openWithinWait } from "./store-open-wait.js";
|
|
|
60
63
|
function historyBlobBackend(config, dialect, pool) {
|
|
61
64
|
const s = config.snapshotBlobStore;
|
|
62
65
|
if (!s)
|
|
63
|
-
return new SqlBlobBackend(dialect, pool, config.snapshotBlobSqlMaxBytes, FILE_HISTORY_BLOB_TABLE);
|
|
66
|
+
return new SqlBlobBackend(dialect, pool, config.snapshotBlobSqlMaxBytes, FILE_HISTORY_BLOB_TABLE, createLogger(config.logLevel));
|
|
64
67
|
return new MinioBlobBackend({
|
|
65
68
|
endpoint: s.endpoint,
|
|
66
69
|
bucket: s.bucket,
|
|
@@ -74,7 +77,7 @@ function historyBlobBackend(config, dialect, pool) {
|
|
|
74
77
|
function legacyBlobBackend(config, dialect, pool) {
|
|
75
78
|
const s = config.snapshotBlobStore;
|
|
76
79
|
if (!s)
|
|
77
|
-
return new SqlBlobBackend(dialect, pool, config.snapshotBlobSqlMaxBytes);
|
|
80
|
+
return new SqlBlobBackend(dialect, pool, config.snapshotBlobSqlMaxBytes, undefined, createLogger(config.logLevel));
|
|
78
81
|
return new MinioBlobBackend({
|
|
79
82
|
endpoint: s.endpoint,
|
|
80
83
|
bucket: s.bucket,
|
|
@@ -120,10 +123,12 @@ class TiDBBackend {
|
|
|
120
123
|
}
|
|
121
124
|
ensureSchema() { return ensureTidbSchema(this.pool); }
|
|
122
125
|
close() { return this.pool.end(); }
|
|
123
|
-
run() { return new TiDBRunStore(this.pool); }
|
|
126
|
+
run() { return (this.runStoreInst ??= new TiDBRunStore(this.pool)); }
|
|
127
|
+
runStoreInst;
|
|
124
128
|
resumeAnchor() { return new TiDBResumeAnchorStore(this.pool); }
|
|
125
129
|
approvalExemption() { return new TiDBApprovalExemptionStore(this.pool); }
|
|
126
130
|
approvalNonce() { return new TiDBApprovalNonceStore(this.pool); }
|
|
131
|
+
orgDeliveryQuota() { return new TiDBOrgDeliveryQuotaStore(this.pool); }
|
|
127
132
|
approvalAsk() { return new TiDBApprovalAskStore(this.pool); }
|
|
128
133
|
permissionRule() { return createSqlPermissionRuleStores(mysqlDriver(this.pool)); }
|
|
129
134
|
sendFileLedger() { return new TiDBSendFileLedger(this.pool); }
|
|
@@ -141,8 +146,11 @@ class TiDBBackend {
|
|
|
141
146
|
completionInbox(onWarn) { return new TiDBWorkflowCompletionInbox(this.pool, onWarn); }
|
|
142
147
|
notifyJournal() { return new TiDBWorkflowNotifyJournalStore(this.pool); }
|
|
143
148
|
workflowAgentSessionIndex() { return new TiDBWorkflowAgentSessionIndex(this.pool); }
|
|
149
|
+
workflowParkDecisions() { return (this.parkDecisionsInst ??= new SqlWorkflowParkDecisionStore(this.run())); }
|
|
150
|
+
parkDecisionsInst;
|
|
144
151
|
sharedMemoryStore(authorizer) { return new TiDBSharedMemoryStore(this.pool, authorizer); }
|
|
145
152
|
checkpoint(logger) { return new TiDBCheckpointStore(this.pool, logger); }
|
|
153
|
+
checkpointReadView() { return this.checkpoint(); }
|
|
146
154
|
toolResult() { return new TiDBToolResultStore(this.pool); }
|
|
147
155
|
imageIndex() { return new TiDBImageIndex(this.pool); }
|
|
148
156
|
imageBake() { return new TiDBImageBake(this.pool); }
|
|
@@ -153,7 +161,7 @@ class TiDBBackend {
|
|
|
153
161
|
breaker(onWriteFail) { return new TiDBBreakerState(this.pool, onWriteFail); }
|
|
154
162
|
costQuota(limitMicroUsd, windowMs, onDegraded) { return new TiDBCostQuota(this.pool, limitMicroUsd, windowMs, undefined, onDegraded, this.config.dbQueryTimeoutMs); }
|
|
155
163
|
rateLimiter(limit, onDegraded) { return new TiDBRateLimiter(this.pool, limit, undefined, undefined, onDegraded, this.config.dbQueryTimeoutMs); }
|
|
156
|
-
session() { return new TiDBSessionStore(this.pool); }
|
|
164
|
+
session() { return new TiDBSessionStore(this.pool, { log: createLogger(this.config.logLevel) }); }
|
|
157
165
|
adoptionLog() { return new TiDBAdoptionLogStore(this.pool); }
|
|
158
166
|
mysqlPool() { return this.pool; }
|
|
159
167
|
pgPool() { return undefined; }
|
|
@@ -169,10 +177,12 @@ class PgBackend {
|
|
|
169
177
|
}
|
|
170
178
|
ensureSchema() { return ensurePgSchema(this.pool); }
|
|
171
179
|
close() { return this.pool.end(); }
|
|
172
|
-
run() { return new PgRunStore(this.pool); }
|
|
180
|
+
run() { return (this.runStoreInst ??= new PgRunStore(this.pool)); }
|
|
181
|
+
runStoreInst;
|
|
173
182
|
resumeAnchor() { return new PgResumeAnchorStore(this.pool); }
|
|
174
183
|
approvalExemption() { return new PgApprovalExemptionStore(this.pool); }
|
|
175
184
|
approvalNonce() { return new PgApprovalNonceStore(this.pool); }
|
|
185
|
+
orgDeliveryQuota() { return new PgOrgDeliveryQuotaStore(this.pool); }
|
|
176
186
|
approvalAsk() { return new PgApprovalAskStore(this.pool); }
|
|
177
187
|
permissionRule() { return createSqlPermissionRuleStores(pgDriver(this.pool)); }
|
|
178
188
|
sendFileLedger() { return new PgSendFileLedger(this.pool); }
|
|
@@ -190,8 +200,11 @@ class PgBackend {
|
|
|
190
200
|
completionInbox(onWarn) { return new PgWorkflowCompletionInbox(this.pool, onWarn); }
|
|
191
201
|
notifyJournal() { return new PgWorkflowNotifyJournalStore(this.pool); }
|
|
192
202
|
workflowAgentSessionIndex() { return new PgWorkflowAgentSessionIndex(this.pool); }
|
|
203
|
+
workflowParkDecisions() { return (this.parkDecisionsInst ??= new SqlWorkflowParkDecisionStore(this.run())); }
|
|
204
|
+
parkDecisionsInst;
|
|
193
205
|
sharedMemoryStore(authorizer) { return new PgSharedMemoryStore(this.pool, authorizer); }
|
|
194
206
|
checkpoint(logger) { return new PgCheckpointStore(this.pool, logger); }
|
|
207
|
+
checkpointReadView() { return this.checkpoint(); }
|
|
195
208
|
toolResult() { return new PgToolResultStore(this.pool); }
|
|
196
209
|
imageIndex() { return new PgImageIndex(this.pool); }
|
|
197
210
|
imageBake() { return new PgImageBake(this.pool); }
|
|
@@ -202,7 +215,7 @@ class PgBackend {
|
|
|
202
215
|
breaker(onWriteFail) { return new PgBreakerState(this.pool, onWriteFail); }
|
|
203
216
|
costQuota(limitMicroUsd, windowMs, onDegraded) { return new PgCostQuota(this.pool, limitMicroUsd, windowMs, undefined, onDegraded, this.config.dbQueryTimeoutMs); }
|
|
204
217
|
rateLimiter(limit, onDegraded) { return new PgRateLimiter(this.pool, limit, undefined, undefined, onDegraded, this.config.dbQueryTimeoutMs); }
|
|
205
|
-
session() { return new PgSessionStore(this.pool); }
|
|
218
|
+
session() { return new PgSessionStore(this.pool, { log: createLogger(this.config.logLevel) }); }
|
|
206
219
|
adoptionLog() { return new PgAdoptionLogStore(this.pool); }
|
|
207
220
|
mysqlPool() { return undefined; }
|
|
208
221
|
pgPool() { return this.pool; }
|
|
@@ -216,6 +229,7 @@ class LocalBackend {
|
|
|
216
229
|
resumeAnchorStore;
|
|
217
230
|
approvalExemptionStore;
|
|
218
231
|
approvalNonceStore;
|
|
232
|
+
orgDeliveryQuotaStore;
|
|
219
233
|
approvalAskStore;
|
|
220
234
|
sendFileLedgerStore;
|
|
221
235
|
userInputLedgerStore;
|
|
@@ -224,6 +238,7 @@ class LocalBackend {
|
|
|
224
238
|
onWarn;
|
|
225
239
|
onError;
|
|
226
240
|
discloseWarn;
|
|
241
|
+
parkDecisionLedgerRoot;
|
|
227
242
|
constructor(root, config, onWarn, onError) {
|
|
228
243
|
this.onWarn = onWarn;
|
|
229
244
|
this.discloseWarn = onWarn ?? ((msg, meta) => console.warn(msg, meta));
|
|
@@ -248,9 +263,11 @@ class LocalBackend {
|
|
|
248
263
|
strictHydrate: config.runStoreStrictHydrate,
|
|
249
264
|
});
|
|
250
265
|
this.sessionStore = new LocalSessionStore(createLocalSessionRepo(this.fileBackend.root), this.runStore, this.fileBackend.root, { log: createLogger(config.logLevel) });
|
|
266
|
+
this.parkDecisionLedgerRoot = config.workflowRunStoreBackend === "memory" ? undefined : join(this.fileBackend.root, "workflows");
|
|
251
267
|
this.resumeAnchorStore = new FileResumeAnchorStore(this.fileBackend.root);
|
|
252
268
|
this.approvalExemptionStore = new FileApprovalExemptionStore(this.fileBackend.root, { warn: corruptReadWarn });
|
|
253
269
|
this.approvalNonceStore = new FileApprovalNonceStore(this.fileBackend.root, { warn: corruptReadWarn });
|
|
270
|
+
this.orgDeliveryQuotaStore = new FileOrgDeliveryQuotaStore(this.fileBackend.root, { warn: corruptReadWarn });
|
|
254
271
|
this.approvalAskStore = new FileApprovalAskStore(this.fileBackend.root);
|
|
255
272
|
this.sendFileLedgerStore = new FileSendFileLedger(this.fileBackend.root);
|
|
256
273
|
this.userInputLedgerStore = new FileUserInputLedgerStore(this.fileBackend.root);
|
|
@@ -283,9 +300,14 @@ class LocalBackend {
|
|
|
283
300
|
await this.fileBackend.dispose();
|
|
284
301
|
}
|
|
285
302
|
run() { return this.runStore; }
|
|
303
|
+
workflowParkDecisions() {
|
|
304
|
+
return (this.parkDecisionsInst ??= new LocalWorkflowParkDecisionStore(this.runStore, this.parkDecisionLedgerRoot));
|
|
305
|
+
}
|
|
306
|
+
parkDecisionsInst;
|
|
286
307
|
resumeAnchor() { return this.resumeAnchorStore; }
|
|
287
308
|
approvalExemption() { return this.approvalExemptionStore; }
|
|
288
309
|
approvalNonce() { return this.approvalNonceStore; }
|
|
310
|
+
orgDeliveryQuota() { return this.orgDeliveryQuotaStore; }
|
|
289
311
|
approvalAsk() { return this.approvalAskStore; }
|
|
290
312
|
permissionRule() {
|
|
291
313
|
if (!this.permissionRuleStoresInst) {
|
|
@@ -299,20 +321,25 @@ class LocalBackend {
|
|
|
299
321
|
permissionRuleStoresInst;
|
|
300
322
|
sendFileLedger() { return this.sendFileLedgerStore; }
|
|
301
323
|
userInputLedger() { return this.userInputLedgerStore; }
|
|
324
|
+
checkpointStoreOf() {
|
|
325
|
+
return (this.checkpointStoreInst ??= new LocalCheckpointStore(this.fileBackend.root, {
|
|
326
|
+
getActiveTaskId: (sessionId) => this.runStore.getActiveTaskId(sessionId),
|
|
327
|
+
ownerOf: (sessionId) => this.sessionStore.ownerOf(sessionId),
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
302
330
|
checkpoint() {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
ownerOf: (sessionId) => this.sessionStore.ownerOf(sessionId),
|
|
307
|
-
});
|
|
308
|
-
this.checkpointStoreInst = cs;
|
|
331
|
+
const cs = this.checkpointStoreOf();
|
|
332
|
+
if (!this.checkpointProbeWired) {
|
|
333
|
+
this.checkpointProbeWired = true;
|
|
309
334
|
this.runStore.setCheckpointProbe({
|
|
310
335
|
hasPending: async (sessionId) => (await cs.findPendingTokenBySession(sessionId)) !== null,
|
|
311
336
|
hasExpired: (sessionId) => cs.hasExpiredBySession(sessionId),
|
|
312
337
|
});
|
|
313
338
|
}
|
|
314
|
-
return
|
|
339
|
+
return cs;
|
|
315
340
|
}
|
|
341
|
+
checkpointReadView() { return this.checkpointStoreOf(); }
|
|
342
|
+
checkpointProbeWired = false;
|
|
316
343
|
checkpointStoreInst;
|
|
317
344
|
sessionPolicy() { return this.fileBackend.sessionPolicyStore; }
|
|
318
345
|
fileUsageWindowStore() { return this.fileBackend.usageWindowStore; }
|
|
@@ -183,6 +183,22 @@ export declare function readLegacyHolderDeathCode(row: {
|
|
|
183
183
|
* 正常失败(别的码 / 无码)/ park 过期收割(`approval.expired`:腿 park 过)都**不是**死亡判决。
|
|
184
184
|
*/
|
|
185
185
|
export declare function isHolderDeathVerdict(run: Pick<RunRecord, "status" | "errorCode">): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* `listRuns` 的查询(三只 run 店同一份形)。过滤都是精确匹配(`""` 是合法的精确值,不是「不滤」—— B10)。
|
|
188
|
+
* `owner`:串 = 恰这一个主体的 run;`null` = 属主为 null 的 run(不带主体提交的任务:匿名 / 单用户 —— 审批读面的公共 scope `_` 由调用方译成它,店里不认 `_`);
|
|
189
|
+
* 缺席 = 不按属主过滤。SQL 两方言 `null` ⇒ `owner IS NULL`(`owner = NULL` 恒不为真)。
|
|
190
|
+
*/
|
|
191
|
+
export interface RunListQuery {
|
|
192
|
+
status?: string;
|
|
193
|
+
jobId?: string;
|
|
194
|
+
source?: string;
|
|
195
|
+
owner?: string | null;
|
|
196
|
+
cursor?: {
|
|
197
|
+
createdAt: string;
|
|
198
|
+
taskId: string;
|
|
199
|
+
};
|
|
200
|
+
limit: number;
|
|
201
|
+
}
|
|
186
202
|
export interface RunRecord {
|
|
187
203
|
taskId: string;
|
|
188
204
|
sessionId: string;
|
|
@@ -272,6 +288,32 @@ export type CreateRunOutcome = {
|
|
|
272
288
|
existing?: undefined;
|
|
273
289
|
activeTaskId: string;
|
|
274
290
|
};
|
|
291
|
+
/** SQL 认领栅栏的结局:`held: false` = 认领此刻不是这条 run 的(或它已不在跑),`write` 一次都没调。 */
|
|
292
|
+
export type ClaimFenced<T> = {
|
|
293
|
+
readonly held: true;
|
|
294
|
+
readonly value: T;
|
|
295
|
+
} | {
|
|
296
|
+
readonly held: false;
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* 进程内栅栏 `write` 交回的**落定记号**。`write` 的型是 `() => FenceLanded`:只有**同步**交回这只记号的回调编得过 —— async 回调交回的是
|
|
300
|
+
* `Promise<FenceLanded>`(把真正的写挪到栅栏判完、放开之后的别的微任务里,「判认领与落行同一拍」就不成立了),不是它;栅栏方法没有类型参数,
|
|
301
|
+
* 显式写宽(`<unknown>` / `<void>` / `<object>`)无处可写,回调把返回标宽也编不过。要带出值,用闭包。
|
|
302
|
+
*/
|
|
303
|
+
export declare const FENCE_LANDED: unique symbol;
|
|
304
|
+
export type FenceLanded = typeof FENCE_LANDED;
|
|
305
|
+
/**
|
|
306
|
+
* **宿主会话的认领当写栅栏用 —— 进程内那一形**(属主 = run 店;Memory / File 两孪生同律)。认领 = 会话 → 持有它的 taskId,
|
|
307
|
+
* 由 {@link CreateRunOutcome} 的建行(或续跑腿的 markResuming)取得、终局 / 收割放掉 —— 「这次受理还持有会话吗」只问它,不另记身份。
|
|
308
|
+
*
|
|
309
|
+
* `whileHoldingClaim(sessionId, taskId, write)`:**只有** `taskId` 此刻持有 `sessionId` 的认领、且这条 run 是活的(`running`)时才调 `write`、答 `true`,
|
|
310
|
+
* 同一拍把这条 run 的活性戳刷新(一次栅栏写也是一次心跳);否则一次都不调、答 `false`。整只是**同步**的 —— `write` 也是:判、刷新、`write` 落定是同一个同步段,
|
|
311
|
+
* 中间没有让出,所以认领在 `write` 落定之前挪不动(这一条由类型担保 —— `write` 必须同步交回 {@link FENCE_LANDED},不靠「这里恰好没有 await」)。
|
|
312
|
+
* SQL 孪生的栅栏是一个事务(`run-store-sql.ts` `SqlRunStore.whileHoldingClaim`,`write` 收那只事务连接,结局 {@link ClaimFenced}),不是本型。
|
|
313
|
+
*/
|
|
314
|
+
export interface InProcessClaimFence {
|
|
315
|
+
whileHoldingClaim(sessionId: string, taskId: string, write: () => FenceLanded): boolean;
|
|
316
|
+
}
|
|
275
317
|
/**
|
|
276
318
|
* `RunRecord["status"]`(= `"running" | TaskStatus`)的**唯一分类表** —— 词表的属主 = 判据的属主,
|
|
277
319
|
* 与类型定义同住一个文件。四个类:
|
|
@@ -20,6 +20,7 @@ export function readLegacyHolderDeathCode(row) {
|
|
|
20
20
|
export function isHolderDeathVerdict(run) {
|
|
21
21
|
return run.status === "failed" && run.errorCode !== null && RUN_HOLDER_DEATH_CODE_WORDS.has(run.errorCode);
|
|
22
22
|
}
|
|
23
|
+
export const FENCE_LANDED = Symbol("in-process-claim-fence.landed");
|
|
23
24
|
export const RUN_STATUS_CLASS = {
|
|
24
25
|
running: "live",
|
|
25
26
|
completed: "succeeded",
|
|
@@ -23,7 +23,12 @@ export declare function tidbPoolOptions(tidb: NonNullable<ServiceConfig["tidb"]>
|
|
|
23
23
|
* · `lib/base/pool.js` / `lib/promise/pool.js` —— 池层与 promise 包装层都**不**把连接 error 再
|
|
24
24
|
* emit 到池对象上(池层只 emit acquire/connection/enqueue/release)。
|
|
25
25
|
* ⇒ 空闲连接被 KILL / 故障切换杀掉 = 库内吞并淘汰,进程不死、池自愈。真 TiDB KILL 钉在
|
|
26
|
-
* `test/pool-idle-error-db-integration.test.ts` 第③格。升 mysql2 大版时按上面三坐标复核。
|
|
26
|
+
* `test/pool-idle-error-db-integration.test.ts` 第③格。升 mysql2 大版时按上面三坐标复核。
|
|
27
|
+
*
|
|
28
|
+
* **另一种病不在上面三坐标里 —— 库回完一个错误包随后才关连接**(1153 语句超过 `max_allowed_packet`:库读完包头就拒、回错、关连接):
|
|
29
|
+
* mysql2 的 `pool.query` 只看见「这条语句完了」,连接照常归还,库的 FIN / RST 晚一拍才到,紧接着的下一笔借到这条半死的连接、答 `write ECONNRESET`
|
|
30
|
+
* (`lib/base/pool.js` 的 `query` 只对只读节点三个错误号销毁连接)。所以交出去的池是 {@link createCloseAwarePool} 包过的:池上的裸语句改为每条租一条连接,
|
|
31
|
+
* 收到 `isConnectionUnusableError` 一类的错先销毁再抛(借出给店的连接走同一只守卫,`sql-driver.ts` 的 `leaseOf`)。 */
|
|
27
32
|
export declare function createTidbPool(config: ServiceConfig): Pool;
|
|
28
33
|
/**
|
|
29
34
|
* Idempotent schema. `session_event` is the append-only L1 event log (positional slicing by
|
|
@@ -9,6 +9,7 @@ import { TIDB_RETENTION_STATEMENTS } from "./retention-store-sql.js";
|
|
|
9
9
|
import { SESSION_META_INCARNATION_COLUMN } from "../session-incarnation.js";
|
|
10
10
|
import { SESSION_RULES_COLUMN } from "./session-rules-column.js";
|
|
11
11
|
import { SESSION_TITLE_MAX_CHARS } from "../session-row.js";
|
|
12
|
+
import { PRINCIPAL_MAX_UTF8_BYTES } from "../security.js";
|
|
12
13
|
import { ensureIndexes } from "./ensure-index.js";
|
|
13
14
|
import { CENTRAL_SCHEMA_INDEXES } from "./schema-indexes.js";
|
|
14
15
|
import { SESSION_INDEXES } from "./pg-session-storage.js";
|
|
@@ -24,6 +25,7 @@ import { PERMISSION_RULE_INDEXES } from "./permission-rule-store-sql.js";
|
|
|
24
25
|
import { RETENTION_INDEXES } from "./retention-store-sql.js";
|
|
25
26
|
import { LEADER_RUN_INDEXES } from "./leader-run-store-sql.js";
|
|
26
27
|
import { pollUntilLocked } from "./ensure-schema-lock-policy.js";
|
|
28
|
+
import { createCloseAwarePool } from "./sql-driver.js";
|
|
27
29
|
export function tidbPoolOptions(tidb) {
|
|
28
30
|
const { host, port, user, password, database, connectionLimit } = tidb;
|
|
29
31
|
const limit = connectionLimit ?? 10;
|
|
@@ -48,7 +50,7 @@ export function createTidbPool(config) {
|
|
|
48
50
|
throw new Error("TiDB config missing. Set MYSQL_HOST / MYSQL_USER / MYSQL_DATABASE (and MYSQL_PASSWORD/PORT) " +
|
|
49
51
|
"when SESSION_BACKEND=mysql.");
|
|
50
52
|
}
|
|
51
|
-
return mysql.createPool(tidbPoolOptions(config.tidb));
|
|
53
|
+
return createCloseAwarePool(mysql.createPool(tidbPoolOptions(config.tidb)));
|
|
52
54
|
}
|
|
53
55
|
export const SCHEMA_STATEMENTS = [
|
|
54
56
|
`CREATE TABLE IF NOT EXISTS session_meta (
|
|
@@ -193,7 +195,7 @@ export const SCHEMA_STATEMENTS = [
|
|
|
193
195
|
-- ever served an operator's ad-hoc WHERE error_code LIKE 'budget.%', while every task_run write paid its
|
|
194
196
|
-- maintenance cost. If you need that ad-hoc query, build the index temporarily and drop it after.
|
|
195
197
|
) COLLATE utf8mb4_bin`,
|
|
196
|
-
`CREATE TABLE IF NOT EXISTS
|
|
198
|
+
`CREATE TABLE IF NOT EXISTS breaker_state (
|
|
197
199
|
breaker_key VARCHAR(190) NOT NULL,
|
|
198
200
|
phase VARCHAR(16) NOT NULL,
|
|
199
201
|
failures INT NOT NULL DEFAULT 0,
|
|
@@ -373,6 +375,25 @@ export const SCHEMA_STATEMENTS = [
|
|
|
373
375
|
expires_at_ms BIGINT NOT NULL,
|
|
374
376
|
PRIMARY KEY (session_id, nonce),
|
|
375
377
|
KEY idx_approval_nonce_expires (expires_at_ms)
|
|
378
|
+
) COLLATE utf8mb4_bin`,
|
|
379
|
+
`CREATE TABLE IF NOT EXISTS org_delivery_sender_quota (
|
|
380
|
+
from_scope VARBINARY(${PRINCIPAL_MAX_UTF8_BYTES}) NOT NULL,
|
|
381
|
+
window_start_ms BIGINT NOT NULL,
|
|
382
|
+
attempts INT NOT NULL,
|
|
383
|
+
PRIMARY KEY (from_scope)
|
|
384
|
+
) COLLATE utf8mb4_bin`,
|
|
385
|
+
`CREATE TABLE IF NOT EXISTS org_delivery_recipient_quota (
|
|
386
|
+
to_scope VARBINARY(${PRINCIPAL_MAX_UTF8_BYTES}) NOT NULL,
|
|
387
|
+
window_start_ms BIGINT NOT NULL,
|
|
388
|
+
delivered INT NOT NULL,
|
|
389
|
+
PRIMARY KEY (to_scope)
|
|
390
|
+
) COLLATE utf8mb4_bin`,
|
|
391
|
+
`CREATE TABLE IF NOT EXISTS org_delivery_pair_quota (
|
|
392
|
+
to_scope VARBINARY(${PRINCIPAL_MAX_UTF8_BYTES}) NOT NULL,
|
|
393
|
+
from_scope VARBINARY(${PRINCIPAL_MAX_UTF8_BYTES}) NOT NULL,
|
|
394
|
+
window_start_ms BIGINT NOT NULL,
|
|
395
|
+
delivered INT NOT NULL,
|
|
396
|
+
PRIMARY KEY (to_scope, from_scope)
|
|
376
397
|
) COLLATE utf8mb4_bin`,
|
|
377
398
|
`CREATE TABLE IF NOT EXISTS user_input_acceptance (
|
|
378
399
|
accept_id VARCHAR(64) NOT NULL,
|
|
@@ -517,18 +538,19 @@ export const SCHEMA_STATEMENTS = [
|
|
|
517
538
|
) COLLATE utf8mb4_bin`,
|
|
518
539
|
`CREATE TABLE IF NOT EXISTS workflow_journal (
|
|
519
540
|
run_id VARCHAR(191) NOT NULL,
|
|
541
|
+
incarnation VARCHAR(64) NOT NULL,
|
|
520
542
|
ordinal INT NOT NULL,
|
|
521
|
-
-- scope (SVC-2 / CORE-9 audit BLOCKER): the table predates scope — it was added when the
|
|
522
|
-
-- WorkflowJournalStore seam grew a scope param for cross-tenant resume isolation. Every new append writes the
|
|
523
|
-
-- run's REAL scope. EXISTING (pre-migration) rows carry '' = CROSS-SCOPE ORPHANS, harmless by construction: a
|
|
524
|
-
-- real resume filters WHERE scope = <caller>, so the blank-scope residue never matches a tenant. The
|
|
525
|
-
-- NOT NULL DEFAULT '' is what let the original ALTER succeed on a table that already had rows — keep the
|
|
526
|
-
-- default so the "'' = orphan, never a tenant" reading stays true.
|
|
527
|
-
scope VARCHAR(190) NOT NULL DEFAULT '',
|
|
528
543
|
call_key VARCHAR(255) NOT NULL,
|
|
529
544
|
result MEDIUMTEXT NOT NULL,
|
|
530
545
|
created_at_ms BIGINT NOT NULL,
|
|
531
|
-
PRIMARY KEY (run_id, ordinal)
|
|
546
|
+
PRIMARY KEY (run_id, incarnation, ordinal)
|
|
547
|
+
) COLLATE utf8mb4_bin`,
|
|
548
|
+
`CREATE TABLE IF NOT EXISTS workflow_journal_owner (
|
|
549
|
+
run_id VARCHAR(191) NOT NULL,
|
|
550
|
+
scope VARCHAR(190) NOT NULL,
|
|
551
|
+
incarnation VARCHAR(64) NOT NULL,
|
|
552
|
+
appended_at_ms BIGINT NOT NULL,
|
|
553
|
+
PRIMARY KEY (run_id)
|
|
532
554
|
) COLLATE utf8mb4_bin`,
|
|
533
555
|
`CREATE TABLE IF NOT EXISTS workflow_resume_claim (
|
|
534
556
|
source_run_id VARCHAR(191) NOT NULL,
|
|
@@ -556,6 +578,18 @@ export const SCHEMA_STATEMENTS = [
|
|
|
556
578
|
scope VARCHAR(190) NOT NULL,
|
|
557
579
|
PRIMARY KEY (session_id, run_id),
|
|
558
580
|
KEY idx_wfagentsess_run (run_id)
|
|
581
|
+
) COLLATE utf8mb4_bin`,
|
|
582
|
+
`CREATE TABLE IF NOT EXISTS workflow_park_decision (
|
|
583
|
+
token VARCHAR(120) NOT NULL,
|
|
584
|
+
run_id VARCHAR(191) NOT NULL,
|
|
585
|
+
host_session_id VARCHAR(190) NOT NULL,
|
|
586
|
+
outcome MEDIUMTEXT NOT NULL,
|
|
587
|
+
fingerprint VARCHAR(64) NOT NULL,
|
|
588
|
+
delivered_task_id VARCHAR(191) NOT NULL,
|
|
589
|
+
accepted_at_ms BIGINT NOT NULL,
|
|
590
|
+
PRIMARY KEY (token),
|
|
591
|
+
KEY idx_wfparkdec_host (host_session_id),
|
|
592
|
+
KEY idx_wfparkdec_run (run_id)
|
|
559
593
|
) COLLATE utf8mb4_bin`,
|
|
560
594
|
`CREATE TABLE IF NOT EXISTS workflow_completion_inbox (
|
|
561
595
|
seq BIGINT NOT NULL AUTO_INCREMENT,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseSessionStorage, type
|
|
1
|
+
import { BaseSessionStorage, type SessionMetadata, type SessionTreeEntry, type SessionWriteOptions } from "@sema-agent/core";
|
|
2
2
|
import type { Pool } from "mysql2/promise";
|
|
3
3
|
export declare const SESSION_EVENT_LATEST_BY_TYPE_SQL: {
|
|
4
4
|
readonly floor: `SELECT /*+ USE_INDEX(session_event, idx_session_event_type) */ ${string} FROM session_event WHERE session_id = ? AND type = 'compaction' ORDER BY seq DESC LIMIT 1`;
|
|
@@ -24,17 +24,14 @@ export declare class TiDBSessionStorage extends BaseSessionStorage {
|
|
|
24
24
|
private readonly floorSeq;
|
|
25
25
|
constructor(pool: Pool, sessionId: string, metadata: SessionMetadata, entries: SessionTreeEntry[], leafId: string | null, floorEntryId?: string | null, floorSeq?: number);
|
|
26
26
|
/**
|
|
27
|
-
* [ref] S3 [ref] pull seam — `SessionStorage.getEpochAnchor?()`: the nearest epoch carrier BELOW the
|
|
28
|
-
* bounded-wake floor
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* malformed carriers, so these only exist via out-of-band writes); none ⇒ undefined = a genuine
|
|
34
|
-
* pre-epoch session (core mints legacy_migration, the correct meaning). core re-normalizes whatever we
|
|
35
|
-
* return, so this stays honest even if the two sides ever disagree on strictness.
|
|
27
|
+
* [ref] S3 [ref] pull seam — `SessionStorage.getEpochAnchor?()`: the nearest prompt-epoch carrier BELOW the
|
|
28
|
+
* bounded-wake floor, AS STORED (engine 7.52.0: `Promise<unknown>`; the engine reads the record, a retired shape
|
|
29
|
+
* included). The engine's `Session.getPromptEpoch()` asks for it only when the in-window branch walk finds no carrier
|
|
30
|
+
* (a rewind/resumeAt cut inside the kept tail; compactions without a restatement). The one reading of every windowed
|
|
31
|
+
* storage (both SQL twins, the local leg's view window) is {@link scanEpochAnchor}; this backend supplies its page query
|
|
32
|
+
* (keyset-paged to exhaustion) and decodes its own rows.
|
|
36
33
|
*/
|
|
37
|
-
getEpochAnchor(): Promise<
|
|
34
|
+
getEpochAnchor(): Promise<unknown>;
|
|
38
35
|
/**
|
|
39
36
|
* Rebuild a session from its event log (= wake). Returns null if the session does not exist.
|
|
40
37
|
*
|