Skip to content

Commit 922ebc6

Browse files
steipetePeter Steinberger
andauthored
refactor: split review orchestration and unblock safe repair validation (#1000)
* refactor: split review orchestration and unblock safe repair validation * fix: preserve fail-closed validation process and command guards --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 1c9cb5d commit 922ebc6

17 files changed

Lines changed: 10952 additions & 9759 deletions

‎src/clawsweeper-close-decision.ts‎

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-record-metadata.ts‎

Lines changed: 769 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-related-context.ts‎

Lines changed: 824 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-review-comments-workflow.ts‎

Lines changed: 1829 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-review-planning.ts‎

Lines changed: 1177 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-review-runtime.ts‎

Lines changed: 1113 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper-status-context.ts‎

Lines changed: 560 additions & 0 deletions
Large diffs are not rendered by default.

‎src/clawsweeper.ts‎

Lines changed: 4027 additions & 9734 deletions
Large diffs are not rendered by default.

‎src/repair/process-tree-containment.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,15 +710,25 @@ def reap_exited_children(primary_pid, background_pids):
710710
background_pids.add(pid)
711711
712712
713-
def reap_adopted_children(primary_pid, background_pids):
713+
def reap_adopted_children(primary_pid, background_pids, primary_process=None):
714714
for pid, parent_pid in process_rows():
715715
if parent_pid != os.getpid() or pid == primary_pid:
716716
continue
717-
background_pids.add(pid)
718717
try:
719-
os.waitpid(pid, os.WNOHANG)
718+
reaped_pid, _status = os.waitpid(pid, os.WNOHANG)
720719
except ChildProcessError:
721-
pass
720+
background_pids.discard(pid)
721+
continue
722+
if reaped_pid == 0:
723+
background_pids.add(pid)
724+
elif primary_process is not None and primary_process.poll() is not None:
725+
# The helper survived the primary command even if both exited
726+
# between supervisor polls; preserve that fail-closed evidence.
727+
background_pids.add(pid)
728+
else:
729+
# Short-lived detached package-manager helpers are already gone while
730+
# the primary command is still running; they were not left behind.
731+
background_pids.discard(pid)
722732
723733
724734
def terminate_and_reap_descendants(primary_pid, background_pids):
@@ -788,7 +798,7 @@ def main():
788798
child = subprocess.Popen(command, close_fds=True)
789799
background_pids = set()
790800
while True:
791-
reap_adopted_children(child.pid, background_pids)
801+
reap_adopted_children(child.pid, background_pids, child)
792802
return_code = child.poll()
793803
if return_code is not None:
794804
break

‎src/repair/target-validation.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,23 +1666,34 @@ export function requiredValidationCommands(
16661666
options: TargetValidationOptions,
16671667
) {
16681668
const toolchain = getToolchain(options);
1669+
const gate = toolchain.changedGate;
1670+
const injectedChangedGate =
1671+
gate && !options.skipOpenClawChangedGate && requiresChangedGate(cwd, toolchain)
1672+
? gate.command
1673+
: null;
16691674
const replacementCommands = [
16701675
...(options.additionalValidationCommands ?? []),
16711676
...toolchain.baseValidationCommands,
16721677
];
1673-
const sanitized = sanitizeStaleChangedGateCommands(
1674-
commands ?? [],
1675-
toolchain,
1676-
replacementCommands,
1677-
);
1678-
const out = [...sanitized, ...replacementCommands];
1679-
const gate = toolchain.changedGate;
1680-
if (gate && !options.skipOpenClawChangedGate && requiresChangedGate(cwd, toolchain)) {
1681-
out.push(gate.command);
1678+
let sanitized = sanitizeStaleChangedGateCommands(commands ?? [], toolchain, replacementCommands);
1679+
// Model-authored formatter invocations mutate the checkout and can never be
1680+
// validation. When a trusted repository gate already covers the same change,
1681+
// discard those narrow hints instead of aborting every issue-fix retry.
1682+
if (replacementCommands.length > 0 || injectedChangedGate) {
1683+
sanitized = sanitized.filter((command) => !isMutatingFormatterValidationHint(command));
16821684
}
1685+
const out = [...sanitized, ...replacementCommands];
1686+
if (injectedChangedGate) out.push(injectedChangedGate);
16831687
return uniqueStrings(out);
16841688
}
16851689

1690+
function isMutatingFormatterValidationHint(command: LooseRecord): boolean {
1691+
if (typeof command !== "string") return false;
1692+
return /^(?:pnpm(?: +run)?|npm +run|bun +run) +format(?: +(?!-)[A-Za-z0-9@_./-]+)+$/.test(
1693+
command.replace(/^ +| +$/g, ""),
1694+
);
1695+
}
1696+
16861697
/**
16871698
* Drop validation commands that look like "some other repo's changed gate"
16881699
* when the current target repo does not have one. This protects against stale

0 commit comments

Comments
 (0)