-
Notifications
You must be signed in to change notification settings - Fork 0
fix(guardrails): PR #90 review findings + 14 test cases #139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -160,12 +160,12 @@ async function git(dir: string, args: string[]) { | |||||||||
| stdout: "pipe", | ||||||||||
| stderr: "pipe", | ||||||||||
| }) | ||||||||||
| const [stdout, stderr] = await Promise.all([ | ||||||||||
| const [stdout, stderr, code] = await Promise.all([ | ||||||||||
| new Response(proc.stdout).text(), | ||||||||||
| new Response(proc.stderr).text(), | ||||||||||
| proc.exited, | ||||||||||
| ]) | ||||||||||
| return { stdout, stderr } | ||||||||||
| return { stdout, stderr, code } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function free(data: { | ||||||||||
|
|
@@ -549,8 +549,22 @@ export default async function guardrail(input: { | |||||||||
| if (flag(data.git_freshness_checked)) return | ||||||||||
| await mark({ git_freshness_checked: true }) | ||||||||||
| try { | ||||||||||
| const fetchCheck = await git(input.worktree, ["fetch", "--dry-run"]) | ||||||||||
| if (fetchCheck.stdout.trim() || fetchCheck.stderr.includes("From")) { | ||||||||||
| const proc = Bun.spawn(["git", "-C", input.worktree, "fetch", "--dry-run"], { | ||||||||||
| stdout: "pipe", | ||||||||||
| stderr: "pipe", | ||||||||||
| }) | ||||||||||
| const fetchResult = await Promise.race([ | ||||||||||
| Promise.all([ | ||||||||||
| new Response(proc.stdout).text(), | ||||||||||
| new Response(proc.stderr).text(), | ||||||||||
| proc.exited, | ||||||||||
| ]).then(([stdout, stderr, code]) => ({ stdout, stderr, code })), | ||||||||||
| Bun.sleep(5000).then(() => { | ||||||||||
| proc.kill() | ||||||||||
| return null | ||||||||||
| }), | ||||||||||
| ]) | ||||||||||
| if (fetchResult && fetchResult.code === 0 && (fetchResult.stdout.trim() || fetchResult.stderr.includes("From"))) { | ||||||||||
| out.parts.push({ | ||||||||||
| id: crypto.randomUUID(), | ||||||||||
| sessionID: out.message.sessionID, | ||||||||||
|
|
@@ -565,7 +579,7 @@ export default async function guardrail(input: { | |||||||||
| // Branch hygiene: surface stored branch warning from session.created | ||||||||||
| const branchWarn = str(data.branch_warning) | ||||||||||
| if (branchWarn) { | ||||||||||
| const statusCheck = await git(input.worktree, ["status", "--porcelain"]).catch(() => ({ stdout: "", stderr: "" })) | ||||||||||
| const statusCheck = await git(input.worktree, ["status", "--porcelain"]).catch(() => ({ stdout: "", stderr: "", code: 1 })) | ||||||||||
| const dirty = statusCheck.stdout.trim().length > 0 && !statusCheck.stderr.trim() | ||||||||||
| out.parts.push({ | ||||||||||
| id: crypto.randomUUID(), | ||||||||||
|
|
@@ -630,7 +644,7 @@ export default async function guardrail(input: { | |||||||||
| throw new Error(text("shell access to protected files")) | ||||||||||
| } | ||||||||||
| // [W9] pre-merge: tier-aware gate + CRITICAL/HIGH block (consolidated) | ||||||||||
| if (/\b(git\s+merge|gh\s+pr\s+merge)\b/i.test(cmd)) { | ||||||||||
| if (/\bgit\s+merge(\s|$)/i.test(cmd) || /\bgh\s+pr\s+merge(\s|$)/i.test(cmd)) { | ||||||||||
| // Check CRITICAL/HIGH first (applies to all tiers) | ||||||||||
| const criticalCount = num(bashData.review_critical_count) | ||||||||||
| const highCount = num(bashData.review_high_count) | ||||||||||
|
|
@@ -791,7 +805,7 @@ export default async function guardrail(input: { | |||||||||
| throw new Error(text("branch rename/force-move blocked: prevents commit guard bypass")) | ||||||||||
| } | ||||||||||
| // Enforce soak time: develop→main merge requires half-day minimum | ||||||||||
| if (/\b(git\s+merge|gh\s+pr\s+merge)\b/i.test(cmd)) { | ||||||||||
| if (/\bgit\s+merge(\s|$)/i.test(cmd) || /\bgh\s+pr\s+merge(\s|$)/i.test(cmd)) { | ||||||||||
| const lastMerge = str(bashData.last_merge_at) | ||||||||||
| if (lastMerge) { | ||||||||||
| const elapsed = Date.now() - new Date(lastMerge).getTime() | ||||||||||
|
|
@@ -1017,9 +1031,16 @@ export default async function guardrail(input: { | |||||||||
| edit_count_since_check: 0, | ||||||||||
| }) | ||||||||||
| } | ||||||||||
| // Reset review_state on mutating bash commands (sed -i, redirects, etc.) | ||||||||||
| if (bash(cmd)) { | ||||||||||
| await mark({ | ||||||||||
| edits_since_review: num(data.edits_since_review) + 1, | ||||||||||
| review_state: "", | ||||||||||
| }) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ((item.tool === "edit" || item.tool === "write") && file) { | ||||||||||
| if ((item.tool === "edit" || item.tool === "write" || item.tool === "apply_patch") && file) { | ||||||||||
|
||||||||||
| if ((item.tool === "edit" || item.tool === "write" || item.tool === "apply_patch") && file) { | |
| const isMutatingFileTool = item.tool === "edit" || item.tool === "write" || item.tool === "apply_patch" | |
| if (isMutatingFileTool && file) { |
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.
The
Promise.racetimeout prevents blocking the chat pipeline, but the underlyinggit fetch --dry-runprocess is not cancelled when the sleep wins. This can leave a long-runninggitprocess (and open pipes) alive for the rest of the session, and it can still fail later outside the awaited control-flow. Consider spawninggit fetchinline here and explicitly killing the process on timeout (or using a Bun/process-level timeout mechanism) so the timeout actually bounds resource usage.