Skip to content

fix(review-guard): narrow entry cap and preserve PR verdict history across replacement PRs (CHE-11061) [squash] - #2295

Open
congvc-bot-x99[bot] wants to merge 5 commits into
mainfrom
agent/x99-codex-luna-2/che-11061-e498f988e152
Open

congvc-bot-x99[bot] wants to merge 5 commits into
mainfrom
agent/x99-codex-luna-2/che-11061-e498f988e152

Conversation

@congvc-bot-x99

@congvc-bot-x99 congvc-bot-x99 Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Status

Draft PR for CHE-11061. Base: main at a91aa3dce4e6418196b22d3df16cb8615e4b7fd6. Head: f4f39ff366fec96faf9fdc0bfd179b22af3d8900.

Conditions

This PR targets main. Keep this PR draft through independent review and required human final review.

Why

Routine author revisions could exhaust the review entry cap and send an active issue to need_decision. A replacement PR could also reset the CHANGES verdict count (CHE-11061). After CHE-11211 narrowed round counting on main to recorded review_changes_requested verdicts, replacement PRs still started at zero and repeated CHANGES verdicts on one head were not deduplicated.

What changed

  • Replaced CountChangesRoundsForPR with CountChangesRoundsForReviewContext (server/pkg/db/queries/agent.sql, server/pkg/db/generated/agent.sql.go) so CHANGES verdicts count distinct reviewed heads across all PRs on an issue while preserving CHE-11211 exclusion of mechanical handoff wakeups.
  • Added HasChangesRoundForHead and wired guardChangesVerdict, reviewRoundsCapped, recordRoundsCapped, and recordVerdict (server/internal/handler/review_loop_guard.go) to deduplicate repeated CHANGES verdicts on the same head and resolve PR context across author and reviewer runs (reviewContextHasPR).
  • Updated and expanded handler regression tests (server/internal/handler/review_loop_guard_test.go, server/internal/handler/review_round_cap_test.go, server/internal/handler/review_verdict_resolve_test.go), and formatted server/internal/handler/review_round_cap.go with gofmt.
stateDiagram-v2
    state "In progress" as Work
    state "Agent review" as Review
    state "Blocked" as Blocked
    state "Need decision" as Decision
    Work --> Review: author submits a revision; ordinary entry is not capped
    Blocked --> Review: mechanical retry does not count as CHANGES
    Review --> Work: CHANGES on a distinct head; count spans replacement PRs
    Review --> Review: reviewer wakeup; recorded without consuming CHANGES limit
    Review --> Decision: 3rd distinct-head CHANGES verdict reached
Loading

Scope

Covers CHE-11061 Step 1: review-loop entry cap reconciliation with CHE-11211, replacement-PR verdict history preservation, and distinct-head deduplication without adding a third counter. Leaves downstream auto-split and arbiter steps to their dedicated follow-up issues.

Tradeoffs

Keeping the counter scoped to a single PR is simpler, but closing and opening a replacement PR resets verdict history to zero. Counting distinct head_sha values across linked PRs preserves the three-round bound while preventing duplicate verdicts on one head from burning rounds.

Blast Radius

The handler guard (server/internal/handler/review_loop_guard.go) and SQL queries (server/pkg/db/queries/agent.sql) govern issue review transitions. A counting regression would either open premature decision cards or let repeated distinct-head rejections exceed three rounds. On parent commit 78fe52ba10a23ef9610b5d6a04647ce5d312ffa2, forty-six targeted handler integration tests ran against PostgreSQL (PASS, 0 failed). Head f4f39ff366fec96faf9fdc0bfd179b22af3d8900 removes two blank lines in server/internal/handler/review_round_cap.go (gofmt -l and git diff --check exited 0, while local PostgreSQL tests were NOT-RUN on f4f39ff366fec96faf9fdc0bfd179b22af3d8900 because another test run held the shared test database). Proof level: 1 (read-only + gofmt on exact head f4f39ff366fec96faf9fdc0bfd179b22af3d8900, with integration proof level 3 observed on AST-identical parent 78fe52ba10a23ef9610b5d6a04647ce5d312ffa2).

Verification

  1. Targeted handler suite against PostgreSQL on AST-identical parent 78fe52ba10a23ef9610b5d6a04647ce5d312ffa2:
    cd server && GOMEMLIMIT=2800MiB GOMAXPROCS=2 GOGC=50 go test -c -p 1 -o ../handler.test ./internal/handler && cd internal/handler && ../../../handler.test -test.v -test.count=1 -test.run 'Test(RoundCap|ReviewLoop|VerdictResolve)'
    Result: PASS (46 top-level tests passed, 0 failed, including TestRoundCap_FourOrdinaryEntriesDoNotTripRecoveryBound, TestRoundCap_BlockedReviewEntriesDoNotCountAsChanges, TestRoundCap_ReplacementPRDoesNotResetRounds, TestRoundCap_FourthEntryWithLinkedPRReplacementHistoryGoesToNeedDecision, TestReviewLoop_ThreeDistinctHeadsAcrossReplacementPRsGoToNeedDecision, TestReviewLoop_RepeatedChangesHeadDoesNotConsumeDistinctHeadLimit, TestReviewLoop_RepeatedCurrentChangesHeadDoesNotConsumeLimit, and TestVerdictResolve_ThreeEntriesLeavingThroughBlockedDoNotCapTheFourth).
  2. Exact-head CI on AST-identical parent 78fe52ba10a23ef9610b5d6a04647ce5d312ffa2 (run 47556134693): backend-test-shards (handler-0, handler-1, handler-2, handler-3, service, rest), e2e, decision-card-e2e, sqlc-check, and migration-checks passed, failing only go-lint (gofmt on server/internal/handler/review_round_cap.go:37:1).
  3. Formatting and generated SQL checks on exact head f4f39ff366fec96faf9fdc0bfd179b22af3d8900:
    gofmt -l server/internal/handler/review_loop_guard.go server/internal/handler/review_loop_guard_test.go server/internal/handler/review_round_cap.go server/internal/handler/review_round_cap_test.go server/internal/handler/review_verdict_resolve_test.go server/pkg/db/generated/agent.sql.go and git diff --check exited 0 with empty output.

Changelog

Changelog: Routine review iterations and replacement PRs now track distinct reviewed heads accurately.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  • Replaced CountChangesRoundsForPR with CountChangesRoundsForReviewContext and added HasChangesRoundForHead in server/pkg/db/queries/agent.sql and server/pkg/db/generated/agent.sql.go.
  • Updated guardChangesVerdict, reviewRoundsCapped, recordRoundsCapped, and recordVerdict in server/internal/handler/review_loop_guard.go and server/internal/handler/review_round_cap.go.
  • Added and updated regression tests in server/internal/handler/review_loop_guard_test.go, server/internal/handler/review_round_cap_test.go, and server/internal/handler/review_verdict_resolve_test.go.

How to Test

  1. Run cd server && go test ./internal/handler -run 'Test(RoundCap|ReviewLoop|VerdictResolve)' -count=1 against a migrated PostgreSQL test database.
  2. Verify all 46 review-loop, round-cap, and verdict-resolution tests pass.

Patterns

Agent-facing

Agent-facing: no

Cost delta

  • C1 Cost delta: 0 additional LLM calls or background runs. Reduces spurious need_decision stalls from repeated-head verdicts while capping replacement-PR loops at 3 distinct heads. Measured via daily decision-card and run-usage reports.
  • C2 Optimality check: Distinct-head SQL aggregation reuses existing activity_log rows without adding a third counter or extra tables.
  • C3 Watch: Monitor daily decision-card volume and review_rounds_capped events after merge. Investigate if routine revisions open cap cards or if replacement-PR loops exceed 3 distinct heads.

Related Issue

Closes CHE-11061

@congvc-bot-x99
congvc-bot-x99 Bot marked this pull request as ready for review December 4, 2026 17:22
@congvc-bot-x99
congvc-bot-x99 Bot marked this pull request as draft December 4, 2026 17:41
@congvc-bot-x99
congvc-bot-x99 Bot marked this pull request as ready for review December 5, 2026 19:54
@congvc-bot-x99

congvc-bot-x99 Bot commented Dec 5, 2026

Copy link
Copy Markdown
Author

Merge-Eligibility: REFUSED
Head: f4f39ff
Source: sweep: receipt, review, merger and scope facts unread; coverage_complete and defaulted_paths unread

  • unverified by the sweep: receipt, cross-lab review, merger and scope; only the merge step can decide them

@congvc-dev
congvc-dev added this pull request to the merge queue Dec 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants