Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,94 @@ describe('HostInteractionCoordinator', () => {
});
});

test('does not hold Session admission while graph wake reconciliation waits', async () => {
await withStore(async ({ owner, store, stores }) => {
const workspace = join(owner.capability.canonicalPath, 'wake-workspace');
await mkdir(workspace);
const session = await stores.sessionStore.create({
cwd: workspace,
llmConnectionId: 'cccccccc-cccc-4ccc-8ccc-cccccccccccc',
llmConnectionSlug: 'fake',
model: 'fake-model',
permissionMode: 'ask',
});
const identity = { ...RUN, sessionId: session.id };
const wakeStarted = deferred();
const releaseWake = deferred();
const wakeFinished = deferred();
const coordinator = new HostInteractionCoordinator({
store,
sandboxBoundaries: stores.sessionStore,
sessionAdmission: new SessionAdmissionGate(),
sessions: stores.sessionStore,
preflightSessionSnapshot: () => true,
refreshCanonicalContinuity: async () => {},
onSandboxBoundarySettled: async () => {
wakeStarted.resolve();
await releaseWake.promise;
wakeFinished.resolve();
},
onPoison: () => {},
});
const binding = coordinator.bindRun(identity);
const request = sandboxBoundaryEvent({
sessionId: session.id,
requestId: 'boundary_wake_wait',
status: 'pending',
baseRevision: 0,
turnId: identity.turnId,
runId: identity.runId,
expansion: { network: { enabled: true } },
justification: 'Connect to the requested service.',
createdAt: 1,
});
await binding.acceptSandboxBoundaryRequest({
request,
continuation: sandboxBoundaryContinuation(identity, request.requestId),
});

let answerSettled = false;
let answerResult:
| Awaited<ReturnType<(typeof coordinator.handlers)['interaction.answer']>>
| undefined;
const answer = coordinator.handlers['interaction.answer'](
{
sessionId: session.id,
interactionId: request.requestId,
answer: { kind: 'sandbox_boundary', decision: 'allow' },
},
connection(),
);
void answer.then(
(result) => {
answerResult = result;
answerSettled = true;
},
() => {
answerSettled = true;
},
);
await wakeStarted.promise;
try {
await new Promise<void>((resolve) => setImmediate(resolve));
assert.equal(
answerSettled,
true,
'interaction answer waited for graph wake reconciliation',
);
assert.equal(answerResult?.ok, true);
if (answerResult?.ok) assert.equal(answerResult.result.status, 'answered');
} finally {
releaseWake.resolve();
await wakeFinished.promise;
await answer;
}
await binding.close('turn_terminal');
binding.release();
await coordinator.close();
});
});

test('a queued stop waits for sandbox boundary publication before closing its Run', async () => {
await withStore(async ({ owner, store, stores }) => {
const workspace = join(owner.capability.canonicalPath, 'publication-workspace');
Expand Down
11 changes: 10 additions & 1 deletion packages/runtime-host/src/server/interaction-coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,16 @@ export class HostInteractionCoordinator implements RuntimeInteractionAuthority {
await this.#refreshCanonicalContinuity(request.sessionId, admission);
this.#throwIfPoisoned();
await this.#applySandboxBoundaryDecisionAndDelete(entry, settlement);
await this.#onSandboxBoundarySettled(request.sessionId);
// The answer owns Session admission. Graph-wake reconciliation may need to
// acquire the activity lease held by the wake turn that is parked on this
// very answer, so awaiting it here deadlocks the Session (#3328, #3866).
// Start it after the durable answer is applied, but keep failures visible
// to the Host's fail-stop path instead of creating an unhandled rejection.
void Promise.resolve()
.then(() => this.#onSandboxBoundarySettled(request.sessionId))
.catch((error: unknown) => {
this.#poison(error);
});
const result = projectSandboxBoundaryInteraction(settlement.request);
if (result.status !== 'answered') {
throw this.#poison(
Expand Down