GeezerVison is showing github.com — fix(provider-acp): reconfigure when approval or sandbox policy changes · pingdotgg/t3code@0f98c52
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2/Adapters packages/provider-acp/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +63Lines changed: 63 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2451,6 +2451,69 @@ describe("AcpAdapterV2", () => { | 2451 | 2451 | }).pipe(Effect.provide(layerTest)), | 2452 | 2452 | ); | 2453 | 2453 |
| | 2454 | + it.live("reconfigures a reused ACP session only when its policy changes", () => | | 2455 | + Effect.gen(function* () { | | 2456 | + const instanceId = ProviderInstanceId.make("acp-policy-changes"); | | 2457 | + const threadId = ThreadId.make("thread-policy-changes"); | | 2458 | + const modelSelection = { instanceId, model: "default" }; | | 2459 | + let configurations = 0; | | 2460 | + const adapter = yield* makeAcpAdapterV2({ | | 2461 | + instanceId, | | 2462 | + selfInvocation: yield* resolveSelfInvocation(), | | 2463 | + flavor: { | | 2464 | + driver: ACP_TEST_DRIVER, | | 2465 | + capabilities: AcpProviderCapabilitiesV2, | | 2466 | + onSessionConfigurationUpdate: () => Effect.sync(() => configurations++), | | 2467 | + makeRuntime: makeMockRuntime({ | | 2468 | + childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, | | 2469 | + mockAgentPath: yield* bundledMockAgentPath, | | 2470 | + }), | | 2471 | + }, | | 2472 | + }); | | 2473 | + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ | | 2474 | + runtimeMode: "approval-required", | | 2475 | + interactionMode: "default", | | 2476 | + cwd: process.cwd(), | | 2477 | + }); | | 2478 | + const runtime = yield* adapter.openSession({ | | 2479 | + threadId, | | 2480 | + providerSessionId: ProviderSessionId.make("session-policy-changes"), | | 2481 | + modelSelection, | | 2482 | + runtimePolicy, | | 2483 | + }); | | 2484 | + const providerThread = yield* runtime.ensureThread({ | | 2485 | + threadId, | | 2486 | + modelSelection, | | 2487 | + runtimePolicy, | | 2488 | + }); | | 2489 | + const changes = []; | | 2490 | + for (const [ordinal, restrictions] of [ | | 2491 | + { approvalPolicy: "on-request" }, | | 2492 | + { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, | | 2493 | + { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, | | 2494 | + ].entries()) { | | 2495 | + const before = configurations; | | 2496 | + yield* runtime.startTurn( | | 2497 | + makeTurnInput({ | | 2498 | + threadId, | | 2499 | + providerThread, | | 2500 | + instanceId, | | 2501 | + modelSelection, | | 2502 | + runtimePolicy: { ...runtimePolicy, ...restrictions }, | | 2503 | + now: yield* DateTime.now, | | 2504 | + ordinal, | | 2505 | + }), | | 2506 | + ); | | 2507 | + yield* runtime.events.pipe( | | 2508 | + Stream.takeUntil((event) => event.type === "turn.terminal"), | | 2509 | + Stream.runDrain, | | 2510 | + ); | | 2511 | + changes.push(configurations - before); | | 2512 | + } | | 2513 | + assert.deepEqual(changes, [1, 1, 0], "approval changed, sandbox changed, unchanged"); | | 2514 | + }).pipe(Effect.provide(layerTest)), | | 2515 | + ); | | 2516 | + | 2454 | 2517 | it.live.each(["failed", "recovered", "cancelled"] as const)( | 2455 | 2518 | "projects Mistral retry notices and their %s outcome", | 2456 | 2519 | (outcome) => | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-acp/src/server/adapter.ts +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2251,9 +2251,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 2251 | 2251 | }); | 2252 | 2252 | const activeSelection = yield* Ref.make<ModelSelection | null>(null); | 2253 | 2253 | const activeInteractionMode = yield* Ref.make<ProviderInteractionMode | null>(null); | 2254 | | - const configuredRuntimeMode = yield* Ref.make< | 2255 | | - ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"] | null | 2256 | | - >(null); | | 2254 | + const configuredRuntimePolicy = | | 2255 | + yield* Ref.make<ProviderAdapter.ProviderAdapterV2RuntimePolicy | null>(null); | 2257 | 2256 | const promptInstructionStates = yield* Ref.make(new Map<string, T3AcpInstructionState>()); | 2258 | 2257 | const promptRuntimeInstructions = yield* Ref.make(new Map<string, string>()); | 2259 | 2258 | // Unique markers keep delayed prompt completions from clearing later compactions. | @@ -8269,7 +8268,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 8269 | 8268 | } | 8270 | 8269 | } | 8271 | 8270 | yield* validateModelSelection(modelSelection); | 8272 | | - yield* Ref.set(configuredRuntimeMode, runtimePolicy.runtimeMode); | | 8271 | + yield* Ref.set(configuredRuntimePolicy, runtimePolicy); | 8273 | 8272 | yield* ( | 8274 | 8273 | flavor.onSessionConfigurationUpdate?.( | 8275 | 8274 | yield* runtime.getConfigOptions, | @@ -9169,11 +9168,18 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 9169 | 9168 | } else { | 9170 | 9169 | const configuredSelection = yield* Ref.get(activeSelection); | 9171 | 9170 | const configuredInteractionMode = yield* Ref.get(activeInteractionMode); | | 9171 | + const configuredPolicy = yield* Ref.get(configuredRuntimePolicy); | 9172 | 9172 | if ( | 9173 | 9173 | configuredSelection === null || | 9174 | 9174 | !modelSelectionsEqual(configuredSelection, turnInput.modelSelection) || | 9175 | 9175 | configuredInteractionMode !== turnInput.runtimePolicy.interactionMode || | 9176 | | - (yield* Ref.get(configuredRuntimeMode)) !== turnInput.runtimePolicy.runtimeMode | | 9176 | + configuredPolicy === null || | | 9177 | + configuredPolicy.runtimeMode !== turnInput.runtimePolicy.runtimeMode || | | 9178 | + !Equal.equals( | | 9179 | + configuredPolicy.approvalPolicy, | | 9180 | + turnInput.runtimePolicy.approvalPolicy, | | 9181 | + ) || | | 9182 | + !Equal.equals(configuredPolicy.sandboxPolicy, turnInput.runtimePolicy.sandboxPolicy) | 9177 | 9183 | ) { | 9178 | 9184 | const currentSessionSetup = yield* Ref.get(activeSessionSetup); | 9179 | 9185 | if (currentSessionSetup === null) { | |
|