Skip to content

Add deterministic completion policy - #719

Merged
gnanam1990 merged 1 commit into
mainfrom
perf/deterministic-completion-policy
Jul 17, 2026
Merged

Add deterministic completion policy#719
gnanam1990 merged 1 commit into
mainfrom
perf/deterministic-completion-policy

Conversation

@anandh8x

@anandh8x anandh8x commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • extract headless completion decisions into a typed deterministic policy with uncertain, complete, and incomplete outcomes
  • preserve bounded continuation handling and stale-plan protection
  • skip semantic verification when local evidence is sufficient, while allowing one task-grounded check for self-correcting profiles
  • add focused policy tests alongside the existing plan-stall regression corpus

Verification

  • make build
  • make test
  • go fmt ./...
  • go vet ./...
  • make lint
  • go run golang.org/x/vuln/cmd/govulncheck@v1.3.0 ./...
  • pinned golangci-lint on ./internal/agent/...: 0 issues

The repository-wide pinned golangci-lint command still reports 36 pre-existing unrelated findings, including findings from the old /tmp/zero-pr717-head checkout.

Summary by CodeRabbit

  • New Features

    • Improved assistant completion handling with bounded continuation prompts.
    • Added optional task-grounded semantic checks for self-correcting runs.
    • Better recognition of incomplete responses and pending work before finalizing.
  • Documentation

    • Clarified completion-signal behavior across interactive and self-correcting run profiles.
  • Tests

    • Added coverage for completion decisions, continuation limits, pending plans, and semantic checks.

Extract completion decisions from the agent loop into a feature-gated typed policy with complete, incomplete, and uncertain outcomes. Preserve bounded plan-stall nudges and allow at most one semantic acceptance check for self-correcting runs.

Tested: make build

Tested: make test

Tested: go fmt ./...

Tested: go vet ./...

Tested: make lint

Tested: govulncheck ./...

Note: repository-wide pinned golangci-lint reports 36 pre-existing unrelated findings; internal/agent/... reports 0 issues.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0b0c7b35-12fc-4f34-af9b-22458474b6e6

📥 Commits

Reviewing files that changed from the base of the PR and between e5670c4 and a3b0921.

📒 Files selected for processing (4)
  • internal/agent/completion_policy.go
  • internal/agent/completion_policy_test.go
  • internal/agent/loop.go
  • internal/agent/types.go

Walkthrough

Adds a deterministic completion policy with bounded continuation nudges and optional one-time semantic checking, integrates it into the headless completion gate, adds focused tests, and documents its interaction with SelfCorrect.

Changes

Completion policy

Layer / File(s) Summary
Completion policy behavior
internal/agent/completion_policy.go, internal/agent/completion_policy_test.go
Defines completion outcomes and actions, prioritizes self-reported incompletion, bounds continuation nudges, supports one semantic check, and tests these decision paths.
Completion gate integration
internal/agent/loop.go, internal/agent/types.go
Uses completionPolicy in Run, routes uncertain evaluations to continuation or semantic-check nudges, handles incomplete results, and documents SelfCorrect behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Run
  participant guards
  participant completionPolicy
  Run->>guards: pendingPlanItems()
  Run->>completionPolicy: evaluate(collected.Text, planPending)
  completionPolicy-->>Run: completionEvaluation
  Run->>Run: continue, semantic-check, or finalize
Loading

Possibly related PRs

  • Gitlawb/zero#325: Changes the same headless completion-gate continuation and acceptance flow.
  • Gitlawb/zero#608: Changes the completion-gate path and self-reported incompletion handling.
  • Gitlawb/zero#670: Addresses pending-plan completion-gate behavior and continuation nudges.

Suggested reviewers: gnanam1990, vasanthdev2004

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: introducing a deterministic completion policy.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/deterministic-completion-policy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: a3b09218aa15
Changed files (4): internal/agent/completion_policy.go, internal/agent/completion_policy_test.go, internal/agent/loop.go, internal/agent/types.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean PR9. This is a faithful extraction — I traced every branch of the new completionPolicy.evaluate against the old inline logic and they line up exactly: a self-reported admission → Incomplete (checked first, so an admitted-impossible task isn't wasted on continue-nudges), a continuation cue / pending plan → bounded continue nudge, then cue→Incomplete while plan-only falls through, SelfCorrect → exactly one task-grounded semantic check, else → Complete. The bounded state (continueNudges, semanticCheckRequested) moves out of loop-locals into a policy created once per run, so it persists across turns identically, and everything stays behind RequireCompletionSignal so default/interactive runs are byte-identical.

The acceptance criteria hold up: the existing completion/plan-stall regression corpus passes unchanged (TestCompletionGate*, TestAcceptance*, TestPendingPlanAloneDoesNotForceIncomplete, TestMaxTurnsCutoffIsIncompleteUnderGate), and the new policy tests cover the decision surface — local-evidence-decides-without-a-semantic-check, bounded plan-stall protection, pending-plan-as-weak-evidence, and exactly-one-required-semantic-check. go build/vet/gofmt clean and the full agent suite is green for me (only the known Windows temp-path sandbox tests fail locally, unrelated). It's a genuine improvement too — the loop sheds ~40 net lines and the completion logic is now typed and unit-testable in isolation.

One tiny take-it-or-leave-it note: evaluate never returns Uncertain with completionActionNone, so the loop's inner action switch always matches today — but if that ever changed, the continue would re-loop with no new message appended. A default arm (or an explicit assert) would make that impossible to regress. Not blocking.

Approving. The only thing still outstanding is the Windows smoke check finishing — the macOS/Ubuntu smokes are green and my local Windows build+tests pass, so I expect it to go green; over to kevin once it does.

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the completion-policy extraction against the previous inline state machine. Bounded continuation handling, stale-plan behavior, self-reported incompletion, the one-time self-correct acceptance check, and default interactive behavior are preserved. Focused tests, build, vet, lint, and all CI checks pass. No blocking findings.

@gnanam1990
gnanam1990 merged commit 18cce35 into main Jul 17, 2026
9 checks passed
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.

3 participants