@bitkyc08/opencodex 2.100.5 → 2.100.6-preview.20261119.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/ocx.mjs +2 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +1 -0
- package/gui/dist/assets/App-D5qUBOoF.js +60 -0
- package/gui/dist/assets/Tray-DMwQSAli.js +1 -0
- package/gui/dist/assets/brand-mark-ycThul7d.js +1 -0
- package/gui/dist/assets/index-Bp_GaFFu.js +138 -0
- package/gui/dist/assets/index-BtwVlpeQ.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-Bquysdn5.js → segment-thumb-features-BLUW2Fb1.js} +1 -1
- package/gui/dist/classic/assets/App-CoiVLRW3.css +1 -0
- package/gui/dist/classic/assets/App-D39mkP2w.js +59 -0
- package/gui/dist/classic/assets/Tray-nUmdL7K9.js +1 -0
- package/gui/dist/classic/assets/index-BJ4uxZk0.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-DFoYm2RY.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +62 -0
- package/native/ocx-child/Cargo.toml +1 -0
- package/native/ocx-child/src/journal.rs +32 -10
- package/native/ocx-child/src/state.rs +2 -1
- package/native/ocx-child/src/toml_surgeon.rs +183 -72
- package/package.json +2 -2
- package/src/adapters/agy-acp/acp.ts +202 -0
- package/src/adapters/agy-acp/adapter.ts +554 -0
- package/src/adapters/agy-acp/binary.ts +79 -0
- package/src/adapters/agy-acp/options.ts +163 -0
- package/src/adapters/agy-acp/output-redaction.ts +270 -0
- package/src/adapters/agy-acp/policy.ts +105 -0
- package/src/adapters/agy-acp/process.ts +218 -0
- package/src/adapters/anthropic/account-metadata.ts +4 -1
- package/src/adapters/anthropic/advisor-tool.ts +43 -9
- package/src/adapters/anthropic/client-identity.ts +2 -0
- package/src/adapters/anthropic.ts +102 -14
- package/src/adapters/antigravity-refusal.ts +5 -1
- package/src/adapters/base.ts +25 -2
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/claude-cli/usage-admission.ts +12 -9
- package/src/adapters/codebuddy/adapter.ts +1 -0
- package/src/adapters/command-code.ts +2 -2
- package/src/adapters/cursor/http1-bidi.ts +7 -2
- package/src/adapters/cursor/live-transport.ts +2 -0
- package/src/adapters/cursor/request-builder.ts +4 -4
- package/src/adapters/cursor/tool-naming.ts +5 -5
- package/src/adapters/cursor/transport-retry.ts +14 -8
- package/src/adapters/cursor/transport.ts +2 -0
- package/src/adapters/cursor.ts +8 -2
- package/src/adapters/google-error-details.ts +105 -0
- package/src/adapters/google-errors.ts +183 -31
- package/src/adapters/google-http.ts +66 -22
- package/src/adapters/google-truncation.ts +48 -3
- package/src/adapters/google-vertex-endpoint.ts +12 -1
- package/src/adapters/google.ts +54 -26
- package/src/adapters/kiro/adapter.ts +39 -38
- package/src/adapters/kiro/stream.ts +59 -9
- package/src/adapters/kiro-retry.ts +5 -3
- package/src/adapters/m365-copilot/LICENSE +21 -0
- package/src/adapters/m365-copilot/fenced.ts +745 -0
- package/src/adapters/m365-copilot/images.ts +89 -0
- package/src/adapters/m365-copilot/tools.ts +284 -0
- package/src/adapters/m365-copilot/transport.ts +232 -0
- package/src/adapters/m365-copilot.ts +143 -0
- package/src/adapters/openai-chat/tool-schema.ts +2 -2
- package/src/adapters/openai-responses/passthrough.ts +1 -0
- package/src/adapters/openai-responses/reasoning.ts +23 -3
- package/src/adapters/physical-send.ts +11 -4
- package/src/adapters/qoder/adapter.ts +17 -3
- package/src/adapters/registry.ts +15 -1
- package/src/adapters/zed.ts +2 -1
- package/src/advisor/consult.ts +1 -0
- package/src/bridge/response-json.ts +6 -2
- package/src/bridge/sse.ts +21 -9
- package/src/chat/inbound.ts +11 -8
- package/src/chat/outbound.ts +28 -7
- package/src/claude/context-windows.ts +32 -8
- package/src/claude/desktop-3p.ts +18 -14
- package/src/claude/desktop-picker-platform.ts +1 -1
- package/src/claude/desktop-picker.ts +3 -3
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +17 -5
- package/src/claude/intercept/picker-ca.ts +162 -27
- package/src/claude/intercept/picker-trust-linux.ts +411 -0
- package/src/claude/intercept/picker-trust.ts +35 -3
- package/src/claude/intercept/runtime.ts +2 -2
- package/src/claude/subagent-force-status.ts +24 -5
- package/src/claude/subscription-reserve.ts +87 -0
- package/src/cli/account-api.ts +3 -0
- package/src/cli/account-auth.ts +65 -11
- package/src/cli/account-extended.ts +1 -1
- package/src/cli/account-next-actions.ts +4 -1
- package/src/cli/account-policy-dto.ts +1 -1
- package/src/cli/account-policy.ts +6 -3
- package/src/cli/account-probe.ts +66 -0
- package/src/cli/account.ts +8 -2
- package/src/cli/capabilities-accounts.ts +8 -1
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +4 -4
- package/src/cli/capabilities-integrations.ts +44 -4
- package/src/cli/capabilities-provider-models.ts +6 -0
- package/src/cli/claude-context-settings.ts +60 -0
- package/src/cli/claude-desktop.ts +2 -2
- package/src/cli/claude.ts +15 -7
- package/src/cli/client-start-fence.ts +64 -1
- package/src/cli/combo-result.ts +1 -0
- package/src/cli/combo-stats.ts +1 -1
- package/src/cli/combo.ts +19 -2
- package/src/cli/config-command.ts +21 -8
- package/src/cli/connect.ts +16 -0
- package/src/cli/cross-home-owner.ts +65 -18
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/gateway-client-command.ts +128 -0
- package/src/cli/index.ts +98 -97
- package/src/cli/init.ts +20 -4
- package/src/cli/integrations.ts +23 -3
- package/src/cli/launcher-context.ts +12 -1
- package/src/cli/link.ts +24 -5
- package/src/cli/models-runtime-subcommands.ts +1 -0
- package/src/cli/models-runtime.ts +32 -0
- package/src/cli/start-owner-fence.ts +5 -2
- package/src/cli/status.ts +3 -3
- package/src/cli/stop-client-process.ts +51 -0
- package/src/cli/stop-restore.ts +383 -36
- package/src/cli/sync-command.ts +2 -2
- package/src/cli/uninstall-client-state.ts +7 -0
- package/src/client/connect.ts +72 -13
- package/src/client/hub-client.ts +38 -0
- package/src/client/hub-relay.ts +61 -36
- package/src/client/hub-session.ts +106 -0
- package/src/client/lifecycle-lock.ts +6 -1
- package/src/client/link-relay.ts +2 -1
- package/src/client/machine-listener.ts +60 -1
- package/src/client/runtime-restart.ts +1 -0
- package/src/client/runtime.ts +104 -34
- package/src/client/state.ts +11 -0
- package/src/client/stop-darwin-process.ts +73 -0
- package/src/client/stop-file-routing.ts +49 -0
- package/src/client/stop-native-handoff.ts +108 -0
- package/src/client/stop-routing.ts +41 -7
- package/src/client/stop-teardown-owner.ts +173 -0
- package/src/client/sync-runtime.ts +23 -4
- package/src/clients/config-export/opencode-wire.ts +24 -0
- package/src/clients/config-export.ts +28 -19
- package/src/codex/auth-api/login-flow.ts +68 -33
- package/src/codex/auth-api/main-account-probe.ts +3 -3
- package/src/codex/auth-api/pool-quota-probe.ts +8 -7
- package/src/codex/auth-api/routes.ts +1 -1
- package/src/codex/catalog/aggregation.ts +22 -10
- package/src/codex/catalog/gather-capture.ts +11 -2
- package/src/codex/catalog/m365-copilot-models.ts +52 -0
- package/src/codex/catalog/provider-models.ts +126 -53
- package/src/codex/catalog/routed-gather.ts +26 -12
- package/src/codex/catalog-admission.ts +4 -6
- package/src/codex/catalog-auto-refresh.ts +4 -2
- package/src/codex/catalog-self-heal.ts +4 -2
- package/src/codex/control-plane-models.ts +6 -0
- package/src/codex/convergence.ts +10 -0
- package/src/codex/desktop-app/picker-freshness.ts +3 -14
- package/src/codex/desktop-app/types.ts +6 -0
- package/src/codex/desktop-app/windows-command-payload.ts +9 -0
- package/src/codex/desktop-app/windows.ts +20 -12
- package/src/codex/desktop-compatibility/installed-build.ts +61 -58
- package/src/codex/desktop-compatibility/runtime-ownership.ts +11 -5
- package/src/codex/desktop-compatibility/runtime.ts +51 -14
- package/src/codex/desktop-compatibility/windows-activation-source.ts +28 -13
- package/src/codex/desktop-compatibility/windows-package-command.ts +73 -33
- package/src/codex/desktop-compatibility/windows-package-launch.ts +41 -9
- package/src/codex/desktop-compatibility/windows-package-proof.ts +104 -0
- package/src/codex/inject/config-toml.ts +67 -73
- package/src/codex/inject/plan.ts +11 -10
- package/src/codex/inject/remove.ts +4 -1
- package/src/codex/inject.ts +1 -0
- package/src/codex/journal-config-restore.ts +31 -4
- package/src/codex/journal.ts +16 -4
- package/src/codex/model-cache.ts +98 -27
- package/src/codex/native-residue.ts +14 -13
- package/src/codex/paths.ts +65 -28
- package/src/codex/quota-observation-freshness.ts +4 -0
- package/src/codex/quota.ts +71 -8
- package/src/codex/routing/selection.ts +32 -8
- package/src/combos/capability-policy.ts +31 -0
- package/src/combos/failover.ts +82 -74
- package/src/combos/identifiers.ts +2 -2
- package/src/combos/index.ts +3 -0
- package/src/combos/jev-model-backend.ts +12 -4
- package/src/combos/jev-session-pin-config.ts +22 -9
- package/src/combos/jev.ts +15 -4
- package/src/combos/request-capability.ts +214 -0
- package/src/combos/request.ts +22 -15
- package/src/combos/resolve.ts +5 -2
- package/src/combos/suggestion-channel.ts +89 -0
- package/src/combos/types.ts +14 -1
- package/src/config/account-auto-pause-revisions.ts +33 -10
- package/src/config/atomic-write.ts +1 -1
- package/src/config/codex-ws-incremental-setting.ts +34 -0
- package/src/config/diagnostics.ts +47 -8
- package/src/config/live-topology.ts +4 -2
- package/src/config/load-degrade.ts +96 -2
- package/src/config/mutation-lock.ts +7 -3
- package/src/config/paths.ts +3 -0
- package/src/config/pending-teardown.ts +19 -3
- package/src/config/process-state.ts +30 -12
- package/src/config/provider-validation.ts +10 -0
- package/src/config/salvage.ts +2 -2
- package/src/config/schema/account-auto-pause.ts +15 -1
- package/src/config/schema/agy-acp-references.ts +257 -0
- package/src/config/schema/config-schema.ts +32 -0
- package/src/config/schema/leaf-validators.ts +42 -0
- package/src/config/schema/subscription-reserve.ts +33 -0
- package/src/config/windows-process-command-line.ts +27 -9
- package/src/config.ts +6 -0
- package/src/generated/compatibility-version.json +806 -402
- package/src/images/loop.ts +79 -39
- package/src/integrations/catalog-refresh.ts +19 -1
- package/src/integrations/gateway-clients/agy.ts +340 -0
- package/src/integrations/gateway-clients/antigravity.ts +224 -0
- package/src/integrations/gateway-clients/index.ts +89 -0
- package/src/integrations/gateway-clients/io.ts +278 -0
- package/src/integrations/gateway-clients/types.ts +80 -0
- package/src/integrations/route-intent-disconnect.ts +37 -21
- package/src/lib/app-owned-memory-stores.ts +9 -0
- package/src/lib/cloud-code-appeal-link.ts +30 -0
- package/src/lib/errors.ts +32 -0
- package/src/lib/executor-physical-send-receipt.ts +42 -0
- package/src/lib/failure-detail.ts +1 -0
- package/src/lib/gcp-adc.ts +5 -0
- package/src/lib/http-date.ts +91 -0
- package/src/lib/lab-passive-linker-registration.ts +2 -1
- package/src/lib/local-chat-completion.ts +13 -3
- package/src/lib/local-internal-call-capability.ts +1 -3
- package/src/lib/messages-error-body.ts +2 -1
- package/src/lib/outbound-credential-registry.ts +40 -4
- package/src/lib/pinned-http.ts +7 -2
- package/src/lib/process-control.ts +1 -0
- package/src/lib/provider-egress.ts +16 -0
- package/src/lib/provider-outbound.ts +3 -0
- package/src/lib/redact-folding.ts +12 -3
- package/src/lib/redact.ts +37 -19
- package/src/lib/request-execution-budget.ts +241 -32
- package/src/lib/request-peer-scope.ts +64 -0
- package/src/lib/response-send-readings.ts +41 -0
- package/src/lib/state-store-registrations.ts +5 -0
- package/src/lib/tool-envelope-echo-filter.ts +33 -5
- package/src/lib/upstream-condition.ts +10 -3
- package/src/lib/upstream-retry.ts +95 -20
- package/src/lib/windows-secret-acl.ts +24 -7
- package/src/link/child-activity.ts +60 -4
- package/src/link/codex-settings.ts +2 -1
- package/src/link/relay-auth.ts +1 -0
- package/src/link/route-rounds.ts +32 -9
- package/src/link/status-projection.ts +42 -5
- package/src/link/supervisor.ts +96 -11
- package/src/link/tunnel-history.ts +5 -0
- package/src/oauth/account-auto-pause-policy.ts +72 -19
- package/src/oauth/account-auto-pause.ts +40 -16
- package/src/oauth/anthropic-account-refusal.ts +7 -0
- package/src/oauth/anthropic-continuity.ts +70 -9
- package/src/oauth/anthropic-identity.ts +75 -11
- package/src/oauth/anthropic-login-slot.ts +258 -0
- package/src/oauth/anthropic-routing.ts +24 -9
- package/src/oauth/anthropic-send-ownership.ts +4 -3
- package/src/oauth/anthropic.ts +30 -11
- package/src/oauth/health.ts +7 -2
- package/src/oauth/index.ts +50 -48
- package/src/oauth/key-providers.ts +2 -0
- package/src/oauth/login-cli.ts +11 -0
- package/src/oauth/login-flow-state.ts +10 -4
- package/src/oauth/m365-copilot-browser.ts +222 -0
- package/src/oauth/m365-copilot-web-session.ts +25 -0
- package/src/oauth/m365-copilot.ts +57 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/plan.ts +44 -0
- package/src/oauth/pool-kernel.ts +22 -8
- package/src/oauth/pool-settings-capability.ts +14 -3
- package/src/oauth/reauth-precheck.ts +27 -0
- package/src/oauth/store-anthropic-instance.ts +3 -1
- package/src/oauth/store.ts +121 -23
- package/src/oauth/types.ts +27 -2
- package/src/protocols/codecs/chat-ir.ts +7 -4
- package/src/protocols/codecs/gemini-interactions.ts +770 -0
- package/src/protocols/codecs/gemini.ts +470 -0
- package/src/protocols/contract.ts +2 -0
- package/src/protocols/encoders/adapter-events.ts +5 -3
- package/src/protocols/encoders/chat.ts +23 -7
- package/src/protocols/settings.ts +3 -0
- package/src/providers/account-quota-disk.ts +26 -8
- package/src/providers/api-key-pause.ts +2 -2
- package/src/providers/api-key-response-ownership.ts +14 -4
- package/src/providers/claude-cli-usage-state.ts +1 -0
- package/src/providers/claude-cli-usage.ts +24 -7
- package/src/providers/default-aliases.ts +11 -5
- package/src/providers/derive.ts +5 -1
- package/src/providers/fastwire.ts +6 -5
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/google-vertex-location.ts +2 -1
- package/src/providers/google-vertex-model-discovery.ts +22 -0
- package/src/providers/key-failover.ts +18 -23
- package/src/providers/m365-copilot-discovery-fetch.ts +17 -0
- package/src/providers/m365-copilot-discovery.ts +68 -0
- package/src/providers/m365-copilot-models.ts +32 -0
- package/src/providers/model-rename-fields.ts +6 -0
- package/src/providers/new-model-policy-runtime.ts +27 -6
- package/src/providers/openai-forward-destination.ts +19 -0
- package/src/providers/openai-tiers-destination.ts +3 -19
- package/src/providers/quota/account-cache.ts +183 -27
- package/src/providers/quota/anthropic-account-quota.ts +21 -17
- package/src/providers/quota/anthropic-cooldown-recovery.ts +57 -27
- package/src/providers/quota/anthropic-decision-windows.ts +7 -3
- package/src/providers/quota/anthropic-usage-windows.ts +34 -4
- package/src/providers/quota/antigravity-account-probe.ts +165 -0
- package/src/providers/quota/antigravity.ts +71 -3
- package/src/providers/quota/vendor-probes-oauth.ts +52 -28
- package/src/providers/quota-decision-publication.ts +1 -1
- package/src/providers/quota-decision-snapshot.ts +4 -1
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +8 -7
- package/src/providers/registry/agy-acp-models.ts +3 -0
- package/src/providers/registry/entries-core.ts +9 -0
- package/src/providers/registry/entries-extended.ts +60 -0
- package/src/providers/registry/model-seeds.ts +51 -0
- package/src/providers/request-pacing.ts +37 -7
- package/src/providers/service-tier.ts +2 -0
- package/src/providers/xai-privacy-mode.ts +52 -0
- package/src/remote/hub-management-relay.ts +74 -0
- package/src/responses/id-limits.ts +2 -0
- package/src/responses/input-media.ts +15 -3
- package/src/responses/parser-tools.ts +74 -11
- package/src/responses/parser.ts +16 -14
- package/src/responses/provider-opaque-metadata.ts +10 -0
- package/src/responses/reasoning-envelope.ts +3 -0
- package/src/responses/schema.ts +2 -3
- package/src/responses/spill-store.ts +5 -3
- package/src/responses/state/connection-scope.ts +232 -0
- package/src/responses/state/entry-types.ts +47 -0
- package/src/responses/state/snapshot-codec.ts +75 -14
- package/src/responses/state/snapshot-select.ts +2 -0
- package/src/responses/state/spill-codec.ts +59 -0
- package/src/responses/state/spill-queue.ts +11 -2
- package/src/responses/state.ts +178 -159
- package/src/router.ts +2 -6
- package/src/routing/compatibility/behavior.ts +6 -2
- package/src/routing/compatibility/subject.ts +17 -12
- package/src/routing/machine-weighted-routing.ts +58 -0
- package/src/server/advisor-admission-scope.ts +15 -7
- package/src/server/auth-cors.ts +27 -0
- package/src/server/chat-completions.ts +37 -17
- package/src/server/chat-native-eligibility.ts +21 -0
- package/src/server/chat-native.ts +15 -6
- package/src/server/claude-messages.ts +54 -6
- package/src/server/credential-recovery-attempt.ts +32 -0
- package/src/server/effort-policy.ts +6 -3
- package/src/server/gemini-inbound.ts +267 -0
- package/src/server/gemini-interactions-inbound.ts +229 -0
- package/src/server/gemini-interactions-store.ts +129 -0
- package/src/server/gemini-native-catalog.ts +64 -0
- package/src/server/gemini-native-log.ts +33 -0
- package/src/server/gemini-native-paths.ts +88 -0
- package/src/server/gemini-native-wire.ts +201 -0
- package/src/server/gemini-native.ts +218 -0
- package/src/server/grok-upstream-envelope-echo.ts +8 -2
- package/src/server/hub-relay-auth.ts +87 -0
- package/src/server/hub-usage-windows.ts +135 -0
- package/src/server/hub-usage.ts +16 -3
- package/src/server/inbound-body-admission.ts +2 -1
- package/src/server/index/anthropic-model-listing.ts +75 -0
- package/src/server/index/gemini-routes.ts +147 -0
- package/src/server/index/link-management.ts +3 -22
- package/src/server/index/link-relay-sessions.ts +71 -13
- package/src/server/index/link-websocket.ts +2 -0
- package/src/server/index/passive-management-read.ts +55 -0
- package/src/server/index/serve-options.ts +93 -107
- package/src/server/index/websocket-handler.ts +15 -2
- package/src/server/index.ts +10 -0
- package/src/server/inference/client-encoder-delivery.ts +2 -1
- package/src/server/inference/context.ts +33 -6
- package/src/server/management/agent-settings-routes.ts +33 -16
- package/src/server/management/claude-code-settings-patch.ts +6 -0
- package/src/server/management/combo-routes.ts +21 -1
- package/src/server/management/combo-suggestion-routes.ts +212 -0
- package/src/server/management/config-routes.ts +12 -4
- package/src/server/management/context.ts +2 -0
- package/src/server/management/gateway-client-routes.ts +62 -0
- package/src/server/management/integration-routes.ts +5 -0
- package/src/server/management/link-routes.ts +5 -1
- package/src/server/management/m365-copilot-provider-probe.ts +23 -0
- package/src/server/management/model-routes.ts +32 -2
- package/src/server/management/model-rows.ts +36 -3
- package/src/server/management/oauth-account-routes.ts +68 -15
- package/src/server/management/protocol-settings-patch.ts +1 -0
- package/src/server/management/provider-omitted-fields.ts +25 -0
- package/src/server/management/provider-overwrite-carry.ts +33 -8
- package/src/server/management/provider-routes.ts +10 -16
- package/src/server/management/request-history-routes.ts +2 -2
- package/src/server/management/route-registry.ts +10 -0
- package/src/server/management/shared.ts +118 -30
- package/src/server/management/sibling-guard.ts +2 -1
- package/src/server/management/system-routes.ts +6 -0
- package/src/server/management-auth.ts +8 -1
- package/src/server/messages-native-scope.ts +19 -0
- package/src/server/messages-native.ts +156 -59
- package/src/server/messages-shared.ts +6 -0
- package/src/server/models-capabilities.ts +24 -0
- package/src/server/native-chat-bridge.ts +259 -0
- package/src/server/ollama-inbound.ts +36 -184
- package/src/server/passive-route-linker.ts +3 -1
- package/src/server/port-reclaim.ts +48 -4
- package/src/server/proxy-liveness.ts +79 -22
- package/src/server/relay.ts +16 -9
- package/src/server/request-log-account-rotation.ts +2 -1
- package/src/server/request-log-attempt-recovery.ts +24 -2
- package/src/server/request-log-attempt-usage.ts +5 -4
- package/src/server/request-log-committed-terminal.ts +87 -0
- package/src/server/request-log-failure-attribution.ts +3 -3
- package/src/server/request-log-failure-detail.ts +34 -0
- package/src/server/request-log-key-failure.ts +27 -0
- package/src/server/request-log-terminal-status.ts +25 -12
- package/src/server/request-log.ts +59 -63
- package/src/server/responses/adapter-continuation.ts +77 -44
- package/src/server/responses/adapter-delivery.ts +47 -22
- package/src/server/responses/adapter-dispatch.ts +150 -149
- package/src/server/responses/advisor-retention.ts +12 -4
- package/src/server/responses/advisor-slot.ts +97 -2
- package/src/server/responses/agent-task-recovery.ts +44 -11
- package/src/server/responses/agy-acp-preflight.ts +41 -0
- package/src/server/responses/anthropic-image-context.ts +44 -0
- package/src/server/responses/antigravity-validation-refusal.ts +25 -1
- package/src/server/responses/buffered-sse-json.ts +18 -1
- package/src/server/responses/codex-ws-correlation.ts +5 -2
- package/src/server/responses/codex-ws-exchange.ts +91 -8
- package/src/server/responses/codex-ws-incremental.ts +136 -0
- package/src/server/responses/codex-ws-pool.ts +22 -8
- package/src/server/responses/codex-ws-request.ts +5 -0
- package/src/server/responses/codex-ws-send-accounting.ts +8 -0
- package/src/server/responses/codex-ws-session.ts +14 -0
- package/src/server/responses/codex-ws-wire.ts +44 -22
- package/src/server/responses/combo-admission-snapshot.ts +93 -0
- package/src/server/responses/combo-required-tool-stream.ts +16 -4
- package/src/server/responses/combo-selection-keepalive.ts +5 -0
- package/src/server/responses/combo-stream-preflight.ts +182 -73
- package/src/server/responses/compact-response-body.ts +27 -0
- package/src/server/responses/compact.ts +174 -121
- package/src/server/responses/compaction-recovery.ts +7 -0
- package/src/server/responses/core-codex-account.ts +88 -62
- package/src/server/responses/core-combo-failure.ts +15 -0
- package/src/server/responses/core-combo-native.ts +12 -1
- package/src/server/responses/core-combo.ts +340 -94
- package/src/server/responses/core-normalize.ts +19 -12
- package/src/server/responses/core-opaque-recovery.ts +15 -4
- package/src/server/responses/core-options.ts +50 -5
- package/src/server/responses/core-pipeline.ts +11 -0
- package/src/server/responses/core.ts +7 -1
- package/src/server/responses/empty-completion-guard.ts +21 -7
- package/src/server/responses/estimated-usage.ts +2 -1
- package/src/server/responses/fetch-helpers.ts +95 -19
- package/src/server/responses/history-slim.ts +204 -0
- package/src/server/responses/hosted-advisor-spend.ts +49 -0
- package/src/server/responses/image-context-recovery.ts +199 -0
- package/src/server/responses/input-admission.ts +36 -11
- package/src/server/responses/jev-model-invoke.ts +23 -16
- package/src/server/responses/non-replayable-error.ts +12 -2
- package/src/server/responses/passthrough-build-error.ts +5 -3
- package/src/server/responses/passthrough-delivery.ts +74 -33
- package/src/server/responses/passthrough-dispatch.ts +170 -197
- package/src/server/responses/policy-fallback.ts +7 -2
- package/src/server/responses/policy-request-scope.ts +36 -2
- package/src/server/responses/replay-owner.ts +20 -0
- package/src/server/responses/request-prepare.ts +97 -16
- package/src/server/responses/request-send-budget.ts +97 -25
- package/src/server/responses/request-sidecar-auth.ts +138 -65
- package/src/server/responses/request-spend-target.ts +13 -1
- package/src/server/responses/request-spend.ts +228 -47
- package/src/server/responses/request-transport.ts +395 -70
- package/src/server/responses/run-turn-execution.ts +40 -9
- package/src/server/responses/sidecar-execution.ts +214 -67
- package/src/server/responses/sidecar-send-budget.ts +9 -9
- package/src/server/responses/terminal-guard.ts +35 -9
- package/src/server/responses/ws-upstream.ts +27 -6
- package/src/server/responses-phase-inference.ts +32 -9
- package/src/server/responses-terminal-repair.ts +14 -35
- package/src/server/system-env.ts +8 -5
- package/src/server/ws-bridge.ts +23 -17
- package/src/service/health-sentinel-linux.ts +16 -7
- package/src/service/systemd.ts +11 -2
- package/src/service/windows-checked-stop-live.ts +60 -55
- package/src/service/windows-checked-stop.ts +29 -11
- package/src/service/windows-guarded-manager.ts +14 -26
- package/src/service/windows-process-evidence.ts +82 -74
- package/src/service/windows-process-native.ts +69 -20
- package/src/service/windows-service-stop.ts +14 -12
- package/src/service/windows-stop-binding.ts +14 -5
- package/src/service/windows-stop-confirm.ts +1 -1
- package/src/service/windows-task-instance-stop.ts +98 -0
- package/src/service/windows-taskxml.ts +30 -7
- package/src/sidecar/anthropic-binding.ts +1 -1
- package/src/stall-timeout.ts +30 -0
- package/src/telemetry/aggregate.ts +6 -3
- package/src/types/account-auto-pause.ts +19 -1
- package/src/types/accounts.ts +21 -0
- package/src/types/anthropic-account-pool.ts +1 -1
- package/src/types/combo-capability-policy.ts +19 -0
- package/src/types/config.ts +22 -2
- package/src/types/provider.ts +42 -8
- package/src/types/request.ts +15 -0
- package/src/types/tools.ts +22 -5
- package/src/types/wire.ts +1 -0
- package/src/types.ts +4 -0
- package/src/update/check-types.ts +2 -0
- package/src/update/job.ts +8 -3
- package/src/update/managed-release.ts +6 -0
- package/src/update/orchestrated-entry.ts +13 -4
- package/src/update/refresh-scheduler.ts +17 -7
- package/src/usage/attempt-delivery.ts +6 -0
- package/src/usage/cache-provenance.ts +71 -0
- package/src/usage/cost.ts +216 -27
- package/src/usage/credit-billing.ts +88 -0
- package/src/usage/jev-stats.ts +13 -9
- package/src/usage/log.ts +5 -33
- package/src/usage/summary.ts +8 -43
- package/src/usage/user-cost-overlays.ts +13 -1
- package/src/vision/index.ts +8 -3
- package/src/vision/plan.ts +28 -14
- package/src/vision/routed-describe.ts +24 -36
- package/src/web-search/header-deadline.ts +14 -3
- package/src/web-search/index.ts +6 -4
- package/src/web-search/loop.ts +240 -78
- package/src/web-search/progress-stream.ts +29 -2
- package/src/web-search/run-turn-loop.ts +5 -1
- package/gui/dist/assets/App-BGP8I0V4.css +0 -1
- package/gui/dist/assets/App-BRExzhwL.js +0 -60
- package/gui/dist/assets/Tray-DHCWAn8V.js +0 -1
- package/gui/dist/assets/brand-mark-C70PuQ3j.js +0 -1
- package/gui/dist/assets/index-DJxM-imn.css +0 -2
- package/gui/dist/assets/index-Dy1jIGty.js +0 -138
- package/gui/dist/classic/assets/App-B4j-Txmb.css +0 -1
- package/gui/dist/classic/assets/App-CaC-E6Vl.js +0 -59
- package/gui/dist/classic/assets/Tray-BG253fiL.js +0 -1
- package/gui/dist/classic/assets/index-CR_AThOp.js +0 -138
- package/gui/dist/classic/assets/quota-summary-B7KQPpEC.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ServiceChildOwnershipDecision } from "../service/service-child-ownership";
|
|
2
2
|
import { removePidIfValueIs } from "../config/process-state";
|
|
3
3
|
import { observeProxyLiveness, START_OWNERSHIP_LIVENESS, type LiveProxy } from "../server/proxy-liveness";
|
|
4
|
-
import { markCrossHomeSibling, reconcileStartupJournal } from "./cross-home-owner";
|
|
4
|
+
import { hasLiveStartupJournalOwner, markCrossHomeSibling, reconcileStartupJournal } from "./cross-home-owner";
|
|
5
5
|
|
|
6
6
|
/** Called only under the ownership lease; a negative early probe grants no mutation authority. */
|
|
7
7
|
export async function recoverStartJournalAfterOwnerRecheck(
|
|
@@ -14,8 +14,11 @@ export async function recoverStartJournalAfterOwnerRecheck(
|
|
|
14
14
|
if (observation.kind !== "absent") {
|
|
15
15
|
throw new Error("Proxy ownership is unverified; startup refused. PID record and recovery journal were preserved. Retry when the owner can be verified.");
|
|
16
16
|
}
|
|
17
|
-
removePidIfValueIs(owner.pidSnapshot);
|
|
18
17
|
if (!sibling) sibling = await markCrossHomeSibling();
|
|
18
|
+
if (!sibling && observation.loopbackBindProven && hasLiveStartupJournalOwner()) {
|
|
19
|
+
throw new Error("Proxy ownership is unverified; startup refused. A live process still owns the recovery journal.");
|
|
20
|
+
}
|
|
21
|
+
removePidIfValueIs(owner.pidSnapshot);
|
|
19
22
|
if (!sibling) reconcileStartupJournal();
|
|
20
23
|
return sibling;
|
|
21
24
|
}
|
package/src/cli/status.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { inspectDesktopSupervision } from "../service/desktop-supervision.mjs";
|
|
|
12
12
|
import { collectStartupHealth, startupHealthReadBudgetMs, type StartupHealth } from "../codex/autostart-health";
|
|
13
13
|
import { getCodexRoutingKind } from "../codex/inject";
|
|
14
14
|
import { missingOwnedCatalogPath } from "../codex/inject/config-toml";
|
|
15
|
-
import { CODEX_CONFIG_PATH } from "../codex/paths";
|
|
15
|
+
import { CODEX_CONFIG_PATH, activeCodexConfigPath } from "../codex/paths";
|
|
16
16
|
import { diagnoseCodexShim } from "../codex/shim";
|
|
17
17
|
import { displayCodexRuntimePath, effortClampAppliesToRuntime, liveRemovedEfforts, loadLastEffortClamp, resolveCodexRuntime } from "../codex/runtime";
|
|
18
18
|
import { packageVersion } from "./help";
|
|
@@ -833,8 +833,8 @@ export function statusDeadProxyLines(json: StatusRoutingView): string[] {
|
|
|
833
833
|
*/
|
|
834
834
|
export function detectMissingCodexCatalogPath(): string | null {
|
|
835
835
|
try {
|
|
836
|
-
|
|
837
|
-
return missingOwnedCatalogPath(readFileSync(
|
|
836
|
+
const configPath = activeCodexConfigPath();
|
|
837
|
+
return missingOwnedCatalogPath(readFileSync(configPath, "utf8"), configPath);
|
|
838
838
|
} catch {
|
|
839
839
|
return null;
|
|
840
840
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isProcessAlive, ProxyOwnershipRefusedError, waitForExit } from "../lib/process-control";
|
|
2
|
+
import { openVerifiedPidfd } from "../service/health-sentinel-linux";
|
|
3
|
+
import { windowsProcessNative } from "../service/windows-process-native";
|
|
4
|
+
import { unsupportedConnectedStop } from "./stop-restore";
|
|
5
|
+
|
|
6
|
+
/** Terminate the attested Child only, including at the escalation and port-reclaim boundaries. */
|
|
7
|
+
export function terminateAttestedClient(pid: number, start: string, verify: (phase?: "after-term") => void): void {
|
|
8
|
+
if (!isProcessAlive(pid)) return;
|
|
9
|
+
verify();
|
|
10
|
+
if (process.platform === "linux") {
|
|
11
|
+
const target = openVerifiedPidfd(pid, () => { verify(); return true; });
|
|
12
|
+
if (target.kind !== "bound") {
|
|
13
|
+
throw new ProxyOwnershipRefusedError(
|
|
14
|
+
`Link Child forced stop refused: could not bind a Linux pidfd (${target.reason}). Use a kernel and environment that permit pidfd operations, or stop a managed Child through its supervisor. Then retry ocx stop to complete restoration.`,
|
|
15
|
+
"connected_client_stop_unsupported",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const { handle } = target;
|
|
19
|
+
try {
|
|
20
|
+
for (const signal of [15, 9] as const) {
|
|
21
|
+
if (!isProcessAlive(pid)) return;
|
|
22
|
+
verify(signal === 9 ? "after-term" : undefined);
|
|
23
|
+
const result = handle.terminate(signal);
|
|
24
|
+
if (result === "not_target") return;
|
|
25
|
+
if (result !== "terminated") throw unsupportedConnectedStop();
|
|
26
|
+
if (waitForExit(pid, 5000)) return;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`process ${pid} did not exit`);
|
|
29
|
+
} finally { handle.close(); }
|
|
30
|
+
}
|
|
31
|
+
if (process.platform === "win32") {
|
|
32
|
+
const ticks = /^win32:(\d{1,20})$/.exec(start)?.[1];
|
|
33
|
+
const native = windowsProcessNative();
|
|
34
|
+
if (!ticks || !native) throw unsupportedConnectedStop();
|
|
35
|
+
const result = native.terminate(pid, BigInt(ticks));
|
|
36
|
+
if (result.status === "gone") return;
|
|
37
|
+
if (result.status !== "terminated") throw unsupportedConnectedStop();
|
|
38
|
+
if (!waitForExit(pid, 5000)) throw new Error(`process ${pid} did not exit`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (process.platform !== "darwin") throw unsupportedConnectedStop();
|
|
42
|
+
// The native macOS Child has no authenticated shutdown endpoint. Keep its
|
|
43
|
+
// orderly signal path, with no numeric-PID escalation after the wait.
|
|
44
|
+
process.kill(pid, "SIGTERM");
|
|
45
|
+
if (waitForExit(pid, 5000)) return;
|
|
46
|
+
verify("after-term");
|
|
47
|
+
throw new ProxyOwnershipRefusedError(
|
|
48
|
+
"Link Child did not exit after SIGTERM. Inspect its foreground terminal for the shutdown refusal or check its supervisor, repair the reported evidence, then retry ocx stop.",
|
|
49
|
+
"connected_client_stop_unsupported",
|
|
50
|
+
);
|
|
51
|
+
}
|
package/src/cli/stop-restore.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
+
import { lstatSync, statSync } from "node:fs";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
1
3
|
import { restoreNativeCodexAsync } from "../codex/inject";
|
|
2
4
|
import type { RetainedCodexProviderTable } from "../codex/inject/restore";
|
|
3
5
|
import { stripGrokConfig } from "../grok/inject";
|
|
4
|
-
import { readClientConnectionState, type ClientConnectionState } from "../client/state";
|
|
6
|
+
import { linkStopConnectionOwner, readClientConnectionState, type ClientConnectionState } from "../client/state";
|
|
5
7
|
import { withClientLifecycleSync } from "../client/lifecycle-lock";
|
|
6
|
-
import type
|
|
8
|
+
import { StopRestoreOwnershipError, type RestoreBoundaryOwnership } from "../client/restore-ownership";
|
|
7
9
|
export type { RestoreBoundaryOwnership } from "../client/restore-ownership";
|
|
8
10
|
import { inspectStopRestoreOwnership, stopRestoreWriteGuard } from "./stop-restore-guard";
|
|
9
11
|
export { clearRestoredStopReceipts, settleUnrestoredStopBoundary } from "./stop-restore-guard";
|
|
10
|
-
import { readPid, readRuntimePort } from "../config/process-state";
|
|
12
|
+
import { isOcxStartCommandLine, readAlivePid, readPid, readProcessCommandLine, readRuntimePort, type ClientStopOwner, type RuntimePortState } from "../config/process-state";
|
|
13
|
+
import { getConfigDir } from "../config/paths";
|
|
14
|
+
import type { OutstandingTeardown } from "../config/pending-teardown";
|
|
15
|
+
import type { LinkInheritedTeardown } from "../client/stop-native-handoff";
|
|
11
16
|
import { loadConfig } from "../config";
|
|
12
17
|
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
18
|
+
import { sameFileIdentity, type FileIdentity } from "../lib/file-identity";
|
|
13
19
|
import { createLocalAttestationChallenge, LOCAL_ATTESTATION_CHALLENGE_HEADER, LOCAL_ATTESTATION_PROOF_HEADER, verifyLocalAttestationProof } from "../lib/local-management-attestation";
|
|
14
20
|
import { LOCAL_MANAGEMENT_READ_PATHS } from "../lib/local-management-capability";
|
|
15
21
|
import { gracefulStopHost, isProcessAlive, ProxyOwnershipRefusedError, stopRequestFetch as directStopRequestFetch } from "../lib/process-control";
|
|
16
22
|
import { directLocalHttpFetch } from "../server/direct-local-http";
|
|
17
23
|
import { fetchBoundLocalManagementRead } from "../server/local-management-read-client";
|
|
18
24
|
import { isSharedTeardownDeferredOnExit } from "../server/stop-teardown";
|
|
19
|
-
import { findLiveProxy,
|
|
20
|
-
import { observeGuardedManagerStopped } from "../service/guarded-manager-target";
|
|
25
|
+
import { findLiveProxy, isPackageTreeFencedHealthz, probeEndpointLiveness } from "../server/proxy-liveness";
|
|
26
|
+
import { inspectGuardedManagerTarget, observeGuardedManagerStopped } from "../service/guarded-manager-target";
|
|
27
|
+
import { assertServiceEnvironmentMatchesInstall } from "../service/guards";
|
|
28
|
+
import { installedServiceListenPort } from "../service/health";
|
|
21
29
|
import type { StartExitTeardown } from "./dispatch";
|
|
22
30
|
import type { StopOutcome } from "./stop-report";
|
|
23
31
|
|
|
@@ -33,16 +41,188 @@ export function preserveConnectedClientRoutingOnExit(teardown: StartExitTeardown
|
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
type ConnectedStopTarget = { pid: number; port: number; hostname?: string };
|
|
44
|
+
export type StopTargetProof = { target: ConnectedStopTarget; verify: () => void; siblingOnly?: true; terminateSibling?: () => void };
|
|
45
|
+
export type LinkStopPreflight = StopTargetProof & { owner: ClientStopOwner; inheritedTeardownDigest?: string; forceKill: (pid: number) => void };
|
|
46
|
+
|
|
36
47
|
const CONNECTED_STOP_PROBE_MS = 2000;
|
|
37
|
-
const unsupportedConnectedStop = () => new ProxyOwnershipRefusedError(
|
|
38
|
-
"Connected-client stop refused: runtime identity, shutdown preservation or safe runtime absence could not be verified. Inspect 'ocx service status'
|
|
48
|
+
export const unsupportedConnectedStop = () => new ProxyOwnershipRefusedError(
|
|
49
|
+
"Connected-client stop refused: runtime identity, saved connection ownership, shutdown preservation or safe runtime absence could not be verified. No process was stopped by this check. Inspect 'ocx service status', repair saved connection ownership or update/restart an incompatible runtime through its supervisor, then retry. Use 'ocx disconnect' only if you intend to release those integrations.",
|
|
39
50
|
"connected_client_stop_unsupported",
|
|
40
51
|
);
|
|
41
52
|
|
|
53
|
+
export function unclassifiedStopTarget(pid: number): ProxyOwnershipRefusedError {
|
|
54
|
+
return new ProxyOwnershipRefusedError(
|
|
55
|
+
`Stop refused: could not verify that live OpenCodex PID ${pid} is standalone. Run 'ocx service status' to identify its supervisor, or check the terminal that started it. Repair its runtime or saved Link records, then retry 'ocx stop'.`,
|
|
56
|
+
"connected_client_stop_unsupported",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function stopOwnershipRefused(error: ProxyOwnershipRefusedError): StopOutcome {
|
|
61
|
+
console.error(error.message);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return { ok: false, summary: { schema: "ocx-stop/1", ok: false, outcome: "failed", exitCode: 1,
|
|
64
|
+
runtimeDown: false, service: "absent", proxy: "ownership-refused", sharedTeardown: "skipped", message: error.message } };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isRegisteredServiceStopTarget(pid: number): boolean {
|
|
68
|
+
try {
|
|
69
|
+
assertServiceEnvironmentMatchesInstall();
|
|
70
|
+
const manager = inspectGuardedManagerTarget(pid, installedServiceListenPort());
|
|
71
|
+
return (manager.kind === "bound" || manager.kind === "bound-stray") && manager.pid === pid;
|
|
72
|
+
} catch { return false; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function legacyLinkStopRefusal(): ProxyOwnershipRefusedError {
|
|
76
|
+
return new ProxyOwnershipRefusedError(
|
|
77
|
+
"Connected-client stop refused: this older Link Child has no stop fence. No process was stopped. To update/restart while keeping the Home connection: close Codex, Grok and other routed clients. Stop the old owner: press Ctrl+C in its foreground terminal, use Stop and quit its Desktop supervisor, or run the old installation's 'ocx stop' for a background service (including Task Scheduler). Once it is down, run the current installation's 'ocx stop' with the same OPENCODEX_HOME and client homes to clean up file routes. Keep clients closed until cleanup succeeds. Then run 'ocx start' (or 'ocx service start' for an installed service, or open the updated Desktop app) and run 'ocx sync --restart-codex'.",
|
|
78
|
+
"connected_client_stop_unsupported",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function verifyConnectedStopTarget(
|
|
83
|
+
proof: StopTargetProof | undefined, linkStop: LinkStopPreflight | undefined, pid?: number,
|
|
84
|
+
): void {
|
|
85
|
+
const state = readClientConnectionState();
|
|
86
|
+
if (state.kind === "invalid" || state.kind === "mismatched") throw unsupportedConnectedStop();
|
|
87
|
+
if (pid !== undefined && pid !== proof?.target.pid) throw unsupportedConnectedStop();
|
|
88
|
+
if (state.kind === "connected" && state.value.transport === "link" && !linkStop && !proof?.siblingOnly) throw unsupportedConnectedStop();
|
|
89
|
+
if (proof && isProcessAlive(proof.target.pid)) proof.verify();
|
|
90
|
+
const currentPid = readAlivePid();
|
|
91
|
+
if (currentPid !== null && currentPid !== proof?.target.pid) throw unsupportedConnectedStop();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function hasClientRuntimeEvidence(runtime: RuntimePortState): boolean {
|
|
95
|
+
return runtime.role === "client" || runtime.clientLinkOwner !== undefined || runtime.servingGeneration !== undefined
|
|
96
|
+
|| runtime.clientStopping === true || runtime.clientStopOwner !== undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A discovery miss cannot establish the role of a live tracked process. */
|
|
100
|
+
export async function classifyStopRole(
|
|
101
|
+
connection: ClientConnectionState, runtime: RuntimePortState | null, receipts: readonly OutstandingTeardown[],
|
|
102
|
+
): Promise<"connected" | "standalone" | "unknown"> {
|
|
103
|
+
const sibling = runtime?.siblingOfPort;
|
|
104
|
+
if (connection.kind === "connected" && (connection.value.transport === "link" || sibling === undefined)) return "connected";
|
|
105
|
+
if (connection.kind === "mismatched" || receipts.some(read => read.state === "valid" && read.receipt.ownerStartTime !== undefined)) return "connected";
|
|
106
|
+
const { readRouteIntentReceipt } = await import("../integrations/route-intent-state");
|
|
107
|
+
if (readRouteIntentReceipt()?.linkId !== undefined) return "connected";
|
|
108
|
+
if (runtime && isProcessAlive(runtime.pid)) {
|
|
109
|
+
if (hasClientRuntimeEvidence(runtime)) return "connected";
|
|
110
|
+
if (runtime.attestationSecret) {
|
|
111
|
+
const capability = await assertConnectedClientStopSupported(runtime, { healthOnly: true }).catch(() => null);
|
|
112
|
+
if (capability) return capability.linkStopFence || capability.nativeClient ? "connected" : "standalone";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Classification needs only the reported role. The preflight must verify identity itself.
|
|
116
|
+
const live = await findLiveProxy({ attempts: 1, verifyPidFn: () => null }).catch(() => null);
|
|
117
|
+
return live?.role === "client" && live.port !== sibling ? "connected" : "unknown";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function readStopDirectoryIdentity(path: string | undefined): FileIdentity | undefined {
|
|
121
|
+
if (!path) return;
|
|
122
|
+
try {
|
|
123
|
+
const stat = statSync(path, { bigint: true });
|
|
124
|
+
if (stat.isDirectory()) return stat;
|
|
125
|
+
} catch { /* An unreadable directory cannot establish identity. */ }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Called after role discovery yields no affirmative result. Never adopts an orphan PID. */
|
|
129
|
+
export async function proveStandaloneStopRecord(
|
|
130
|
+
runtime: RuntimePortState | null, pid: number, receipts: readonly OutstandingTeardown[],
|
|
131
|
+
): Promise<(() => void) | undefined> {
|
|
132
|
+
if (runtime?.pid !== pid || hasClientRuntimeEvidence(runtime)
|
|
133
|
+
|| receipts.some(read => read.state !== "valid" || read.receipt.ownerStartTime !== undefined)) return;
|
|
134
|
+
const { readRouteIntentReceiptStrict } = await import("../integrations/route-intent-state");
|
|
135
|
+
const hasNoLinkReceipt = () => {
|
|
136
|
+
try { return readRouteIntentReceiptStrict()?.linkId === undefined; } catch { return false; }
|
|
137
|
+
};
|
|
138
|
+
if (!hasNoLinkReceipt()) return;
|
|
139
|
+
const { isLegacyWindowsStartCommandLine, readClientStopProcessStart, readLegacyStopProcessHome } = await import("../client/stop-teardown-owner");
|
|
140
|
+
const start = readClientStopProcessStart(pid);
|
|
141
|
+
if (!start) return;
|
|
142
|
+
let legacyHomeIsCurrent: (() => boolean) | undefined;
|
|
143
|
+
if (runtime.startTime !== undefined) {
|
|
144
|
+
if (runtime.startTime !== start) return;
|
|
145
|
+
} else {
|
|
146
|
+
const command = readProcessCommandLine(pid);
|
|
147
|
+
if (!command) return;
|
|
148
|
+
const windows = process.platform === "win32";
|
|
149
|
+
// CIM does not expose the environment. Windows uses the SID-checked creation
|
|
150
|
+
// identity above, exact start argv and ownership of the recorded bind instead.
|
|
151
|
+
if (windows) {
|
|
152
|
+
if (!isLegacyWindowsStartCommandLine(command)) return;
|
|
153
|
+
} else {
|
|
154
|
+
if (!isOcxStartCommandLine(command)) return;
|
|
155
|
+
const home = readStopDirectoryIdentity(getConfigDir());
|
|
156
|
+
if (!home) return;
|
|
157
|
+
const matchesHome = (path: string | undefined) => {
|
|
158
|
+
const identity = readStopDirectoryIdentity(path);
|
|
159
|
+
return identity !== undefined && sameFileIdentity(identity, home);
|
|
160
|
+
};
|
|
161
|
+
legacyHomeIsCurrent = () => matchesHome(readLegacyStopProcessHome(pid)) && matchesHome(getConfigDir());
|
|
162
|
+
if (!legacyHomeIsCurrent()) return;
|
|
163
|
+
}
|
|
164
|
+
const { inspectIpv4LoopbackListener, ownsLegacyStopBind, scanListenPidsForAddress } = await import("../server/port-reclaim");
|
|
165
|
+
const bind = runtime.hostname?.trim().replace(/^\[(.*)\]$/, "$1");
|
|
166
|
+
const wildcard = bind === "0.0.0.0" || bind === "::";
|
|
167
|
+
const address = windows || wildcard
|
|
168
|
+
? (bind && bind.toLowerCase() !== "localhost" ? bind : "127.0.0.1")
|
|
169
|
+
: gracefulStopHost(runtime.hostname).replace(/^\[(.*)\]$/, "$1");
|
|
170
|
+
if (windows || wildcard) {
|
|
171
|
+
if (!await ownsLegacyStopBind(runtime.port, pid, address)) return;
|
|
172
|
+
} else if (address === "127.0.0.1") {
|
|
173
|
+
if ((await inspectIpv4LoopbackListener(runtime.port, pid)).kind !== "match") return;
|
|
174
|
+
} else {
|
|
175
|
+
const listeners = scanListenPidsForAddress(runtime.port, address);
|
|
176
|
+
if (!listeners.ok || listeners.pids.length !== 1 || listeners.pids[0] !== pid) return;
|
|
177
|
+
}
|
|
178
|
+
if (readClientStopProcessStart(pid) !== start || legacyHomeIsCurrent?.() === false) return;
|
|
179
|
+
}
|
|
180
|
+
return () => {
|
|
181
|
+
if (readClientConnectionState().kind !== "disconnected" || !hasNoLinkReceipt()) throw unsupportedConnectedStop();
|
|
182
|
+
if (isProcessAlive(pid) && (readClientStopProcessStart(pid) !== start
|
|
183
|
+
|| !Bun.deepEquals(readRuntimePort(pid), runtime, true) || legacyHomeIsCurrent?.() === false)) throw unclassifiedStopTarget(pid);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A guessed endpoint can name a standalone teardown obligation but cannot direct POST.
|
|
188
|
+
export function configuredStopEndpoint(): { hostname: string; port: number } {
|
|
189
|
+
try {
|
|
190
|
+
const config = loadConfig();
|
|
191
|
+
return {
|
|
192
|
+
hostname: config.hostname ?? "127.0.0.1",
|
|
193
|
+
port: typeof config.port === "number" && config.port > 0 ? config.port : 10100,
|
|
194
|
+
};
|
|
195
|
+
} catch {
|
|
196
|
+
return { hostname: "127.0.0.1", port: 10100 };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Only a definitive "nothing is answering" authorizes finishing somebody else's
|
|
201
|
+
// abandoned teardown. The tri-state probe distinguishes that from "we could not tell"
|
|
202
|
+
// (timeout, a listener that withholds /healthz), which `findLiveProxy` collapses into
|
|
203
|
+
// the same null (#3008).
|
|
204
|
+
export async function abandonedTeardownIsSafeToFinish(
|
|
205
|
+
endpoint: { hostname: string; port: number } | null,
|
|
206
|
+
): Promise<boolean> {
|
|
207
|
+
// The endpoint has to come from the receipt. A crashed owner usually leaves no
|
|
208
|
+
// runtime-port record, and the configured port is the wrong question for a proxy
|
|
209
|
+
// started with an explicit --port: it refuses while the live one keeps serving.
|
|
210
|
+
// An obligation that cannot name its endpoint cannot be proven discharged.
|
|
211
|
+
if (!endpoint) return false;
|
|
212
|
+
try {
|
|
213
|
+
return await probeEndpointLiveness(endpoint) === "dead";
|
|
214
|
+
} catch {
|
|
215
|
+
// A probe that could not run is not evidence of absence.
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
42
220
|
/** Require the pinned runtime's proof before accepting its shutdown contract. */
|
|
43
|
-
export async function assertConnectedClientStopSupported(
|
|
221
|
+
export async function assertConnectedClientStopSupported(
|
|
222
|
+
target: ConnectedStopTarget | null, options: { requireLinkStopFence?: boolean; healthOnly?: boolean } = {},
|
|
223
|
+
): Promise<{ linkStopFence: boolean; nativeClient: boolean } | null> {
|
|
44
224
|
if (!target) throw unsupportedConnectedStop();
|
|
45
|
-
if (!isProcessAlive(target.pid)) return; // A manager may already have ended this exact target.
|
|
225
|
+
if (!isProcessAlive(target.pid)) return null; // A manager may already have ended this exact target.
|
|
46
226
|
const runtime = readRuntimePort(target.pid);
|
|
47
227
|
if (!runtime?.attestationSecret || runtime.pid !== target.pid || runtime.port !== target.port
|
|
48
228
|
|| gracefulStopHost(runtime.hostname) !== gracefulStopHost(target.hostname)) throw unsupportedConnectedStop();
|
|
@@ -50,13 +230,13 @@ export async function assertConnectedClientStopSupported(target: ConnectedStopTa
|
|
|
50
230
|
const readPinnedRuntime = () => {
|
|
51
231
|
const current = readRuntimePort(target.pid);
|
|
52
232
|
return current?.pid === runtime.pid && current.port === runtime.port && current.hostname === runtime.hostname
|
|
53
|
-
&& current.attestationSecret === runtime.attestationSecret ? current : null;
|
|
233
|
+
&& current.attestationSecret === runtime.attestationSecret && current.clientLinkOwner === runtime.clientLinkOwner ? current : null;
|
|
54
234
|
};
|
|
55
235
|
const origin = `http://${endpoint.hostname}:${endpoint.port}`;
|
|
56
236
|
const deadline = Date.now() + CONNECTED_STOP_PROBE_MS;
|
|
57
237
|
const signal = AbortSignal.timeout(CONNECTED_STOP_PROBE_MS);
|
|
58
|
-
const readDocument = async (response: Response): Promise<Record<string, unknown> | null> => {
|
|
59
|
-
if (!response.ok) { void response.body?.cancel().catch(() => {}); return null; }
|
|
238
|
+
const readDocument = async (response: Response, allowFenced = false): Promise<Record<string, unknown> | null> => {
|
|
239
|
+
if (!response.ok && !(allowFenced && response.status === 503)) { void response.body?.cancel().catch(() => {}); return null; }
|
|
60
240
|
const body = await readBoundedResponseBody(response, { maxBytes: 4096, signal, fatalUtf8: true });
|
|
61
241
|
if (body.truncated) return null;
|
|
62
242
|
const parsed: unknown = JSON.parse(body.text);
|
|
@@ -72,10 +252,15 @@ export async function assertConnectedClientStopSupported(target: ConnectedStopTa
|
|
|
72
252
|
void response.body?.cancel().catch(() => {});
|
|
73
253
|
throw unsupportedConnectedStop();
|
|
74
254
|
}
|
|
75
|
-
const health = await readDocument(response);
|
|
255
|
+
const health = await readDocument(response, options.healthOnly);
|
|
256
|
+
if (!response.ok && (!health || !isPackageTreeFencedHealthz(health))) throw unsupportedConnectedStop();
|
|
76
257
|
if (!readPinnedRuntime() || health?.service !== "opencodex" || health.pid !== target.pid) throw unsupportedConnectedStop();
|
|
77
|
-
|
|
78
|
-
if (
|
|
258
|
+
const linkStopFence = health.linkStopFence === true;
|
|
259
|
+
if (options.requireLinkStopFence && !linkStopFence) throw unsupportedConnectedStop();
|
|
260
|
+
// A native listener proves its contract on health and has no /api/stop route.
|
|
261
|
+
if (health.role === "client") return { linkStopFence, nativeClient: true };
|
|
262
|
+
if (health.role !== undefined) throw unsupportedConnectedStop();
|
|
263
|
+
if (options.healthOnly) return { linkStopFence, nativeClient: false };
|
|
79
264
|
const remaining = deadline - Date.now();
|
|
80
265
|
if (remaining <= 0) throw unsupportedConnectedStop();
|
|
81
266
|
const read = await fetchBoundLocalManagementRead({ ...endpoint, source: "runtime" }, LOCAL_MANAGEMENT_READ_PATHS.stop, {
|
|
@@ -84,32 +269,48 @@ export async function assertConnectedClientStopSupported(target: ConnectedStopTa
|
|
|
84
269
|
if (read.kind !== "response") throw unsupportedConnectedStop();
|
|
85
270
|
const capability = await readDocument(read.response);
|
|
86
271
|
if (readPinnedRuntime() && capability?.schema === "ocx-stop-capabilities/1"
|
|
87
|
-
&& capability.pid === target.pid && capability.connectedClientOwnership === true) return;
|
|
272
|
+
&& capability.pid === target.pid && capability.connectedClientOwnership === true) return { linkStopFence, nativeClient: false };
|
|
88
273
|
} catch { /* A missing or replaced runtime never grants shutdown authority. */ }
|
|
89
274
|
throw unsupportedConnectedStop();
|
|
90
275
|
}
|
|
91
276
|
|
|
92
277
|
/** Fail before either service-manager path, including a manager that cascades process exit. */
|
|
93
|
-
export async function preflightConnectedClientStop(
|
|
278
|
+
export async function preflightConnectedClientStop(
|
|
279
|
+
approved: ConnectedStopTarget | undefined, onFence: (finish: () => Promise<void>) => void,
|
|
280
|
+
inheritedTeardowns?: readonly LinkInheritedTeardown[],
|
|
281
|
+
onLinkStop?: (preflight: LinkStopPreflight) => void,
|
|
282
|
+
onTarget?: (proof: StopTargetProof) => void,
|
|
283
|
+
siblingOfPort?: number,
|
|
284
|
+
): Promise<StopOutcome | "already-stopped" | null> {
|
|
94
285
|
try {
|
|
286
|
+
const connection = readClientConnectionState();
|
|
287
|
+
if (connection.kind === "invalid" || connection.kind === "mismatched") throw unsupportedConnectedStop();
|
|
95
288
|
let target = approved;
|
|
96
289
|
if (!target) {
|
|
97
|
-
const
|
|
98
|
-
const runtime = readRuntimePort(
|
|
99
|
-
|
|
100
|
-
|
|
290
|
+
const trackedPid = readPid() ?? readAlivePid();
|
|
291
|
+
const runtime = readRuntimePort();
|
|
292
|
+
const pid = trackedPid ?? (runtime?.servingGeneration ? runtime.pid : undefined);
|
|
293
|
+
if (pid && (trackedPid === pid || isProcessAlive(pid))) {
|
|
294
|
+
if (runtime?.pid !== pid) throw unsupportedConnectedStop();
|
|
101
295
|
target = { ...runtime, pid };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (await proveLiveProxyOwnedByHome(live) !== "proven") throw unsupportedConnectedStop();
|
|
296
|
+
} else {
|
|
297
|
+
const live = await findLiveProxy({ acceptPackageTreeFenced: true, attempts: 1 });
|
|
298
|
+
if (live && live.port !== siblingOfPort) {
|
|
299
|
+
if (!live.pid) throw unsupportedConnectedStop();
|
|
107
300
|
target = { ...live, pid: live.pid };
|
|
108
301
|
} else {
|
|
302
|
+
if (runtime && isProcessAlive(runtime.pid)) throw unsupportedConnectedStop();
|
|
109
303
|
const config = loadConfig();
|
|
110
|
-
const endpoints = [...(runtime ? [runtime] : []),
|
|
111
|
-
|
|
112
|
-
|
|
304
|
+
const endpoints = [...(runtime ? [runtime] : []),
|
|
305
|
+
...(config.port === 0 || config.port === siblingOfPort ? [] : [{ port: config.port, hostname: config.hostname }])];
|
|
306
|
+
const clientMayRemain = connection.kind !== "disconnected" || runtime?.clientLinkOwner !== undefined
|
|
307
|
+
|| runtime?.servingGeneration !== undefined;
|
|
308
|
+
const manager = await observeGuardedManagerStopped({ kind: "absent" });
|
|
309
|
+
const offlineForegroundLink = manager === "unknown"
|
|
310
|
+
&& connection.kind === "connected" && connection.value.transport === "link"
|
|
311
|
+
&& (await import("../service/systemd")).systemdInstallationAbsent();
|
|
312
|
+
if ((clientMayRemain && endpoints.length === 0)
|
|
313
|
+
|| (manager !== "inactive" && !offlineForegroundLink)) throw unsupportedConnectedStop();
|
|
113
314
|
for (const endpoint of endpoints) {
|
|
114
315
|
if (await probeEndpointLiveness(endpoint) !== "dead") throw unsupportedConnectedStop();
|
|
115
316
|
}
|
|
@@ -118,14 +319,134 @@ export async function preflightConnectedClientStop(approved?: ConnectedStopTarge
|
|
|
118
319
|
}
|
|
119
320
|
}
|
|
120
321
|
if (!isProcessAlive(target.pid)) throw unsupportedConnectedStop();
|
|
121
|
-
|
|
322
|
+
const stopTarget = target;
|
|
323
|
+
const pinned = readRuntimePort(target.pid);
|
|
324
|
+
const standaloneSibling = siblingOfPort !== undefined && pinned?.siblingOfPort === siblingOfPort
|
|
325
|
+
&& pinned.clientLinkOwner === undefined && pinned.servingGeneration === undefined;
|
|
326
|
+
const savedLink = connection.kind === "connected" && connection.value.transport === "link";
|
|
327
|
+
const publishedLink = pinned?.clientLinkOwner != null;
|
|
328
|
+
const clientRecord = pinned?.servingGeneration !== undefined || pinned?.clientLinkOwner !== undefined;
|
|
329
|
+
const { readClientStopProcessStart } = await import("../client/stop-teardown-owner");
|
|
330
|
+
const targetStart = savedLink || clientRecord ? readClientStopProcessStart(target.pid) : undefined;
|
|
331
|
+
if ((savedLink || clientRecord) && !targetStart) throw unsupportedConnectedStop();
|
|
332
|
+
const capability = await assertConnectedClientStopSupported(target, { healthOnly: connection.kind === "disconnected" || standaloneSibling });
|
|
333
|
+
const sameStart = () => targetStart === undefined || readClientStopProcessStart(stopTarget.pid) === targetStart;
|
|
334
|
+
const checkPinnedRecord = (afterTerm?: RuntimePortState) => {
|
|
335
|
+
const current = readRuntimePort(stopTarget.pid);
|
|
336
|
+
if (!Bun.deepEquals(current, pinned, true) && !(afterTerm && Bun.deepEquals(current, afterTerm, true))) throw unsupportedConnectedStop();
|
|
337
|
+
};
|
|
338
|
+
const checkPinnedTarget = (afterTerm?: RuntimePortState) => {
|
|
339
|
+
checkPinnedRecord(afterTerm);
|
|
340
|
+
if (!sameStart()) throw unsupportedConnectedStop();
|
|
341
|
+
};
|
|
342
|
+
// Attestation is read-only. Recheck the record now. The Link path must
|
|
343
|
+
// revalidate the incarnation when it binds the fence or terminates a sibling.
|
|
344
|
+
checkPinnedRecord();
|
|
345
|
+
if (!capability) throw unsupportedConnectedStop();
|
|
346
|
+
if (standaloneSibling && !capability.nativeClient && !capability.linkStopFence) {
|
|
347
|
+
onTarget?.({ target, verify: checkPinnedTarget, siblingOnly: true });
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
if (savedLink && capability.nativeClient && !capability.linkStopFence && pinned?.clientLinkOwner === undefined) {
|
|
351
|
+
throw legacyLinkStopRefusal();
|
|
352
|
+
}
|
|
353
|
+
if (savedLink || publishedLink || capability.linkStopFence) {
|
|
354
|
+
if (!capability.linkStopFence || !targetStart) throw unsupportedConnectedStop();
|
|
355
|
+
const link = connection.kind === "connected" && linkStopConnectionOwner(connection.value);
|
|
356
|
+
if (!link || pinned?.clientLinkOwner !== link) throw unsupportedConnectedStop();
|
|
357
|
+
if (siblingOfPort !== undefined || pinned.siblingOfPort !== undefined) {
|
|
358
|
+
if (siblingOfPort === undefined || pinned.siblingOfPort !== siblingOfPort || !capability.nativeClient
|
|
359
|
+
|| !pinned.servingGeneration) throw unsupportedConnectedStop();
|
|
360
|
+
const { terminateAttestedClient } = await import("./stop-client-process");
|
|
361
|
+
const stopping = { ...pinned, clientStopping: true as const };
|
|
362
|
+
const verify = (phase?: "after-term") => {
|
|
363
|
+
checkPinnedTarget(phase === "after-term" ? stopping : undefined);
|
|
364
|
+
const current = readClientConnectionState();
|
|
365
|
+
if (current.kind !== "connected" || linkStopConnectionOwner(current.value) !== link) throw unsupportedConnectedStop();
|
|
366
|
+
};
|
|
367
|
+
// The sibling owns its listener only. Keep shared routing and teardown with the owner.
|
|
368
|
+
onTarget?.({ target, verify, siblingOnly: true, terminateSibling: () => terminateAttestedClient(stopTarget.pid, targetStart, verify) });
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
if (loadConfig().port !== target.port) throw unsupportedConnectedStop();
|
|
372
|
+
// A native Child has no /api/stop refusal: SIGTERM can escalate to SIGKILL.
|
|
373
|
+
// Refuse known inherited restore blockers before any manager or kill step.
|
|
374
|
+
const { inheritedTeardownDigest, readLinkInheritedTeardowns } = await import("../client/stop-native-handoff");
|
|
375
|
+
const normalizeHost = (value: string | undefined) => (value ?? "127.0.0.1").trim().toLowerCase().replace(/^\[(.*)\]$/, "$1");
|
|
376
|
+
const verifiedForeign: Buffer[] = [];
|
|
377
|
+
for (const read of inheritedTeardowns ?? readLinkInheritedTeardowns()) {
|
|
378
|
+
if (read.state === "valid" && read.receipt.endpointSource === "exact") {
|
|
379
|
+
const endpoint = read.receipt.endpoint;
|
|
380
|
+
if (endpoint.port === target.port && normalizeHost(endpoint.hostname) === normalizeHost(target.hostname)) continue;
|
|
381
|
+
if (read.bytes && await probeEndpointLiveness(endpoint) === "dead") {
|
|
382
|
+
verifiedForeign.push(read.bytes);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
throw new ProxyOwnershipRefusedError("Link Child native teardown preflight refused: pending recovery evidence would prevent native restoration. No process was stopped; repair that evidence, then retry ocx stop.", "link_native_teardown_refused");
|
|
387
|
+
}
|
|
388
|
+
// A manager can kill the Child before its signal handler runs. Drain these file routes
|
|
389
|
+
// first, under an exact runtime fence; refusal must return before any manager/kill step.
|
|
390
|
+
if (!pinned?.attestationSecret || !Bun.deepEquals(readRuntimePort(target.pid), pinned, true)) throw unsupportedConnectedStop();
|
|
391
|
+
const { finishClientRuntimeStop, markClientRuntimeStopping, markClientRuntimeStoppingWithRetry } = await import("../client/sync-runtime");
|
|
392
|
+
const { restoreLinkFileRouting } = await import("../client/stop-file-routing");
|
|
393
|
+
const startTime = readClientStopProcessStart(process.pid);
|
|
394
|
+
if (!startTime) throw unsupportedConnectedStop();
|
|
395
|
+
const owner = { pid: process.pid, startTime, nonce: randomBytes(16).toString("hex") };
|
|
396
|
+
const identity = { pid: target.pid, port: target.port, attestationSecret: pinned.attestationSecret };
|
|
397
|
+
// The CLI holds its ownership mutation lease through this finalizer. A retained listener
|
|
398
|
+
// can distinguish a finished stop from one still about to call a manager or kill fallback.
|
|
399
|
+
onFence(async () => {
|
|
400
|
+
const finished = await markClientRuntimeStoppingWithRetry(identity, { mark: () => {
|
|
401
|
+
if (sameStart()) finishClientRuntimeStop(identity, owner);
|
|
402
|
+
} });
|
|
403
|
+
if (!finished) console.warn("The retained Child's stop state could not be finalized; repair its runtime record before retrying recovery.");
|
|
404
|
+
});
|
|
405
|
+
const stopping = { ...pinned, clientStopping: true, clientStopRequested: true, clientStopOwner: owner };
|
|
406
|
+
const checkRuntime = () => {
|
|
407
|
+
if (!sameStart() || !Bun.deepEquals(readRuntimePort(identity.pid), stopping, true)) throw new Error("client_runtime_changed");
|
|
408
|
+
};
|
|
409
|
+
const fenced = await markClientRuntimeStoppingWithRetry(identity, {
|
|
410
|
+
mark: () => stopRestoreWriteGuard(connection.value).run(() => {
|
|
411
|
+
const current = readRuntimePort(identity.pid);
|
|
412
|
+
if (!sameStart() || (!Bun.deepEquals(current, pinned, true) && !Bun.deepEquals(current, stopping, true))) throw new Error("client_runtime_changed");
|
|
413
|
+
// The marker is checked by every sync commit, including already admitted work.
|
|
414
|
+
markClientRuntimeStopping(identity, owner);
|
|
415
|
+
}),
|
|
416
|
+
});
|
|
417
|
+
try {
|
|
418
|
+
if (!fenced) throw new Error("the runtime sync fence could not be verified");
|
|
419
|
+
await restoreLinkFileRouting(connection.value, { beforeWrite: checkRuntime });
|
|
420
|
+
const { terminateAttestedClient } = await import("./stop-client-process");
|
|
421
|
+
const guard = stopRestoreWriteGuard(connection.value);
|
|
422
|
+
const verify = () => {
|
|
423
|
+
try { guard.run(() => {
|
|
424
|
+
checkRuntime();
|
|
425
|
+
if (loadConfig().port !== identity.port) throw new Error("client_route_port_changed");
|
|
426
|
+
}); }
|
|
427
|
+
catch { throw unsupportedConnectedStop(); }
|
|
428
|
+
};
|
|
429
|
+
onTarget?.({ target, verify });
|
|
430
|
+
onLinkStop?.({ target, owner, inheritedTeardownDigest: inheritedTeardownDigest(verifiedForeign), verify, forceKill: pid => {
|
|
431
|
+
if (pid !== stopTarget.pid) throw unsupportedConnectedStop();
|
|
432
|
+
terminateAttestedClient(pid, targetStart, verify);
|
|
433
|
+
} });
|
|
434
|
+
} catch (error) {
|
|
435
|
+
throw new ProxyOwnershipRefusedError(`Link Child file routing restore refused: ${error instanceof Error ? error.message : "restoration failed"}. No process was stopped. ${fenced ? "Sync remains fenced; " : ""}repair the client configuration or ownership evidence, then retry ocx stop.`, "link_file_restore_refused");
|
|
436
|
+
}
|
|
437
|
+
} else if (capability.nativeClient && (connection.kind !== "connected" || pinned?.clientLinkOwner !== null)) {
|
|
438
|
+
// Older native listeners cannot distinguish Hub from Link once the saved connection drifts.
|
|
439
|
+
throw unsupportedConnectedStop();
|
|
440
|
+
} else {
|
|
441
|
+
if (connection.kind === "disconnected" && clientRecord) throw unsupportedConnectedStop();
|
|
442
|
+
// This path has no fence write. Require a live incarnation before the
|
|
443
|
+
// manager can use the proof, even if the Child left its record behind.
|
|
444
|
+
checkPinnedTarget();
|
|
445
|
+
onTarget?.({ target, verify: checkPinnedTarget });
|
|
446
|
+
}
|
|
122
447
|
return null;
|
|
123
|
-
} catch {
|
|
124
|
-
|
|
125
|
-
console.error(error.message);
|
|
126
|
-
process.exitCode = 1;
|
|
127
|
-
return { ok: false, summary: { schema: "ocx-stop/1", ok: false, outcome: "failed", exitCode: 1,
|
|
128
|
-
runtimeDown: false, service: "absent", proxy: "ownership-refused", sharedTeardown: "skipped", message: error.message } };
|
|
448
|
+
} catch (cause) {
|
|
449
|
+
return stopOwnershipRefused(cause instanceof ProxyOwnershipRefusedError ? cause : unsupportedConnectedStop());
|
|
129
450
|
}
|
|
130
451
|
}
|
|
131
452
|
|
|
@@ -190,6 +511,14 @@ export function restoreBoundaryOwnership(deps: {
|
|
|
190
511
|
}
|
|
191
512
|
}
|
|
192
513
|
|
|
514
|
+
async function hasLinkFileRouteEvidence(): Promise<boolean> {
|
|
515
|
+
const { readRouteIntentReceiptStrict } = await import("../integrations/route-intent-state");
|
|
516
|
+
const { homeRouteIntentPath } = await import("../client/link-home");
|
|
517
|
+
try { lstatSync(homeRouteIntentPath()); return true; }
|
|
518
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
519
|
+
return readRouteIntentReceiptStrict()?.linkId !== undefined;
|
|
520
|
+
}
|
|
521
|
+
|
|
193
522
|
/**
|
|
194
523
|
* Restore shared client state after a stop.
|
|
195
524
|
*
|
|
@@ -214,6 +543,24 @@ export async function restoreSharedClientStateAfterStop(
|
|
|
214
543
|
let historyDeferred = false;
|
|
215
544
|
let other = false;
|
|
216
545
|
const guard = stopRestoreWriteGuard();
|
|
546
|
+
try {
|
|
547
|
+
const connection = readClientConnectionState();
|
|
548
|
+
if (connection.kind === "connected" && connection.value.transport === "link") {
|
|
549
|
+
const { restoreLinkFileRouting } = await import("../client/stop-file-routing");
|
|
550
|
+
await restoreLinkFileRouting(connection.value);
|
|
551
|
+
} else if (await hasLinkFileRouteEvidence()) {
|
|
552
|
+
throw new Error("Link route receipts remain. Repair the saved Link ownership and rerun 'ocx stop' before reopening clients.");
|
|
553
|
+
}
|
|
554
|
+
} catch (error) {
|
|
555
|
+
if (error instanceof StopRestoreOwnershipError) {
|
|
556
|
+
if (error.boundary === "unproven") return { historyOnly, historyDeferred, other, boundary: error.boundary };
|
|
557
|
+
// A concurrent Hub connection can supersede native teardown. A surviving Link file
|
|
558
|
+
// receipt still needs recovery and must not be silently settled with the native receipt.
|
|
559
|
+
if (!await hasLinkFileRouteEvidence().catch(() => true)) return { historyOnly, historyDeferred, other, boundary: error.boundary };
|
|
560
|
+
}
|
|
561
|
+
console.error(`⚠️ Link Child file routing restore failed: ${error instanceof Error ? error.message : "ownership could not be verified"}`);
|
|
562
|
+
return { historyOnly, historyDeferred, other: true };
|
|
563
|
+
}
|
|
217
564
|
try {
|
|
218
565
|
const result = await restoreNativeCodexAsync({ withWriteGuard: guard.run });
|
|
219
566
|
if (guard.boundary() !== "restore") throw new Error("stop_restore_ownership_changed");
|
package/src/cli/sync-command.ts
CHANGED
|
@@ -187,7 +187,7 @@ export async function runSyncCommand(deps: CliDispatchDeps): Promise<number> {
|
|
|
187
187
|
if (live) {
|
|
188
188
|
try {
|
|
189
189
|
const config = deps.loadConfig();
|
|
190
|
-
const { refreshOwnedCatalogIntegrations } = await import("../integrations/catalog-refresh");
|
|
190
|
+
const { catalogRefreshClientIds, refreshOwnedCatalogIntegrations } = await import("../integrations/catalog-refresh");
|
|
191
191
|
results.push(...await refreshOwnedCatalogIntegrations({
|
|
192
192
|
models: async () => {
|
|
193
193
|
const { loadExportModels } = await import("../server/management/model-rows");
|
|
@@ -195,7 +195,7 @@ export async function runSyncCommand(deps: CliDispatchDeps): Promise<number> {
|
|
|
195
195
|
},
|
|
196
196
|
config,
|
|
197
197
|
port: live.port,
|
|
198
|
-
},
|
|
198
|
+
}, catalogRefreshClientIds("cliSync")));
|
|
199
199
|
} catch (error) {
|
|
200
200
|
console.warn(`Client integrations were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
|
|
201
201
|
}
|