-
Notifications
You must be signed in to change notification settings - Fork 34
fix(api): preflight missing repository before builder dispatch #168
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
Open
elirethDev
wants to merge
2
commits into
theam:main
Choose a base branch
from
elirethDev:fix/checks-configured-dispatch-gate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| export const CHECKS_NOT_CONFIGURED = "checks_not_configured"; | ||
|
|
||
| // Extract the machine code from a run's stored error: the runner posts JSON | ||
| // fault payloads (possibly followed by stderr tail), and the platform marks | ||
| // early failures with the same JSON shape. Anything else is not a coded error. | ||
| export function runErrorCode(error: string | null | undefined): string | null { | ||
| if (!error) return null; | ||
| const trimmed = error.trim(); | ||
| if (!trimmed) return null; | ||
| if (trimmed.startsWith("{")) { | ||
| const end = trimmed.indexOf("}"); | ||
| if (end > 1) { | ||
| try { | ||
| const parsed = JSON.parse(trimmed.slice(0, end + 1)) as { code?: unknown }; | ||
| if (typeof parsed.code === "string") return parsed.code; | ||
| } catch { | ||
| // Not a JSON error payload — render the raw string below. | ||
| } | ||
| } | ||
| } | ||
| return /^[a-z][a-z0-9_]*$/.test(trimmed) ? trimmed : null; | ||
| } | ||
|
|
||
| export type RunErrorPresentation = { | ||
| code: string; | ||
| message: string; | ||
| href: string | null; | ||
| }; | ||
|
|
||
| export function runErrorPresentation( | ||
| error: string | null | undefined, | ||
| projectId: string | null, | ||
| ): RunErrorPresentation | null { | ||
| const code = runErrorCode(error); | ||
| if (code !== CHECKS_NOT_CONFIGURED) return null; | ||
| return { | ||
| code, | ||
| message: | ||
| "No acceptance checks are configured for this project, so the builder run could not deliver.", | ||
| href: projectId ? `/projects/${projectId}/settings` : null, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { runErrorCode, runErrorPresentation } from "@/components/run/run-error"; | ||
|
|
||
| describe("runErrorCode", () => { | ||
| it("extracts the runner's JSON fault code", () => { | ||
| expect(runErrorCode('{"code":"checks_not_configured"}')).toBe("checks_not_configured"); | ||
| }); | ||
|
|
||
| it("still reads the code when the runner appends stderr tail after the JSON", () => { | ||
| expect( | ||
| runErrorCode('{"code":"checks_not_configured"} npm error something\nnpm ERR! exit 1'), | ||
| ).toBe("checks_not_configured"); | ||
| }); | ||
|
|
||
| it("accepts a bare machine code", () => { | ||
| expect(runErrorCode("checks_not_configured")).toBe("checks_not_configured"); | ||
| }); | ||
|
|
||
| it("returns null for unknown codes, plain text, and empty errors", () => { | ||
| expect(runErrorCode('{"code":"provision_failed"}')).toBe("provision_failed"); | ||
| expect(runErrorCode("the database exploded")).toBeNull(); | ||
| expect(runErrorCode('{"message":"not a code"}')).toBeNull(); | ||
| expect(runErrorCode("")).toBeNull(); | ||
| expect(runErrorCode(null)).toBeNull(); | ||
| expect(runErrorCode(undefined)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("runErrorPresentation", () => { | ||
| it("maps checks_not_configured to a human explanation with a settings link", () => { | ||
| expect(runErrorPresentation('{"code":"checks_not_configured"}', "project_1")).toEqual({ | ||
| code: "checks_not_configured", | ||
| message: | ||
| "No acceptance checks are configured for this project, so the builder run could not deliver.", | ||
| href: "/projects/project_1/settings", | ||
| }); | ||
| }); | ||
|
|
||
| it("drops the settings link when no project is known", () => { | ||
| expect(runErrorPresentation("checks_not_configured", null)).toMatchObject({ href: null }); | ||
| }); | ||
|
|
||
| it("leaves unknown errors to the raw renderer", () => { | ||
| expect(runErrorPresentation("error: something broke", "project_1")).toBeNull(); | ||
| expect(runErrorPresentation(null, "project_1")).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { RunBundle } from "./state.js"; | ||
|
|
||
| type AcceptanceRepo = Pick<RunBundle["repo"], "cloneUrl">; | ||
| type AcceptanceBundle = { mode: string; repo: AcceptanceRepo } & Pick<RunBundle, "checkCmds">; | ||
|
|
||
| export const CHECKS_NOT_CONFIGURED = "checks_not_configured"; | ||
|
|
||
| export const CHECKS_NOT_CONFIGURED_MESSAGE = | ||
| "This project has no acceptance checks configured — a builder run cannot deliver. " + | ||
| "Configure them in Settings."; | ||
|
|
||
| // Delivery-mode agents ship repository changes, so the platform requires | ||
| // acceptance evidence. Mirrors the runner's requiresDelivery so the | ||
| // dispatch-time refusal and the runner's delivery gate agree. | ||
| export function requiresDelivery(mode: string) { | ||
| return mode === "builder" || mode.endsWith("-builder"); | ||
| } | ||
|
|
||
| function normalizedMode(mode: string) { | ||
| return mode.replace(/^codex-/, "").replace(/-/g, "_"); | ||
| } | ||
|
|
||
| function repairRepositoryMode(mode: string) { | ||
| return normalizedMode(mode) === "address_review" || normalizedMode(mode) === "ci_doctor"; | ||
| } | ||
|
|
||
| // GitHub-backed repositories let their own CI accept the signed draft pull | ||
| // request, so acceptance is owned there even when no sandbox checks are | ||
| // configured. Mirrors the runner's githubCiOwnsAcceptance: refusing these | ||
| // would block deliveries that currently succeed. | ||
| export function githubCiOwnsAcceptance(bundle: AcceptanceBundle): boolean { | ||
| if (!bundle.repo.cloneUrl?.startsWith("https://github.com/")) return false; | ||
| return requiresDelivery(bundle.mode) || repairRepositoryMode(bundle.mode); | ||
| } | ||
|
|
||
| // The runner's acceptance gate, evaluated at dispatch time: a delivery-mode | ||
| // agent may only run when acceptance is configured or the repository's own CI | ||
| // owns acceptance. | ||
| export function checksConfiguredForDispatch(bundle: AcceptanceBundle): boolean { | ||
| return ( | ||
| githubCiOwnsAcceptance(bundle) || !requiresDelivery(bundle.mode) || bundle.checkCmds.length > 0 | ||
| ); | ||
| } | ||
|
|
||
| // Issue-trigger variant: buildRunBundle synthesizes a repo row's clone URL the | ||
| // same way, so a trigger-time refusal uses exactly the bundle the runner would | ||
| // see — including the GitHub-backed exemption. | ||
| export function checksConfiguredForRepo(input: { | ||
| mode: string; | ||
| checkCmds: string[]; | ||
| repo: { owner: string; name: string } | null; | ||
| }): boolean { | ||
| return checksConfiguredForDispatch({ | ||
| mode: input.mode, | ||
| checkCmds: input.checkCmds, | ||
| repo: input.repo | ||
| ? { cloneUrl: `https://github.com/${input.repo.owner}/${input.repo.name}.git` } | ||
| : { cloneUrl: null }, | ||
| }); | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t seem to catch the case from #28 anymore.
checksConfiguredForRepo()gives every connected repo a GitHub URL, so this always passes for a builder even whencheckCmdsis empty. The only builder it blocks has no repo; asking that user to configure checks is misleading, because the run will then start and fail withdelivery_repo_not_configured. Could we either preflight the missing repo too, or re-scope this now that GitHub CI owns acceptance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, yeah, you're right. Looking at the current flow, I think the right thing to do is:
delivery_repo_not_configuredguard for builder runs without a repository, before creating keys or provisioning a sandbox;checksConfiguredForRepo()preflight from connected GitHub repository triggers;That way, connected repositories follow the current GitHub CI acceptance model, while builder runs without a repository fail early instead of spending resources on a run that cannot deliver.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in
19d5d88.Connected GitHub repositories no longer run the check-command preflight. Builder runs without a repository now fail before key creation or sandbox provisioning with
delivery_repo_not_configured, with matching UI copy and regression coverage. I also updated the PR title and description to reflect the current GitHub CI acceptance model.Focused checks pass: 32 API tests, 8 web tests, both typechecks, Biome, and diff whitespace checks.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reran the database-backed suites with Docker and Postgres healthy. The result was 90 passed, 1 timing-based timeout in
coalesces a CI notification burst, and no skipped tests.I also confirmed that
pnpm verifystill stops at its first Lint step on Windows withscripts/verify.mjscallingspawnSync("pnpm")and receivingENOENT.