From 3b751d2654dd0bd72b750d79fd5a0aa23d3e8ee1 Mon Sep 17 00:00:00 2001 From: raulraja Date: Mon, 30 Nov 2026 22:23:47 +0100 Subject: [PATCH] Fix gate: release the turn once Predictable accepted the agent's false-positive report predictable-code#3360 makes every agent fix question the finding first and, for a false positive, change nothing and file 'predictable report --kind false-positive'. The analysis still reports such a finding, so the Stop hook blocked the turn. It now lets the turn end when an accepted claim for that finding is on file under the database root's fixes/false-positives/; the driver ends the fix false-positive on its own evidence. A regression still blocks. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- scripts/fix-gate.sh | 55 +++++++++++++++++++++++++++++++++++++++++ tests/run-hooks-test.sh | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b7357e..e71096f 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ to run it. | **`UserPromptSubmit` / `PreCompact`** | Re-injects the last verdict so the agent always knows the sync state. | | **`PreToolUse`** (Bash `git push`/`git commit`) | Runs `sync` synchronously and **blocks only on a broken requirement** (`specViolation`). Every other verdict is advisory (warn, don't block), and a sync that does not run never blocks — the gate says why. Before that, a `git commit` that would carry spec pages the analysis inferred (staged, or added by a `git add -A` in the same command) is refused with each page named and how to leave it out (`predictable staged-inferred-pages`): they belong to Predictable's database, never to the code's branch. | | **`Stop` / `SubagentStop`** | Advisory turn-end `sync` (skipped if one is already running) so the agent keeps working toward an in-sync state. | -| **`Stop`** (inside a `predictable fix` session) | The fix gate (`scripts/fix-gate.sh`): the agent may not end its turn until `predictable fix-check` reads `gone` for the finding being fixed — no longer reported, and the project left with fewer findings than the fix started from. It is released when nothing changed since its last block (the `predictable fix` driver then decides whether the loop is stuck) and never traps a session whose check cannot run. | +| **`Stop`** (inside a `predictable fix` session) | The fix gate (`scripts/fix-gate.sh`): the agent may not end its turn until `predictable fix-check` reads `gone` for the finding being fixed — no longer reported, and the project left with fewer findings than the fix started from. It is released when nothing changed since its last block (the `predictable fix` driver then decides whether the loop is stuck), and when the agent showed the finding is not a defect and `predictable report --kind false-positive` accepted its report (a claim under the database's `fixes/false-positives/`; the driver then ends the fix `false-positive` on its own evidence). It never traps a session whose check cannot run. | Edits do **not** trigger a sync: the skill runs its own `predictable sync` after changing code, and two syncs on one project at once are never allowed — every hook diff --git a/scripts/fix-gate.sh b/scripts/fix-gate.sh index e736a12..3a0e57b 100755 --- a/scripts/fix-gate.sh +++ b/scripts/fix-gate.sh @@ -12,6 +12,11 @@ # # It never traps a session: # - a check that cannot run (no binary, no answer) lets the turn end — the driver decides; +# - a finding the agent showed is NOT a defect lets the turn end once `predictable report --kind +# false-positive` ACCEPTED its report (#3360): the analysis still reports it, by design, and the +# driver — not this gate — ends the fix `false-positive` on its own evidence (the accepted claim +# and the code left as it was). The claim is the file `predictable report` writes under the +# database root's `fixes/false-positives/`, matched here by the finding it names; # - a second stop with NOTHING changed since the last block lets the turn end — the agent has # nothing new to try in this turn, and the driver's own rule decides whether it is stuck. @@ -19,6 +24,47 @@ self_dir=$(cd -- "$(dirname -- "$0")" >/dev/null 2>&1 && pwd) # shellcheck source=scripts/lib.sh . "$self_dir/lib.sh" +# The database root the fix's state lives in, as the CLI decides it (`StateLayout.databaseRootOf`): +# for `/.predictable-code//.predictable-code`, the first `.predictable-code`; for any +# other state directory, the directory itself. Without PREDICTABLE_FIX_PATH, the project's own. +pc_fix_database_root() { + base="${PREDICTABLE_FIX_PATH:-}" + if [ -z "$base" ]; then + printf '%s/.predictable-code' "$(pc_project_dir)" + return + fi + case "$base" in + /*) ;; + *) base="$(pc_project_dir)/$base" ;; + esac + base="${base%/}" + case "$base" in + */.predictable-code/*/.predictable-code) + printf '%s/.predictable-code' "${base%%/.predictable-code/*}" + ;; + *) printf '%s' "$base" ;; + esac +} + +# Whether `predictable report` accepted a false-positive report about this finding (#3360): a claim +# under `fixes/false-positives/` naming its fqn and its tag (the vc, else the category — the CLI's +# key rule, which matches a tag given as either). +pc_false_positive_claimed() { + claims="$(pc_fix_database_root)/fixes/false-positives" + [ -d "$claims" ] || return 1 + for claim in "$claims"/*.json; do + [ -f "$claim" ] || continue + if jq -e --arg fqn "$1" --arg vc "$2" --arg cat "$3" ' + (.finding.fqn == $fqn) and + ((.finding.vc // .finding.category // "") as $tag + | $tag != "" and ($tag == $vc or $tag == $cat)) + ' "$claim" >/dev/null 2>&1; then + return 0 + fi + done + return 1 +} + stdin_json=$(mktemp 2>/dev/null || echo "/tmp/pc-fix-gate.$$") cat >"$stdin_json" cleanup() { rm -f "$stdin_json" 2>/dev/null || true; } @@ -77,6 +123,15 @@ if [ "$verdict" = "gone" ]; then cleanup exit 0 fi +# THE AGENT SHOWED IT IS NOT A DEFECT, and Predictable accepted the report: nothing to fix, so the +# turn ends here and the driver decides. Only for a finding still reported — a regression is the +# agent's own change, which a report about the original finding does not answer. +if [ "$verdict" = "reported" ] && pc_false_positive_claimed "$fqn" "$vc" "$category"; then + rm -f "$last_digest_file" 2>/dev/null || true + pc_log Stop fix-gate released-false-positive + cleanup + exit 0 +fi # Blocked before and nothing changed since: let the turn end rather than spin on the same tree. if [ "$active" = "true" ] && [ -n "$digest" ] && [ -f "$last_digest_file" ] && [ "$(cat "$last_digest_file" 2>/dev/null)" = "$digest" ]; then diff --git a/tests/run-hooks-test.sh b/tests/run-hooks-test.sh index 6c4b283..10aeb4a 100755 --- a/tests/run-hooks-test.sh +++ b/tests/run-hooks-test.sh @@ -369,6 +369,51 @@ run_hook fix-gate.sh stop-hook-active.json contains "$OUT" '"decision": "block"' check "fix-gate blocked before but the code changed -> blocks again" $? +# A FALSE POSITIVE THE AGENT REPORTED (#3360): `predictable report` accepted it and left a claim +# under the database root, so the still-reported finding no longer holds the turn. +fp_claim() { # dir fqn vc + mkdir -p "$1" + printf '{"finding":{"fqn":"%s","vc":"%s","category":null},"title":"t","why":"w","digest":"d","state":"recorded","number":null,"url":null,"payload":null}' \ + "$2" "$3" >"$1/c1.json" +} + +fresh_data +fix_target +reported reported "a complete sync still reports it" d1 +fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference +run_hook fix-gate.sh stop.json +rc=1 +[ -z "$OUT" ] && [ "$CODE" -eq 0 ] && rc=0 +check "fix-gate reported, its false positive accepted -> the turn may end" "$rc" "got: $OUT" + +fresh_data +fix_target +reported reported "a complete sync still reports it" d1 +fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.other il1.null-dereference +run_hook fix-gate.sh stop.json +contains "$OUT" '"decision": "block"' +check "fix-gate: a claim about ANOTHER finding releases nothing" $? + +fresh_data +fix_target +reported regressed "gone, but introduced others" d1 '"Code.cards.lastUnits|il1.x"' +fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference +run_hook fix-gate.sh stop.json +contains "$OUT" '"decision": "block"' +check "fix-gate: a regression still blocks, whatever was reported" $? + +fresh_data +fix_target +reported reported "a complete sync still reports it" d1 +PREDICTABLE_FIX_PATH="$CLAUDE_PROJECT_DIR/.predictable-code/main/.predictable-code" +export PREDICTABLE_FIX_PATH +fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference +run_hook fix-gate.sh stop.json +rc=1 +[ -z "$OUT" ] && [ "$CODE" -eq 0 ] && rc=0 +check "fix-gate finds the claim at the database root of a branch's state dir" "$rc" "got: $OUT" +unset PREDICTABLE_FIX_PATH + fresh_data fix_target STUB_FAIL=1 run_hook fix-gate.sh stop.json