Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit e4294cb

Browse files
Merging fad940a into trunk-temp/pr-4003/8469c107-c587-4687-b6d1-3a35d9105c3c
2 parents d74080f + fad940a commit e4294cb

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

packages/agent/src/adapters/local-tools/tools/signed-commit.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,41 @@ describe("signed-commit tool handler", () => {
117117
});
118118
});
119119

120+
it("persists the branch when cwd uses an equivalent path representation", async () => {
121+
await signedCommitTool.handler(
122+
{
123+
cwd: "/tmp/workspace/repos/posthog/code/.",
124+
token: "ghs_x",
125+
taskId: "task-1",
126+
taskRunId: "run-1",
127+
},
128+
{ message: "chore: bump", cwd: "." },
129+
);
130+
131+
expect(reportTaskRunBranch).toHaveBeenCalledWith({
132+
taskId: "task-1",
133+
taskRunId: "run-1",
134+
branch: "posthog-code/feature",
135+
});
136+
});
137+
138+
it("does not persist a branch created in a sibling repository", async () => {
139+
await signedCommitTool.handler(
140+
{
141+
cwd: "/tmp/workspace/repos/posthog/code",
142+
token: "ghs_x",
143+
taskId: "task-1",
144+
taskRunId: "run-1",
145+
},
146+
{
147+
message: "chore: bump",
148+
cwd: "/tmp/workspace/repos/posthog/grafana-dashboards",
149+
},
150+
);
151+
152+
expect(reportTaskRunBranch).not.toHaveBeenCalled();
153+
});
154+
120155
it("returns the no-token error without invoking createSignedCommit", async () => {
121156
const savedGh = process.env.GH_TOKEN;
122157
const savedGithub = process.env.GITHUB_TOKEN;

packages/agent/src/adapters/local-tools/tools/signed-git-tool.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ export function defineSignedGitTool<S extends z.ZodRawShape, R>(opts: {
4343
string,
4444
unknown
4545
>;
46-
const cwd = argCwd ? path.resolve(ctx.cwd, argCwd) : ctx.cwd;
46+
const taskRepositoryCwd = path.resolve(ctx.cwd);
47+
const cwd = argCwd
48+
? path.resolve(taskRepositoryCwd, argCwd)
49+
: taskRepositoryCwd;
4750
return opts.run(
4851
{
4952
cwd,
53+
taskRepositoryCwd,
5054
token,
5155
taskId: ctx.taskId,
5256
taskRunId: ctx.taskRunId,

packages/agent/src/adapters/signed-commit-shared.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ export interface SignedCommitToolResult {
135135
[key: string]: unknown;
136136
}
137137

138-
export type SignedCommitToolCtx = SignedCommitCtx & { taskRunId?: string };
138+
export type SignedCommitToolCtx = SignedCommitCtx & {
139+
taskRunId?: string;
140+
/** The task repository cwd, before a tool-call `cwd` override is applied. */
141+
taskRepositoryCwd: string;
142+
};
139143

140144
async function runSignedTool<A>(
141145
toolName: string,
@@ -176,11 +180,17 @@ export function runSignedCommitTool(
176180
SIGNED_COMMIT_TOOL_NAME,
177181
async (c, a: SignedCommitInput) => {
178182
const result = await createSignedCommit(c, a);
179-
await reportTaskRunBranch({
180-
taskId: ctx.taskId,
181-
taskRunId: ctx.taskRunId,
182-
branch: result.branch,
183-
});
183+
// TaskRun.branch is the branch that provisioning checks out in the task's
184+
// repository on resume. A task can also commit to sibling repositories by
185+
// passing `cwd`; persisting one of those branches here makes the next run
186+
// try to clone the task repository at a branch that only exists elsewhere.
187+
if (ctx.cwd === ctx.taskRepositoryCwd) {
188+
await reportTaskRunBranch({
189+
taskId: ctx.taskId,
190+
taskRunId: ctx.taskRunId,
191+
branch: result.branch,
192+
});
193+
}
184194
// The "commit hook": every pushed commit becomes a `commit` artefact on the signal
185195
// reports this task is associated with. Best-effort and awaited inside the tool's
186196
// try/catch-free success path — reportCommitArtefacts never throws, so a failed

0 commit comments

Comments
 (0)