From 823fe4da6aa0cafe63ce9bd963f03169cba34e9a Mon Sep 17 00:00:00 2001 From: Brendan Date: Wed, 16 Sep 2026 15:15:41 +0000 Subject: [PATCH 1/2] Fix Codex dev job startup detection --- packages/app/src/exe.ts | 9 ++++++++- packages/app/src/tenant.ts | 7 ++++++- packages/app/test/workspace.test.ts | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/app/src/exe.ts b/packages/app/src/exe.ts index a1049eac..b523839b 100644 --- a/packages/app/src/exe.ts +++ b/packages/app/src/exe.ts @@ -107,6 +107,13 @@ export function herdrAgentStatus(body: string): string | null { return match?.[1].toLowerCase() ?? null; } +/** Codex can be alive in the pane while still waiting for an interactive startup decision. */ +export function agentStartupBlocked(body: string): boolean { + const normalized = body.replace(/\x1b\[[0-?]*[ -\/]*[@-~]/g, " ").replace(/\s+/g, " ").toLowerCase(); + return normalized.includes("do you trust the contents of this directory?") + || normalized.includes("press enter to continue") && normalized.includes("yes, continue") && normalized.includes("no, quit"); +} + export function agentOutputCommand(connection: ExeConnection, agentName: string): string { return `${herdrPrefix(connection)} && ${herdrBinary(connection)} agent read ${shellAtom(agentName)} --source recent --format text`; } @@ -144,7 +151,7 @@ function herdrBinary(connection: ExeConnection): string { function agentCommand(connection: ExeConnection, prompt?: string, cwd?: string): string { const command = connection.agentCommand?.trim() || defaultAgentCommand(connection.agentKind); const args = command ? shellWords(command).map(shellAtom) : []; - if (connection.agentKind === "codex" && cwd) args.push("--dangerously-bypass-hook-trust", "-c", shellAtom(`projects.${JSON.stringify(cwd)}.trust_level="trusted"`)); + if (connection.agentKind === "codex" && cwd) args.push("--dangerously-bypass-hook-trust", "--cd", shellAtom(cwd), "-c", shellAtom(`projects.${JSON.stringify(cwd)}.trust_level="trusted"`)); if (prompt !== undefined) args.push("--", shellAtom(prompt)); return args.length ? ` -- ${args.join(" ")}` : ""; } diff --git a/packages/app/src/tenant.ts b/packages/app/src/tenant.ts index 50cb281e..20040cc7 100644 --- a/packages/app/src/tenant.ts +++ b/packages/app/src/tenant.ts @@ -1,7 +1,7 @@ import { DurableObject } from "cloudflare:workers"; import Mustache from "mustache"; import { decrypt, encrypt } from "./crypto"; -import { agentListCommand, agentOutputCommand, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, paneGetCommand, paneProcessInfoCommand, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe"; +import { agentListCommand, agentOutputCommand, agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, paneGetCommand, paneProcessInfoCommand, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe"; import { findOwnedAgent, ownsPane, parseAgent, parseAgentList, parsePaneProcess, type HerdrIdentity } from "./recovery"; import { LINEAR_ISSUE_PROJECT_QUERY, LINEAR_OPTION_QUERIES, LINEAR_PROJECTS_QUERY } from "./linear"; import { matchingIssue } from "./matcher"; @@ -607,6 +607,11 @@ export class Tenant extends DurableObject { } const identity = parseAgent(verification.body); if (!identity) return this.beginRecovery(run, pipe, connection, "agent start succeeded but its structured identity was inconsistent"); + const startupOutput = await backend.readOutput(launched.handle); + this.commandActivity(run.id, "initial agent readiness", startupOutput); + if (startupOutput.ok && agentStartupBlocked(startupOutput.body)) { + return this.finishRun(run, "failed", "The agent process started but stopped at an interactive startup permission prompt."); + } this.ctx.storage.sql.exec("UPDATE runs SET prompt_delivery_state='accepted',prompt_delivery_request=?,prompt_delivery_response=?,prompt_delivery_status=?,prompt_delivery_exit_code=?,prompt_accepted=1,updated_at=? WHERE id=?", execRequest, execResponse, result.status, result.exitCode, now(), run.id); this.activity(run.id, "prompt_delivered_at_launch", "The initial prompt was passed as a positional harness argument in the successful Herdr launch command."); this.persistIdentity(run.id, identity, "running"); diff --git a/packages/app/test/workspace.test.ts b/packages/app/test/workspace.test.ts index dc03073d..5bec5da3 100644 --- a/packages/app/test/workspace.test.ts +++ b/packages/app/test/workspace.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { agentStatusCommand, connectionCheckCommand, defaultAgentCommand, garbageCollectPaneCommand, herdrAgentStatus, launchAgentCommand, promptAgentCommand, replaceForegroundCommand, shellAtom, startAgentCommand } from "../src/exe"; +import { agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, garbageCollectPaneCommand, herdrAgentStatus, launchAgentCommand, promptAgentCommand, replaceForegroundCommand, shellAtom, startAgentCommand } from "../src/exe"; import { workingDirectoryFor, workspaceNameFor } from "../src/workspace"; describe("flow workspaces", () => { @@ -43,6 +43,7 @@ describe("flow workspaces", () => { expect(launch).toContain("/tmp/factorize-prompts/factorize-1/prompt.md"); expect(launch).toContain("Read and follow the complete task instructions in"); expect(launch).toContain("--dangerously-bypass-hook-trust"); + expect(launch).toContain("--cd '/repo/.factorize-runs/run'"); expect(launch).toContain('projects."/repo/.factorize-runs/run".trust_level="trusted"'); expect(launch).not.toContain("agent prompt"); expect(delivery).toContain("agent prompt 'factorize-1'"); @@ -94,6 +95,11 @@ describe("flow workspaces", () => { expect(herdrAgentStatus('{"result":{"agent":{"state":"idle"}}}')).toBe("idle"); }); + it("detects an interactive Codex trust screen as a blocked startup", () => { + expect(agentStartupBlocked("Do you trust the contents of this directory? 1. Yes, continue 2. No, quit Press enter to continue")).toBe(true); + expect(agentStartupBlocked('{"result":{"agent":{"agent_status":"working"}}}')).toBe(false); + }); + it("revalidates exact pane and process identities before bounded escalation", () => { const command = replaceForegroundCommand("flow-1", { vmName: "vm", apiToken: "token", agentKind: "codex", cwd: "/repo" }, "pane-7"); expect(command.match(/pane process-info --pane 'pane-7'/g)).toHaveLength(2); From ea51991adc1f5f931296c55b56cb9e52b930dd3e Mon Sep 17 00:00:00 2001 From: Brendan Date: Wed, 16 Sep 2026 15:27:55 +0000 Subject: [PATCH 2/2] Fix merge queue authorization check --- .github/workflows/auto-merge.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index ed3685a8..53c07dd1 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -16,9 +16,6 @@ permissions: jobs: enable: name: Enable auto-merge - if: > - github.event.pull_request.draft == false && - contains(fromJSON('["OWNER", "MEMBER"]'), github.event.pull_request.author_association) runs-on: ubuntu-latest timeout-minutes: 5 steps: @@ -30,4 +27,20 @@ jobs: # downstream push-triggered workflows such as production deployment. GH_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }} PR_URL: ${{ github.event.pull_request.html_url }} - run: gh pr merge --auto --squash "$PR_URL" + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_DRAFT: ${{ github.event.pull_request.draft }} + EVENT_AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }} + run: | + echo "Event author association: $EVENT_AUTHOR_ASSOCIATION" + if [ "$PR_DRAFT" = "true" ]; then + echo "Skipping draft pull request." + exit 0 + fi + + permission=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$PR_AUTHOR/permission" --jq '.user.permissions | .admin or .maintain or .push') + if [ "$permission" != "true" ]; then + echo "Skipping pull request from an author without write permission." + exit 0 + fi + + gh pr merge --auto --merge "$PR_URL"