evolcore 0.0.40 → 0.0.41-test.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/CHANGELOG.md +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -8,22 +8,24 @@ import { isShellToolName } from '../core/permission/tool-canonical.js';
|
|
|
8
8
|
import { normalizeExecutionPermissionMode, normalizePermissionMode, resolvePhaseOneExecutionSandbox } from '../core/permission/mode.js';
|
|
9
9
|
import { assertWindowsCodexFilesystemRuleBudget, buildCodexProtectedFilesystemRules, compactCodexLinuxFilesystemRules, getExistingRelationAttachmentDirs, isSameOrDescendant, resolveProtectedCandidate, } from '../core/permission/protected-paths.js';
|
|
10
10
|
import { CODEX_THREAD_ACTIVE_WRITER, CodexAppServerClient, } from './codex/app-server-client.js';
|
|
11
|
+
import { getSandboxInitializationFailureCounters, isNestedSandboxInitializationFailure, recordSandboxInitializationFailure, SANDBOX_INITIALIZATION_FAILED, } from '../core/permission/sandbox-runtime.js';
|
|
11
12
|
import { resolveOpenaiConfig, resolveCodexCliPath, resolveCodexPowerShellShimPath, } from './baseagent.js';
|
|
12
13
|
import { logger } from '../utils/logger.js';
|
|
13
14
|
import { resolveProviderService } from '../config/providers.js';
|
|
14
15
|
import { catalogHash } from '../core/model/catalog-service.js';
|
|
15
16
|
import { summarizeToolInputForAudit } from '../utils/tool-summary.js';
|
|
16
|
-
import { auditCodexApprovalDecision, auditPermissionLifecycle, auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
|
|
17
|
+
import { auditCodexApprovalDecision, auditPermissionLifecycle, auditToolInfrastructureFailure, auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
|
|
17
18
|
import { classifyError, ErrorType, getToolResultErrorText, isOutputTokenLimitError, isRetryableError } from '../utils/error-utils.js';
|
|
19
|
+
import { findModelSpec, getGatewayPricing as getSharedGatewayPricing } from '../stats/price-resolver.js';
|
|
18
20
|
import { renderActionAsText } from '../core/interaction-router.js';
|
|
19
21
|
import { buildEnvelope, isInteractionSendAccepted, sendInteractionPayload } from '../core/message/message-utils.js';
|
|
20
22
|
import { resolveCodexCapabilityThreadConfigForProject } from '../core/capability/capability-manager.js';
|
|
21
|
-
import { AGENT_DELEGATION_TOKEN_ENV, CODEX_SESSION_TOKEN_ENV, hashDelegatedCommandArgv } from '../core/auth/agent-delegation.js';
|
|
23
|
+
import { AGENT_DELEGATION_TOKEN_ENV, CODEX_SESSION_TOKEN_ENV, hashDelegatedCommandArgv, hashDelegatedCommandSpec, parseDelegatedExecutionSpec, } from '../core/auth/agent-delegation.js';
|
|
22
24
|
import { sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
23
|
-
import { classifyEvolcoreShellCommand, containsLiteralManagedTmpDirOutsideSendContent, containsUnresolvedManagedTmpDirReference, hasCodexCmdCarrierEcIntent, hasPowerShellCredentialAssignment, normalizeEvolcoreCommandArgv,
|
|
25
|
+
import { classifyEvolcoreShellCommand, containsLiteralManagedTmpDirOutsideSendContent, containsUnresolvedManagedTmpDirReference, hasCodexCmdCarrierEcIntent, hasPowerShellCredentialAssignment, normalizeEvolcoreCommandArgv, parseLiteralShellArgv, resolveCodexShellCarrierArgv, parseShellApplyPatchInvocation, resolveCanonicalEvolcoreToolInput, serializeCanonicalEvolcoreExecutionSpec, } from '../core/permission/ec-command-parser.js';
|
|
24
26
|
import { compareVersions } from '../utils/npm-ops.js';
|
|
25
|
-
import { agentCodexTokenPath, resolvePaths, resolveRoot } from '../paths.js';
|
|
26
|
-
import {
|
|
27
|
+
import { agentCodexTokenPath, getPackageRoot, resolvePaths, resolveRoot } from '../paths.js';
|
|
28
|
+
import { MAIN_CLI_BIN } from '../product.js';
|
|
27
29
|
import { ensureSessionRuntimeDir, getManagedTaskTempDir } from '../cli/task-context.js';
|
|
28
30
|
import { buildTranscriptTurns } from '../core/session/session-transcript.js';
|
|
29
31
|
import { CodexSessionFileAdapter } from '../core/session/adapters/codex-session-file-adapter.js';
|
|
@@ -157,6 +159,22 @@ function codexItemErrorFields(item) {
|
|
|
157
159
|
const errorDetailCode = normalizeToolErrorDetailCode(rawCode);
|
|
158
160
|
return errorDetailCode ? { errorDetailCode } : {};
|
|
159
161
|
}
|
|
162
|
+
function attachCanonicalMetadata(argv, metadata) {
|
|
163
|
+
const result = { argv };
|
|
164
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
165
|
+
if (value === undefined)
|
|
166
|
+
continue;
|
|
167
|
+
Object.defineProperty(result, key, {
|
|
168
|
+
value,
|
|
169
|
+
enumerable: false,
|
|
170
|
+
configurable: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
function matchesCodexTask(identity, target) {
|
|
176
|
+
return identity?.taskId === target.taskId && identity.generation === target.generation;
|
|
177
|
+
}
|
|
160
178
|
function waitForCodexOperation(operation, signal) {
|
|
161
179
|
return new Promise((resolve, reject) => {
|
|
162
180
|
const onAbort = () => {
|
|
@@ -421,7 +439,10 @@ export class CodexRunner {
|
|
|
421
439
|
modelContextId;
|
|
422
440
|
effort;
|
|
423
441
|
activeAbortControllers = new Map();
|
|
442
|
+
/** Identity of the run owning each session-scoped abort controller. */
|
|
443
|
+
activeAbortTargets = new Map();
|
|
424
444
|
activeStreams = new Map();
|
|
445
|
+
activeStreamTargets = new Map();
|
|
425
446
|
activeSessions = new Map(); // sessionId → threadId
|
|
426
447
|
/** New threads held in memory until the exact first turn is visible in the rollout. */
|
|
427
448
|
provisionalSessions = new Map();
|
|
@@ -434,12 +455,14 @@ export class CodexRunner {
|
|
|
434
455
|
threadExternalToolBoundaries = new Map();
|
|
435
456
|
trackedApprovalItems = new Map();
|
|
436
457
|
pendingToolDenials = new Map();
|
|
458
|
+
registeredSafeOutputCalls = new Map();
|
|
437
459
|
pendingInterrupts = new Map();
|
|
438
460
|
unconfirmedInterrupts = new Map();
|
|
439
461
|
steeringTails = new Map();
|
|
440
462
|
threadOperationLocks = new Map();
|
|
441
463
|
queryOperations = new Map();
|
|
442
464
|
activeOperationReleases = new Map();
|
|
465
|
+
activeOperationReleaseTargets = new Map();
|
|
443
466
|
/** Last app-server client that loaded each thread, including unsubscribed threads. */
|
|
444
467
|
threadSubscriptions = new Map();
|
|
445
468
|
/** Ordinary sessions stay behind the EvolCore H/L filesystem guard. */
|
|
@@ -765,173 +788,62 @@ export class CodexRunner {
|
|
|
765
788
|
}
|
|
766
789
|
this.threadSubscriptions.set(threadId, { client: targetClient, state: 'subscribed' });
|
|
767
790
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
791
|
+
resolveCanonicalEcApproval(toolInput, managedTempDir, expectedCredentialToken) {
|
|
792
|
+
const rawCommand = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
793
|
+
const safeOutput = this.parseSafeOutputToolInput(toolInput);
|
|
794
|
+
if (safeOutput) {
|
|
795
|
+
return attachCanonicalMetadata([...safeOutput.spec.argv], {
|
|
796
|
+
spec: safeOutput.spec,
|
|
797
|
+
executionSpec: serializeCanonicalEvolcoreExecutionSpec(safeOutput.spec),
|
|
798
|
+
specHash: hashDelegatedCommandSpec(safeOutput.spec) ?? undefined,
|
|
799
|
+
});
|
|
775
800
|
}
|
|
776
|
-
const
|
|
801
|
+
const options = {
|
|
777
802
|
allowManagedTmpDir: true,
|
|
778
|
-
dialect,
|
|
779
803
|
verifyShellExecutable: process.platform === 'win32',
|
|
780
804
|
...(managedTempDir ? { managedTempDir } : {}),
|
|
781
805
|
...(expectedCredentialToken !== undefined ? { expectedCredentialToken } : {}),
|
|
782
806
|
};
|
|
783
|
-
const
|
|
784
|
-
if (
|
|
785
|
-
return { argv: canonicalizeEvolcoreCommandArgv(classification.command.argv) };
|
|
786
|
-
}
|
|
787
|
-
// Keep the approval/delegation parser aligned with the preflight parser:
|
|
788
|
-
// the session-managed `$TMPDIR` token is a permitted EC path reference.
|
|
789
|
-
const parsed = executable
|
|
790
|
-
? parseCodexCarrierCommand({ command, dialect, executable }, parseOptions)
|
|
791
|
-
: dialect === 'powershell'
|
|
792
|
-
? parseCodexCarrierCommand({ command, dialect }, parseOptions)
|
|
793
|
-
: parseLiteralShellCommand(command, parseOptions);
|
|
794
|
-
if (!parsed.ok)
|
|
795
|
-
return { parseFailure: parsed };
|
|
796
|
-
if (normalizeEvolcoreCommandArgv(parsed.argv)[0] !== 'ec')
|
|
807
|
+
const resolved = resolveCanonicalEvolcoreToolInput(toolInput, options);
|
|
808
|
+
if (resolved.kind === 'not-ec')
|
|
797
809
|
return {};
|
|
798
|
-
if (
|
|
810
|
+
if (resolved.kind === 'invalid')
|
|
811
|
+
return { parseFailure: resolved.failure };
|
|
812
|
+
const spec = resolved.spec;
|
|
813
|
+
if (containsLiteralManagedTmpDirOutsideSendContent(spec.argv)
|
|
814
|
+
|| containsUnresolvedManagedTmpDirReference(spec.argv)) {
|
|
799
815
|
return { parseFailure: {
|
|
800
|
-
issue: 'unsafe-expansion',
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
inputLength: command.length,
|
|
816
|
+
issue: 'unsafe-expansion', offset: 0, tokenIndex: 0,
|
|
817
|
+
dialect: spec.dialect, inputLength: rawCommand.length,
|
|
818
|
+
canonicalizationStage: 'managed-temp-argv',
|
|
819
|
+
wrapper: spec.wrapper,
|
|
805
820
|
} };
|
|
806
821
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
resolveCanonicalEcApproval(toolInput, managedTempDir, expectedCredentialToken) {
|
|
813
|
-
const rawCommand = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
814
|
-
if (/\\\$(?:TMPDIR|\{TMPDIR\})/i.test(rawCommand)
|
|
815
|
-
&& /\bec\s+fs\s+(?:cp|ls|stat|find|cat|mkdir|rm|mv|upload)\b/i.test(rawCommand)
|
|
816
|
-
&& !/\bec\s+(?:msg|group)\s+send\b/i.test(rawCommand)
|
|
817
|
-
&& !/\bec\s+trigger\s+(?:create|set|update)\b/i.test(rawCommand)) {
|
|
822
|
+
const unresolvedOutput = spec.outputPath?.startsWith('$TMPDIR')
|
|
823
|
+
&& (!managedTempDir || !path.isAbsolute(managedTempDir));
|
|
824
|
+
if (unresolvedOutput) {
|
|
818
825
|
return { parseFailure: {
|
|
819
826
|
issue: 'unsafe-expansion', offset: 0, tokenIndex: 0,
|
|
820
|
-
dialect:
|
|
827
|
+
dialect: spec.dialect, inputLength: rawCommand.length,
|
|
828
|
+
canonicalizationStage: 'managed-temp-resolution',
|
|
829
|
+
wrapper: spec.wrapper,
|
|
830
|
+
redirectDetected: true,
|
|
831
|
+
managedTempPath: true,
|
|
832
|
+
managedTempResolved: false,
|
|
821
833
|
} };
|
|
822
834
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
?
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
issue: 'invalid-control-char', offset: 0,
|
|
831
|
-
tokenIndex: explicitArgv.findIndex(value => value.includes('\0')),
|
|
832
|
-
dialect: 'posix', inputLength: 0,
|
|
833
|
-
} };
|
|
834
|
-
}
|
|
835
|
-
return containsLiteralManagedTmpDirOutsideSendContent(explicitArgv) || containsUnresolvedManagedTmpDirReference(explicitArgv)
|
|
836
|
-
? { parseFailure: { issue: 'unsafe-expansion', offset: 0, tokenIndex: 0, dialect: 'posix', inputLength: 0 } }
|
|
837
|
-
: { argv: canonicalizeEvolcoreCommandArgv(explicitArgv) };
|
|
838
|
-
}
|
|
839
|
-
const explicitCarrier = explicitArgv
|
|
840
|
-
? resolveCodexShellCarrierArgv(explicitArgv)
|
|
841
|
-
: undefined;
|
|
842
|
-
if (explicitCarrier !== undefined) {
|
|
843
|
-
return this.approvedLiteralEvolcoreCommand(explicitCarrier.command, managedTempDir, explicitCarrier.dialect, expectedCredentialToken, explicitCarrier.executable);
|
|
844
|
-
}
|
|
845
|
-
if (explicitArgv?.length === 1 && typeof explicitArgv[0] === 'string') {
|
|
846
|
-
const parsed = parseCodexToolCommand({ commandArgv: explicitArgv }, {
|
|
847
|
-
allowManagedTmpDir: true,
|
|
848
|
-
verifyShellExecutable: process.platform === 'win32',
|
|
849
|
-
...(managedTempDir ? { managedTempDir } : {}),
|
|
850
|
-
...(expectedCredentialToken !== undefined ? { expectedCredentialToken } : {}),
|
|
851
|
-
});
|
|
852
|
-
if (parsed.ok && parsed.argv[0] === 'ec') {
|
|
853
|
-
return containsLiteralManagedTmpDirOutsideSendContent(parsed.argv) || containsUnresolvedManagedTmpDirReference(parsed.argv)
|
|
854
|
-
? { parseFailure: { issue: 'unsafe-expansion', offset: 0, tokenIndex: 0, dialect: 'powershell', inputLength: explicitArgv[0].length } }
|
|
855
|
-
: { argv: canonicalizeEvolcoreCommandArgv(parsed.argv) };
|
|
856
|
-
}
|
|
857
|
-
if (!parsed.ok)
|
|
858
|
-
return { parseFailure: parsed };
|
|
859
|
-
}
|
|
860
|
-
if (hasCodexCmdCarrierEcIntent(toolInput)) {
|
|
861
|
-
const parsed = parseCodexToolCommand(toolInput, {
|
|
862
|
-
verifyShellExecutable: process.platform === 'win32',
|
|
863
|
-
...(expectedCredentialToken !== undefined ? { expectedCredentialToken } : {}),
|
|
864
|
-
});
|
|
865
|
-
if (!parsed.ok)
|
|
866
|
-
return { parseFailure: parsed };
|
|
867
|
-
if (parsed.argv[0] === 'ec') {
|
|
868
|
-
return containsLiteralManagedTmpDirOutsideSendContent(parsed.argv) || containsUnresolvedManagedTmpDirReference(parsed.argv)
|
|
869
|
-
? { parseFailure: {
|
|
870
|
-
issue: 'unsafe-expansion', offset: 0, tokenIndex: 0,
|
|
871
|
-
dialect: 'cmd', inputLength: 0,
|
|
872
|
-
} }
|
|
873
|
-
: {
|
|
874
|
-
argv: canonicalizeEvolcoreCommandArgv(parsed.argv),
|
|
875
|
-
...(parsed.credentialToken ? { credentialToken: parsed.credentialToken } : {}),
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
const command = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
879
|
-
const classification = classifyEvolcoreShellCommand(command, { dialect: 'cmd' });
|
|
880
|
-
return {
|
|
881
|
-
parseFailure: {
|
|
882
|
-
issue: classification.kind === 'composite' ? classification.issue : 'shell-composition',
|
|
883
|
-
offset: 0,
|
|
884
|
-
tokenIndex: 0,
|
|
885
|
-
dialect: 'cmd',
|
|
886
|
-
inputLength: command.length,
|
|
887
|
-
},
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
const command = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
891
|
-
const canonicalCommand = parseCodexShellCommandArgv(command, {
|
|
892
|
-
allowManagedTmpDir: true,
|
|
893
|
-
verifyShellExecutable: process.platform === 'win32',
|
|
894
|
-
...(managedTempDir ? { managedTempDir } : {}),
|
|
895
|
-
...(expectedCredentialToken !== undefined ? { expectedCredentialToken } : {}),
|
|
896
|
-
});
|
|
897
|
-
if (canonicalCommand?.[0] === 'ec') {
|
|
898
|
-
return containsLiteralManagedTmpDirOutsideSendContent(canonicalCommand) || containsUnresolvedManagedTmpDirReference(canonicalCommand)
|
|
899
|
-
? { parseFailure: {
|
|
900
|
-
issue: 'unsafe-expansion',
|
|
901
|
-
offset: 0,
|
|
902
|
-
tokenIndex: 0,
|
|
903
|
-
dialect: 'posix',
|
|
904
|
-
inputLength: command.length,
|
|
905
|
-
} }
|
|
906
|
-
: { argv: canonicalizeEvolcoreCommandArgv(canonicalCommand) };
|
|
907
|
-
}
|
|
908
|
-
const outer = parseLiteralShellCommand(command, {
|
|
909
|
-
allowManagedTmpDir: true,
|
|
910
|
-
...(managedTempDir ? { managedTempDir } : {}),
|
|
835
|
+
return attachCanonicalMetadata(spec.argv, {
|
|
836
|
+
spec,
|
|
837
|
+
...(spec.wrapper !== 'literal' ? {
|
|
838
|
+
executionSpec: serializeCanonicalEvolcoreExecutionSpec(spec),
|
|
839
|
+
specHash: hashDelegatedCommandSpec(spec) ?? undefined,
|
|
840
|
+
} : {}),
|
|
841
|
+
...(resolved.credentialToken ? { credentialToken: resolved.credentialToken } : {}),
|
|
911
842
|
});
|
|
912
|
-
if (!outer.ok) {
|
|
913
|
-
const classification = classifyEvolcoreShellCommand(command, {
|
|
914
|
-
allowManagedTmpDir: true,
|
|
915
|
-
...(managedTempDir ? { managedTempDir } : {}),
|
|
916
|
-
});
|
|
917
|
-
if (classification.kind === 'bounded-output'
|
|
918
|
-
&& normalizeEvolcoreCommandArgv(classification.command.argv)[0] === 'ec') {
|
|
919
|
-
const argv = classification.command.argv;
|
|
920
|
-
return containsLiteralManagedTmpDirOutsideSendContent(argv) || containsUnresolvedManagedTmpDirReference(argv)
|
|
921
|
-
? { parseFailure: {
|
|
922
|
-
issue: 'unsafe-expansion',
|
|
923
|
-
offset: 0,
|
|
924
|
-
tokenIndex: 0,
|
|
925
|
-
dialect: 'posix',
|
|
926
|
-
inputLength: command.length,
|
|
927
|
-
} }
|
|
928
|
-
: { argv: canonicalizeEvolcoreCommandArgv(argv) };
|
|
929
|
-
}
|
|
930
|
-
return { parseFailure: outer };
|
|
931
|
-
}
|
|
932
|
-
return {};
|
|
933
843
|
}
|
|
934
844
|
isManagedEvolcoreCommandIntent(toolInput) {
|
|
845
|
+
if (this.parseSafeOutputToolInput(toolInput))
|
|
846
|
+
return true;
|
|
935
847
|
if (Array.isArray(toolInput.commandArgv)) {
|
|
936
848
|
const rawArgv = toolInput.commandArgv;
|
|
937
849
|
if (!rawArgv.every(value => typeof value === 'string'))
|
|
@@ -955,21 +867,71 @@ export class CodexRunner {
|
|
|
955
867
|
const command = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
956
868
|
return classifyEvolcoreShellCommand(command).kind !== 'none';
|
|
957
869
|
}
|
|
958
|
-
armApprovedDelegationCommand(sessionId, argv, approvalId) {
|
|
870
|
+
armApprovedDelegationCommand(sessionId, argv, approvalId, specHash, executionSpec) {
|
|
959
871
|
const threadId = this.activeSessions.get(sessionId) ?? this.provisionalSessions.get(sessionId);
|
|
960
872
|
const sessionToken = threadId ? this.ensureThreadCredentialLoaded(threadId) : undefined;
|
|
961
|
-
const commandHash =
|
|
873
|
+
const commandHash = executionSpec
|
|
874
|
+
? hashDelegatedCommandArgv(executionSpec.argv, executionSpec)
|
|
875
|
+
: hashDelegatedCommandArgv(argv);
|
|
962
876
|
const arm = this.permissionContexts.get(sessionId)?.armApprovedDelegationCommand;
|
|
963
877
|
if (!sessionToken || !commandHash || !arm)
|
|
964
878
|
return false;
|
|
965
879
|
try {
|
|
966
|
-
return
|
|
880
|
+
return specHash === undefined
|
|
881
|
+
? arm(sessionToken, commandHash, approvalId)
|
|
882
|
+
: arm(sessionToken, commandHash, approvalId, specHash);
|
|
967
883
|
}
|
|
968
884
|
catch (error) {
|
|
969
885
|
logger.warn(`[CodexRunner] delegation arm callback failed: session=${sessionId} error=${error instanceof Error ? error.message : String(error)}`);
|
|
970
886
|
return false;
|
|
971
887
|
}
|
|
972
888
|
}
|
|
889
|
+
parseSafeOutputCommand(command) {
|
|
890
|
+
const argv = typeof command === 'string' ? parseLiteralShellArgv(command) : [...command];
|
|
891
|
+
if (!argv || argv.length !== 3 || argv[0] !== process.execPath)
|
|
892
|
+
return undefined;
|
|
893
|
+
const expectedHelper = path.resolve(getPackageRoot(), 'bin', 'ec-safe-output.js');
|
|
894
|
+
if (path.resolve(argv[1]) !== expectedHelper)
|
|
895
|
+
return undefined;
|
|
896
|
+
let payload;
|
|
897
|
+
try {
|
|
898
|
+
const parsed = JSON.parse(Buffer.from(argv[2], 'base64url').toString('utf8'));
|
|
899
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
900
|
+
return undefined;
|
|
901
|
+
payload = parsed;
|
|
902
|
+
}
|
|
903
|
+
catch {
|
|
904
|
+
return undefined;
|
|
905
|
+
}
|
|
906
|
+
const spec = parseDelegatedExecutionSpec(payload.executionSpec);
|
|
907
|
+
if (payload.v !== 3 || payload.kind !== 'ec' || !spec
|
|
908
|
+
|| !Array.isArray(payload.argv)
|
|
909
|
+
|| JSON.stringify(spec.argv) !== JSON.stringify([MAIN_CLI_BIN, ...payload.argv.slice(1)])
|
|
910
|
+
|| spec.cwd !== payload.cwd
|
|
911
|
+
|| spec.outputPath !== payload.outputPath
|
|
912
|
+
|| !!spec.mergeStderr !== !!payload.mergeStderr
|
|
913
|
+
|| JSON.stringify(spec.filterChain ?? []) !== JSON.stringify(payload.filterChain ?? [])
|
|
914
|
+
|| JSON.stringify(spec.suffixArgv ?? []) !== JSON.stringify(payload.suffixArgv ?? []))
|
|
915
|
+
return undefined;
|
|
916
|
+
return { spec, argv };
|
|
917
|
+
}
|
|
918
|
+
parseSafeOutputToolInput(input) {
|
|
919
|
+
if (Array.isArray(input.commandArgv) && input.commandArgv.every(value => typeof value === 'string')) {
|
|
920
|
+
const rawArgv = input.commandArgv;
|
|
921
|
+
const direct = this.parseSafeOutputCommand(rawArgv);
|
|
922
|
+
if (direct)
|
|
923
|
+
return direct;
|
|
924
|
+
const carrier = resolveCodexShellCarrierArgv(rawArgv);
|
|
925
|
+
if (carrier) {
|
|
926
|
+
const nested = this.parseSafeOutputCommand(carrier.command);
|
|
927
|
+
if (nested)
|
|
928
|
+
return nested;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return typeof input.command === 'string'
|
|
932
|
+
? this.parseSafeOutputCommand(input.command)
|
|
933
|
+
: undefined;
|
|
934
|
+
}
|
|
973
935
|
sessionTokenForSession(sessionId, threadId) {
|
|
974
936
|
const candidates = [
|
|
975
937
|
threadId,
|
|
@@ -1327,6 +1289,12 @@ export class CodexRunner {
|
|
|
1327
1289
|
this.resetAppServerClient();
|
|
1328
1290
|
}
|
|
1329
1291
|
getModel() { return this.model; }
|
|
1292
|
+
/** 返回当前网关 /v1/models 的价格缓存(1h TTL,stale-while-revalidate)。
|
|
1293
|
+
* 缺失/过期时异步触发刷新,本轮先返回旧值或 undefined(回退本地价表)。 */
|
|
1294
|
+
getGatewayPricing() {
|
|
1295
|
+
const conn = this.currentProviderConfig();
|
|
1296
|
+
return getSharedGatewayPricing(conn.baseUrl, conn.apiKey, conn.headers);
|
|
1297
|
+
}
|
|
1330
1298
|
getModelCatalog() {
|
|
1331
1299
|
return getRunnerCatalog('codex', this.resolvedConfig.agentAid, this.currentProviderConfig());
|
|
1332
1300
|
}
|
|
@@ -1732,6 +1700,7 @@ export class CodexRunner {
|
|
|
1732
1700
|
role: context.role,
|
|
1733
1701
|
permissionMode: normalizeExecutionPermissionMode(this.chatModes.get(sessionKey) ?? this.currentMode),
|
|
1734
1702
|
allowReadonlySourceDiagnostics: context.allowReadonlySourceDiagnostics === true,
|
|
1703
|
+
safeOutputHelperPath: path.join(getPackageRoot(), 'bin', 'ec-safe-output.js'),
|
|
1735
1704
|
projectPath: preflightProjectPath,
|
|
1736
1705
|
workspacePath: preflightProjectPath,
|
|
1737
1706
|
});
|
|
@@ -1740,44 +1709,125 @@ export class CodexRunner {
|
|
|
1740
1709
|
await recordPreToolUseDenial(preflight.policyCode ?? 'tool_preflight_denied', reason);
|
|
1741
1710
|
return { ok: true, applicable: true, decision: 'deny', reason };
|
|
1742
1711
|
}
|
|
1712
|
+
const updatedInput = preflight.behavior === 'allow' && preflight.input !== normalizedInput
|
|
1713
|
+
? preflight.input
|
|
1714
|
+
: undefined;
|
|
1715
|
+
let safeExecutionSpec;
|
|
1716
|
+
if (updatedInput && preflight.behavior === 'allow' && preflight.executionSpec
|
|
1717
|
+
&& typeof updatedInput.command === 'string') {
|
|
1718
|
+
const safeOutput = this.parseSafeOutputCommand(updatedInput.command);
|
|
1719
|
+
const key = this.safeOutputCallKey(threadId, callId);
|
|
1720
|
+
if (!safeOutput || !key) {
|
|
1721
|
+
const reason = '安全 EC 输出命令无法校验执行规格';
|
|
1722
|
+
await recordPreToolUseDenial('ec_execution_spec_unavailable', reason);
|
|
1723
|
+
return { ok: true, applicable: true, decision: 'deny', reason };
|
|
1724
|
+
}
|
|
1725
|
+
this.registeredSafeOutputCalls.set(key, {
|
|
1726
|
+
spec: safeOutput.spec,
|
|
1727
|
+
updatedArgv: safeOutput.argv,
|
|
1728
|
+
expiresAt: Date.now() + 30_000,
|
|
1729
|
+
});
|
|
1730
|
+
safeExecutionSpec = safeOutput.spec;
|
|
1731
|
+
}
|
|
1732
|
+
const bindSafeExecutionSpec = async () => {
|
|
1733
|
+
if (!safeExecutionSpec)
|
|
1734
|
+
return true;
|
|
1735
|
+
const specHash = hashDelegatedCommandSpec(safeExecutionSpec);
|
|
1736
|
+
const commandHash = hashDelegatedCommandArgv(safeExecutionSpec.argv, safeExecutionSpec);
|
|
1737
|
+
if (callId && sessionToken && specHash && commandHash
|
|
1738
|
+
&& this.armApprovedDelegationCommand(sessionKey, safeExecutionSpec.argv, callId, specHash, safeExecutionSpec))
|
|
1739
|
+
return true;
|
|
1740
|
+
await recordPreToolUseDenial('ec_execution_spec_unavailable', '安全 EC 输出命令无法绑定到当前工具调用');
|
|
1741
|
+
const key = this.safeOutputCallKey(threadId, callId);
|
|
1742
|
+
if (key)
|
|
1743
|
+
this.registeredSafeOutputCalls.delete(key);
|
|
1744
|
+
return false;
|
|
1745
|
+
};
|
|
1743
1746
|
// A tracked interactive thread still needs an authenticated, explicit
|
|
1744
1747
|
// allow so the managed hook can fail closed when no runner matches.
|
|
1745
|
-
if (!context.preToolUsePolicyHook)
|
|
1746
|
-
|
|
1748
|
+
if (!context.preToolUsePolicyHook) {
|
|
1749
|
+
if (!await bindSafeExecutionSpec()) {
|
|
1750
|
+
return { ok: true, applicable: true, decision: 'deny', reason: '安全 EC 输出命令无法绑定到当前工具调用' };
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
ok: true, applicable: true, decision: 'allow',
|
|
1754
|
+
...(updatedInput ? { updatedInput } : {}),
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1747
1757
|
try {
|
|
1748
1758
|
const result = context.preToolUsePolicyHook(toolName, normalizedInput);
|
|
1749
1759
|
if (result?.block) {
|
|
1750
1760
|
const policyCode = result.policyCode ?? 'session_policy_hook';
|
|
1751
1761
|
const reason = result.reason ?? 'session policy denied this tool call';
|
|
1752
1762
|
await recordPreToolUseDenial(policyCode, reason);
|
|
1763
|
+
const key = this.safeOutputCallKey(threadId, callId);
|
|
1764
|
+
if (key)
|
|
1765
|
+
this.registeredSafeOutputCalls.delete(key);
|
|
1753
1766
|
if (policyCode === 'proactive_circuit_break')
|
|
1754
1767
|
context.onProactiveCircuitBreak?.();
|
|
1755
1768
|
return { ok: true, applicable: true, decision: 'deny', reason };
|
|
1756
1769
|
}
|
|
1757
|
-
|
|
1770
|
+
if (!await bindSafeExecutionSpec()) {
|
|
1771
|
+
return { ok: true, applicable: true, decision: 'deny', reason: '安全 EC 输出命令无法绑定到当前工具调用' };
|
|
1772
|
+
}
|
|
1773
|
+
return {
|
|
1774
|
+
ok: true, applicable: true, decision: 'allow',
|
|
1775
|
+
...(updatedInput ? { updatedInput } : {}),
|
|
1776
|
+
};
|
|
1758
1777
|
}
|
|
1759
1778
|
catch (error) {
|
|
1760
1779
|
const reason = `policy hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1761
1780
|
await recordPreToolUseDenial('pre_tool_use_hook_failed', reason);
|
|
1781
|
+
const key = this.safeOutputCallKey(threadId, callId);
|
|
1782
|
+
if (key)
|
|
1783
|
+
this.registeredSafeOutputCalls.delete(key);
|
|
1762
1784
|
return { ok: false, applicable: true, decision: 'deny', reason };
|
|
1763
1785
|
}
|
|
1764
1786
|
}
|
|
1765
1787
|
setPermissionGateway(gw) { this.permissionGateway = gw; }
|
|
1766
1788
|
// ── Stream management (needed by MessageProcessor) ──
|
|
1767
|
-
registerStream(key, stream) {
|
|
1789
|
+
registerStream(key, stream, target) {
|
|
1790
|
+
const currentTarget = this.activeStreamTargets.get(key);
|
|
1791
|
+
if (target && currentTarget && !matchesCodexTask(currentTarget, target)
|
|
1792
|
+
&& currentTarget.generation > target.generation)
|
|
1793
|
+
return;
|
|
1768
1794
|
this.activeStreams.set(key, stream);
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1795
|
+
this.activeStreamTargets.set(key, target ?? this.activeAbortTargets.get(key));
|
|
1796
|
+
}
|
|
1797
|
+
cleanupStream(key, target) {
|
|
1798
|
+
const currentStreamTarget = this.activeStreamTargets.get(key);
|
|
1799
|
+
const currentAbortTarget = this.activeAbortTargets.get(key);
|
|
1800
|
+
const releaseTarget = this.activeOperationReleaseTargets.get(key);
|
|
1801
|
+
if (target && ((currentStreamTarget && !matchesCodexTask(currentStreamTarget, target))
|
|
1802
|
+
|| (currentAbortTarget && !matchesCodexTask(currentAbortTarget, target))))
|
|
1803
|
+
return;
|
|
1804
|
+
if (target && this.activeOperationReleases.has(key) && !matchesCodexTask(releaseTarget, target))
|
|
1805
|
+
return;
|
|
1806
|
+
const operations = this.queryOperations.get(key);
|
|
1807
|
+
if (target && [...(operations ?? [])].some(operation => {
|
|
1808
|
+
const operationTarget = this.targetForOperation(operation);
|
|
1809
|
+
return operationTarget
|
|
1810
|
+
&& operationTarget.generation > target.generation
|
|
1811
|
+
&& !matchesCodexTask(operationTarget, target);
|
|
1812
|
+
}))
|
|
1813
|
+
return;
|
|
1814
|
+
const capturedController = this.activeAbortControllers.get(key);
|
|
1815
|
+
const capturedStream = this.activeStreams.get(key);
|
|
1816
|
+
const hadController = capturedController !== undefined;
|
|
1772
1817
|
const hadTurn = this.activeTurns.has(key);
|
|
1773
1818
|
const provisionalThread = this.provisionalSessions.get(key);
|
|
1774
1819
|
const subscribedThreadId = this.activeTurns.get(key)?.threadId
|
|
1775
1820
|
?? this.activeSessions.get(key)
|
|
1776
1821
|
?? provisionalThread;
|
|
1777
1822
|
const subscription = subscribedThreadId ? this.threadSubscriptions.get(subscribedThreadId) : undefined;
|
|
1778
|
-
this.activeStreams.
|
|
1779
|
-
|
|
1780
|
-
|
|
1823
|
+
if (this.activeStreams.get(key) === capturedStream) {
|
|
1824
|
+
this.activeStreams.delete(key);
|
|
1825
|
+
this.activeStreamTargets.delete(key);
|
|
1826
|
+
}
|
|
1827
|
+
if (capturedController !== undefined && this.activeAbortControllers.get(key) === capturedController) {
|
|
1828
|
+
this.activeAbortControllers.delete(key);
|
|
1829
|
+
this.activeAbortTargets.delete(key);
|
|
1830
|
+
}
|
|
1781
1831
|
// A stale runner-start path may dispose the stream without ever entering
|
|
1782
1832
|
// transformAppServerStream. Reclaim its provisional thread, but preserve
|
|
1783
1833
|
// a replacement run that has already installed a new controller/turn.
|
|
@@ -1792,6 +1842,7 @@ export class CodexRunner {
|
|
|
1792
1842
|
}
|
|
1793
1843
|
if (release) {
|
|
1794
1844
|
this.activeOperationReleases.delete(key);
|
|
1845
|
+
this.activeOperationReleaseTargets.delete(key);
|
|
1795
1846
|
if (releaseAfterSubscription) {
|
|
1796
1847
|
void releaseAfterSubscription.then(release, release);
|
|
1797
1848
|
}
|
|
@@ -1807,6 +1858,35 @@ export class CodexRunner {
|
|
|
1807
1858
|
const operations = this.queryOperations.get(sessionId);
|
|
1808
1859
|
return !!operations && [...operations].some(operation => !taskId || operation.taskId === taskId);
|
|
1809
1860
|
}
|
|
1861
|
+
targetForOperation(operation) {
|
|
1862
|
+
if (!operation.taskId || !Number.isSafeInteger(operation.generation))
|
|
1863
|
+
return undefined;
|
|
1864
|
+
return { taskId: operation.taskId, generation: operation.generation };
|
|
1865
|
+
}
|
|
1866
|
+
clearActiveController(sessionId, controller) {
|
|
1867
|
+
if (this.activeAbortControllers.get(sessionId) !== controller)
|
|
1868
|
+
return;
|
|
1869
|
+
this.activeAbortControllers.delete(sessionId);
|
|
1870
|
+
this.activeAbortTargets.delete(sessionId);
|
|
1871
|
+
}
|
|
1872
|
+
setActiveTurn(sessionId, turn) {
|
|
1873
|
+
const current = this.activeTurns.get(sessionId);
|
|
1874
|
+
if (current?.generation !== undefined && turn.generation !== undefined
|
|
1875
|
+
&& current.generation > turn.generation)
|
|
1876
|
+
return;
|
|
1877
|
+
this.activeTurns.set(sessionId, turn);
|
|
1878
|
+
}
|
|
1879
|
+
clearActiveStream(sessionId, target) {
|
|
1880
|
+
if (target && !matchesCodexTask(this.activeStreamTargets.get(sessionId), target))
|
|
1881
|
+
return;
|
|
1882
|
+
this.activeStreams.delete(sessionId);
|
|
1883
|
+
this.activeStreamTargets.delete(sessionId);
|
|
1884
|
+
}
|
|
1885
|
+
clearActiveTurn(sessionId, target) {
|
|
1886
|
+
if (target && !matchesCodexTask(this.activeTurns.get(sessionId), target))
|
|
1887
|
+
return;
|
|
1888
|
+
this.activeTurns.delete(sessionId);
|
|
1889
|
+
}
|
|
1810
1890
|
cancelQueuedTurn(sessionId, identity) {
|
|
1811
1891
|
const operation = [...(this.queryOperations.get(sessionId) ?? [])].find(candidate => !candidate.lockAcquired
|
|
1812
1892
|
&& candidate.taskId === identity.taskId
|
|
@@ -1931,6 +2011,7 @@ export class CodexRunner {
|
|
|
1931
2011
|
finally {
|
|
1932
2012
|
if (this.activeOperationReleases.get(sessionId) === release) {
|
|
1933
2013
|
this.activeOperationReleases.delete(sessionId);
|
|
2014
|
+
this.activeOperationReleaseTargets.delete(sessionId);
|
|
1934
2015
|
}
|
|
1935
2016
|
release();
|
|
1936
2017
|
}
|
|
@@ -1953,12 +2034,14 @@ export class CodexRunner {
|
|
|
1953
2034
|
? this.cachedThreadForTopic(sessionId, topicAgentSessionId)
|
|
1954
2035
|
: initialAgentSessionId || this.activeSessions.get(sessionId);
|
|
1955
2036
|
const operationKey = this.threadOperationKey(modelOverride?.recovery?.agentSessionId || knownThreadId, sessionId);
|
|
2037
|
+
this.dropExpiredPendingInterrupt(sessionId, modelOverride?.turn);
|
|
1956
2038
|
const operation = {
|
|
1957
2039
|
controller: new AbortController(),
|
|
1958
2040
|
taskId: modelOverride?.turn?.taskId ?? this.permissionContexts.get(sessionId)?.taskId,
|
|
1959
|
-
generation: modelOverride?.turn?.generation,
|
|
2041
|
+
generation: modelOverride?.turn?.generation ?? this.permissionContexts.get(sessionId)?.turn?.generation,
|
|
1960
2042
|
lockAcquired: false,
|
|
1961
2043
|
};
|
|
2044
|
+
const operationTarget = this.targetForOperation(operation);
|
|
1962
2045
|
const operations = this.queryOperations.get(sessionId) ?? new Set();
|
|
1963
2046
|
operations.add(operation);
|
|
1964
2047
|
this.queryOperations.set(sessionId, operations);
|
|
@@ -1971,12 +2054,16 @@ export class CodexRunner {
|
|
|
1971
2054
|
releaseLock?.();
|
|
1972
2055
|
};
|
|
1973
2056
|
try {
|
|
2057
|
+
if (operationTarget && this.consumePendingInterrupt(sessionId, operationTarget)) {
|
|
2058
|
+
throw Object.assign(new Error('Codex operation interrupted before startup'), { name: 'AbortError' });
|
|
2059
|
+
}
|
|
1974
2060
|
await waitForCodexOperation(this.assertInterruptSettled(sessionId, modelOverride?.recovery?.agentSessionId || knownThreadId), operation.controller.signal);
|
|
1975
2061
|
releaseLock = await this.acquireThreadOperation(operationKey, 'thread/resume+turn/start', operation.controller.signal);
|
|
1976
2062
|
operation.lockAcquired = true;
|
|
1977
2063
|
await waitForCodexOperation(this.assertInterruptSettled(sessionId, modelOverride?.recovery?.agentSessionId || knownThreadId), operation.controller.signal);
|
|
1978
2064
|
const stream = await this.runQueryLocked(sessionId, prompt, projectPath, initialAgentSessionId, images, systemPromptAppend, sessionManager, modelOverride, runtimeEnv, operation.controller);
|
|
1979
2065
|
this.activeOperationReleases.set(sessionId, release);
|
|
2066
|
+
this.activeOperationReleaseTargets.set(sessionId, operationTarget);
|
|
1980
2067
|
return this.holdThreadOperation(stream, sessionId, release);
|
|
1981
2068
|
}
|
|
1982
2069
|
catch (error) {
|
|
@@ -2030,7 +2117,7 @@ export class CodexRunner {
|
|
|
2030
2117
|
const callApprovalPolicy = this.toApprovalPolicy(callMode);
|
|
2031
2118
|
const executionSandbox = this.buildExecutionSandboxOptions(sessionId, callMode, projectPath, modelOverride?.bootstrapAgentMdPath, modelOverride?.personalMdPath, undefined);
|
|
2032
2119
|
const appServer = this.getAppServerClient(callMode === 'fullaccess', modelOverride?.provider);
|
|
2033
|
-
this.dropExpiredPendingInterrupt(sessionId);
|
|
2120
|
+
this.dropExpiredPendingInterrupt(sessionId, modelOverride?.turn);
|
|
2034
2121
|
const effectiveApprovalPolicy = callApprovalPolicy;
|
|
2035
2122
|
const capabilityConfig = await this.resolveCapabilityThreadConfig(projectPath);
|
|
2036
2123
|
const userInputConfig = { features: {
|
|
@@ -2052,48 +2139,62 @@ export class CodexRunner {
|
|
|
2052
2139
|
const persistentRuntimeEnv = runtimeEnv
|
|
2053
2140
|
? Object.fromEntries(Object.entries(runtimeEnv).filter(([name]) => callMode === 'fullaccess' || name.toUpperCase() !== AGENT_DELEGATION_TOKEN_ENV))
|
|
2054
2141
|
: undefined;
|
|
2055
|
-
let
|
|
2142
|
+
let innerSandboxFallback = false;
|
|
2143
|
+
const canFallbackFromInnerSandbox = process.platform === 'linux'
|
|
2144
|
+
&& executionSandbox.decision.state === 'active';
|
|
2145
|
+
const buildThreadOptions = (fallback = false) => ({
|
|
2056
2146
|
model: callModel,
|
|
2057
2147
|
effort: callEffort,
|
|
2058
2148
|
approvalPolicy: effectiveApprovalPolicy,
|
|
2059
2149
|
approvalsReviewer: 'user',
|
|
2060
|
-
...(
|
|
2061
|
-
|
|
2150
|
+
...(fallback
|
|
2151
|
+
? { sandbox: 'danger-full-access' }
|
|
2152
|
+
: executionSandbox.sandbox ? { sandbox: executionSandbox.sandbox } : {}),
|
|
2153
|
+
config: this.sanitizeThreadEnvironmentConfig(this.mergeThreadConfig(fallback ? undefined : executionSandbox.permissionProfileConfig, persistentRuntimeEnv ? { shell_environment_policy: { set: persistentRuntimeEnv } } : undefined, capabilityConfig, userInputConfig, externalToolConfig, this.buildEvolcoreShellEnvironmentConfig(sessionId, threadSessionToken, callMode === 'fullaccess' ? runtimeEnv?.[AGENT_DELEGATION_TOKEN_ENV] : undefined), this.buildLifecycleLockdownConfig(callMode)), callMode, callMode === 'fullaccess' ? runtimeEnv?.[AGENT_DELEGATION_TOKEN_ENV] : undefined),
|
|
2062
2154
|
...(developerInstructions ? { developerInstructions } : {}),
|
|
2063
|
-
};
|
|
2155
|
+
});
|
|
2156
|
+
let threadOptions = buildThreadOptions();
|
|
2064
2157
|
logger.info(`[CodexRunner] runQuery permMode=${requestedPermissionMode}->${callMode} ` +
|
|
2065
2158
|
`role=${executionSandbox.decision.role ?? 'none'} sandbox=${executionSandbox.decision.state}`);
|
|
2066
2159
|
let threadResponse;
|
|
2067
2160
|
let previousAppServer;
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
catch (error) {
|
|
2076
|
-
if (isCodexActiveWriterError(error) && previousAppServer && previousAppServer !== appServer) {
|
|
2077
|
-
// Some Codex builds acknowledge unsubscribe before unloading the
|
|
2078
|
-
// runtime. Archive/unarchive is a synchronous per-thread teardown
|
|
2079
|
-
// and preserves the same persisted thread id for the retry.
|
|
2080
|
-
await this.archiveThreadForHandoff(previousAppServer, appServer, agentSessionId);
|
|
2081
|
-
threadResponse = await appServer.threadResume(agentSessionId, projectPath, threadOptions);
|
|
2161
|
+
const openThread = async () => {
|
|
2162
|
+
if (agentSessionId) {
|
|
2163
|
+
// A thread may have been loaded by the other permission-mode client.
|
|
2164
|
+
// Release that one thread before asking this client to resume it.
|
|
2165
|
+
previousAppServer = await this.prepareThreadSubscription(appServer, agentSessionId);
|
|
2166
|
+
try {
|
|
2167
|
+
return await this.resumeThreadAllowingWriterRelease(appServer, agentSessionId, projectPath, threadOptions, previousAppServer);
|
|
2082
2168
|
}
|
|
2083
|
-
|
|
2169
|
+
catch (error) {
|
|
2170
|
+
if (isCodexActiveWriterError(error) && previousAppServer && previousAppServer !== appServer) {
|
|
2171
|
+
// Some Codex builds acknowledge unsubscribe before unloading the
|
|
2172
|
+
// runtime. Archive/unarchive is a synchronous per-thread teardown
|
|
2173
|
+
// and preserves the same persisted thread id for the retry.
|
|
2174
|
+
await this.archiveThreadForHandoff(previousAppServer, appServer, agentSessionId);
|
|
2175
|
+
return appServer.threadResume(agentSessionId, projectPath, threadOptions);
|
|
2176
|
+
}
|
|
2084
2177
|
// A legacy main session can retain a provider ID after its rollout was
|
|
2085
2178
|
// removed externally. It is safe to recover before input submission;
|
|
2086
2179
|
// topic bindings remain authoritative and fail closed.
|
|
2087
2180
|
if (topicBinding || recoverySessionId || modelOverride?.asyncQuestionAnswer || !isCodexNoRolloutError(error))
|
|
2088
2181
|
throw error;
|
|
2089
|
-
if (typeof sessionManager?.clearMainSessionBackendIfMatches !== 'function')
|
|
2090
|
-
throw error;
|
|
2091
2182
|
const missingThreadId = agentSessionId;
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2183
|
+
if (modelOverride?.capsule) {
|
|
2184
|
+
const recovered = await modelOverride.capsule.recover(missingThreadId, prompt, systemPromptAppend);
|
|
2185
|
+
prompt = recovered.prompt;
|
|
2186
|
+
systemPromptAppend = recovered.systemPrompt;
|
|
2187
|
+
threadOptions.developerInstructions = [systemPromptAppend, managedTempInstruction].filter(Boolean).join('\n\n') || undefined;
|
|
2188
|
+
}
|
|
2189
|
+
else {
|
|
2190
|
+
if (typeof sessionManager?.clearMainSessionBackendIfMatches !== 'function')
|
|
2191
|
+
throw error;
|
|
2192
|
+
const cleared = await sessionManager.clearMainSessionBackendIfMatches(sessionId, missingThreadId);
|
|
2193
|
+
if (cleared !== 'cleared' && cleared !== 'already_clear') {
|
|
2194
|
+
const recoveryError = new Error(`Codex missing-rollout recovery rejected: ${cleared}`);
|
|
2195
|
+
recoveryError.code = 'CODEX_MISSING_ROLLOUT_RECOVERY_REJECTED';
|
|
2196
|
+
throw recoveryError;
|
|
2197
|
+
}
|
|
2097
2198
|
}
|
|
2098
2199
|
if (this.activeSessions.get(sessionId) === missingThreadId)
|
|
2099
2200
|
this.activeSessions.delete(sessionId);
|
|
@@ -2104,17 +2205,64 @@ export class CodexRunner {
|
|
|
2104
2205
|
agentSessionId = undefined;
|
|
2105
2206
|
resumingThread = false;
|
|
2106
2207
|
threadSessionToken = this.createThreadCredential();
|
|
2107
|
-
threadOptions =
|
|
2108
|
-
...threadOptions,
|
|
2109
|
-
config: this.sanitizeThreadEnvironmentConfig(this.mergeThreadConfig(executionSandbox.permissionProfileConfig, persistentRuntimeEnv ? { shell_environment_policy: { set: persistentRuntimeEnv } } : undefined, capabilityConfig, userInputConfig, externalToolConfig, this.buildEvolcoreShellEnvironmentConfig(sessionId, threadSessionToken, callMode === 'fullaccess' ? runtimeEnv?.[AGENT_DELEGATION_TOKEN_ENV] : undefined), this.buildLifecycleLockdownConfig(callMode)), callMode, callMode === 'fullaccess' ? runtimeEnv?.[AGENT_DELEGATION_TOKEN_ENV] : undefined),
|
|
2110
|
-
};
|
|
2208
|
+
threadOptions = buildThreadOptions(innerSandboxFallback);
|
|
2111
2209
|
logger.warn(`[CodexRunner] recovered missing rollout before input submission: session=${sessionId} thread=${missingThreadId}`);
|
|
2112
|
-
|
|
2210
|
+
return appServer.threadStart(projectPath, threadOptions);
|
|
2113
2211
|
}
|
|
2114
2212
|
}
|
|
2213
|
+
return appServer.threadStart(projectPath, threadOptions);
|
|
2214
|
+
};
|
|
2215
|
+
try {
|
|
2216
|
+
threadResponse = await openThread();
|
|
2115
2217
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2218
|
+
catch (error) {
|
|
2219
|
+
if (!canFallbackFromInnerSandbox || !isNestedSandboxInitializationFailure(error))
|
|
2220
|
+
throw error;
|
|
2221
|
+
innerSandboxFallback = true;
|
|
2222
|
+
const circuit = recordSandboxInitializationFailure(error, [], Date.now(), sessionId);
|
|
2223
|
+
const context = this.permissionContexts.get(sessionId);
|
|
2224
|
+
const fallbackRequestId = modelOverride?.turn?.inputId ?? `codex-sandbox-fallback-${Date.now()}`;
|
|
2225
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
2226
|
+
auditToolInfrastructureFailure({
|
|
2227
|
+
toolName: 'Bash',
|
|
2228
|
+
policyCode: SANDBOX_INITIALIZATION_FAILED,
|
|
2229
|
+
reason: detail.slice(0, 512),
|
|
2230
|
+
sessionId,
|
|
2231
|
+
agentAid: context?.selfAid,
|
|
2232
|
+
agentName: context?.agentName,
|
|
2233
|
+
permissionMode: callMode,
|
|
2234
|
+
role: context?.role,
|
|
2235
|
+
callId: fallbackRequestId,
|
|
2236
|
+
taskId: context?.taskId,
|
|
2237
|
+
occurrences: circuit.occurrences,
|
|
2238
|
+
fallback: true,
|
|
2239
|
+
sandboxFailure: {
|
|
2240
|
+
kind: circuit.kind,
|
|
2241
|
+
observation: 'fallback',
|
|
2242
|
+
counters: getSandboxInitializationFailureCounters(),
|
|
2243
|
+
},
|
|
2244
|
+
});
|
|
2245
|
+
await context?.recordExecutionAnomaly?.({
|
|
2246
|
+
code: 'capability_unavailable',
|
|
2247
|
+
severity: 'warning',
|
|
2248
|
+
phase: 'execution',
|
|
2249
|
+
occurredAt: Date.now(),
|
|
2250
|
+
correlationId: fallbackRequestId,
|
|
2251
|
+
requestId: fallbackRequestId,
|
|
2252
|
+
sessionId,
|
|
2253
|
+
toolName: 'Bash',
|
|
2254
|
+
policyCode: SANDBOX_INITIALIZATION_FAILED,
|
|
2255
|
+
decisionSource: 'infrastructure',
|
|
2256
|
+
agentAid: context?.selfAid,
|
|
2257
|
+
agentName: context?.agentName,
|
|
2258
|
+
permissionMode: callMode,
|
|
2259
|
+
summary: `Codex inner sandbox unavailable; retrying with outer EvolCore guard: ${detail}`.slice(0, 512),
|
|
2260
|
+
effect: 'fallback_used',
|
|
2261
|
+
});
|
|
2262
|
+
logger.warn(`[CodexSandbox] inner sandbox initialization failed; retrying with outer H-class guard ` +
|
|
2263
|
+
`session=${sessionId} occurrences=${circuit.occurrences}: ${detail}`);
|
|
2264
|
+
threadOptions = buildThreadOptions(true);
|
|
2265
|
+
threadResponse = await openThread();
|
|
2118
2266
|
}
|
|
2119
2267
|
let threadId = threadResponse.thread?.id || agentSessionId;
|
|
2120
2268
|
if (!threadId)
|
|
@@ -2157,7 +2305,16 @@ export class CodexRunner {
|
|
|
2157
2305
|
this.threadProjectPaths.set(threadId, path.resolve(projectPath));
|
|
2158
2306
|
this.bindExternalToolBoundary(threadId, externalToolConfig);
|
|
2159
2307
|
const controller = operationController ?? new AbortController();
|
|
2160
|
-
|
|
2308
|
+
const runTarget = turn && Number.isSafeInteger(turn.generation)
|
|
2309
|
+
? { taskId: turn.taskId, generation: turn.generation }
|
|
2310
|
+
: undefined;
|
|
2311
|
+
const currentAbortTarget = this.activeAbortTargets.get(sessionId);
|
|
2312
|
+
const ownsAbortSlot = !currentAbortTarget
|
|
2313
|
+
|| !!runTarget && runTarget.generation >= currentAbortTarget.generation;
|
|
2314
|
+
if (ownsAbortSlot) {
|
|
2315
|
+
this.activeAbortControllers.set(sessionId, controller);
|
|
2316
|
+
this.activeAbortTargets.set(sessionId, runTarget);
|
|
2317
|
+
}
|
|
2161
2318
|
const answer = modelOverride?.asyncQuestionAnswer;
|
|
2162
2319
|
if (answer && answer.providerThreadId !== threadId) {
|
|
2163
2320
|
throw new Error('Async question reply cannot resume a different Codex thread');
|
|
@@ -2168,6 +2325,8 @@ export class CodexRunner {
|
|
|
2168
2325
|
const state = {
|
|
2169
2326
|
threadId,
|
|
2170
2327
|
sessionId,
|
|
2328
|
+
taskId: turn?.taskId,
|
|
2329
|
+
generation: turn?.generation,
|
|
2171
2330
|
projectPath,
|
|
2172
2331
|
model: callModel,
|
|
2173
2332
|
modelContextId,
|
|
@@ -2232,6 +2391,8 @@ export class CodexRunner {
|
|
|
2232
2391
|
sessionId,
|
|
2233
2392
|
parentThreadId: threadId,
|
|
2234
2393
|
turnId: childTurnId,
|
|
2394
|
+
taskId: state.taskId,
|
|
2395
|
+
generation: state.generation,
|
|
2235
2396
|
});
|
|
2236
2397
|
}
|
|
2237
2398
|
else if (notification.method === 'turn/completed') {
|
|
@@ -2256,10 +2417,12 @@ export class CodexRunner {
|
|
|
2256
2417
|
const startedTurnId = this.extractTurnId(notification);
|
|
2257
2418
|
if (startedTurnId && !state.turnId) {
|
|
2258
2419
|
state.turnId = startedTurnId;
|
|
2259
|
-
this.
|
|
2260
|
-
|
|
2420
|
+
this.setActiveTurn(sessionId, {
|
|
2421
|
+
threadId, turnId: startedTurnId, taskId: state.taskId, generation: state.generation,
|
|
2422
|
+
});
|
|
2423
|
+
if (controller.signal.aborted || (runTarget && this.consumePendingInterrupt(sessionId, runTarget))) {
|
|
2261
2424
|
void interruptStartedTurn(startedTurnId);
|
|
2262
|
-
this.
|
|
2425
|
+
this.clearActiveTurn(sessionId, runTarget);
|
|
2263
2426
|
}
|
|
2264
2427
|
}
|
|
2265
2428
|
}
|
|
@@ -2275,23 +2438,26 @@ export class CodexRunner {
|
|
|
2275
2438
|
this.endAppServerQueueWhenSubagentsDone(queue, state);
|
|
2276
2439
|
}
|
|
2277
2440
|
});
|
|
2278
|
-
if (controller.signal.aborted || this.consumePendingInterrupt(sessionId)) {
|
|
2441
|
+
if (controller.signal.aborted || (runTarget && this.consumePendingInterrupt(sessionId, runTarget))) {
|
|
2279
2442
|
controller.abort('User interrupt');
|
|
2280
2443
|
queue.end();
|
|
2281
|
-
this.
|
|
2282
|
-
this.
|
|
2444
|
+
this.clearActiveController(sessionId, controller);
|
|
2445
|
+
this.clearActiveStream(sessionId, runTarget);
|
|
2283
2446
|
if (!resumingThread)
|
|
2284
2447
|
this.cleanupProvisionalThread(sessionId, threadId);
|
|
2285
2448
|
logger.info(`[CodexRunner] Applied pending interrupt before turn start: ${sessionId}`);
|
|
2286
2449
|
return this.transformAppServerStream(queue, sessionId, state, controller, unsubscribe, appServer);
|
|
2287
2450
|
}
|
|
2288
2451
|
try {
|
|
2452
|
+
operationController?.signal.throwIfAborted();
|
|
2289
2453
|
const turnResponse = await appServer.turnStart(threadId, input, {
|
|
2290
2454
|
cwd: projectPath,
|
|
2291
2455
|
model: callModel,
|
|
2292
2456
|
effort: callEffort,
|
|
2293
2457
|
approvalPolicy: effectiveApprovalPolicy,
|
|
2294
|
-
...(
|
|
2458
|
+
...(innerSandboxFallback
|
|
2459
|
+
? { sandbox: 'danger-full-access' }
|
|
2460
|
+
: executionSandbox.sandbox ? { sandbox: executionSandbox.sandbox } : {}),
|
|
2295
2461
|
});
|
|
2296
2462
|
if (!resumingThread) {
|
|
2297
2463
|
let confirmationInFlight;
|
|
@@ -2336,7 +2502,9 @@ export class CodexRunner {
|
|
|
2336
2502
|
const turnId = turnResponse.turn?.id;
|
|
2337
2503
|
if (turnId && !state.turnId) {
|
|
2338
2504
|
state.turnId = turnId;
|
|
2339
|
-
this.
|
|
2505
|
+
this.setActiveTurn(sessionId, {
|
|
2506
|
+
threadId, turnId, taskId: state.taskId, generation: state.generation,
|
|
2507
|
+
});
|
|
2340
2508
|
}
|
|
2341
2509
|
if (!resumingThread && turnId) {
|
|
2342
2510
|
// Check immediately, but leave a just-created rollout as a candidate.
|
|
@@ -2344,14 +2512,14 @@ export class CodexRunner {
|
|
|
2344
2512
|
// the short settle window below.
|
|
2345
2513
|
await state.confirmProvisional?.(0);
|
|
2346
2514
|
}
|
|
2347
|
-
if (turnId && (controller.signal.aborted || this.consumePendingInterrupt(sessionId))) {
|
|
2515
|
+
if (turnId && (controller.signal.aborted || (runTarget && this.consumePendingInterrupt(sessionId, runTarget)))) {
|
|
2348
2516
|
if (!state.turnCompleted && !['completed', 'failed', 'interrupted'].includes(turnResponse.turn?.status)) {
|
|
2349
2517
|
await interruptStartedTurn(turnId);
|
|
2350
2518
|
}
|
|
2351
2519
|
controller.abort('User interrupt');
|
|
2352
|
-
this.
|
|
2353
|
-
this.
|
|
2354
|
-
this.
|
|
2520
|
+
this.clearActiveController(sessionId, controller);
|
|
2521
|
+
this.clearActiveStream(sessionId, runTarget);
|
|
2522
|
+
this.clearActiveTurn(sessionId, runTarget);
|
|
2355
2523
|
}
|
|
2356
2524
|
const status = turnResponse.turn?.status;
|
|
2357
2525
|
if (status === 'completed' || status === 'failed') {
|
|
@@ -2364,9 +2532,10 @@ export class CodexRunner {
|
|
|
2364
2532
|
catch (error) {
|
|
2365
2533
|
unsubscribe();
|
|
2366
2534
|
await this.releaseThreadSubscription(appServer, threadId, 'turn-start-failed');
|
|
2367
|
-
this.
|
|
2368
|
-
this.
|
|
2369
|
-
|
|
2535
|
+
this.clearActiveController(sessionId, controller);
|
|
2536
|
+
this.clearActiveTurn(sessionId, runTarget);
|
|
2537
|
+
if (runTarget)
|
|
2538
|
+
this.consumePendingInterrupt(sessionId, runTarget);
|
|
2370
2539
|
if (!resumingThread)
|
|
2371
2540
|
this.cleanupProvisionalThread(sessionId, threadId);
|
|
2372
2541
|
throw error;
|
|
@@ -2374,37 +2543,64 @@ export class CodexRunner {
|
|
|
2374
2543
|
return this.transformAppServerStream(queue, sessionId, state, controller, unsubscribe, appServer);
|
|
2375
2544
|
}
|
|
2376
2545
|
// ── Interrupt ──
|
|
2377
|
-
async interrupt(sessionKey) {
|
|
2378
|
-
this.permissionContexts.get(sessionKey)?.pauseController?.cancel();
|
|
2546
|
+
async interrupt(sessionKey, target) {
|
|
2379
2547
|
const operations = this.queryOperations.get(sessionKey);
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
}
|
|
2548
|
+
const matchingOperations = [...(operations ?? [])].filter(operation => target ? matchesCodexTask(this.targetForOperation(operation), target) : operation.lockAcquired);
|
|
2549
|
+
for (const operation of matchingOperations) {
|
|
2550
|
+
operation.controller.abort(Object.assign(new Error('Codex operation interrupted'), { name: 'AbortError' }));
|
|
2384
2551
|
}
|
|
2385
2552
|
const controller = this.activeAbortControllers.get(sessionKey);
|
|
2386
2553
|
const activeTurn = this.activeTurns.get(sessionKey);
|
|
2387
|
-
const
|
|
2388
|
-
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2554
|
+
const matchingController = controller && (!target || matchesCodexTask(this.activeAbortTargets.get(sessionKey), target))
|
|
2555
|
+
? controller : undefined;
|
|
2556
|
+
const matchingTurn = activeTurn && (!target || matchesCodexTask(activeTurn, target)) ? activeTurn : undefined;
|
|
2557
|
+
const matchingStream = this.activeStreams.has(sessionKey)
|
|
2558
|
+
&& (!target || matchesCodexTask(this.activeStreamTargets.get(sessionKey), target));
|
|
2559
|
+
const hadActiveState = !!matchingController || !!matchingTurn || matchingStream || matchingOperations.length > 0;
|
|
2560
|
+
const hasPendingTarget = target
|
|
2561
|
+
&& (this.pendingInterrupts.get(sessionKey) ?? []).some(entry => matchesCodexTask(entry.target, target));
|
|
2562
|
+
if (target && !hadActiveState && !hasPendingTarget) {
|
|
2563
|
+
const activeOperation = [...(operations ?? [])].some(operation => operation.lockAcquired);
|
|
2564
|
+
if (activeOperation)
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
if (!target || hadActiveState || hasPendingTarget) {
|
|
2568
|
+
this.permissionContexts.get(sessionKey)?.pauseController?.cancel();
|
|
2569
|
+
}
|
|
2570
|
+
const interruptTurn = matchingTurn
|
|
2571
|
+
? this.interruptAppServerTurn(matchingTurn.threadId, matchingTurn.turnId)
|
|
2391
2572
|
: Promise.resolve();
|
|
2392
|
-
const interruptSubagents = this.interruptSubagentTurns(sessionKey);
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2573
|
+
const interruptSubagents = this.interruptSubagentTurns(sessionKey, matchingTurn?.threadId, target);
|
|
2574
|
+
// Only a task-scoped request may be retained for a runner that has not
|
|
2575
|
+
// reached its first turn yet. A session-only interrupt must never poison
|
|
2576
|
+
// a later task during this startup gap.
|
|
2577
|
+
if (target && !hadActiveState && !hasPendingTarget && !(operations && operations.size > 0)
|
|
2578
|
+
&& !controller && !activeTurn && !this.activeStreams.has(sessionKey)) {
|
|
2579
|
+
this.rememberPendingInterrupt(sessionKey, target);
|
|
2580
|
+
}
|
|
2581
|
+
if (matchingController)
|
|
2582
|
+
matchingController.abort('User interrupt');
|
|
2397
2583
|
if (hadActiveState) {
|
|
2398
|
-
this.activeAbortControllers.
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2584
|
+
if (matchingController && this.activeAbortControllers.get(sessionKey) === matchingController) {
|
|
2585
|
+
this.clearActiveController(sessionKey, matchingController);
|
|
2586
|
+
}
|
|
2587
|
+
if (matchingStream && (!target || this.activeStreamTargets.get(sessionKey)?.taskId === target?.taskId
|
|
2588
|
+
&& this.activeStreamTargets.get(sessionKey)?.generation === target?.generation)) {
|
|
2589
|
+
this.activeStreams.delete(sessionKey);
|
|
2590
|
+
this.activeStreamTargets.delete(sessionKey);
|
|
2591
|
+
}
|
|
2592
|
+
if (matchingTurn && (!target || matchesCodexTask(this.activeTurns.get(sessionKey), target))) {
|
|
2593
|
+
this.activeTurns.delete(sessionKey);
|
|
2594
|
+
}
|
|
2595
|
+
logger.info(`[CodexRunner] Interrupted ${target ? `task=${target.taskId} generation=${target.generation}` : 'session'}: ${sessionKey}`);
|
|
2402
2596
|
}
|
|
2403
2597
|
await Promise.all([interruptTurn, interruptSubagents]);
|
|
2404
2598
|
}
|
|
2405
|
-
async interruptSubagentTurns(sessionId, parentThreadId) {
|
|
2599
|
+
async interruptSubagentTurns(sessionId, parentThreadId, target) {
|
|
2406
2600
|
const entries = [...this.activeSubagentTurns.entries()]
|
|
2407
|
-
.filter(([, active]) => active.sessionId === sessionId
|
|
2601
|
+
.filter(([, active]) => active.sessionId === sessionId
|
|
2602
|
+
&& (!parentThreadId || active.parentThreadId === parentThreadId)
|
|
2603
|
+
&& (!target || matchesCodexTask(active, target)));
|
|
2408
2604
|
await Promise.all(entries.map(async ([childThreadId, active]) => {
|
|
2409
2605
|
await this.interruptAppServerTurn(childThreadId, active.turnId).catch(() => { });
|
|
2410
2606
|
const current = this.activeSubagentTurns.get(childThreadId);
|
|
@@ -2412,21 +2608,34 @@ export class CodexRunner {
|
|
|
2412
2608
|
this.activeSubagentTurns.delete(childThreadId);
|
|
2413
2609
|
}));
|
|
2414
2610
|
}
|
|
2415
|
-
rememberPendingInterrupt(sessionId) {
|
|
2416
|
-
this.pendingInterrupts.
|
|
2611
|
+
rememberPendingInterrupt(sessionId, target) {
|
|
2612
|
+
const entries = this.pendingInterrupts.get(sessionId) ?? [];
|
|
2613
|
+
entries.push({ requestedAt: Date.now(), target });
|
|
2614
|
+
this.pendingInterrupts.set(sessionId, entries);
|
|
2417
2615
|
}
|
|
2418
|
-
consumePendingInterrupt(sessionId) {
|
|
2419
|
-
|
|
2616
|
+
consumePendingInterrupt(sessionId, target) {
|
|
2617
|
+
const entries = this.pendingInterrupts.get(sessionId);
|
|
2618
|
+
if (!entries?.length)
|
|
2420
2619
|
return false;
|
|
2421
|
-
const
|
|
2422
|
-
|
|
2423
|
-
|
|
2620
|
+
const now = Date.now();
|
|
2621
|
+
const matching = entries.findIndex(entry => matchesCodexTask(entry.target, target) && now - entry.requestedAt <= this.pendingInterruptTtlMs);
|
|
2622
|
+
const remaining = entries.filter((entry, index) => index !== matching && now - entry.requestedAt <= this.pendingInterruptTtlMs);
|
|
2623
|
+
if (remaining.length > 0)
|
|
2624
|
+
this.pendingInterrupts.set(sessionId, remaining);
|
|
2625
|
+
else
|
|
2626
|
+
this.pendingInterrupts.delete(sessionId);
|
|
2627
|
+
return matching >= 0;
|
|
2424
2628
|
}
|
|
2425
|
-
dropExpiredPendingInterrupt(sessionId) {
|
|
2426
|
-
const
|
|
2427
|
-
if (
|
|
2629
|
+
dropExpiredPendingInterrupt(sessionId, currentTarget) {
|
|
2630
|
+
const entries = this.pendingInterrupts.get(sessionId);
|
|
2631
|
+
if (!entries)
|
|
2632
|
+
return;
|
|
2633
|
+
const active = entries.filter(entry => Date.now() - entry.requestedAt <= this.pendingInterruptTtlMs
|
|
2634
|
+
&& (!currentTarget || entry.target.generation >= currentTarget.generation));
|
|
2635
|
+
if (active.length > 0)
|
|
2636
|
+
this.pendingInterrupts.set(sessionId, active);
|
|
2637
|
+
else
|
|
2428
2638
|
this.pendingInterrupts.delete(sessionId);
|
|
2429
|
-
}
|
|
2430
2639
|
}
|
|
2431
2640
|
async interruptAppServerTurn(threadId, turnId) {
|
|
2432
2641
|
const sessionId = this.findSessionKeyByThread(threadId);
|
|
@@ -2571,13 +2780,17 @@ export class CodexRunner {
|
|
|
2571
2780
|
&& this.threadSubscriptions.get(capturedThreadId) === capturedSubscription) {
|
|
2572
2781
|
await this.releaseThreadSubscription(capturedSubscription.client, capturedThreadId, 'session-closed');
|
|
2573
2782
|
}
|
|
2574
|
-
if (capturedStream !== undefined && this.activeStreams.get(sessionId) === capturedStream)
|
|
2783
|
+
if (capturedStream !== undefined && this.activeStreams.get(sessionId) === capturedStream) {
|
|
2575
2784
|
this.activeStreams.delete(sessionId);
|
|
2576
|
-
|
|
2785
|
+
this.activeStreamTargets.delete(sessionId);
|
|
2786
|
+
}
|
|
2787
|
+
if (capturedController !== undefined && this.activeAbortControllers.get(sessionId) === capturedController) {
|
|
2577
2788
|
this.activeAbortControllers.delete(sessionId);
|
|
2789
|
+
this.activeAbortTargets.delete(sessionId);
|
|
2790
|
+
}
|
|
2578
2791
|
if (capturedTurn !== undefined && this.activeTurns.get(sessionId) === capturedTurn)
|
|
2579
2792
|
this.activeTurns.delete(sessionId);
|
|
2580
|
-
if (
|
|
2793
|
+
if (!lifecycleReplaced)
|
|
2581
2794
|
this.pendingInterrupts.delete(sessionId);
|
|
2582
2795
|
if (this.permissionContexts.get(sessionId) === capturedPermissionContext)
|
|
2583
2796
|
this.permissionContexts.delete(sessionId);
|
|
@@ -2597,6 +2810,7 @@ export class CodexRunner {
|
|
|
2597
2810
|
}
|
|
2598
2811
|
this.clearTrackedApprovalItemsForThread(capturedThreadId);
|
|
2599
2812
|
this.cleanupChildThreadsForSession(sessionId);
|
|
2813
|
+
this.activeOperationReleaseTargets.delete(sessionId);
|
|
2600
2814
|
this.pruneThreadOperationLocks();
|
|
2601
2815
|
}
|
|
2602
2816
|
}
|
|
@@ -2630,6 +2844,10 @@ export class CodexRunner {
|
|
|
2630
2844
|
}
|
|
2631
2845
|
this.activeSessions.delete(sessionId);
|
|
2632
2846
|
this.activeTurns.delete(sessionId);
|
|
2847
|
+
this.activeAbortTargets.delete(sessionId);
|
|
2848
|
+
this.activeStreamTargets.delete(sessionId);
|
|
2849
|
+
this.activeOperationReleaseTargets.delete(sessionId);
|
|
2850
|
+
this.activeOperationReleases.delete(sessionId);
|
|
2633
2851
|
this.steeringTails.delete(sessionId);
|
|
2634
2852
|
this.chatModes.delete(sessionId);
|
|
2635
2853
|
this.threadProjectPaths.delete(threadId);
|
|
@@ -3110,6 +3328,16 @@ export class CodexRunner {
|
|
|
3110
3328
|
return undefined;
|
|
3111
3329
|
return JSON.stringify([threadId, turnId, itemId]);
|
|
3112
3330
|
}
|
|
3331
|
+
safeOutputCallKey(threadId, callId) {
|
|
3332
|
+
return callId ? JSON.stringify([threadId, callId]) : undefined;
|
|
3333
|
+
}
|
|
3334
|
+
pruneRegisteredSafeOutputCalls() {
|
|
3335
|
+
const now = Date.now();
|
|
3336
|
+
for (const [key, value] of this.registeredSafeOutputCalls) {
|
|
3337
|
+
if (value.expiresAt <= now)
|
|
3338
|
+
this.registeredSafeOutputCalls.delete(key);
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3113
3341
|
trackApprovalItemNotification(notification) {
|
|
3114
3342
|
const params = (notification.params || {});
|
|
3115
3343
|
const item = params.item && typeof params.item === 'object' ? params.item : undefined;
|
|
@@ -3117,6 +3345,9 @@ export class CodexRunner {
|
|
|
3117
3345
|
const threadId = this.requestThreadId(params);
|
|
3118
3346
|
const turnId = params.turnId ?? params.turn_id;
|
|
3119
3347
|
const key = this.approvalItemKey(threadId, turnId, itemId);
|
|
3348
|
+
if (notification.method === 'item/completed' && threadId && typeof itemId === 'string') {
|
|
3349
|
+
this.registeredSafeOutputCalls.delete(JSON.stringify([threadId, itemId]));
|
|
3350
|
+
}
|
|
3120
3351
|
if (notification.method === 'item/started' && key && item && threadId) {
|
|
3121
3352
|
this.trackedApprovalItems.set(key, {
|
|
3122
3353
|
threadId,
|
|
@@ -3454,10 +3685,41 @@ export class CodexRunner {
|
|
|
3454
3685
|
const isCommandApproval = request.method === 'item/commandExecution/requestApproval'
|
|
3455
3686
|
|| request.method === 'execCommandApproval';
|
|
3456
3687
|
const sessionCredential = this.sessionTokenForSession(sessionKey, typeof params.threadId === 'string' ? params.threadId : undefined);
|
|
3457
|
-
|
|
3688
|
+
let canonicalEcApproval = isCommandApproval
|
|
3458
3689
|
? this.resolveCanonicalEcApproval(toolInput, this.getManagedTempDir(sessionKey), sessionCredential)
|
|
3459
3690
|
: undefined;
|
|
3460
|
-
const
|
|
3691
|
+
const approvalItemId = approvalCallId ?? approvalRequestId;
|
|
3692
|
+
const approvalThreadId = this.requestThreadId(params) ?? sessionKey;
|
|
3693
|
+
const preToolOutput = canonicalEcApproval?.executionSpec
|
|
3694
|
+
? parseDelegatedExecutionSpec(canonicalEcApproval.executionSpec)
|
|
3695
|
+
: undefined;
|
|
3696
|
+
if (preToolOutput) {
|
|
3697
|
+
this.pruneRegisteredSafeOutputCalls();
|
|
3698
|
+
const key = this.safeOutputCallKey(approvalThreadId, approvalItemId);
|
|
3699
|
+
const registered = key ? this.registeredSafeOutputCalls.get(key) : undefined;
|
|
3700
|
+
const safeOutput = this.parseSafeOutputToolInput(toolInput);
|
|
3701
|
+
if (key)
|
|
3702
|
+
this.registeredSafeOutputCalls.delete(key);
|
|
3703
|
+
if (!registered || !safeOutput
|
|
3704
|
+
|| JSON.stringify(registered.updatedArgv) !== JSON.stringify(safeOutput.argv)
|
|
3705
|
+
|| hashDelegatedCommandSpec(registered.spec) !== hashDelegatedCommandSpec(preToolOutput)) {
|
|
3706
|
+
canonicalEcApproval = {
|
|
3707
|
+
parseFailure: {
|
|
3708
|
+
issue: 'shell-composition',
|
|
3709
|
+
offset: 0,
|
|
3710
|
+
tokenIndex: 0,
|
|
3711
|
+
dialect: preToolOutput.dialect,
|
|
3712
|
+
inputLength: typeof toolInput.command === 'string' ? toolInput.command.length : 0,
|
|
3713
|
+
canonicalizationStage: 'safe-output-binding',
|
|
3714
|
+
wrapper: preToolOutput.wrapper,
|
|
3715
|
+
redirectDetected: true,
|
|
3716
|
+
},
|
|
3717
|
+
};
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
const approvedCommand = !canonicalEcApproval?.parseFailure && preToolOutput
|
|
3721
|
+
? [...preToolOutput.argv]
|
|
3722
|
+
: !canonicalEcApproval?.parseFailure ? canonicalEcApproval?.argv : undefined;
|
|
3461
3723
|
// Canonical parsing is authoritative. Intent classification remains a
|
|
3462
3724
|
// fail-closed signal for malformed EC-shaped commands that cannot be armed.
|
|
3463
3725
|
const managedEcIntent = isCommandApproval && (approvedCommand?.[0] === 'ec' || this.isManagedEvolcoreCommandIntent(toolInput));
|
|
@@ -3539,7 +3801,7 @@ export class CodexRunner {
|
|
|
3539
3801
|
return await denyInfrastructure('delegation_token_mismatch', 'EC command approval contains a delegation token different from the active thread credential');
|
|
3540
3802
|
}
|
|
3541
3803
|
if ((hasSessionCredential || canArmDelegation)
|
|
3542
|
-
&& !this.armApprovedDelegationCommand(sessionKey, approvedCommand,
|
|
3804
|
+
&& !this.armApprovedDelegationCommand(sessionKey, approvedCommand, approvalItemId, canonicalEcApproval?.specHash, preToolOutput)) {
|
|
3543
3805
|
return await denyInfrastructure('delegation_not_armed', 'EC command approval failed to arm delegation');
|
|
3544
3806
|
}
|
|
3545
3807
|
}
|
|
@@ -4042,6 +4304,8 @@ export class CodexRunner {
|
|
|
4042
4304
|
const command = Array.isArray(rawCommand) ? rawCommand.join(' ') : (rawCommand || '');
|
|
4043
4305
|
return {
|
|
4044
4306
|
command,
|
|
4307
|
+
...(typeof params.itemId === 'string' ? { itemId: params.itemId } : {}),
|
|
4308
|
+
...(typeof params.callId === 'string' ? { callId: params.callId } : {}),
|
|
4045
4309
|
...(Array.isArray(rawCommand) ? { commandArgv: rawCommand } : {}),
|
|
4046
4310
|
cwd: params.cwd ?? trackedItem?.cwd,
|
|
4047
4311
|
reason: params.reason,
|
|
@@ -5009,13 +5273,17 @@ export class CodexRunner {
|
|
|
5009
5273
|
unsubscribe();
|
|
5010
5274
|
await this.releaseThreadSubscription(appServer, state.threadId, 'turn-finished');
|
|
5011
5275
|
if (this.activeAbortControllers.get(sessionId) === controller) {
|
|
5012
|
-
this.
|
|
5276
|
+
this.clearActiveController(sessionId, controller);
|
|
5013
5277
|
}
|
|
5014
5278
|
const activeTurn = this.activeTurns.get(sessionId);
|
|
5015
5279
|
if (activeTurn?.threadId === state.threadId
|
|
5016
5280
|
&& (!state.turnId || activeTurn.turnId === state.turnId)) {
|
|
5017
5281
|
this.activeTurns.delete(sessionId);
|
|
5018
5282
|
}
|
|
5283
|
+
if (this.activeStreamTargets.get(sessionId)?.taskId === state.taskId
|
|
5284
|
+
&& this.activeStreamTargets.get(sessionId)?.generation === state.generation) {
|
|
5285
|
+
this.activeStreamTargets.delete(sessionId);
|
|
5286
|
+
}
|
|
5019
5287
|
if (!state.committed)
|
|
5020
5288
|
this.cleanupProvisionalThread(sessionId, state.threadId);
|
|
5021
5289
|
for (const childThreadId of state.activeSubagentThreads)
|
|
@@ -5030,7 +5298,12 @@ export class CodexRunner {
|
|
|
5030
5298
|
const turnId = this.extractTurnId(notification);
|
|
5031
5299
|
if (turnId) {
|
|
5032
5300
|
state.turnId = turnId;
|
|
5033
|
-
this.
|
|
5301
|
+
this.setActiveTurn(sessionId, {
|
|
5302
|
+
threadId: state.threadId,
|
|
5303
|
+
turnId,
|
|
5304
|
+
taskId: state.taskId,
|
|
5305
|
+
generation: state.generation,
|
|
5306
|
+
});
|
|
5034
5307
|
}
|
|
5035
5308
|
// turn/start 已落地并回执 turn/started ⇒ 用户输入已被 app-server 接受。
|
|
5036
5309
|
// 此后中断不能把该输入当作「未提交」重放,否则会产生重复用户轮次。
|
|
@@ -5895,6 +6168,7 @@ export class CodexRunner {
|
|
|
5895
6168
|
this.threadExternalToolFingerprints.clear();
|
|
5896
6169
|
this.threadExternalToolBoundaries.clear();
|
|
5897
6170
|
this.trackedApprovalItems.clear();
|
|
6171
|
+
this.registeredSafeOutputCalls.clear();
|
|
5898
6172
|
this.pendingInterrupts.clear();
|
|
5899
6173
|
for (const record of this.unconfirmedInterrupts.values())
|
|
5900
6174
|
record.unsubscribe?.();
|
|
@@ -5904,6 +6178,8 @@ export class CodexRunner {
|
|
|
5904
6178
|
this.chatModes.clear();
|
|
5905
6179
|
this.pruneThreadOperationLocks();
|
|
5906
6180
|
this.threadOperationLocks.clear();
|
|
6181
|
+
this.activeOperationReleases.clear();
|
|
6182
|
+
this.activeOperationReleaseTargets.clear();
|
|
5907
6183
|
await Promise.all([
|
|
5908
6184
|
...[...this.retiredProviderClients].map(client => client.close()),
|
|
5909
6185
|
this.appServerClient?.close(),
|