GeezerVison is showing github.com — fix(server): subagents pick up their parent's renamed worktree branch by maria-rcks · Pull Request #20079 · pingdotgg/t3code
fix(server): subagents pick up their parent's renamed worktree branch
#20079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(4)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2539,6 +2539,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
cause: `Thread ${command.threadId} worktree changed before the metadata update could be applied.`,
});
}
if (
command.type === "thread.metadata.update" &&
command.expectedBranch !== undefined &&
command.expectedBranch !== thread.branch
) {
return yield* new OrchestratorDispatchError({
commandId: command.commandId,
commandType: command.type,
cause: `Thread ${command.threadId} branch changed before the metadata update could be applied.`,
});
}
if (command.type === "thread.metadata.update" && command.expectedEmpty === true) {
const records = yield* projectionStore
.getThreadRecords(command.threadId, ["runs"])
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1184,11 +1184,91 @@ it.effect("renames a temporary t3/<hash> branch off the provisioning critical pa
(yield* threads.getThreadProjection(launched.threadId)).thread.branch,
"t3/abcd1234",
);
const parent = yield* threads.getThreadProjection(launched.threadId);
const run = parent.runs[0]!;
assert.isNotNull(run.rootNodeId);
yield* threads.dispatch({
type: "delegated_task.request",
commandId: CommandId.make("command:launch:temp-branch:delegate"),
parentThreadId: launched.threadId,
parentRunId: run.id,
parentNodeId: run.rootNodeId!,
task: "Work in the parent's checkout",
modelSelection,
runtimeMode: "full-access",
interactionMode: "default",
createdBy: "agent",
creationSource: "mcp",
});
const delegated = yield* threads.getThreadProjection(launched.threadId);
const childThreadId = delegated.subagents[0]!.childThreadId!;
const child = yield* threads.getThreadProjection(childThreadId);
assert.equal(child.thread.branch, "t3/abcd1234");
assert.equal(child.thread.worktreePath, "/repo-worktrees/temp");
assert.equal(child.thread.lineage.parentThreadId, launched.threadId);
const otherThreadId = ThreadId.make("thread:launch:other-branch");
const otherPathThreadId = ThreadId.make("thread:launch:other-worktree");
for (const [threadId, branch, worktreePath] of [
[otherThreadId, "other-feature", "/repo-worktrees/temp"],
[otherPathThreadId, "t3/abcd1234", "/repo-worktrees/other"],
] as const) {
yield* threads.dispatch({
type: "thread.create",
commandId: CommandId.make(`command:create:${threadId}`),
threadId,
projectId,
title: "Unrelated thread",
modelSelection,
runtimeMode: "full-access",
interactionMode: "default",
branch,
worktreePath,
createdBy: "user",
creationSource: "web",
});
}
const unrelated = yield* threads.getThreadProjection(otherThreadId);
const otherPath = yield* threads.getThreadProjection(otherPathThreadId);
yield* Deferred.succeed(allowBranchName, undefined);
yield* waitUntil(() =>
threads
.getThreadProjection(launched.threadId)
.pipe(Effect.map((projection) => projection.thread.branch === "generated-branch")),
yield* threads.streamStoredEventsFrom({ threadId: childThreadId }).pipe(
Stream.filter(
(stored) =>
stored.event.type === "thread.metadata-updated" &&
stored.event.payload.branch === "generated-branch",
),
Stream.runHead,
);
assert.equal(
(yield* threads.getThreadProjection(launched.threadId)).thread.branch,
"generated-branch",
);
assert.equal(
(yield* threads.getThreadProjection(childThreadId)).thread.branch,
"generated-branch",
);
assert.deepEqual(
(yield* threads.getThreadProjection(otherThreadId)).thread,
unrelated.thread,
);
assert.deepEqual(
(yield* threads.getThreadProjection(otherPathThreadId)).thread,
otherPath.thread,
);
const staleUpdate = yield* threads
.dispatch({
type: "thread.metadata.update",
commandId: CommandId.make("command:launch:stale-branch-update"),
threadId: otherThreadId,
branch: "generated-branch",
expectedBranch: "t3/abcd1234",
expectedWorktreePath: "/repo-worktrees/temp",
})
.pipe(Effect.flip);
assert.equal(staleUpdate._tag, "OrchestratorDispatchError");
assert.deepEqual(
(yield* threads.getThreadProjection(otherThreadId)).thread,
unrelated.thread,
);
assert.deepEqual(harness.renameBranch.mock.calls[0]?.[0], {
cwd: "/repo-worktrees/temp",
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -518,12 +518,49 @@ const make = Effect.gen(function* () {
}),
),
Effect.flatMap((renamed) =>
threads.dispatch({
type: "thread.metadata.update",
commandId: CommandId.make(`${input.commandId}:branch-rename`),
threadId,
branch: renamed.branch,
worktreePath: worktreeCwd,
Effect.gen(function* () {
yield* threads.dispatch({
type: "thread.metadata.update",
commandId: CommandId.make(`${input.commandId}:branch-rename`),
threadId,
branch: renamed.branch,
worktreePath: worktreeCwd,
expectedBranch: oldBranch,
expectedWorktreePath: worktreeCwd,
});
// Updating the parent first makes later subagents inherit the new name.
// Re-read after each pass for children of subagents updated in that pass.
const visited = new Set([threadId]);
while (true) {
const snapshot = yield* threads.getShellSnapshot();
const sharing = snapshot.threads.filter(
(thread) =>
!visited.has(thread.id) &&
thread.worktreePath === worktreeCwd &&
thread.branch === oldBranch,
);
if (sharing.length === 0) break;
for (const thread of sharing) {
visited.add(thread.id);
yield* threads
.dispatch({
type: "thread.metadata.update",
commandId: CommandId.make(`${input.commandId}:branch-rename:${thread.id}`),
threadId: thread.id,
branch: renamed.branch,
expectedBranch: oldBranch,
expectedWorktreePath: worktreeCwd,
})
.pipe(
Effect.catchCause((cause) =>
Effect.logWarning("Shared thread worktree branch update failed", {
threadId: thread.id,
cause,
}),
),
);
}
}
}),
),
Effect.catchCause((cause) =>
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2856,6 +2856,7 @@ export const OrchestrationV2Command = Schema.Union([
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
expectedWorktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
expectedBranch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
/** Reject unless no message or run has landed on this thread. */
expectedEmpty: Schema.optional(Schema.Boolean),
limitRecovery: Schema.optional(Schema.NullOr(OrchestrationV2LimitRecoveryUpdate)),
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.