Skip to content

Commit b48f1c9

Browse files
PR Batch Testerclaude
andcommitted
fix(server): track paused subagent requests after an empty startup
A linked environment whose startup snapshot had nothing to publish never turned on paused tracking, so a child that started waiting while publishing was off was missed. The completed startup snapshot now counts as having published. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a3b9a8f commit b48f1c9

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,36 @@ describe("AgentAwarenessRelay", () => {
439439
}),
440440
);
441441

442+
it.effect(
443+
"keeps a subagent request that started while publishing was off after an empty startup",
444+
() =>
445+
Effect.gen(function* () {
446+
const shells = yield* Ref.make(
447+
new Map<ThreadId, OrchestrationV2ThreadShell>([
448+
[THREAD_ID, shell()],
449+
[CHILD_THREAD_ID, waitingChild({ pendingRuntimeRequest: null })],
450+
]),
451+
);
452+
const { relay, secrets, publications, catchUp } = yield* makeTestRelay({
453+
readShell: (threadId) =>
454+
Ref.get(shells).pipe(Effect.map((current) => current.get(threadId) ?? null)),
455+
});
456+
yield* relay.start();
457+
yield* TestClock.adjust("1 second");
458+
assert.equal(catchUp.shellSnapshotReads, 1);
459+
assert.equal(publications.length, 0);
460+
461+
yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("false"));
462+
yield* Ref.update(shells, (current) =>
463+
new Map(current).set(CHILD_THREAD_ID, waitingChild()),
464+
);
465+
yield* relay.publishThread(CHILD_THREAD_ID);
466+
yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("true"));
467+
yield* relay.publishThread(THREAD_ID);
468+
assert.equal(publications[0]?.state?.phase, "waiting_for_approval");
469+
}).pipe(Effect.scoped),
470+
);
471+
442472
it.effect("drops a subagent request that cleared while publishing was off", () =>
443473
Effect.gen(function* () {
444474
const shells = yield* Ref.make(

‎apps/server/src/relay/AgentAwarenessRelay.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ export const make = Effect.gen(function* () {
388388
const publishedStateByThreadRef = yield* Ref.make(new Map<ThreadId, string>());
389389
const subagentRequests = new Map<ThreadId, SubagentRequest>();
390390
// Environments that never publish skip the extra shell read while paused.
391+
// Set by the first publish or by a startup snapshot, even an empty one.
391392
let hasPublished = false;
392393

393394
const readSecretString = (name: string) =>
@@ -831,6 +832,7 @@ export const make = Effect.gen(function* () {
831832
Effect.orElseSucceed(() => "failed" as const),
832833
);
833834
if (result === "published") {
835+
hasPublished = true;
834836
yield* Ref.set(activeSnapshotPublishedRef, true);
835837
if (logEnabledWhenReady) {
836838
const relayConfig = yield* readRelayConfig.pipe(Effect.orElseSucceed(() => null));

0 commit comments

Comments
 (0)