Skip to content

feat(runtime): overlap review with CI and gate approval by SHA - #230

Merged
datacas merged 2 commits into
mainfrom
task-228
Oct 14, 2026
Merged

datacas merged 2 commits into
mainfrom
task-228

Conversation

@datacas

@datacas datacas commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Closes #228

Work item: #228 — feat(runtime): overlap review with CI and gate approval by SHA

Summary

An opt-in parallel CI policy lets the review start while the code host's checks run, and moves the CI wait to one deterministic, runtime-owned gate after a clean review. strict stays the default and the original serial flow: identical prompts, and the runtime never reads checks.

  • Policy: code_cycle.ci.policy: strict|parallel and ci.timeout (default 900 s); run_cycle.py --ci-policy / --ci-timeout; orchestrator ci_policy=. The command-line value wins. GitHub only: another code_host is refused and keeps strict.
  • Awaiting state: a clean review under parallel reports REVIEW_PASSED_AWAITING_CI, never an approval, with reviewed_head_sha == head_sha, an empty blocking_findings list, readable findings, and its schema-2 receipt. The runtime validates the result and the trusted receipt (the record of the state) before it waits; it never writes to GitHub.
  • One gate: scripts/ci_gate.py reads required checks from classic protection and active rulesets (every reported check when none is declared), dedupes repeated runs by name and app to their latest, passes only on success, and confirms the PR head on every read. Results: CI_PASSED, CI_FAILED, CI_SKIPPED, CI_TIMEOUT, NO_CI_CHECKS_FOUND, CI_UNREADABLE, CI_HEAD_MOVED (plus CI_PENDING for a single read). run_cycle.py imports it; both orchestrators run its command line instead of polling.
  • Transitions: CHANGES_REQUESTED → resolution at once (one non-waiting read hands an already failed check to it); clean + CI_PASSED with the receipt still the latest publication → READY_FOR_MANUAL_MERGE; CI_FAILED → one resolution told the SHA and count, never check names (an unchanged head then stops as no_progress); CI_HEAD_MOVED → one fresh rereview, a second move stops (head_moved); skipped/neutral or no checks → HUMAN_INTERVENTION (ci_not_passing); timeout/unreadable → BLOCKED (ci_timeout keeps the clean review).
  • Resume: --from rereview --pr N --ci-policy parallel reuses the latest trusted clean receipt of the current head and only runs the gate; a moved head, a later receipt, a malformed receipt or a blocking finding reviews the head; unreadable state stops as BLOCKED. --from review always reviews.
  • Telemetry (schema 19): reviewed_head_sha / checks_head_sha on verdicts, a ci row per gate read or wait with its SHA, and cycle-level ci_policy, ci_wait_ms, ci_polls, final_ci_status, redundant_reviews, review_reused. Under parallel, first_pass_approved / final_approved need a CI pass of the reviewed SHA; cc-stats and the measured first-pass rate follow. The status file shows the gate apart from any stage.
  • Skills and docs: cc-implement-issue does not wait under parallel; both reviews define the awaiting status; cc-resolve-comments diagnoses named CI failures beside the findings; both orchestrators share one byte-identical ## CI policy section that the validator enforces (every gate status, the one call, resume). Configuration, review lifecycle, workflows, telemetry and instrumentation pages, and the changelog.

Settled decisions IR-001/IR-002/IR-003/IU-001 and the second review's IR-001/IR-002 are applied as written. The single helper lives in its own module, scripts/ci_gate.py, so the orchestrators can run the same code run_cycle.py imports; it is the only waiter, not a second scheduler.

Coordination: #182 — the resolution keeps its own wait for the head it pushes under both policies, and parallel is not stated to cc-resolve-comments; #182 can turn that on against these semantics. #145 — failures are routed by SHA and count; classification and the flaky retry stay there. #164 — the SHA-tied ci rows and the status file's ci key are reusable by the monitor. #189 — the new surface is a separate module plus small closures.

Diagnosis

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 Runtime: parallel policy, CI gate, receipt validation, resume reuse, schema-19 telemetry, status scripts/ci_gate.py, scripts/run_cycle.py, scripts/cycle.py, scripts/telemetry.py, scripts/cycle_status.py, scripts/review_contract.py, scripts/stats.py, scripts/runtime.manifest tests/test_ci_gate.py, tests/test_ci_policy.py (the two key cases on a controlled fake CI, races, missing/skipped/unreadable checks, SHA changes, resume, polling ownership, and a simulated strict-vs-parallel benchmark), tests/test_cycle_outcomes.py, tests/test_telemetry.py, tests/test_stats.py targeted 307 tests exit 0; full suite 1375 exit 0; boundary runs below dependent: revert with WU-2, whose validator and skills use its vocabulary and ci_gate.py; schema-19 rows already written stay readable by older code
WU-2 Skills, both orchestrators' shared ## CI policy, validator rule, docs, changelog skills/cc-*/SKILL.md (6), scripts/validate-package.py, docs/*.md (6), CHANGELOG.md tests/test_validate_package.py (drift, lost gate status, missing section, review status, implementation wait) python3 scripts/validate-package.py exit 0; full suite 1375 exit 0 independent

Verification (agent-reported)

These results are agent-reported, not runtime-observed.

Level Command Exit Tests
static python3 scripts/validate-package.py 0 —
test python3 -m unittest tests.test_ci_gate tests.test_ci_policy tests.test_cycle_outcomes tests.test_telemetry tests.test_stats tests.test_validate_package 0 307
test python3 -m unittest discover -s tests 0 1375 (1292 before the change)
boundary python3 scripts/ci_gate.py --repo datacas/code-cycle-toolkit --pr 204 --sha 20947f45839e0c150c56aac4c17f4ad2cc411c8d --once | grep -q '"status": "CI_SKIPPED"' 0 —
boundary python3 scripts/ci_gate.py --repo datacas/code-cycle-toolkit --pr 227 --sha 734b8dc0579ddadc1f374ab7b9e0826ec917e1df --once | grep -q '"status": "CI_UNREADABLE"' (merged PR) 0 —
boundary python3 scripts/ci_gate.py --repo datacas/no-such-repository-228 --pr 1 --sha aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --once | grep -q 'gh api exited 1' 0 —
boundary python3 scripts/ci_gate.py --repo bad --pr 1 --sha abc 2>&1 | grep -q 'must be owner/name' 0 —
boundary python3 scripts/run_cycle.py --task 228 --repo owner/name --config /tmp/cc228-boundary/bitbucket.yml --database /tmp/cc228-boundary/t.sqlite --workspace current --cwd /tmp/cc228-boundary --ci-policy parallel 2>&1 | grep -q 'parallel CI policy reads GitHub checks' 0 —
boundary python3 scripts/run_cycle.py --task 228 --repo owner/name --config /tmp/cc228-boundary/typo.yml --database /tmp/cc228-boundary/t.sqlite --workspace current --cwd /tmp/cc228-boundary 2>&1 | grep -q 'unknown key under code_cycle.ci: polcy' 0 —
boundary test ! -e /tmp/cc228-boundary/t.sqlite (the refusals happen before any dispatch or telemetry write) 0 —

Conclusion: verified_with_reservations; boundary required (CLI entry points, the gh provider boundary, runtime configuration loading).

Not verified: a complete --ci-policy parallel cycle dispatching real Codex/Claude stages against a live PR and its CI (excessive cost: paid dispatches and a disposable PR); it is covered with a controlled fake CI and fake stages in tests/test_ci_policy.py. Windows is covered by CI only. The orchestrator prose is checked by the validator, not executed by an agent here.

Environment shared with CI: Python 3 (local 3.10.12) with PyYAML; a Git checkout on a named branch (the runtime tests already need one: an export without .git fails pre-existing tests too). Not shared: the boundary runs used this machine's authenticated gh against live GitHub; the unit tests make no network calls (fake provider, injected gh runner).

The checks of the pushed head follow in a comment once they finish.

Add an opt-in `parallel` CI policy (`code_cycle.ci.policy`, `--ci-policy`;
`strict` stays the default and the original flow). Under `parallel` the
implementation and the reviews are told not to wait for checks, a review
requesting changes goes to resolution at once, and a clean review may report
REVIEW_PASSED_AWAITING_CI, which is never an approval.

scripts/ci_gate.py is the one deterministic wait on a change request's
checks, with a command line both orchestrators can run. Required checks come
from classic protection and active rulesets, or every reported check when
none is declared, deduplicated to their latest run by name and app. Only
`success` passes; failed, skipped, neutral, missing, unreadable or moved-head
results never do, and every read confirms the SHA is still the PR head.

run_cycle.py validates a clean review (full reviewed_head_sha equal to
head_sha, empty blocking_findings, readable findings) and its trusted
schema-2 receipt, waits once, and approves only on CI_PASSED with the
receipt still the latest publication. A CI failure opens one resolution told
the SHA and count, a moved head gets one fresh rereview, and a timeout stops
as BLOCKED keeping the clean review, which `--from rereview` reuses without
another review. Before a resolution after CHANGES_REQUESTED, one read of the
reviewed head passes an already failed check to it.

Telemetry schema 19 records reviewed_head_sha and checks_head_sha on
verdicts, a `ci` row per gate read or wait, and the cycle's ci_policy, CI
wait time, polls, final CI status, redundant reviews and review reuse; first
pass and final approval under `parallel` count a clean review only with a CI
pass of its SHA. The status file shows the gate apart from any stage.

Refs #228
cc-implement-issue reads its pushed head's checks once and returns under
`parallel` instead of waiting. cc-initial-review and cc-rereview define
REVIEW_PASSED_AWAITING_CI: a complete clean review whose checks have not
all passed, never an approval, reported with reviewed_head_sha equal to
head_sha and an empty blocking_findings list, and never turning a check's
state into a finding. cc-resolve-comments diagnoses failed checks the cycle
names by SHA and count beside the findings; its own wait for the head it
pushes is unchanged (#182 owns that).

Both orchestrators share one byte-identical `## CI policy` section with the
same transitions as run_cycle.py: the ci_policy input, the one
`ci_gate.py` call per clean review, the action for every gate result, the
single read before a resolution, and resume reuse of a clean receipt. The
validator keeps the section identical, requires every gate status the
runtime can return after a wait, and checks the review skills define the
awaiting status and the implementation does not wait.

Configuration, review lifecycle, workflows, telemetry and instrumentation
pages document the policy with CLI and YAML examples, the awaiting state,
the gate's results, resume, schema 19, and how to compare the policies.

Refs #228
@datacas

datacas commented Oct 13, 2026

Copy link
Copy Markdown
Owner Author

Implementation summary — IMPLEMENTED

Work item #228 is implemented on task-228 as two work units (9d95a1d runtime, dec9262 skills and docs). Diagnosis, work units and agent-reported verification are in the description.

Checks of the pushed head dec9262c06952785a649fc57f8314f5cc9885e88

Check Run State
Skills, manifests, and Bash installer 38445615857 pass
Skills, manifests, and Bash installer 38445933716 pass
PowerShell installer 38445615857 pass
PowerShell installer 38445933716 pass

gh pr checks 230 exited 0 with every check passed: 4 passed, 0 failed, 0 pending on that SHA. The new gate read the same head as it will under parallel: python3 scripts/ci_gate.py --repo datacas/code-cycle-toolkit --pr 230 --sha dec9262c06952785a649fc57f8314f5cc9885e88 --timeout 60 returned CI_PASSED (exit 0), with the 2 ruleset-declared checks passed after it deduplicated the 4 runs to their latest per name and app.

This stage ran under the default strict policy: it waited for these checks before reporting. The change request has not been reviewed yet.

@datacas

datacas commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261014-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:2

Initial review — APPROVED

Reviewed the accumulated diff origin/main (merge base 6adf53b) → dec9262c06952785a649fc57f8314f5cc9885e88: 4805 lines, SHA-256 707331d8…a014a679, line count and hash confirmed, read in sections per file. Conventions applied: AGENTS.md (routing only; no review rules), .code-cycle.yml (trusted_authors: [datacas], no security_review.always_when).

Result: no findings. Nothing blocks approval. The work item (#228) is covered: opt-in parallel CI policy, runtime-owned CI gate (scripts/ci_gate.py), REVIEW_PASSED_AWAITING_CI as a non-approval state, SHA-tied approval, resume reuse, schema-19 telemetry, skills/docs/validator. strict stays the default and unchanged.

What was checked

  • Gate semantics (ci_gate.py): only success passes; skipped/neutral are CI_SKIPPED; no checks, unreadable, moved head and timeout each have their own non-pass status; latest run per name and app; head confirmed on every read and once more after a pass; required checks from classic protection plus active rulesets, every reported check otherwise.
  • Approval invariant (run_cycle.py): under parallel only the gate's CI_PASSED on the reviewed SHA, with the review's trusted receipt still the latest publication, reaches READY_FOR_MANUAL_MERGE; CycleReport.approved now follows the cycle's own ending, which is equivalent under strict. Transitions for CI_FAILED, CI_HEAD_MOVED (one fresh rereview, a second move stops), skipped/no checks, timeout and unreadable match the docs and both orchestrator sections.
  • Resume: --from rereview reuses only a clean receipt of the current head with no blocking published finding; otherwise it reviews.
  • Prompt safety: check names never enter a prompt (SHA and count only) and are passed through readable() for screens.
  • Telemetry/stats: schema 19 rows (ci, reviewed_head_sha, checks_head_sha), first_pass_approved/final_approved left unset until the gate decides.

Security triage

Rule half: no security_review.always_when is declared, so the defaults applied; none of the changed paths or labels (no labels) matched. Reviewer half: the change decides merge-readiness from trusted-author receipts and shells out to gh, so a focused audit was run by this review itself, not as a separately delegated cc-security-review pass (degraded). It covered: gh is invoked with an argv list and no shell; --repo, --pr, --sha are validated by regex on the command line, the base branch is URL-quoted; receipts count only from review.trusted_authors, scoped to repo and change-request ID; untrusted check names stay out of instructions. No confirmed vulnerability. Residual: GitHubChecks does not re-validate repo when called from run_cycle.py (it comes from the trusted .code-cycle.yml selector or --repo).

Commands executed and observed

Command Result
python3 scripts/validate-package.py exit 0, VALID: 15 skills … shared sections in sync
python3 -m unittest discover -s tests exit 0, 1375 tests OK (404 s)
python3 scripts/ci_gate.py --repo datacas/code-cycle-toolkit --pr 230 --sha dec9262c… --once (read-only, live) exit 0, CI_PASSED, required_source: declared, 2 passed (Skills, manifests, and Bash installer, PowerShell installer)
Probe of parallel + local_only (throwaway test outside the repo) stops HUMAN_INTERVENTION / local_only before any review, so no approval-telemetry gap; not a finding

Unverified

  • A full --ci-policy parallel cycle dispatching real Codex/Claude stages against a live PR (the author states this too); covered by the fake-CI tests in tests/test_ci_policy.py, which passed here.
  • Orchestrator prose is enforced by the validator, not executed by an agent.
  • Windows, beyond the PowerShell installer check.

CI

gh pr checks 230: 4 passed, 0 failed, 0 pending, 0 skipped. Both ruleset-required checks (Skills, manifests, and Bash installer, PowerShell installer) are among them and passed on this head. PR is not a draft.

Residual risks

  • Without declared required checks, every reported check is required, so an always-skipped optional job yields CI_SKIPPED and a human stop; this is documented behaviour, not a defect.
  • Checks that GitHub creates after the gate's last read (for example a chained workflow) are only reported as late, not waited for.

Verdict

APPROVED for head dec9262c06952785a649fc57f8314f5cc9885e88. Merge stays manual. The structured result of this run is returned to the runtime in its response.

@datacas
datacas merged commit 42fa7bc into main Oct 14, 2026
4 checks passed
@datacas
datacas deleted the task-228 branch October 14, 2026 15:09
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.

feat(runtime): overlap review with CI and gate approval by SHA Wait for the pushed head's CI before a resolution or implementation reports success

1 participant