@sema-agent/server 7.147.0 → 7.149.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 +1468 -24
- package/README.md +35 -7
- package/README.zh-CN.md +18 -8
- package/USAGE.md +444 -193
- package/deploy/sema-up/README.md +16 -5
- package/deploy/sema-up/chart/templates/NOTES.txt +1 -1
- package/deploy/sema-up/chart/templates/_helpers.tpl +20 -4
- package/deploy/sema-up/chart/values.yaml +3 -2
- package/deploy/sema-up/cluster-up.sh +74 -176
- package/deploy/sema-up/kube-up.sh +29 -49
- package/deploy/sema-up/lib/chart-run.sh +23 -0
- package/deploy/sema-up/lib/dataroot.sh +3 -3
- package/deploy/sema-up/lib/health.sh +62 -13
- package/deploy/sema-up/lib/helm-values-cluster.py +18 -0
- package/deploy/sema-up/lib/helm-values-kube.py +35 -0
- package/deploy/sema-up/lib/regcred.py +8 -0
- package/deploy/sema-up/lib/remote/helm-install.sh +3 -0
- package/deploy/sema-up/lib/remote/image-import.sh +6 -0
- package/deploy/sema-up/lib/remote/machine-precheck.sh +11 -0
- package/deploy/sema-up/lib/remote/region-probe.sh +3 -0
- package/deploy/sema-up/lib/remote/stack-ready.sh +26 -0
- package/deploy/sema-up/lib/remote/vxlan-guard.sh +8 -0
- package/deploy/sema-up/lib/render-stack.py +17 -0
- package/deploy/sema-up/lib/shell-text.sh +87 -0
- package/deploy/sema-up/lib/usage-flags.txt +10 -0
- package/deploy/sema-up/lib/usage-head.txt +1 -0
- package/deploy/sema-up/lib/usage-tail.txt +13 -0
- package/deploy/sema-up/preflight.sh +10 -8
- package/deploy/sema-up/sema-up.sh +14 -39
- package/deploy/sema-up/smoke.sh +7 -6
- package/deploy/sema-up/stack/compose.dataroot.yaml +3 -0
- package/deploy/sema-up/stack/compose.yaml +13 -1
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +21 -0
- package/dist/adoption/plan.d.ts +24 -0
- package/dist/adoption/plan.js +53 -1
- package/dist/adoption/runner.d.ts +10 -1
- package/dist/adoption/runner.js +36 -16
- package/dist/approval-card.d.ts +36 -38
- package/dist/approval-gate-currency.js +3 -2
- package/dist/approval-leg-origin.d.ts +33 -0
- package/dist/approval-leg-origin.js +4 -0
- package/dist/approval-reconciler.d.ts +4 -13
- package/dist/approval-reconciler.js +2 -2
- package/dist/approval.d.ts +13 -11
- package/dist/approval.js +3 -3
- package/dist/audit.d.ts +10 -3
- package/dist/audit.js +15 -7
- package/dist/auth-bridge.d.ts +9 -15
- package/dist/auth-bridge.js +4 -11
- package/dist/auth-keys.d.ts +10 -1
- package/dist/auth-keys.js +8 -0
- package/dist/auto-mode-face.d.ts +10 -7
- package/dist/auto-mode-face.js +7 -4
- package/dist/background-agent-name.d.ts +19 -1
- package/dist/background-agent-name.js +12 -2
- package/dist/background-session-reap.d.ts +1 -1
- package/dist/bake-runner/main.js +9 -6
- package/dist/bench/s1/arms.js +6 -5
- package/dist/bench/s1/live-deps.js +5 -2
- package/dist/bench/s1/run-firm.js +6 -5
- package/dist/bind-host.d.ts +25 -0
- package/dist/bind-host.js +25 -0
- package/dist/boot/adoption.d.ts +3 -0
- package/dist/boot/adoption.js +1 -0
- package/dist/boot/deployment-mods.d.ts +1 -1
- package/dist/boot/execution-env.d.ts +17 -7
- package/dist/boot/execution-env.js +47 -42
- package/dist/boot/execution-lane.d.ts +6 -4
- package/dist/boot/execution-lane.js +3 -1
- package/dist/boot/exit-boundary.d.ts +2 -2
- package/dist/boot/exit-boundary.js +6 -5
- package/dist/boot/fatal-exit.d.ts +3 -5
- package/dist/boot/fatal-exit.js +2 -2
- package/dist/boot/leader.d.ts +15 -0
- package/dist/boot/leader.js +17 -15
- package/dist/boot/memory-consolidation.d.ts +37 -29
- package/dist/boot/memory-consolidation.js +11 -5
- package/dist/boot/org-delivery.d.ts +3 -2
- package/dist/boot/org-memory.js +1 -1
- package/dist/boot/parked-revive-gate.js +2 -2
- package/dist/boot/reapers.d.ts +4 -3
- package/dist/boot/reapers.js +19 -16
- package/dist/boot/resolve-spec.d.ts +5 -3
- package/dist/boot/resolve-spec.js +60 -70
- package/dist/boot/retention-lane.d.ts +4 -4
- package/dist/boot/retention-lane.js +2 -2
- package/dist/boot/runner-deps.d.ts +28 -7
- package/dist/boot/runner-deps.js +14 -5
- package/dist/boot/runtime-caps.d.ts +2 -2
- package/dist/boot/runtime-caps.js +16 -2
- package/dist/boot/session-faces.d.ts +16 -7
- package/dist/boot/session-faces.js +114 -94
- package/dist/boot/shutdown.d.ts +5 -4
- package/dist/boot/shutdown.js +6 -4
- package/dist/boot/stage-01-config.d.ts +1 -0
- package/dist/boot/stage-01-config.js +13 -4
- package/dist/boot/stage-02-web-admin-pull.d.ts +2 -0
- package/dist/boot/stage-02-web-admin-pull.js +16 -3
- package/dist/boot/stage-03-store-backend.d.ts +4 -0
- package/dist/boot/stage-03-store-backend.js +4 -3
- package/dist/boot/stage-04-stores.d.ts +3 -0
- package/dist/boot/stage-04-stores.js +2 -2
- package/dist/boot/stage-05-execution-env.d.ts +8 -3
- package/dist/boot/stage-05-execution-env.js +2 -2
- package/dist/boot/stage-06-runners.d.ts +12 -13
- package/dist/boot/stage-06-runners.js +23 -15
- package/dist/boot/stage-07-capability-layer.d.ts +13 -9
- package/dist/boot/stage-07-capability-layer.js +5 -3
- package/dist/boot/stage-08-reapers.d.ts +13 -9
- package/dist/boot/stage-08-reapers.js +3 -3
- package/dist/boot/stage-09-leader.d.ts +14 -16
- package/dist/boot/stage-09-leader.js +12 -4
- package/dist/boot/stage-10-http-server.d.ts +14 -16
- package/dist/boot/stage-10-http-server.js +7 -4
- package/dist/boot/store-evidence.d.ts +20 -0
- package/dist/boot/store-evidence.js +13 -0
- package/dist/boot/stores.d.ts +6 -0
- package/dist/boot/stores.js +41 -27
- package/dist/boot/task-list-lane.d.ts +4 -4
- package/dist/boot/web-admin.d.ts +4 -2
- package/dist/boot/web-admin.js +55 -35
- package/dist/boot/webfetch-summarize-lane.d.ts +1 -1
- package/dist/boot-reclaim.d.ts +3 -1
- package/dist/boot-reclaim.js +1 -1
- package/dist/brain.d.ts +7 -18
- package/dist/brain.js +5 -17
- package/dist/budget.js +6 -6
- package/dist/capabilities/center-plugins.d.ts +7 -1
- package/dist/capabilities/center-plugins.js +32 -10
- package/dist/capabilities/center-wiring.js +1 -1
- package/dist/capabilities/composite-members.d.ts +2 -2
- package/dist/capabilities/composite-members.js +2 -2
- package/dist/capabilities/repo-tools.d.ts +2 -0
- package/dist/capabilities/repo-tools.js +14 -12
- package/dist/capabilities/scenarios.d.ts +6 -15
- package/dist/capabilities/scenarios.js +11 -16
- package/dist/capabilities/skills.d.ts +1 -1
- package/dist/capabilities/tool-defer.d.ts +1 -1
- package/dist/capability-facts.d.ts +39 -11
- package/dist/capability-facts.js +35 -7
- package/dist/card-settle-stored-scope.d.ts +56 -0
- package/dist/card-settle-stored-scope.js +27 -0
- package/dist/card-void.d.ts +8 -13
- package/dist/card-void.js +2 -7
- package/dist/center-credential-renewer.d.ts +6 -2
- package/dist/center-credential-renewer.js +7 -3
- package/dist/config-catalog.d.ts +28 -1
- package/dist/config-catalog.js +95 -85
- package/dist/config-dir-trust.d.ts +37 -4
- package/dist/config-dir-trust.js +88 -44
- package/dist/config-invariants.d.ts +43 -3
- package/dist/config-invariants.js +69 -5
- package/dist/config-lkg.d.ts +23 -1
- package/dist/config-lkg.js +17 -3
- package/dist/config-provider.d.ts +9 -9
- package/dist/config-provider.js +25 -110
- package/dist/config-pull-failure.d.ts +50 -0
- package/dist/config-pull-failure.js +48 -0
- package/dist/config-types.d.ts +62 -21
- package/dist/config.d.ts +14 -21
- package/dist/config.js +141 -64
- package/dist/context-window-notice.d.ts +31 -0
- package/dist/context-window-notice.js +28 -0
- package/dist/delegated-session-owner.d.ts +1 -1
- package/dist/deleted-session-ids.d.ts +3 -2
- package/dist/deployment-governance.d.ts +3 -3
- package/dist/deployment-shape.d.ts +46 -11
- package/dist/deployment-shape.js +8 -0
- package/dist/egress-redirect.d.ts +25 -7
- package/dist/egress-redirect.js +20 -2
- package/dist/elicitation.d.ts +6 -5
- package/dist/elicitation.js +23 -22
- package/dist/engine-identity.d.ts +28 -0
- package/dist/engine-identity.js +10 -0
- package/dist/entry-problems.d.ts +5 -7
- package/dist/entry-problems.js +1 -1
- package/dist/env-facts.js +2 -1
- package/dist/env-name-allowlist-knobs.d.ts +6 -5
- package/dist/env-name-allowlist-knobs.js +5 -0
- package/dist/env-witness.d.ts +7 -0
- package/dist/env-witness.js +16 -0
- package/dist/execution-lane-caps.d.ts +25 -23
- package/dist/execution-lane-caps.js +18 -26
- package/dist/execution-placement.d.ts +58 -18
- package/dist/execution-placement.js +41 -2
- package/dist/field-conflict.d.ts +7 -11
- package/dist/field-conflict.js +3 -3
- package/dist/file-history-capture.d.ts +3 -3
- package/dist/file-history-disclosure.js +1 -0
- package/dist/fleet/fleet-bus.d.ts +21 -3
- package/dist/fleet/fleet-bus.js +35 -25
- package/dist/fleet/fleet-reconciler.js +2 -2
- package/dist/fleet/serving-lease.js +3 -3
- package/dist/fleet-client.js +3 -3
- package/dist/fleet-lease.d.ts +0 -1
- package/dist/fleet-lease.js +4 -5
- package/dist/history-anchor.d.ts +23 -3
- package/dist/history-anchor.js +24 -4
- package/dist/hitl-delivery.d.ts +90 -0
- package/dist/hitl-delivery.js +98 -0
- package/dist/hooks/classic-stations.d.ts +8 -11
- package/dist/hooks/classic-stations.js +0 -7
- package/dist/hooks/command-spawn.d.ts +7 -2
- package/dist/hooks/command-spawn.js +13 -6
- package/dist/hooks/hook-llm.d.ts +5 -1
- package/dist/hooks/hook-llm.js +24 -15
- package/dist/hooks/hook-runner.d.ts +72 -57
- package/dist/hooks/hook-runner.js +271 -193
- package/dist/host-lsp-manager.d.ts +22 -8
- package/dist/host-lsp-manager.js +4 -1
- package/dist/http/active-run-conflict.d.ts +2 -43
- package/dist/http/active-run-conflict.js +3 -7
- package/dist/http/admission.d.ts +4 -18
- package/dist/http/admission.js +76 -79
- package/dist/http/approval-sweeps.d.ts +3 -3
- package/dist/http/approval-sweeps.js +56 -31
- package/dist/http/caller-trust.d.ts +8 -10
- package/dist/http/caller-trust.js +1 -2
- package/dist/http/claim-heartbeat.d.ts +49 -0
- package/dist/http/claim-heartbeat.js +46 -0
- package/dist/http/claimed-run.d.ts +16 -8
- package/dist/http/claimed-run.js +8 -0
- package/dist/http/dispatch.d.ts +8 -1
- package/dist/http/dispatch.js +78 -30
- package/dist/http/durable-run-leg.d.ts +11 -4
- package/dist/http/durable-run-leg.js +45 -21
- package/dist/http/execution-context.d.ts +122 -47
- package/dist/http/execution-context.js +135 -43
- package/dist/http/health-reader.d.ts +36 -0
- package/dist/http/health-reader.js +21 -0
- package/dist/http/health-self-report.d.ts +9 -9
- package/dist/http/health-self-report.js +4 -4
- package/dist/http/idempotency.d.ts +9 -5
- package/dist/http/idempotency.js +4 -4
- package/dist/http/memory-compliance-failure-reply.d.ts +15 -16
- package/dist/http/memory-compliance-failure-reply.js +4 -2
- package/dist/http/memory-face-fault-reply.d.ts +67 -0
- package/dist/http/memory-face-fault-reply.js +71 -0
- package/dist/http/memory-store-refusal-reply.d.ts +1 -1
- package/dist/http/memory-store-refusal-reply.js +3 -0
- package/dist/http/owner-access.d.ts +392 -67
- package/dist/http/owner-access.js +370 -35
- package/dist/http/principal-gate.d.ts +39 -89
- package/dist/http/principal-gate.js +26 -68
- package/dist/http/refusal-body.d.ts +35 -2
- package/dist/http/refusal-body.js +34 -0
- package/dist/http/request-guards.d.ts +9 -13
- package/dist/http/request-guards.js +34 -68
- package/dist/http/resume-composition.d.ts +37 -0
- package/dist/http/resume-composition.js +18 -0
- package/dist/http/resume-ctx-read.d.ts +46 -12
- package/dist/http/resume-ctx-read.js +31 -6
- package/dist/http/resume-legs.d.ts +54 -19
- package/dist/http/resume-legs.js +408 -196
- package/dist/http/retired-skill-manifest.d.ts +1 -1
- package/dist/http/route-ctx.d.ts +31 -32
- package/dist/http/routes/a2a-serve.d.ts +43 -5
- package/dist/http/routes/a2a-serve.js +60 -37
- package/dist/http/routes/admin-config-refresh.js +2 -2
- package/dist/http/routes/admin-drain.js +2 -2
- package/dist/http/routes/admin-memory-optout.js +4 -3
- package/dist/http/routes/adoption.d.ts +3 -0
- package/dist/http/routes/adoption.js +17 -10
- package/dist/http/routes/agents-roster.js +13 -7
- package/dist/http/routes/approvals-assistant.js +73 -67
- package/dist/http/routes/attachments.js +2 -2
- package/dist/http/routes/background.d.ts +3 -3
- package/dist/http/routes/background.js +9 -17
- package/dist/http/routes/capabilities.js +16 -19
- package/dist/http/routes/config-catalog.js +2 -2
- package/dist/http/routes/devices.d.ts +3 -3
- package/dist/http/routes/devices.js +4 -4
- package/dist/http/routes/diagnostics.d.ts +29 -3
- package/dist/http/routes/diagnostics.js +49 -18
- package/dist/http/routes/engine.js +2 -2
- package/dist/http/routes/fleet.js +5 -3
- package/dist/http/routes/images.js +10 -6
- package/dist/http/routes/leader.d.ts +7 -2
- package/dist/http/routes/leader.js +12 -3
- package/dist/http/routes/mcp-reconnect.d.ts +1 -1
- package/dist/http/routes/mcp-reconnect.js +7 -15
- package/dist/http/routes/memory-bundle.js +4 -7
- package/dist/http/routes/memory-compliance.js +4 -4
- package/dist/http/routes/memory-consolidation.js +6 -9
- package/dist/http/routes/memory-origin.d.ts +2 -0
- package/dist/http/routes/memory-origin.js +7 -8
- package/dist/http/routes/memory-policy.js +17 -12
- package/dist/http/routes/notify-wake.js +10 -19
- package/dist/http/routes/observability.js +3 -3
- package/dist/http/routes/principal-inbox.d.ts +4 -2
- package/dist/http/routes/principal-inbox.js +5 -4
- package/dist/http/routes/projects.d.ts +1 -1
- package/dist/http/routes/projects.js +3 -2
- package/dist/http/routes/retention-ops.js +6 -9
- package/dist/http/routes/rules.js +20 -5
- package/dist/http/routes/run-memory-capture.d.ts +2 -2
- package/dist/http/routes/run-memory-capture.js +6 -12
- package/dist/http/routes/run-permission-mode.d.ts +2 -2
- package/dist/http/routes/run-permission-mode.js +10 -17
- package/dist/http/routes/runs.js +155 -237
- package/dist/http/routes/session-memory-sync.d.ts +2 -2
- package/dist/http/routes/session-memory-sync.js +7 -13
- package/dist/http/routes/session-sync.d.ts +28 -7
- package/dist/http/routes/session-sync.js +63 -50
- package/dist/http/routes/sessions-list.d.ts +3 -3
- package/dist/http/routes/sessions-list.js +9 -9
- package/dist/http/routes/sessions.js +87 -124
- package/dist/http/routes/shared-memory.js +6 -6
- package/dist/http/routes/side-query.js +2 -2
- package/dist/http/routes/tasks.js +237 -187
- package/dist/http/routes/trace-usage.d.ts +0 -12
- package/dist/http/routes/trace-usage.js +40 -46
- package/dist/http/routes/workflows.d.ts +39 -4
- package/dist/http/routes/workflows.js +42 -14
- package/dist/http/run-concurrency-cap.d.ts +20 -12
- package/dist/http/run-concurrency-cap.js +39 -26
- package/dist/http/run-read-face.d.ts +3 -5
- package/dist/http/run-read-face.js +8 -13
- package/dist/http/send.d.ts +12 -3
- package/dist/http/send.js +42 -6
- package/dist/http/server.d.ts +43 -45
- package/dist/http/server.js +61 -11
- package/dist/http/sse-log.d.ts +17 -10
- package/dist/http/sse-log.js +7 -7
- package/dist/http/stored-body-replay.d.ts +12 -0
- package/dist/http/stored-body-replay.js +2 -2
- package/dist/http/submit-ctx.d.ts +17 -8
- package/dist/http/submit-ctx.js +8 -5
- package/dist/http/submit-replay.d.ts +19 -6
- package/dist/http/submit-replay.js +18 -6
- package/dist/http/sync-submit-body.d.ts +3 -4
- package/dist/http/sync-submit-body.js +4 -5
- package/dist/http/wire-types.d.ts +4 -3
- package/dist/identity-source.d.ts +36 -5
- package/dist/identity-source.js +27 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -0
- package/dist/key-resolver.d.ts +32 -0
- package/dist/key-resolver.js +23 -9
- package/dist/leader/diffup.js +2 -1
- package/dist/leader/endpoint.d.ts +26 -5
- package/dist/leader/endpoint.js +154 -14
- package/dist/leader/fanout.d.ts +3 -0
- package/dist/leader/fanout.js +78 -63
- package/dist/leader/leader.d.ts +16 -0
- package/dist/leader/leader.js +43 -3
- package/dist/leader/merge.d.ts +9 -1
- package/dist/leader/merge.js +16 -1
- package/dist/leader/repair-wire.js +1 -1
- package/dist/leader/wire.d.ts +36 -3
- package/dist/leader/wire.js +59 -18
- package/dist/leg-facts.d.ts +7 -2
- package/dist/leg-facts.js +1 -0
- package/dist/local-store-declaration.d.ts +54 -0
- package/dist/local-store-declaration.js +59 -0
- package/dist/lsp-evict.d.ts +6 -4
- package/dist/lsp-evict.js +2 -3
- package/dist/mcp-assertion-header.d.ts +1 -1
- package/dist/mcp-assertion-header.js +1 -1
- package/dist/memory-operator-faces.d.ts +5 -4
- package/dist/memory-operator-faces.js +1 -1
- package/dist/memory-project-layer.js +1 -1
- package/dist/memory-scope.d.ts +33 -6
- package/dist/memory-scope.js +68 -19
- package/dist/memory-store-refusal.d.ts +5 -2
- package/dist/memory-sync-client.d.ts +3 -2
- package/dist/memory-sync-client.js +8 -5
- package/dist/model-compat.d.ts +17 -8
- package/dist/model-compat.js +6 -2
- package/dist/model-context-window.d.ts +57 -0
- package/dist/model-context-window.js +21 -0
- package/dist/model-entry-headers.d.ts +46 -4
- package/dist/model-entry-headers.js +2 -2
- package/dist/model-entry-refusal.d.ts +40 -20
- package/dist/model-entry-refusal.js +57 -30
- package/dist/model-plane-face.d.ts +19 -11
- package/dist/model-plane-face.js +9 -1
- package/dist/model-plane-probe.d.ts +2 -0
- package/dist/model-plane-probe.js +17 -0
- package/dist/model-provider.d.ts +3 -3
- package/dist/model-reach-scope.d.ts +2 -1
- package/dist/model-route-endpoint.d.ts +9 -5
- package/dist/model-route-endpoint.js +29 -7
- package/dist/model-select.d.ts +16 -0
- package/dist/model-select.js +4 -0
- package/dist/mountinfo.d.ts +37 -0
- package/dist/mountinfo.js +47 -0
- package/dist/namespaced-rule-name.d.ts +23 -14
- package/dist/namespaced-rule-name.js +8 -11
- package/dist/net-address.d.ts +1 -1
- package/dist/observability/corrupt-read-seat.d.ts +4 -4
- package/dist/observability/corrupt-read-seat.js +5 -3
- package/dist/observability/fail-open.d.ts +72 -40
- package/dist/observability/fail-open.js +74 -40
- package/dist/observability/logger.d.ts +22 -1
- package/dist/observability/logger.js +89 -12
- package/dist/observability/metrics.js +4 -5
- package/dist/observability/otel-exporter.js +2 -1
- package/dist/observability/principal-context.d.ts +14 -7
- package/dist/observability/principal-context.js +8 -3
- package/dist/observability/run-terminal.d.ts +7 -1
- package/dist/observability/run-terminal.js +6 -2
- package/dist/observability/secret-env-scrub.d.ts +1 -1
- package/dist/observability/secret-env-scrub.js +1 -1
- package/dist/orchestration/hardened-vm-runner.d.ts +1 -0
- package/dist/orchestration/hardened-vm-runner.js +11 -5
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +0 -14
- package/dist/orchestration/hardened-vm-worker-runner.js +5 -0
- package/dist/orchestration/hardened-vm-worker.js +2 -1
- package/dist/orchestration/workflow-completion-inbox.d.ts +3 -3
- package/dist/orchestration/workflow-completion-inbox.js +3 -2
- package/dist/org-delivery-gate.d.ts +36 -10
- package/dist/org-delivery-gate.js +12 -8
- package/dist/outbound-dispatcher.d.ts +1 -1
- package/dist/outbound-dispatcher.js +6 -12
- package/dist/owner-brands.d.ts +81 -0
- package/dist/owner-brands.js +42 -0
- package/dist/owner-faces.d.ts +532 -0
- package/dist/owner-faces.js +126 -0
- package/dist/park-row-commit.d.ts +67 -0
- package/dist/park-row-commit.js +76 -0
- package/dist/parked-decide.d.ts +76 -12
- package/dist/parked-decide.js +152 -11
- package/dist/parked-revive-surface.d.ts +14 -4
- package/dist/parked-revive-surface.js +5 -4
- package/dist/peer-directory.d.ts +7 -9
- package/dist/peer-directory.js +3 -2
- package/dist/permission-rule-vocab.d.ts +53 -8
- package/dist/permission-rule-vocab.js +30 -2
- package/dist/plugins/adoption-log-sql.d.ts +3 -25
- package/dist/plugins/adoption-log-sql.js +23 -21
- package/dist/plugins/approval-ask-retired-delete-by-task-m50.d.ts +7 -0
- package/dist/plugins/approval-ask-retired-delete-by-task-m50.js +17 -0
- package/dist/plugins/approval-ask-store-file.d.ts +18 -7
- package/dist/plugins/approval-ask-store-file.js +37 -14
- package/dist/plugins/approval-ask-store-memory.d.ts +12 -4
- package/dist/plugins/approval-ask-store-memory.js +24 -10
- package/dist/plugins/approval-ask-store-sql.d.ts +40 -21
- package/dist/plugins/approval-ask-store-sql.js +44 -15
- package/dist/plugins/approval-exemption-skill-cutoff.d.ts +64 -0
- package/dist/plugins/approval-exemption-skill-cutoff.js +122 -0
- package/dist/plugins/approval-exemption-skill-m46.d.ts +14 -0
- package/dist/plugins/approval-exemption-skill-m46.js +21 -0
- package/dist/plugins/approval-exemption-store.d.ts +32 -2
- package/dist/plugins/approval-exemption-store.js +42 -19
- package/dist/plugins/approval-nonce-store.d.ts +39 -12
- package/dist/plugins/approval-nonce-store.js +72 -23
- package/dist/plugins/blob-backend.d.ts +2 -0
- package/dist/plugins/blob-backend.js +9 -6
- package/dist/plugins/caching-session-store.d.ts +13 -1
- package/dist/plugins/caching-session-store.js +43 -4
- package/dist/plugins/checkpoint-index-columns.d.ts +32 -5
- package/dist/plugins/checkpoint-index-columns.js +36 -1
- package/dist/plugins/checkpoint-store-face.d.ts +83 -10
- package/dist/plugins/checkpoint-store-face.js +18 -1
- package/dist/plugins/device-store-sql.js +1 -0
- package/dist/plugins/ensure-index.d.ts +13 -1
- package/dist/plugins/ensure-index.js +154 -21
- package/dist/plugins/ensure-schema-lock-policy.d.ts +36 -18
- package/dist/plugins/ensure-schema-lock-policy.js +76 -9
- package/dist/plugins/file-run-store.d.ts +85 -32
- package/dist/plugins/file-run-store.js +177 -94
- package/dist/plugins/host-platform.d.ts +24 -3
- package/dist/plugins/host-platform.js +15 -1
- package/dist/plugins/image-bake-store-sql.js +2 -0
- package/dist/plugins/imported-layer-root-retirement.d.ts +2 -2
- package/dist/plugins/k8s-pod-reaper.d.ts +1 -3
- package/dist/plugins/k8s-pod-reaper.js +0 -1
- package/dist/plugins/leader-run-store-sql.d.ts +22 -0
- package/dist/plugins/leader-run-store-sql.js +34 -4
- package/dist/plugins/local-checkpoint-store.d.ts +62 -23
- package/dist/plugins/local-checkpoint-store.js +197 -77
- package/dist/plugins/local-data-dir-modes-m39.js +2 -1
- package/dist/plugins/local-data-root-admission.d.ts +52 -0
- package/dist/plugins/local-data-root-admission.js +100 -0
- package/dist/plugins/local-docker-capacity.d.ts +93 -0
- package/dist/plugins/local-docker-capacity.js +194 -0
- package/dist/plugins/local-docker-reaper.d.ts +92 -0
- package/dist/plugins/local-docker-reaper.js +102 -0
- package/dist/plugins/local-engine-high-water.d.ts +29 -6
- package/dist/plugins/local-engine-high-water.js +27 -19
- package/dist/plugins/local-session-store.d.ts +458 -140
- package/dist/plugins/local-session-store.js +906 -292
- package/dist/plugins/local-session-window.d.ts +3 -2
- package/dist/plugins/local-session-window.js +3 -2
- package/dist/plugins/local-sidecar-quarantine.js +3 -2
- package/dist/plugins/local-task-attachment-store.d.ts +18 -1
- package/dist/plugins/local-task-attachment-store.js +22 -1
- package/dist/plugins/memory-embedder.js +9 -7
- package/dist/plugins/memory-engine-pg.d.ts +3 -2
- package/dist/plugins/memory-engine-pg.js +14 -5
- package/dist/plugins/memory-engine-sql-apply.d.ts +8 -4
- package/dist/plugins/memory-engine-sql-apply.js +6 -8
- package/dist/plugins/memory-engine-tidb.d.ts +4 -2
- package/dist/plugins/memory-engine-tidb.js +11 -2
- package/dist/plugins/memory-optout-grant-store-sql.d.ts +1 -1
- package/dist/plugins/memory-optout-grant-store-sql.js +3 -3
- package/dist/plugins/memory-run-store.d.ts +53 -36
- package/dist/plugins/memory-run-store.js +116 -88
- package/dist/plugins/one-time-migration-marker.d.ts +26 -0
- package/dist/plugins/one-time-migration-marker.js +13 -0
- package/dist/plugins/one-time-migrations.d.ts +214 -47
- package/dist/plugins/one-time-migrations.js +481 -135
- package/dist/plugins/org-delivery-quota-store.d.ts +34 -11
- package/dist/plugins/org-delivery-quota-store.js +31 -15
- package/dist/plugins/permission-rule-store-file.d.ts +3 -3
- package/dist/plugins/permission-rule-store-sql.d.ts +5 -64
- package/dist/plugins/permission-rule-store-sql.js +11 -95
- package/dist/plugins/pg-pool.d.ts +2 -32
- package/dist/plugins/pg-pool.js +24 -17
- package/dist/plugins/remote-env-device.d.ts +3 -2
- package/dist/plugins/remote-env-e2b.d.ts +8 -32
- package/dist/plugins/remote-env-e2b.js +44 -32
- package/dist/plugins/remote-env-host.d.ts +51 -17
- package/dist/plugins/remote-env-host.js +111 -42
- package/dist/plugins/remote-env-k8s.d.ts +40 -45
- package/dist/plugins/remote-env-k8s.js +111 -60
- package/dist/plugins/remote-env-local-docker.d.ts +152 -15
- package/dist/plugins/remote-env-local-docker.js +352 -72
- package/dist/plugins/remote-scratchpad.js +4 -0
- package/dist/plugins/retention-deployment.d.ts +49 -17
- package/dist/plugins/retention-deployment.js +39 -8
- package/dist/plugins/run-preview-m45.d.ts +11 -0
- package/dist/plugins/run-preview-m45.js +19 -0
- package/dist/plugins/run-store-sql.d.ts +82 -75
- package/dist/plugins/run-store-sql.js +164 -125
- package/dist/plugins/s3-answer.d.ts +2 -1
- package/dist/plugins/sandbox-reaper.d.ts +26 -0
- package/dist/plugins/sandbox-reaper.js +2 -0
- package/dist/plugins/scenario-prefix-switch-m42.d.ts +56 -0
- package/dist/plugins/scenario-prefix-switch-m42.js +56 -0
- package/dist/plugins/scheduler-support.d.ts +16 -1
- package/dist/plugins/scheduler-support.js +22 -2
- package/dist/plugins/schema-consistency.d.ts +131 -14
- package/dist/plugins/schema-consistency.js +388 -18
- package/dist/plugins/schema-drift-sentence.d.ts +10 -6
- package/dist/plugins/schema-drift-sentence.js +15 -7
- package/dist/plugins/schema-ensure-legs.d.ts +9 -0
- package/dist/plugins/schema-ensure-legs.js +1 -1
- package/dist/plugins/schema-indexes.js +3 -0
- package/dist/plugins/schema-live-columns.d.ts +14 -5
- package/dist/plugins/schema-live-columns.js +10 -10
- package/dist/plugins/send-user-file.js +2 -1
- package/dist/plugins/session-birth.d.ts +37 -0
- package/dist/plugins/session-birth.js +38 -0
- package/dist/plugins/session-epoch-anchor.d.ts +40 -12
- package/dist/plugins/session-epoch-anchor.js +33 -11
- package/dist/plugins/session-ext-table.d.ts +27 -3
- package/dist/plugins/session-ext-table.js +19 -6
- package/dist/plugins/session-fork.d.ts +15 -1
- package/dist/plugins/session-fork.js +3 -0
- package/dist/plugins/session-ownership.d.ts +1 -1
- package/dist/plugins/session-placement.d.ts +27 -20
- package/dist/plugins/session-placement.js +15 -12
- package/dist/plugins/session-row-sql.d.ts +12 -0
- package/dist/plugins/session-row-sql.js +3 -3
- package/dist/plugins/session-run-rollup.d.ts +29 -0
- package/dist/plugins/session-run-rollup.js +40 -0
- package/dist/plugins/session-store-sql.d.ts +38 -12
- package/dist/plugins/session-store-sql.js +130 -30
- package/dist/plugins/session-withdraw-sql.d.ts +36 -0
- package/dist/plugins/session-withdraw-sql.js +42 -0
- package/dist/plugins/shared-memory-store-sql.d.ts +0 -69
- package/dist/plugins/shared-memory-store-sql.js +2 -1
- package/dist/plugins/shell-sentinel-owner-m48.d.ts +42 -0
- package/dist/plugins/shell-sentinel-owner-m48.js +9 -0
- package/dist/plugins/snapshot-bucket-presence.d.ts +2 -1
- package/dist/plugins/sql-driver.d.ts +1 -1
- package/dist/plugins/sql-driver.js +2 -1
- package/dist/plugins/sql-errors.d.ts +32 -5
- package/dist/plugins/sql-errors.js +55 -7
- package/dist/plugins/sql-json-column.d.ts +8 -7
- package/dist/plugins/sql-json-column.js +10 -6
- package/dist/plugins/stop-then-start-sentence.d.ts +16 -0
- package/dist/plugins/stop-then-start-sentence.js +7 -0
- package/dist/plugins/store-backend.d.ts +99 -16
- package/dist/plugins/store-backend.js +230 -65
- package/dist/plugins/store-contracts.d.ts +123 -33
- package/dist/plugins/store-contracts.js +38 -1
- package/dist/plugins/store-fault.d.ts +28 -2
- package/dist/plugins/store-fault.js +20 -2
- package/dist/plugins/task-attachment-store.d.ts +15 -3
- package/dist/plugins/task-attachment-store.js +22 -9
- package/dist/plugins/tidb-pool.d.ts +11 -6
- package/dist/plugins/tidb-pool.js +39 -18
- package/dist/plugins/web-search.js +5 -3
- package/dist/plugins/workflow-run-store-sql.d.ts +6 -1
- package/dist/plugins/workflow-run-store-sql.js +11 -5
- package/dist/plugins/workspace-custody.d.ts +44 -0
- package/dist/plugins/workspace-custody.js +47 -0
- package/dist/principal-jwt.d.ts +4 -4
- package/dist/principal-jwt.js +20 -5
- package/dist/principal-shape.d.ts +41 -0
- package/dist/principal-shape.js +19 -0
- package/dist/project-identity.d.ts +8 -7
- package/dist/project-identity.js +40 -17
- package/dist/project-layer-key.d.ts +13 -2
- package/dist/project-layer-key.js +9 -1
- package/dist/question.d.ts +13 -23
- package/dist/question.js +21 -39
- package/dist/read-deny-floor-notice.d.ts +36 -0
- package/dist/read-deny-floor-notice.js +40 -0
- package/dist/{plain-string-record.d.ts → request-declaration-disposition.d.ts} +9 -23
- package/dist/request-declaration-disposition.js +39 -0
- package/dist/request-declaration-refusal.d.ts +35 -12
- package/dist/request-declaration-refusal.js +21 -9
- package/dist/request-form.d.ts +58 -0
- package/dist/request-form.js +72 -0
- package/dist/request-image-urls.d.ts +8 -2
- package/dist/request-image-urls.js +2 -1
- package/dist/request-images.d.ts +20 -0
- package/dist/request-images.js +59 -0
- package/dist/request-key-closure.d.ts +6 -7
- package/dist/request-key-closure.js +15 -2
- package/dist/resource-suspend.d.ts +7 -16
- package/dist/resource-suspend.js +1 -1
- package/dist/retired-name-host-notice.d.ts +21 -0
- package/dist/retired-name-host-notice.js +12 -0
- package/dist/rule-entry-list.d.ts +2 -2
- package/dist/rule-entry-list.js +3 -4
- package/dist/rule-issue-reading.d.ts +58 -0
- package/dist/rule-issue-reading.js +14 -0
- package/dist/rules-consent.d.ts +5 -3
- package/dist/rules-consent.js +1 -0
- package/dist/run-acceptance.d.ts +3 -1
- package/dist/run-acceptance.js +3 -0
- package/dist/run-cancel-card.d.ts +28 -0
- package/dist/run-cancel-card.js +19 -0
- package/dist/run-cancel-context.d.ts +10 -0
- package/dist/run-cancel-context.js +1 -0
- package/dist/run-local.d.ts +14 -6
- package/dist/run-local.js +117 -90
- package/dist/run-stale-default.d.ts +7 -0
- package/dist/run-stale-default.js +2 -0
- package/dist/runs.d.ts +56 -21
- package/dist/runs.js +73 -43
- package/dist/runtime-caps-resolver.d.ts +21 -6
- package/dist/runtime-caps-resolver.js +17 -4
- package/dist/runtime-governance.d.ts +2 -2
- package/dist/runtime-governance.js +5 -3
- package/dist/sealed-key-layout.d.ts +12 -5
- package/dist/sealed-key-layout.js +5 -0
- package/dist/sealed-key.d.ts +12 -2
- package/dist/sealed-key.js +115 -27
- package/dist/security.d.ts +128 -158
- package/dist/security.js +163 -59
- package/dist/sema-config-dir.d.ts +20 -0
- package/dist/sema-config-dir.js +25 -0
- package/dist/server-secret-env.d.ts +55 -25
- package/dist/server-secret-env.js +75 -22
- package/dist/session-agent.d.ts +3 -2
- package/dist/session-children-retire.d.ts +13 -8
- package/dist/session-children-retire.js +9 -7
- package/dist/session-deletion.d.ts +88 -0
- package/dist/session-deletion.js +8 -0
- package/dist/session-erase.d.ts +145 -0
- package/dist/session-erase.js +115 -0
- package/dist/session-error-wire.d.ts +5 -5
- package/dist/session-error-wire.js +1 -1
- package/dist/session-incarnation.d.ts +52 -5
- package/dist/session-incarnation.js +19 -2
- package/dist/session-policy-wire.d.ts +6 -3
- package/dist/session-policy-wire.js +11 -1
- package/dist/session-resident-background.d.ts +0 -71
- package/dist/session-resident-background.js +4 -3
- package/dist/session-row.d.ts +2 -1
- package/dist/session-rules-seat.d.ts +12 -0
- package/dist/session-rules-seat.js +19 -0
- package/dist/session-titler.d.ts +7 -15
- package/dist/session-titler.js +1 -1
- package/dist/session-workspace.d.ts +3 -3
- package/dist/spec-fields.d.ts +57 -3
- package/dist/spec-fields.js +72 -51
- package/dist/store-admission.d.ts +33 -0
- package/dist/store-admission.js +49 -0
- package/dist/store-posture.d.ts +141 -20
- package/dist/store-posture.js +205 -3
- package/dist/stored-request-hooks-m20.js +2 -2
- package/dist/stores-sql/background-agent-store-sql.d.ts +11 -2
- package/dist/stores-sql/background-agent-store-sql.js +73 -20
- package/dist/stores-sql/checkpoint-store-sql.d.ts +34 -29
- package/dist/stores-sql/checkpoint-store-sql.js +78 -49
- package/dist/stores-sql/file-history-store-sql.d.ts +1 -1
- package/dist/stores-sql/file-history-store-sql.js +3 -5
- package/dist/stores-sql/mailbox-store-sql.d.ts +7 -4
- package/dist/stores-sql/mailbox-store-sql.js +31 -32
- package/dist/stores-sql/pg-session-storage.d.ts +7 -5
- package/dist/stores-sql/pg-session-storage.js +54 -46
- package/dist/stores-sql/retention-store-sql.d.ts +87 -19
- package/dist/stores-sql/retention-store-sql.js +92 -27
- package/dist/stores-sql/session-policy-store-sql.d.ts +32 -10
- package/dist/stores-sql/session-policy-store-sql.js +44 -36
- package/dist/stores-sql/session-write-hooks.d.ts +12 -6
- package/dist/stores-sql/tidb-session-storage.d.ts +4 -4
- package/dist/stores-sql/tidb-session-storage.js +13 -8
- package/dist/stores-sql/tidb-session-store.d.ts +36 -17
- package/dist/stores-sql/tidb-session-store.js +69 -39
- package/dist/stores-sql/tool-result-store-sql.d.ts +1 -1
- package/dist/stores-sql/tool-result-store-sql.js +4 -6
- package/dist/stores-sql/windowed-session-storage.d.ts +5 -0
- package/dist/stores-sql/windowed-session-storage.js +9 -0
- package/dist/submission-exit.d.ts +50 -0
- package/dist/submission-exit.js +108 -0
- package/dist/task-a2a.d.ts +3 -8
- package/dist/task-a2a.js +28 -30
- package/dist/task-cwd.d.ts +43 -7
- package/dist/task-cwd.js +11 -0
- package/dist/task-mcp.d.ts +3 -3
- package/dist/task-mcp.js +4 -4
- package/dist/task-settings.d.ts +14 -10
- package/dist/task-settings.js +19 -7
- package/dist/terminal.d.ts +27 -43
- package/dist/terminal.js +49 -14
- package/dist/tool-approval.d.ts +173 -163
- package/dist/tool-approval.js +247 -232
- package/dist/trace/core-keyset-guard.d.ts +13 -6
- package/dist/trace/core-vocab-wire.d.ts +95 -0
- package/dist/trace/core-vocab-wire.js +15 -0
- package/dist/trace/engine-notice-wire.d.ts +24 -21
- package/dist/trace/engine-notice-wire.js +7 -3
- package/dist/trace/exit-seat.d.ts +30 -4
- package/dist/trace/exit-seat.js +40 -36
- package/dist/trace/extension-call-face.d.ts +3 -2
- package/dist/trace/extension-call-face.js +3 -1
- package/dist/trace/ledger-events.d.ts +4 -7
- package/dist/trace/ledger-sink.d.ts +4 -31
- package/dist/trace/ledger-sink.js +0 -11
- package/dist/trace/model-segment.d.ts +5 -5
- package/dist/trace/model-segment.js +5 -5
- package/dist/trace/project.d.ts +59 -44
- package/dist/trace/project.js +60 -26
- package/dist/trace/redact.d.ts +135 -27
- package/dist/trace/redact.js +884 -260
- package/dist/trace/self-minted-wire.d.ts +567 -20
- package/dist/trace/self-minted-wire.js +205 -24
- package/dist/trace/wire-projection-faces.d.ts +5 -6
- package/dist/trace/wire-projection-faces.js +2 -2
- package/dist/upstream-body.d.ts +23 -0
- package/dist/upstream-body.js +16 -0
- package/dist/url-refusal.d.ts +3 -3
- package/dist/url-refusal.js +11 -4
- package/dist/user-authored-text.d.ts +1 -1
- package/dist/user-input-ledger.d.ts +7 -8
- package/dist/user-input-ledger.js +1 -1
- package/dist/web-admin-client/apply-effective.d.ts +6 -3
- package/dist/web-admin-client/apply-effective.js +33 -23
- package/dist/web-admin-client/apply-ledger.d.ts +16 -7
- package/dist/web-admin-client/apply-ledger.js +5 -2
- package/dist/web-admin-client/center-request.d.ts +2 -2
- package/dist/web-admin-client/center-request.js +15 -15
- package/dist/web-admin-client/effective-keys.d.ts +1 -1
- package/dist/web-admin-client/effective-keys.js +1 -1
- package/dist/web-admin-client/entry-metadata.d.ts +8 -0
- package/dist/web-admin-client/entry-metadata.js +13 -0
- package/dist/web-admin-client/http-client.d.ts +1 -1
- package/dist/web-admin-client/http-client.js +23 -4
- package/dist/web-admin-client/mcp-revocation.d.ts +1 -1
- package/dist/web-admin-client/mcp-revocation.js +2 -1
- package/dist/web-admin-client/read-warnings.d.ts +1 -0
- package/dist/web-admin-client/read-warnings.js +1 -0
- package/dist/web-admin-client/restart-signal.js +8 -4
- package/dist/web-admin-client/skills-mcp.d.ts +2 -2
- package/dist/web-admin-client/types.d.ts +1 -2
- package/dist/workspace-space.d.ts +3 -2
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +4 -4
- package/docs/error-text-lexicon.json +317 -0
- package/package.json +8 -3
- package/scripts/drain-check-local.mjs +118 -147
- package/scripts/drain-check.mysql.sql +22 -2
- package/scripts/drain-check.pg.sql +22 -2
- package/scripts/embed-minimal.mjs +183 -0
- package/wire-changes/server@7.148.0.json +1517 -0
- package/wire-changes/server@7.149.0.json +372 -0
- package/dist/http/memory-control-plane-corrupt-reply.d.ts +0 -25
- package/dist/http/memory-control-plane-corrupt-reply.js +0 -19
- package/dist/http/memory-layer-reply.d.ts +0 -30
- package/dist/http/memory-layer-reply.js +0 -24
- package/dist/lsp/e2b-bridge.d.ts +0 -57
- package/dist/lsp/e2b-bridge.js +0 -139
- package/dist/lsp/e2b-manager.d.ts +0 -93
- package/dist/lsp/e2b-manager.js +0 -178
- package/dist/lsp/lsp-frames.d.ts +0 -14
- package/dist/lsp/lsp-frames.js +0 -25
- package/dist/lsp/manager.d.ts +0 -129
- package/dist/lsp/manager.js +0 -127
- package/dist/lsp/types.d.ts +0 -12
- package/dist/lsp/types.js +0 -2
- package/dist/lsp/ws-transport.d.ts +0 -40
- package/dist/lsp/ws-transport.js +0 -210
- package/dist/plain-string-record.js +0 -70
|
@@ -2,20 +2,21 @@ import { emitLeafAdvance } from "../session-leaf-bus.js";
|
|
|
2
2
|
import { StoredSession, SessionError, uuidv7, validateEntriesForImport, leafIdAfterEntry, admitSessionPlacement, } from "@sema-agent/core";
|
|
3
3
|
import { decodeSessionEventPayload } from "./session-event-payload.js";
|
|
4
4
|
import { WindowedSessionStorage } from "./windowed-session-storage.js";
|
|
5
|
-
import { scanEpochAnchor } from "../plugins/session-epoch-anchor.js";
|
|
5
|
+
import { epochAnchorPageSql, epochFloorOf, scanEpochAnchor, sqlEpochAnchorRowOf } from "../plugins/session-epoch-anchor.js";
|
|
6
6
|
import { jsonColumnText } from "../plugins/sql-json-column.js";
|
|
7
7
|
import { pgSafeJsonStringify } from "../plugins/pg-safe-json.js";
|
|
8
8
|
import { toIso } from "../plugins/sql-row-helpers.js";
|
|
9
|
-
import { placementCapabilityOf, LIST_PLACED_BATCH, PLACEMENT_SELECT_COLUMNS, placedRowFromRow, placementFromRow,
|
|
9
|
+
import { placementCapabilityOf, LIST_PLACED_BATCH, PLACEMENT_SELECT_COLUMNS, placedRowFromRow, placementFromRow, placementInsertCells, SESSION_DURABILITY, SESSION_PLACEMENTS, } from "../plugins/session-placement.js";
|
|
10
10
|
import { contentForkRelation, fastForwardSharedContentDiverged } from "../session-sync-content.js";
|
|
11
11
|
import { classifySyncRelationshipByIds, SyncConflictError, StagedCommitOwnerChangedError, stagingIdFor, STAGING_ID_MARKER, STAGING_GC_GRACE_MS, } from "../session-sync-kernel.js";
|
|
12
12
|
import { isPgUniqueViolation } from "../plugins/sql-errors.js";
|
|
13
13
|
import { MANAGED_RETENTION, UNMANAGED_RETENTION } from "../plugins/retention-declaration.js";
|
|
14
|
-
import { SESSION_META_INCARNATION_COLUMN, headFromRow, incarnationFromCell, mintSessionIncarnation, sessionFaceFromRow } from "../session-incarnation.js";
|
|
14
|
+
import { SESSION_META_INCARNATION_COLUMN, SESSION_META_LINEAGE_COLUMNS, forkLineageOfRow, headFromRow, incarnationFromCell, mintSessionIncarnation, sessionFaceFromRow } from "../session-incarnation.js";
|
|
15
15
|
import { ensureIndexes } from "../plugins/ensure-index.js";
|
|
16
|
+
import { withdrawSessionOn } from "./tidb-session-store.js";
|
|
16
17
|
import { assertFirstOwnerWritable, forkOwnerOf, isSessionOwnerValue, placedSessionOwnerOf } from "../plugins/session-ownership.js";
|
|
17
|
-
import { selectForkRows } from "@sema-agent/core";
|
|
18
|
-
import { FORK_LOG_ROW_SHAPE, ForkTargetUnsettledError, classifyForkTarget, forkByFreshId, forkPointOf } from "../plugins/session-fork.js";
|
|
18
|
+
import { forkRowCells, selectForkRows } from "@sema-agent/core";
|
|
19
|
+
import { FORK_LOG_ROW_SHAPE, ForkTargetUnsettledError, classifyForkTarget, forkByFreshId, forkPointOf, sameSourceGeneration } from "../plugins/session-fork.js";
|
|
19
20
|
const statementsOn = (conn) => ({
|
|
20
21
|
async query(sql, params) {
|
|
21
22
|
const res = await conn.query(sql, params ?? []);
|
|
@@ -56,6 +57,8 @@ export const PG_SESSION_SCHEMA = [
|
|
|
56
57
|
placed_at TIMESTAMPTZ(3),
|
|
57
58
|
-- S-790 / S-506:会话化身(TiDB 孪生同名同义;列定义唯一属主 = src/session-incarnation.ts 的 SESSION_META_INCARNATION_COLUMN)。
|
|
58
59
|
${SESSION_META_INCARNATION_COLUMN.pg},
|
|
60
|
+
-- fork 谱系(TiDB 孪生同名同义;列定义唯一属主 = src/session-incarnation.ts 的 SESSION_META_LINEAGE_COLUMNS):NULL = 不是 fork 建的行 / 两列落地之前建的 fork(不回填)。
|
|
61
|
+
${SESSION_META_LINEAGE_COLUMNS.pg},
|
|
59
62
|
PRIMARY KEY (session_id)
|
|
60
63
|
)`,
|
|
61
64
|
`CREATE TABLE IF NOT EXISTS session_event (
|
|
@@ -91,13 +94,13 @@ export class PgSessionStorage extends WindowedSessionStorage {
|
|
|
91
94
|
this.floorSeq = floorSeq;
|
|
92
95
|
}
|
|
93
96
|
async getEpochAnchor() {
|
|
94
|
-
return scanEpochAnchor(this.floorSeq, async (beforeSeq) => {
|
|
95
|
-
const res = await this.pool.query(
|
|
96
|
-
return res.rows;
|
|
97
|
+
return scanEpochAnchor(epochFloorOf(this.floorSeq, await this.windowFloorEntry()), async (beforeSeq) => {
|
|
98
|
+
const res = await this.pool.query(epochAnchorPageSql("pg"), [this.sessionId, beforeSeq]);
|
|
99
|
+
return res.rows.map(sqlEpochAnchorRowOf);
|
|
97
100
|
}, (row) => decodeSessionEventPayload(row.payload, this.sessionId, row.seq));
|
|
98
101
|
}
|
|
99
102
|
static async wake(pool, sessionId) {
|
|
100
|
-
const metaRes = await pool.query(`SELECT created_at, leaf_id, leaf_seq, incarnation, ${PLACEMENT_SELECT_COLUMNS} FROM session_meta WHERE session_id = $1`, [sessionId]);
|
|
103
|
+
const metaRes = await pool.query(`SELECT created_at, leaf_id, leaf_seq, incarnation, ${PLACEMENT_SELECT_COLUMNS}, forked_from, forked_from_incarnation FROM session_meta WHERE session_id = $1`, [sessionId]);
|
|
101
104
|
const meta = metaRes.rows[0];
|
|
102
105
|
if (!meta)
|
|
103
106
|
return null;
|
|
@@ -105,7 +108,13 @@ export class PgSessionStorage extends WindowedSessionStorage {
|
|
|
105
108
|
const eventRes = await pool.query(`SELECT seq, ${jsonColumnText("pg", "payload")} FROM session_event WHERE session_id = $1 AND seq >= $2 ORDER BY seq ASC`, [sessionId, floorSeq]);
|
|
106
109
|
const entries = eventRes.rows.map((r) => decodeSessionEventPayload(r.payload, sessionId, r.seq));
|
|
107
110
|
const placement = placementFromRow(meta);
|
|
108
|
-
const metadata = {
|
|
111
|
+
const metadata = {
|
|
112
|
+
id: sessionId,
|
|
113
|
+
createdAt: toIso(meta.created_at),
|
|
114
|
+
incarnation: incarnationFromCell(sessionId, meta.incarnation),
|
|
115
|
+
...(placement !== undefined ? { placement } : {}),
|
|
116
|
+
...forkLineageOfRow(sessionId, meta.forked_from, meta.forked_from_incarnation),
|
|
117
|
+
};
|
|
109
118
|
return new PgSessionStorage(pool, sessionId, metadata, entries, meta.leaf_id ?? null, floorEntryId, floorSeq);
|
|
110
119
|
}
|
|
111
120
|
static async computeFloor(pool, sessionId) {
|
|
@@ -213,21 +222,42 @@ export class PgSessionStore {
|
|
|
213
222
|
return { session: new StoredSession(storage), sessionId };
|
|
214
223
|
}
|
|
215
224
|
async register(sessionId, owner) {
|
|
225
|
+
await this.registerWithReceipt(sessionId, owner);
|
|
226
|
+
}
|
|
227
|
+
async registerWithReceipt(sessionId, owner) {
|
|
216
228
|
if (!isSessionOwnerValue(owner)) {
|
|
217
229
|
if ((await this.headOf(sessionId)) !== undefined)
|
|
218
|
-
return;
|
|
230
|
+
return {};
|
|
219
231
|
assertFirstOwnerWritable(sessionId, owner);
|
|
220
232
|
}
|
|
221
|
-
|
|
233
|
+
const incarnation = mintSessionIncarnation();
|
|
234
|
+
await this.insertMeta(sessionId, owner, undefined, incarnation);
|
|
235
|
+
return { minted: { sessionId, owner, incarnation } };
|
|
236
|
+
}
|
|
237
|
+
async deleteSessionIf(sessionId, cond) {
|
|
238
|
+
const conn = await this.pool.connect();
|
|
239
|
+
try {
|
|
240
|
+
await conn.query("BEGIN");
|
|
241
|
+
const outcome = await withdrawSessionOn(statementsOn(conn), "pg", this.hooks, sessionId, cond);
|
|
242
|
+
await conn.query(outcome.withdrawn ? "COMMIT" : "ROLLBACK");
|
|
243
|
+
return outcome;
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
await conn.query("ROLLBACK").catch(() => undefined);
|
|
247
|
+
throw err;
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
conn.release();
|
|
251
|
+
}
|
|
222
252
|
}
|
|
223
253
|
async createOnAcquire(sessionId, placement) {
|
|
224
254
|
await this.insertMeta(sessionId, placement === undefined ? null : placedSessionOwnerOf(sessionId, placement), placement);
|
|
225
255
|
}
|
|
226
|
-
async insertMeta(sessionId, owner, placement) {
|
|
256
|
+
async insertMeta(sessionId, owner, placement, incarnation = mintSessionIncarnation()) {
|
|
227
257
|
const now = new Date();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
"VALUES ($1,$2,$3,$4,NULL,0,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT (session_id) DO NOTHING", [sessionId, owner, now, now,
|
|
258
|
+
const placed = placementInsertCells(placement, now);
|
|
259
|
+
await this.pool.query(`INSERT INTO session_meta (session_id, owner, created_at, updated_at, leaf_id, leaf_seq, incarnation, ${placed.columns}) ` +
|
|
260
|
+
"VALUES ($1,$2,$3,$4,NULL,0,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT (session_id) DO NOTHING", [sessionId, owner, now, now, incarnation, ...placed.values]);
|
|
231
261
|
}
|
|
232
262
|
async placementOf(sessionId) {
|
|
233
263
|
const res = await this.pool.query(`SELECT ${PLACEMENT_SELECT_COLUMNS} FROM session_meta WHERE session_id = $1`, [sessionId]);
|
|
@@ -312,7 +342,8 @@ export class PgSessionStore {
|
|
|
312
342
|
throw new ForkTargetUnsettledError(target.id);
|
|
313
343
|
}
|
|
314
344
|
async forkToOnce(sourceId, owner, target) {
|
|
315
|
-
const
|
|
345
|
+
const sourceRow = "SELECT leaf_id, owner, incarnation FROM session_meta WHERE session_id = $1";
|
|
346
|
+
const metaRes = await this.pool.query(sourceRow, [sourceId]);
|
|
316
347
|
if (!metaRes.rows[0])
|
|
317
348
|
return null;
|
|
318
349
|
const leafId = metaRes.rows[0].leaf_id ?? null;
|
|
@@ -321,16 +352,20 @@ export class PgSessionStore {
|
|
|
321
352
|
if (storage === null)
|
|
322
353
|
return null;
|
|
323
354
|
const point = await forkPointOf(storage);
|
|
355
|
+
const cells = forkRowCells(await storage.getMetadata());
|
|
324
356
|
const eventRes = await this.pool.query(`SELECT entry_id, parent_id, type, ${jsonColumnText("pg", "payload")}, ts FROM session_event WHERE session_id = $1 ORDER BY seq ASC`, [sourceId]);
|
|
357
|
+
const afterRes = await this.pool.query(sourceRow, [sourceId]);
|
|
358
|
+
if (!sameSourceGeneration(cells.forkedFromIncarnation, metaRes.rows[0].incarnation, afterRes.rows[0]?.incarnation))
|
|
359
|
+
return null;
|
|
325
360
|
const { rows, leafId: forkLeafId } = selectForkRows(eventRes.rows, leafId, point, FORK_LOG_ROW_SHAPE);
|
|
326
361
|
const now = new Date();
|
|
327
362
|
const conn = await this.pool.connect();
|
|
328
363
|
let collided = false;
|
|
329
364
|
try {
|
|
330
365
|
await conn.query("BEGIN");
|
|
366
|
+
const placed = placementInsertCells(target.placement, now);
|
|
331
367
|
try {
|
|
332
|
-
await conn.query(
|
|
333
|
-
"placement_kind, placement_scope, placement_parent_session_id, placement_root_session_id, placement_handle, placed_at) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)", [target.id, forkOwner, now, now, forkLeafId, rows.length, mintSessionIncarnation(), ...placementInsertValues(target.placement, now)]);
|
|
368
|
+
await conn.query(`INSERT INTO session_meta (session_id, owner, created_at, updated_at, leaf_id, leaf_seq, incarnation, ${placed.columns}, forked_from, forked_from_incarnation) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)`, [target.id, forkOwner, now, now, forkLeafId, rows.length, mintSessionIncarnation(), ...placed.values, cells.forkedFrom, cells.forkedFromIncarnation ?? null]);
|
|
334
369
|
}
|
|
335
370
|
catch (err) {
|
|
336
371
|
if (!isDupKey(err))
|
|
@@ -500,33 +535,6 @@ export class PgSessionStore {
|
|
|
500
535
|
}
|
|
501
536
|
return removed;
|
|
502
537
|
}
|
|
503
|
-
async deleteSession(sessionId, owner) {
|
|
504
|
-
const conn = await this.pool.connect();
|
|
505
|
-
try {
|
|
506
|
-
await conn.query("BEGIN");
|
|
507
|
-
const locked = await conn.query("SELECT session_id FROM session_meta WHERE session_id = $1 FOR UPDATE", [sessionId]);
|
|
508
|
-
if (locked.rows.length > 0)
|
|
509
|
-
settleHookVerdict(await this.hooks.beforeCommit(statementsOn(conn), { op: "delete", rootSessionId: sessionId }));
|
|
510
|
-
const metaRes = await conn.query("DELETE FROM session_meta WHERE session_id = $1 AND owner IS NOT DISTINCT FROM $2", [sessionId, owner]);
|
|
511
|
-
if ((metaRes.rowCount ?? 0) > 0)
|
|
512
|
-
await conn.query("DELETE FROM session_event WHERE session_id = $1", [sessionId]);
|
|
513
|
-
await conn.query("COMMIT");
|
|
514
|
-
return (metaRes.rowCount ?? 0) > 0;
|
|
515
|
-
}
|
|
516
|
-
catch (err) {
|
|
517
|
-
try {
|
|
518
|
-
await conn.query("ROLLBACK");
|
|
519
|
-
}
|
|
520
|
-
catch {
|
|
521
|
-
}
|
|
522
|
-
if (err instanceof HookRefusal)
|
|
523
|
-
throw err.refuse;
|
|
524
|
-
throw err;
|
|
525
|
-
}
|
|
526
|
-
finally {
|
|
527
|
-
conn.release();
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
538
|
get size() {
|
|
531
539
|
return this.pending.size;
|
|
532
540
|
}
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
* 破坏性事务的次序(K4,一步不省):
|
|
14
14
|
* `holdLock`(首句)→ 候选加锁读(`FOR UPDATE`,含每只候选的会话行)→ 每只候选根 `session.beforeCommit`(仅会话树)→
|
|
15
15
|
* `liveReferences`(余下候选)→ `beforeDelete`(终集)→ 本执行器删自己的行、落墓碑 → `audit`(提交前末句)→ COMMIT。
|
|
16
|
-
* 一只被某个钩放下的会话不进任何后续钩的入参。部署那一半(server 的 hold / 审计 / 认领判 /
|
|
16
|
+
* 一只被某个钩放下的会话不进任何后续钩的入参。部署那一半(server 的 hold / 审计 / 认领判 / 十三张部署表)在
|
|
17
17
|
* `plugins/retention-deployment.ts`,组合在 `plugins/store-backend.ts`(`createSqlRetentionExecutor`)。
|
|
18
|
+
* **会话树事务体是删净会话的唯一一段**({@link SqlRetentionStore.eraseTreesInTxn}):留存的 `deleteExpiredSessions` 与在线删除的 `eraseSession`
|
|
19
|
+
* (锁行 → 会话座事务内钩的 `erase` 判在删令牌 → 同一段事务体;组合座 `createSqlSessionEraser`)同调 —— 一只会话无论哪个决定者删,行面一个执行体(`session-erase.ts` 头注)。
|
|
18
20
|
*
|
|
19
21
|
* ── 域(domain)口径 ────────────────────────────────────────────────────────────────────────────────
|
|
20
22
|
* 域 = 租户键。三张保留表各有自己的载体列:`session_meta.owner`(**可空**)、`checkpoint.scope`(非空)、
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
* `test/schema-naming-invariants.test.ts` 机器执法(「一张表是一类行的集合,表名说的是『一行是什么』」)。
|
|
43
45
|
* ⇒ 落库名一律单数:`retention_audit` / `retention_hold` / `retention_lease` / `retention_tombstone`。
|
|
44
46
|
*/
|
|
45
|
-
import type
|
|
47
|
+
import { type ManagedRetentionCapability, type RetentionReceipt } from "@sema-agent/core";
|
|
46
48
|
import type { SessionWriteHooks } from "./session-write-hooks.js";
|
|
47
49
|
import type { SqlDriver, SqlTxConn } from "../plugins/sql-driver.js";
|
|
48
50
|
import type { IndexSpec } from "../plugins/ensure-index.js";
|
|
@@ -98,6 +100,37 @@ export interface RetentionPreview {
|
|
|
98
100
|
sessions: number;
|
|
99
101
|
toolResults: number;
|
|
100
102
|
}
|
|
103
|
+
/** 会话树事务体删掉的行面(两只入口同形):每只会话(id + 删前属主 + 住客化身)+ 全库无出处卸载结果数。组合座据它交收尾(`session-erase.ts`)。 */
|
|
104
|
+
export interface ErasedTreeRows {
|
|
105
|
+
readonly sessions: readonly {
|
|
106
|
+
readonly sessionId: string;
|
|
107
|
+
readonly owner: string | null;
|
|
108
|
+
readonly incarnation: string | undefined;
|
|
109
|
+
}[];
|
|
110
|
+
readonly unattributableToolResults: number;
|
|
111
|
+
}
|
|
112
|
+
/** 会话树清扫的回执 = core 契约的三计数 + 本仓一位:`erasedRows` present-iff 本次删掉了至少一棵树。 */
|
|
113
|
+
export type SessionTreesReceipt = RetentionReceipt & {
|
|
114
|
+
readonly erasedRows?: ErasedTreeRows;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 会话规则行的 rev 高水位记号随不随会话走 —— 会话树事务体里两个决定者**唯一**的行面之差(其余每一句同):
|
|
118
|
+
* · `keep`(在线删除 `eraseSession`):被删会话的 workflow run 可以活过这次删除(在线删除不判在跑的 workflow),同 id 重登记之后规则的谱系
|
|
119
|
+
* (rev 高水位 + 下一代 `gen`)必须活过行,读者才分得出「新行」与「续行」—— 店的抹除语义;
|
|
120
|
+
* · `drop`(托管留存 `deleteExpiredSessions`):候选按定义没有活引用,那条 rev 线已无读者;记号带明文 `session_id` ⇒ 随会话树删。
|
|
121
|
+
* 在线删除也判在跑的 workflow 之日,两支合成 `drop`。
|
|
122
|
+
*/
|
|
123
|
+
export type RuleMarks = "keep" | "drop";
|
|
124
|
+
/** 删一只在删会话(`eraseSession`)的答案(闭集):行不在 / 属主不是那一位 ⇒ `absent`;会话座的事务内钩拒(`erase`:这一行不是这只令牌的在删态)⇒ `refused`(带它的错);删完 ⇒ `erased`。三支都**先于任何 DELETE** 定。 */
|
|
125
|
+
export type SessionEraseOutcome = {
|
|
126
|
+
readonly outcome: "absent";
|
|
127
|
+
} | {
|
|
128
|
+
readonly outcome: "refused";
|
|
129
|
+
readonly refusal: Error;
|
|
130
|
+
} | {
|
|
131
|
+
readonly outcome: "erased";
|
|
132
|
+
readonly rows: ErasedTreeRows;
|
|
133
|
+
};
|
|
101
134
|
/** 执行器的构造选项(core-stores-sql `SqlStorageBackendOptions` 里与留存相关的那一格 + 诊断日志座)。 */
|
|
102
135
|
export interface SqlRetentionStoreOptions {
|
|
103
136
|
/** 部署在执行器事务里的钩表(K4)。缺席 = 部署没有自己的表参与(没有 hold、没有审计行、没有部署行要随会话删)。 */
|
|
@@ -107,6 +140,11 @@ export interface SqlRetentionStoreOptions {
|
|
|
107
140
|
info?(msg: string, meta?: unknown): void;
|
|
108
141
|
warn?(msg: string, meta?: unknown): void;
|
|
109
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* 会话盒的分区读法 —— 在场 ⇔ 收件箱四表在场(组合座按装配层的必填答案 `RetentionExecutorOptions.mailboxTables` 交入服务的唯一派生);
|
|
145
|
+
* 在场 ⇒ 会话树的最后一腿丢被删会话的会话盒(`scope = sessionBoxScope(删前属主)`)。
|
|
146
|
+
*/
|
|
147
|
+
sessionBoxScope?: (owner: string | null) => string;
|
|
110
148
|
}
|
|
111
149
|
/** 单次调用的候选上界(**安全界,不是分批语义**)。设计稿 §3 的 v1 口径是「先由 cutoff 天然限量」,
|
|
112
150
|
* 这里额外扣一个上界,理由是运维面而不是功能面:一个从未清过账的大租户会让「一个事务删十余张表的
|
|
@@ -149,10 +187,10 @@ export declare class SqlRetentionStore implements ManagedRetentionCapability {
|
|
|
149
187
|
/** 首句:部署锁读本域的 hold 记录。无钩 ⇒ 部署没有 hold 面,`proceed`。 */
|
|
150
188
|
private heldBy;
|
|
151
189
|
/**
|
|
152
|
-
*
|
|
153
|
-
* {@link SqlRetentionStore.deleteExpiredSessions} 头注「receipt 口径」)。
|
|
190
|
+
* 每只根问一次会话座的事务内钩(根的会话行已由本事务锁住):`erase`(删一只在删会话,`eraseSession`,带令牌)/ `retention-delete`(留存候选根)。
|
|
191
|
+
* 无钩 ⇒ 放行;`{ refuse }` ⇒ 交回那只错(`eraseSession` 答 `refused`;留存这棵树本轮不删、计进 `skipped`,账法见 {@link SqlRetentionStore.deleteExpiredSessions} 头注「receipt 口径」)。
|
|
154
192
|
*/
|
|
155
|
-
private
|
|
193
|
+
private refusalOf;
|
|
156
194
|
/** 部署仍在引用的候选(无钩 ⇒ 空集)。 */
|
|
157
195
|
private referencedBy;
|
|
158
196
|
/** 提交前末句:部署的审计行。无钩 ⇒ 部署不记审计。 */
|
|
@@ -226,8 +264,13 @@ export declare class SqlRetentionStore implements ManagedRetentionCapability {
|
|
|
226
264
|
* 抽成一处是因为它同时被「可过期候选」与「被 pin 的计数」两条查询用,手抄两份必分家。
|
|
227
265
|
*/
|
|
228
266
|
private horizonArms;
|
|
229
|
-
/**
|
|
230
|
-
|
|
267
|
+
/**
|
|
268
|
+
* 「这张卡**所属的 run** 被一次活跑占着」= [ref] 的 live-pinned 判据(SQL 谓词形,两方言同文本;候选读、pinned 计数、
|
|
269
|
+
* CAS 更新三处同一只,`row` 只换行引用名)。连的是归属列 `host_session_id` —— run 的认领 `task_active` 挂在 run 的会话上,
|
|
270
|
+
* cascade 的级上卡自己的会话(`session_id`)上没有认领;按卡自己的会话判,一条仍挂着的 cascade run 的那张卡会被当成无主
|
|
271
|
+
* 过期,随后 run 收割把这条 run 判失败。归属为 NULL(滚动升级窗内旧副本写的行,下次起服 M49 回填)⇒ 不算被占。
|
|
272
|
+
*/
|
|
273
|
+
private static pinnedExists;
|
|
231
274
|
/**
|
|
232
275
|
* **可过期**的候选 token(保护谓词写在 SQL 里、扣在 `LIMIT` **之前**)。
|
|
233
276
|
*
|
|
@@ -316,7 +359,7 @@ export declare class SqlRetentionStore implements ManagedRetentionCapability {
|
|
|
316
359
|
* {@link SqlRetentionStore.sessionCandidates});每只候选的会话行在此锁住;
|
|
317
360
|
* ②′ 读写序律的写者半 = `session.beforeCommit` 钩(每只候选根一次,`op: "retention-delete"`;会话座的那一只钩):用**本事务的连接、新语句**锁定读一次认领;
|
|
318
361
|
* 有认领 ⇒ `{ refuse }`,整棵跳过;然后 `liveReferences` 钩(余下候选;部署不给 ⇒ 空集);
|
|
319
|
-
* ③ `beforeDelete` 钩(
|
|
362
|
+
* ③ `beforeDelete` 钩(终集,行带化身:部署删它的十三张表、自算结束了的空间)→ 本执行器按序删引擎座表({@link SqlRetentionStore.purgeSessionTrees})
|
|
320
363
|
* → 墓碑 → `audit` 钩(提交前末句,同事务)→ COMMIT。
|
|
321
364
|
*
|
|
322
365
|
* 🔴 活引用重查为什么是**候选查询本身**而不是第二条查询(codex 交叉复审 R1 的两条 high 合并采纳):
|
|
@@ -354,25 +397,50 @@ export declare class SqlRetentionStore implements ManagedRetentionCapability {
|
|
|
354
397
|
deleteExpiredSessions(input: {
|
|
355
398
|
domain: string;
|
|
356
399
|
cutoffMs: number;
|
|
357
|
-
}): Promise<
|
|
400
|
+
}): Promise<SessionTreesReceipt>;
|
|
401
|
+
/**
|
|
402
|
+
* **删一只在删会话**(在线删除的执行体;合同外,本仓自己的面 —— 与 `previewRetention` 同类)。与 {@link deleteExpiredSessions} 跑**同一段**会话树事务体
|
|
403
|
+
* ({@link eraseTreesInTxn}),只是「删谁」由调用方点名(删除协调器的围栏写下的令牌)而不是视界选:
|
|
404
|
+
* E1 锁行 `session_meta … FOR UPDATE`(读属主 + 化身)—— 行不在 / 属主不是围栏判过的那一位(`owner`:域键,部署行与墓碑按它写)⇒ `absent`。
|
|
405
|
+
* 同 id 的重登记(`INSERT … ON DUPLICATE`)、围栏、认领都先锁这一行 ⇒ 都等在这把锁上;
|
|
406
|
+
* E2 会话座的事务内钩 `erase`:这一行此刻处于 `token` 那一次删除的在删态(判官读旁表的在删令牌,同一连接)—— 不是 ⇒ `refused`(另一次删除接管了它,
|
|
407
|
+
* 或它已删完而同 id 是新住客 —— 新行不带这只令牌)。令牌只在围栏判过属主、判过认领之后写下,在删期间认领落不下 ⇒ 这里不再判属主与认领;
|
|
408
|
+
* E3–E6 部署行(`beforeDelete` 钩)→ 引擎座行({@link purgeSessionTrees},行最后 + 命中数断言)→ 墓碑(域 = 属主,`""` = 无主桶)→ 提交;之后读一次无出处卸载结果数。
|
|
409
|
+
* 事务里只有 SQL 语句(完成信箱围栏在部署钩、会话盒在最后一腿,都在里面);对象存储字节、空间、进程态在调用方的提交之后(`session-erase.ts` 的收尾)。没有 hold / 审计:那是留存决定者的事。
|
|
410
|
+
*/
|
|
411
|
+
eraseSession(input: {
|
|
412
|
+
readonly sessionId: string;
|
|
413
|
+
readonly owner: string | null;
|
|
414
|
+
readonly token: string;
|
|
415
|
+
}): Promise<SessionEraseOutcome>;
|
|
416
|
+
/**
|
|
417
|
+
* 全库无出处卸载结果数(告知数:这类行任何会话删除都删不到 ⇒ 删除不完整)。**在破坏性事务之前**读,两只入口同调:聚合读加不了锁、也不决定任何写 ⇒ 不进事务;
|
|
418
|
+
* 删一棵会话树不改它(按出处列删的行出处非空);读失败 ⇒ 抛在任何一字节被删之前(重试从同一状态开始),不会让一次已提交的删除丢掉收尾。
|
|
419
|
+
*/
|
|
420
|
+
private unattributableToolResults;
|
|
421
|
+
/**
|
|
422
|
+
* **会话树事务体 —— 删净会话的唯一一段**(`eraseSession` 与 `deleteExpiredSessions` 同调;调用方已锁住这批会话行、判过认领):
|
|
423
|
+
* 部署行(`beforeDelete` 钩:部署的十三张表)→ 引擎座行({@link purgeSessionTrees})→ 墓碑。全库无出处卸载结果数在事务之前读({@link unattributableToolResults})。
|
|
424
|
+
* `domain` = 这批会话的域键(`COALESCE(owner, '')`);行面回执里每只会话的删前属主由它读回(`""` ⇒ 无主)。
|
|
425
|
+
* `ruleMarks` = 规则行的 rev 高水位记号随不随会话走 —— 两个决定者唯一的行面之差({@link RuleMarks})。
|
|
426
|
+
*/
|
|
427
|
+
private eraseTreesInTxn;
|
|
358
428
|
/**
|
|
359
|
-
* 会话树里**引擎座表**这一半的删除:同一组 DELETE
|
|
429
|
+
* 会话树里**引擎座表**这一半的删除:同一组 DELETE、同一个相对次序,发在执行器事务的连接上。部署的十三张表在这之前已由
|
|
360
430
|
* `beforeDelete` 钩删完(K4 次序:部署行先于执行器行;部署那一半见 `plugins/retention-deployment.ts`)。
|
|
361
431
|
* 次序的承重理由:
|
|
362
432
|
* · `checkpoint` 的属主门是 `session_meta.owner` 的 EXISTS 子查询 ⇒ 它**必须**排在 `session_meta` 删除**之前**
|
|
363
433
|
* (meta 一没,门就恒假、一行都删不掉);部署钩里的 `checkpoint_ctx` 同一道门,同一条理由(钩先于本方法,天然满足);
|
|
364
|
-
* · file-history 的 scope
|
|
434
|
+
* · file-history 的 scope 哨兵先锁、再抹规则行(记号随不随会话走 = {@link RuleMarks})、再删 file-history 的行。
|
|
365
435
|
* 引擎 [ref] 的会话树步表(`RETENTION_SESSION_TREE_STEPS`)里本方法执行的是 6(检查点)/ 7(工具结果)/ 8(会话策略)/ 9(文件历史)/
|
|
366
|
-
* 11(会话本体)
|
|
367
|
-
* ——
|
|
436
|
+
* 10(会话信箱,收件箱四表在场时;信箱店 `drop` 的同一组语句)/ 11(会话本体)六步,相对次序与表同;1–5 共五步
|
|
437
|
+
* (workflow journal 与 run、后台子代与其信箱、名册)本执行器不删 —— 登记过的既有欠(对表钉在 `test/retention-hook-order.test.ts`)。
|
|
368
438
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* 对无主域,`<=>` 拿字符串 `""` 去比 NULL 会**一行都不匹配** —— 那正是「无主会话永远清不掉」的病。
|
|
373
|
-
* 这条改写只对 **`session_meta.owner` 这一族门**(meta / checkpoint,以及部署钩里的 checkpoint_ctx)成立。
|
|
439
|
+
* 属主门读**域键**(两只入口同:留存传本轮的域,`eraseSession` 传 `owner ?? ""`),经 {@link SqlRetentionStore.domainWhere} 表达 —— `""` = 无主桶
|
|
440
|
+
* `(owner IS NULL OR owner = '')`;有主域 `owner = ?`。`<=>` 拿字符串 `""` 去比 NULL 会一行都不匹配(「无主会话永远清不掉」的病),所以这一族门
|
|
441
|
+
* (meta / checkpoint,以及部署钩里的 checkpoint_ctx)只用这一种写法。
|
|
374
442
|
*/
|
|
375
|
-
protected purgeSessionTrees(conn: SqlTxConn, domain: string, ids: readonly string[]): Promise<number>;
|
|
443
|
+
protected purgeSessionTrees(conn: SqlTxConn, domain: string, ids: readonly string[], ruleMarks: RuleMarks): Promise<number>;
|
|
376
444
|
/**
|
|
377
445
|
* 属主 session 已亡的 offloaded 结果(core 契约:「whose owning sessions are gone (or past the horizon),
|
|
378
446
|
* skipping refs still reachable from live transcripts」)。
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { peerSessionBoxHandle } from "@sema-agent/core";
|
|
1
2
|
import { incarnationFromCell } from "../session-incarnation.js";
|
|
2
3
|
import { MANAGED_RETENTION } from "../plugins/retention-declaration.js";
|
|
3
4
|
import { retentionDomainWhere, retentionIdSet } from "../plugins/retention-sql.js";
|
|
5
|
+
import { dropMailboxBoxOn } from "./mailbox-store-sql.js";
|
|
6
|
+
import { SEALED_EVENT, eraseSessionPolicyRowsOn } from "./session-policy-store-sql.js";
|
|
4
7
|
export const RETENTION_TOMBSTONE_TABLE = "retention_tombstone";
|
|
5
8
|
export const TIDB_RETENTION_TOMBSTONE_STATEMENTS = [
|
|
6
9
|
`CREATE TABLE IF NOT EXISTS ${RETENTION_TOMBSTONE_TABLE} (
|
|
@@ -44,6 +47,13 @@ class RetentionAborted extends Error {
|
|
|
44
47
|
this.why = why;
|
|
45
48
|
}
|
|
46
49
|
}
|
|
50
|
+
class EraseRefused extends Error {
|
|
51
|
+
refusal;
|
|
52
|
+
constructor(refusal) {
|
|
53
|
+
super(`session erase refused: ${refusal.message}`);
|
|
54
|
+
this.refusal = refusal;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
47
57
|
export const RETENTION_SESSION_BATCH = 500;
|
|
48
58
|
export const RETENTION_ROW_BATCH = 2000;
|
|
49
59
|
export class SqlRetentionStore {
|
|
@@ -103,15 +113,16 @@ export class SqlRetentionStore {
|
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
|
-
async
|
|
116
|
+
async refusalOf(face, write) {
|
|
117
|
+
const rootSessionId = write.rootSessionId;
|
|
107
118
|
const beforeCommit = this.opts.transactionHooks?.session?.beforeCommit;
|
|
108
119
|
if (beforeCommit === undefined)
|
|
109
|
-
return
|
|
110
|
-
const answer = await beforeCommit(face,
|
|
120
|
+
return undefined;
|
|
121
|
+
const answer = await beforeCommit(face, write);
|
|
111
122
|
if (answer === "proceed")
|
|
112
|
-
return
|
|
123
|
+
return undefined;
|
|
113
124
|
if (typeof answer === "object" && answer !== null && answer.refuse instanceof Error)
|
|
114
|
-
return
|
|
125
|
+
return answer.refuse;
|
|
115
126
|
throw new Error(`retention: session.beforeCommit answered ${JSON.stringify(answer)} for root ${JSON.stringify(rootSessionId)} — the closed answer set is "proceed" | { refuse }; rolling back.`);
|
|
116
127
|
}
|
|
117
128
|
async referencedBy(face, candidates) {
|
|
@@ -168,8 +179,8 @@ export class SqlRetentionStore {
|
|
|
168
179
|
const w = this.domainWhere("scope", input.domain, 2);
|
|
169
180
|
const set = this.idSet("token", doomed, 3);
|
|
170
181
|
const res = await conn.query(this.q(`UPDATE checkpoint SET status = 'expired', decided_at_ms = ? WHERE ${w.sql} AND status = 'pending' AND ${set.sql} ` +
|
|
171
|
-
`AND NOT
|
|
172
|
-
`AND NOT
|
|
182
|
+
`AND NOT ${SqlRetentionStore.pinnedExists("checkpoint")}`, `UPDATE checkpoint SET status = 'expired', decided_at_ms = $1 WHERE ${w.sql} AND status = 'pending' AND ${set.sql} ` +
|
|
183
|
+
`AND NOT ${SqlRetentionStore.pinnedExists("checkpoint")}`), [Date.now(), ...w.params, ...set.params]);
|
|
173
184
|
expired = res.affected;
|
|
174
185
|
}
|
|
175
186
|
const receipt = { domain: input.domain, deleted: expired, skipped: pinned, tombstones: 0 };
|
|
@@ -188,19 +199,21 @@ export class SqlRetentionStore {
|
|
|
188
199
|
? `((c.deadline IS NOT NULL AND c.deadline <= ?) OR (c.deadline IS NULL AND c.created_at_ms <= ?))`
|
|
189
200
|
: `((c.deadline IS NOT NULL AND c.deadline <= $${pgFirst}) OR (c.deadline IS NULL AND c.created_at_ms <= $${pgFirst + 1}))`;
|
|
190
201
|
}
|
|
191
|
-
static
|
|
202
|
+
static pinnedExists(row) {
|
|
203
|
+
return `EXISTS (SELECT 1 FROM task_active ta WHERE ta.session_id = ${row}.host_session_id)`;
|
|
204
|
+
}
|
|
192
205
|
async expiryCandidates(exec, input) {
|
|
193
206
|
const w = this.domainWhere("c.scope", input.domain, 1);
|
|
194
207
|
const { rows } = await exec.query(this.q(`SELECT c.token FROM checkpoint c WHERE ${w.sql} AND c.status = 'pending' AND ${this.horizonArms(2)} ` +
|
|
195
|
-
`AND NOT ${SqlRetentionStore.
|
|
196
|
-
`AND NOT ${SqlRetentionStore.
|
|
208
|
+
`AND NOT ${SqlRetentionStore.pinnedExists("c")} ORDER BY c.created_at_ms ASC LIMIT ?`, `SELECT c.token FROM checkpoint c WHERE ${w.sql} AND c.status = 'pending' AND ${this.horizonArms(2)} ` +
|
|
209
|
+
`AND NOT ${SqlRetentionStore.pinnedExists("c")} ORDER BY c.created_at_ms ASC LIMIT $4`), [...w.params, input.cutoffMs, input.cutoffMs, RETENTION_ROW_BATCH]);
|
|
197
210
|
return rows.map((r) => String(r.token));
|
|
198
211
|
}
|
|
199
212
|
async countPinnedExpiryCandidates(exec, input) {
|
|
200
213
|
const w = this.domainWhere("c.scope", input.domain, 1);
|
|
201
214
|
const { rows } = await exec.query(this.q(`SELECT COUNT(*) AS n FROM (SELECT 1 AS one FROM checkpoint c WHERE ${w.sql} AND c.status = 'pending' AND ${this.horizonArms(2)} ` +
|
|
202
|
-
`AND ${SqlRetentionStore.
|
|
203
|
-
`AND ${SqlRetentionStore.
|
|
215
|
+
`AND ${SqlRetentionStore.pinnedExists("c")} LIMIT ?) x`, `SELECT COUNT(*) AS n FROM (SELECT 1 AS one FROM checkpoint c WHERE ${w.sql} AND c.status = 'pending' AND ${this.horizonArms(2)} ` +
|
|
216
|
+
`AND ${SqlRetentionStore.pinnedExists("c")} LIMIT $4) x`), [...w.params, input.cutoffMs, input.cutoffMs, RETENTION_ROW_BATCH]);
|
|
204
217
|
return Number(rows[0]?.n ?? 0);
|
|
205
218
|
}
|
|
206
219
|
liveReferenceExists() {
|
|
@@ -248,6 +261,7 @@ export class SqlRetentionStore {
|
|
|
248
261
|
async deleteExpiredSessions(input) {
|
|
249
262
|
const call = { domain: input.domain, op: "deleteExpiredSessions" };
|
|
250
263
|
let skippedOnAbort = 0;
|
|
264
|
+
const unattributable = await this.unattributableToolResults();
|
|
251
265
|
try {
|
|
252
266
|
return await this.tx(async (conn) => {
|
|
253
267
|
const face = this.statementFace(conn);
|
|
@@ -258,24 +272,17 @@ export class SqlRetentionStore {
|
|
|
258
272
|
const candidates = await this.sessionCandidates(conn, input, true);
|
|
259
273
|
const admitted = [];
|
|
260
274
|
for (const c of candidates)
|
|
261
|
-
if (await this.
|
|
275
|
+
if ((await this.refusalOf(face, { op: "retention-delete", rootSessionId: c.id })) === undefined)
|
|
262
276
|
admitted.push(c);
|
|
263
277
|
const referenced = await this.referencedBy(face, admitted.map((c) => c.id));
|
|
264
278
|
const doomed = admitted.filter((c) => !referenced.has(c.id));
|
|
265
279
|
const skipped = (await this.countProtectedSessions(conn, input)) + (candidates.length - doomed.length);
|
|
266
280
|
skippedOnAbort = doomed.length + skipped;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const ids = doomed.map((d) => d.id);
|
|
270
|
-
if (ids.length > 0) {
|
|
271
|
-
await this.opts.transactionHooks?.retention?.beforeDelete?.(face, doomed.map((d) => ({ sessionId: d.id, incarnation: d.incarnation })));
|
|
272
|
-
deleted = await this.purgeSessionTrees(conn, input.domain, ids);
|
|
273
|
-
tombstones = await this.writeTombstones(conn, input.domain, "session", ids);
|
|
274
|
-
}
|
|
275
|
-
const receipt = { domain: input.domain, deleted, skipped, tombstones };
|
|
281
|
+
const erased = doomed.length > 0 ? await this.eraseTreesInTxn(conn, face, input.domain, doomed, "drop") : undefined;
|
|
282
|
+
const receipt = { domain: input.domain, deleted: erased?.deleted ?? 0, skipped, tombstones: erased?.tombstones ?? 0 };
|
|
276
283
|
await this.auditedBy(face, call, receipt);
|
|
277
|
-
return receipt;
|
|
278
|
-
});
|
|
284
|
+
return { receipt, erased: erased?.rows };
|
|
285
|
+
}).then(({ receipt, erased }) => (erased !== undefined ? { ...receipt, erasedRows: { ...erased, unattributableToolResults: unattributable } } : receipt));
|
|
279
286
|
}
|
|
280
287
|
catch (err) {
|
|
281
288
|
if (err instanceof RetentionAborted)
|
|
@@ -283,7 +290,46 @@ export class SqlRetentionStore {
|
|
|
283
290
|
throw err;
|
|
284
291
|
}
|
|
285
292
|
}
|
|
286
|
-
async
|
|
293
|
+
async eraseSession(input) {
|
|
294
|
+
if (this.opts.transactionHooks?.session?.beforeCommit === undefined) {
|
|
295
|
+
throw new Error(`retention: eraseSession(${JSON.stringify(input.sessionId)}) needs the session write hook (the erase token judge) — refusing to delete a session that no judge can confirm is in this deletion's deleting state`);
|
|
296
|
+
}
|
|
297
|
+
const unattributable = await this.unattributableToolResults();
|
|
298
|
+
const out = await this.tx(async (conn) => {
|
|
299
|
+
const face = this.statementFace(conn);
|
|
300
|
+
const { rows } = await conn.query(this.q("SELECT owner, incarnation FROM session_meta WHERE session_id = ? FOR UPDATE", "SELECT owner, incarnation FROM session_meta WHERE session_id = $1 FOR UPDATE"), [input.sessionId]);
|
|
301
|
+
const row = rows[0];
|
|
302
|
+
if (row === undefined)
|
|
303
|
+
return { outcome: "absent" };
|
|
304
|
+
const owner = row.owner === null || row.owner === undefined ? null : String(row.owner);
|
|
305
|
+
if (owner !== input.owner)
|
|
306
|
+
return { outcome: "absent" };
|
|
307
|
+
const incarnation = incarnationFromCell(input.sessionId, row.incarnation, "absent");
|
|
308
|
+
const refusal = await this.refusalOf(face, { op: "erase", rootSessionId: input.sessionId, token: input.token });
|
|
309
|
+
if (refusal !== undefined)
|
|
310
|
+
throw new EraseRefused(refusal);
|
|
311
|
+
const erased = await this.eraseTreesInTxn(conn, face, owner ?? "", [{ id: input.sessionId, incarnation }], "keep");
|
|
312
|
+
return { outcome: "erased", rows: erased.rows };
|
|
313
|
+
}).catch((err) => {
|
|
314
|
+
if (err instanceof EraseRefused)
|
|
315
|
+
return { outcome: "refused", refusal: err.refusal };
|
|
316
|
+
throw err;
|
|
317
|
+
});
|
|
318
|
+
return out.outcome === "erased" ? { outcome: "erased", rows: { ...out.rows, unattributableToolResults: unattributable } } : out;
|
|
319
|
+
}
|
|
320
|
+
async unattributableToolResults() {
|
|
321
|
+
const { rows: unowned } = await this.db.query("SELECT COUNT(*) AS n FROM tool_result WHERE owner_session_id IS NULL");
|
|
322
|
+
return Number(unowned[0]?.n ?? 0);
|
|
323
|
+
}
|
|
324
|
+
async eraseTreesInTxn(conn, face, domain, doomed, ruleMarks) {
|
|
325
|
+
const ids = doomed.map((d) => d.id);
|
|
326
|
+
await this.opts.transactionHooks?.retention?.beforeDelete?.(face, doomed.map((d) => ({ sessionId: d.id, incarnation: d.incarnation })));
|
|
327
|
+
const deleted = await this.purgeSessionTrees(conn, domain, ids, ruleMarks);
|
|
328
|
+
const tombstones = await this.writeTombstones(conn, domain, "session", ids);
|
|
329
|
+
const owner = domain === "" ? null : domain;
|
|
330
|
+
return { deleted, tombstones, rows: { sessions: doomed.map((d) => ({ sessionId: d.id, owner, incarnation: d.incarnation })) } };
|
|
331
|
+
}
|
|
332
|
+
async purgeSessionTrees(conn, domain, ids, ruleMarks) {
|
|
287
333
|
const set = (col, pgIndex) => this.idSet(col, ids, pgIndex);
|
|
288
334
|
{
|
|
289
335
|
const s = set("checkpoint.session_id", 1);
|
|
@@ -298,9 +344,23 @@ export class SqlRetentionStore {
|
|
|
298
344
|
const s = set("scope", 1);
|
|
299
345
|
await conn.query(`SELECT scope FROM file_history_scope WHERE ${s.sql} ORDER BY scope FOR UPDATE`, s.params);
|
|
300
346
|
}
|
|
347
|
+
if (ruleMarks === "drop") {
|
|
348
|
+
for (const table of ["session_policy", "session_policy_rev_mark"]) {
|
|
349
|
+
const s = set("session_id", 1);
|
|
350
|
+
await conn.query(`DELETE FROM ${table} WHERE ${s.sql}`, s.params);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const sealed = await eraseSessionPolicyRowsOn(conn, this.db.dialect, ids);
|
|
355
|
+
if (sealed.length > 0) {
|
|
356
|
+
this.opts.logger?.warn?.(SEALED_EVENT, {
|
|
357
|
+
sessionIds: ids,
|
|
358
|
+
keys: sealed,
|
|
359
|
+
note: "these rows' counters were unreadable, so the erase could not end their lineage: each key now carries a sealed rev mark and answers every read and write with SessionPolicyError corrupt until an operator unseals its session_policy_rev_mark row in place (USAGE §9.11)",
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
301
363
|
for (const [table, col] of [
|
|
302
|
-
["session_policy", "session_id"],
|
|
303
|
-
["session_policy_rev_mark", "session_id"],
|
|
304
364
|
["file_history_tracked", "scope"],
|
|
305
365
|
["file_history_version", "scope"],
|
|
306
366
|
["file_history_boundary", "scope"],
|
|
@@ -311,6 +371,11 @@ export class SqlRetentionStore {
|
|
|
311
371
|
const s = set(col, 1);
|
|
312
372
|
await conn.query(`DELETE FROM ${table} WHERE ${s.sql}`, s.params);
|
|
313
373
|
}
|
|
374
|
+
if (this.opts.sessionBoxScope !== undefined) {
|
|
375
|
+
const scope = this.opts.sessionBoxScope(domain === "" ? null : domain);
|
|
376
|
+
for (const id of ids)
|
|
377
|
+
await dropMailboxBoxOn(conn, this.db.dialect, scope, peerSessionBoxHandle(id));
|
|
378
|
+
}
|
|
314
379
|
const s = set("session_id", 1);
|
|
315
380
|
const w = this.domainWhere("owner", domain, 2);
|
|
316
381
|
const metaRes = await conn.query(`DELETE FROM session_meta WHERE ${s.sql} AND ${w.sql}`, [...s.params, ...w.params]);
|