Skip to content

Commit 443edd5

Browse files
only21milclaudemaria-rcks
authored
fix(provider-core): subagent threads no longer inherit the parent's pin (pingdotgg#21271)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent a49a3f7 commit 443edd5

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/SubagentProjection.test.ts‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@t3tools/contracts";
1717
import * as DateTime from "effect/DateTime";
1818
import * as Effect from "effect/Effect";
19+
import * as Layer from "effect/Layer";
1920

2021
import {
2122
makeSubagentChildThread,
@@ -26,7 +27,9 @@ import {
2627
endRunlessRootTurns,
2728
} from "@t3tools/provider-core/server/subagentProjection";
2829

29-
import { emptyProjection } from "./ProjectionStore.ts";
30+
import * as SqlitePersistence from "../persistence/Sqlite.ts";
31+
import * as ProjectionStore from "./ProjectionStore.ts";
32+
import { resolveAutoSettlementAt } from "./ThreadSettlementService.ts";
3033

3134
const parentThreadId = ThreadId.make("thread:subagent-snoozed-parent");
3235
const childThreadId = ThreadId.make("thread:subagent-awake-child");
@@ -117,8 +120,62 @@ it("keeps a subagent child awake when its parent thread is snoozed", () => {
117120
});
118121
});
119122

123+
it.effect.each([
124+
["sql", ProjectionStore.layer.pipe(Layer.provideMerge(SqlitePersistence.layerMemory))],
125+
] as const)(
126+
"%s: a pinned parent's subagent child is born unpinned and settles once idle",
127+
([, testLayer]) =>
128+
Effect.gen(function* () {
129+
const store = yield* ProjectionStore.ProjectionStoreV2;
130+
const parentThread = { ...makeParentThread(), pinnedAt: parentCreatedAt, pinOrderKey: "a0" };
131+
const childThread = makeSubagentChildThread({
132+
parentThread,
133+
childThreadId,
134+
parentNodeId: NodeId.make("node:subagent-parent"),
135+
activeProviderThreadId: null,
136+
providerInstanceId: childProviderInstanceId,
137+
modelSelection: childModelSelection,
138+
title: "Child",
139+
now: childCreatedAt,
140+
createdBy: "agent",
141+
creationSource: "provider",
142+
});
143+
144+
assert.equal(parentThread.pinnedAt, parentCreatedAt);
145+
assert.equal(parentThread.pinOrderKey, "a0");
146+
assert.isNull(childThread.pinnedAt);
147+
assert.isNull(childThread.pinOrderKey);
148+
149+
for (const thread of [parentThread, childThread]) {
150+
yield* store.apply({
151+
id: EventId.make(`event:${thread.id}`),
152+
type: "thread.created",
153+
threadId: thread.id,
154+
occurredAt: thread.createdAt,
155+
payload: thread,
156+
});
157+
}
158+
const savedParent = yield* store.getThread(parentThreadId);
159+
assert.deepEqual(savedParent.pinnedAt, parentCreatedAt);
160+
assert.equal(savedParent.pinOrderKey, "a0");
161+
const candidates = yield* store.getSettlementCandidates();
162+
assert.deepEqual(
163+
candidates.map((candidate) => candidate.id),
164+
[childThreadId],
165+
);
166+
const settledAt = resolveAutoSettlementAt({
167+
thread: candidates[0]!,
168+
pullRequest: null,
169+
nowMs: DateTime.toEpochMillis(DateTime.add(childCreatedAt, { days: 4 })),
170+
autoSettleAfterDays: 3,
171+
autoSettleOnMerge: false,
172+
});
173+
assert.equal(settledAt && DateTime.formatIso(settledAt), DateTime.formatIso(childCreatedAt));
174+
}).pipe(Effect.provide(testLayer)),
175+
);
176+
120177
function taskFixture() {
121-
const projection = emptyProjection({
178+
const projection = ProjectionStore.emptyProjection({
122179
type: "thread.created",
123180
id: EventId.make("task-fixture"),
124181
threadId: parentThreadId,

‎packages/provider-core/src/server/subagentProjection.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export function makeSubagentChildThread(input: {
8282
settledAt: null,
8383
snoozedUntil: null,
8484
snoozedAt: null,
85+
pinnedAt: null,
86+
pinOrderKey: null,
8587
// A guest link belongs to the thread it was made for.
8688
guestShare: null,
8789
lastVisitedAt: null,

0 commit comments

Comments
 (0)