Skip to content

Deduplicate candidate and workflow policy handling - #1845

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/575-dedupe-candidate-policy
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/575-dedupe-candidate-policy

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Deduplicate candidate and workflow policy handling

Context and goal

  • Context: Related to Keep loop-zero improvement builders full: refill continuously (Marcin standing order) #575. The candidate path revalidates already-checked event fields and repeats repository identity extraction, while workflow loading and hosted refresh use duplicate paths for equivalent outcomes.
  • Problem: Repeated control flow consumes source headroom needed by approved changes.
  • Goal: Remove 40 source lines while preserving validation order, public configuration, and GitHub status publication. Keep test lines unchanged.

Acceptance

  • Candidate number, ref, head, draft, app identity and checkout target checks keep their outcomes and diagnostics.
  • Configuration refresh uses the existing Git runner. Absent input mappings and fixed environment entries retain their empty defaults.
  • Hosted refresh preserves status writes and error handling on both source and candidate paths.
  • Source delta at most -40 and test delta zero or negative.

Base

Base: 839d8fa

Validation

Recorded for f88384bd474b

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

Architecture-Review: unchanged; keep the same attestation inputs, trusted workflow policy, and hosted publication boundaries.
Co-Authored-By: Codex <noreply@openai.com>
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Equivalence evidence for the removed paths

  • Candidate: the only snapshot caller supplies the same event number and head already validated before the first lookup. A live ref equal to that validated string already has the required queue prefix. The closed and non-open diagnostics remain distinct; draft, identity, SHA, and target checks keep their order. The shared repository key reads the same id and full name for candidate head/base and source base. Source snapshots are inserted in the already sorted lineage order, so the same entries are returned in the same order.
  • Config: refresh passes the same Git arguments, directory, environment allowlist, and timeout through the existing runner. The loader applies the same decoder, validation, and error messages and attaches the resolved revision once after choosing the effective policy. Missing inputs still yield a new empty mapping, a missing fixed environment still yields an empty tuple, and packed refs and limit keys are checked using the same bytes and keys.
  • Hosted: the candidate event verdict and a source’s merged state both feed the same pre-publication return. The generic-error handler still attempts the same best-effort failure status, exempts status limits, and re-raises the original error. Final status publication and readback stay in their existing path.

Candidate/config/hosted tests: 202 passed, 9 skipped. Size and complexity gates passed. At base 839d8fa9, source 8,224 → 8,184 and tests 13,718 → 13,718.

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on 413b14c9ba0b16de72fc1c01867348c9caf70df2, 36.3s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/candidate.py
expected_repo = (repository.get("id"), repository.get("full_name"))
_require(_identity(candidate.get("user")) == expected_identity,
"Candidate author is not the verified Mergify GitHub App")
head, base = candidate.get("head"), candidate.get("base")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Head-ref prefix check now depends on an earlier check in the caller

_candidate_snapshot no longer checks that event_head is a dict or that head.ref starts with QUEUE_BRANCH_PREFIX. Today nothing changes, because the only caller, _attest_candidate_once, does both checks first: _object(...) at line 444 and the prefix check at line 446. The new check head.get("ref") == event_head.get("ref") still rejects any ref that isn't a queue branch, and the error message is unchanged. The risk is in the future: the function's safety now rests on a check that lives somewhere else. If anyone calls _candidate_snapshot from a different place, the prefix check is silently lost. A small fix is to add a one-line comment or docstring saying event_head must already be validated and prefix-checked.

Comment thread src/loopzero/config.py
try:
data = tomllib.loads(shown.stdout.encode("utf-8", errors="surrogateescape").decode("utf-8"))
text = shown.stdout.encode("utf-8", errors="surrogateescape").decode("utf-8")
return _build(tomllib.loads(text)), revision

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: _build now runs inside the TOML parse/decode try block

The result is the same today. _build raises only ConfigError, and ConfigError derives from LoopZeroError, not from UnicodeDecodeError or TOMLDecodeError, so every error still reaches the same handler as before. The new layout is still more fragile: if _build ever raises a ValueError subclass that matches an earlier except clause, it would get the wrong message. No change is needed. Just keep this in mind if _build starts calling decoding helpers.

Architecture-Review: unchanged; the shared Git runner still honors main’s remaining read budget.
Co-Authored-By: Codex <noreply@openai.com>
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The conflict refresh preserves #1829’s read_timeout(60) for Git refresh and passes its timeout function through both effective-policy lookups. The same Git runner still receives the same argv, cwd, allowlist, and now the same bounded timeout as main. The source/test deltas remain −40/0, complexity passed, and all 69 config tests passed on this head.

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero delta review by claude on f88384bd474b66685e67242276b327962000119a, 8.9s: approve (0 critical, 0 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

@eowca
eowca marked this pull request as ready for review November 26, 2026 11:45
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as d0587c9 at 11:51 UTC

5 min in the queue, 4 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 11:46 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1852
  • ✅ Merged 11:51 · d0587c9 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit d0587c9 into main Nov 26, 2026
16 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/575-dedupe-candidate-policy branch November 26, 2026 11:52
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