Skip to content

fix(ci): make chunk state atomic with merge - #319

Merged
abiorh-claw merged 2 commits into
mainfrom
codex/ws-ci-003-atomic-chunk-state
Aug 11, 2026
Merged

fix(ci): make chunk state atomic with merge#319
abiorh-claw merged 2 commits into
mainfrom
codex/ws-ci-003-atomic-chunk-state

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Workstream PR Trust Bundle

Chunk

WS-CI-003-01 — Atomic Chunk State

Goal

Make human merge the only transition needed to complete a chunk: implementation
and its durable state land in the same PR.

Root cause

Chunk state was duplicated across contracts, chunk maps, initiative status, and
current state, but nothing required those files to describe the post-merge
outcome. PR #318 repaired earlier stale records and still landed its own HK1 row
as In review.

What changed

  • Added a deterministic atomic chunk-state checker.
  • Implementation-surface PRs require exactly one changed chunk contract.
  • Changed contracts declare Outcome on merge.
  • The same PR must update CHUNK_MAP, STATUS, and CURRENT_STATE with the exact
    chunk and final outcome.
  • Completed chunks cannot land with review-only wording.
  • Planning-only PRs may define multiple planned chunks.
  • Agent Gates runs the checker against the exact base/head diff.
  • Contributor, agent, and PR templates describe the single-step workflow.
  • Corrected merged WS-CI-002 state through PR fix(ci): make agent gates deterministic per head #311.

What did not change

  • No post-merge workflow or second PR.
  • No write token or direct push.
  • No branch-protection, coverage, test-selection, product, or schema change.
  • Human review and human merge remain authoritative.

Evidence

  • 21 focused unit/regression tests passed.
  • Atomic checker passed against origin/main...HEAD.
  • Markdown links and stale wording checks passed.
  • git diff --check passed.

Human review focus

Confirm this makes chunk state atomic without introducing another workflow or
turning historical review evidence into authority.

Human merge ownership

  • The change and root cause are documented.
  • CI and approval requirements are not weakened.
  • The user explicitly approves this PR for merge.

Summary by CodeRabbit

  • New Features

    • Added automated validation to ensure implementation changes have synchronized completion state across project records.
    • Added checks for declared merge outcomes and consistent final-state documentation.
  • Documentation

    • Updated contribution guidance, workflow instructions, and pull request templates with chunk completion requirements.
  • Tests

    • Added coverage for valid, incomplete, inconsistent, and documentation-only change scenarios.
    • Expanded workflow regression checks to include the new validation.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR defines atomic chunk-state contracts, adds a validator for synchronized state projections, integrates the check into Agent Gates, expands regression tests, and records completed initiative state.

Changes

Atomic chunk-state enforcement

Layer / File(s) Summary
Define chunk-state contract
.agent-loop/initiatives/..., AGENTS.md, CONTRIBUTING.md, .agent-loop/templates/PR_TRUST_BUNDLE.md, .github/pull_request_template.md
Chunk contracts and contribution rules require one implementation chunk, an explicit merge outcome, and synchronized final-state records.
Validate synchronized state
scripts/check_chunk_state_sync.py, scripts/test_chunk_state_sync.py
The validator checks changed paths, chunk contracts, outcomes, projection updates, and lifecycle wording. Tests cover complete, planned, invalid, and documentation-only changes.
Run validation in Agent Gates
.github/workflows/agent-gates.yml, scripts/test_lightweight_agent_gates.py
Agent Gates runs the validator with the pull request base SHA and includes its regression tests.
Record completed initiative state
.agent-loop/CURRENT_STATE.md, .agent-loop/initiatives/...
WS-CI-002 and WS-CI-003-01 are recorded as complete with synchronized outcomes.

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

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant AgentGates
  participant ChunkStateValidator
  participant StateProjections
  PullRequest->>AgentGates: trigger checks with base SHA
  AgentGates->>ChunkStateValidator: validate changed chunk state
  ChunkStateValidator->>StateProjections: compare chunk map, status, and current state
  StateProjections-->>ChunkStateValidator: return projection results
  ChunkStateValidator-->>AgentGates: return validation status
  AgentGates-->>PullRequest: report gate result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the goal and changes, but it omits most required template sections, including scope, design, acceptance proof, reviewer results, risks, and CI integrity. Complete the required trust-bundle sections and include scope, design decisions, acceptance criteria, test delta, review results, CI integrity, risks, and follow-up details.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: enforcing atomic chunk state at merge.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ws-ci-003-atomic-chunk-state

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
@.agent-loop/initiatives/WS-CI-003-atomic-chunk-state/chunks/WS-CI-003-01-atomic-chunk-state.md:
- Around line 49-51: Update scripts/check_chunk_state_sync.py’s projection-state
validation to parse the state field or perform token-aware, negation-safe
matching rather than substring checks, so “complete” does not match “not
complete” or “incomplete.” Add regression tests covering these false positives
while preserving valid exact outcome matches.
- Line 46: Update scripts/check_chunk_state_sync.py to parse the canonical
“Outcome on merge” field only within the contract’s “## Merge state” section,
rejecting contracts with zero or multiple declarations instead of accepting the
first match. Add regression tests covering missing, duplicate, and
misplaced/conflicting outcome declarations while preserving valid single-outcome
contracts.

In `@scripts/check_chunk_state_sync.py`:
- Around line 62-64: Update _projection_lines to match chunk_id only as a
complete identifier using an identifier-boundary regular expression, preventing
longer IDs from satisfying shorter-ID checks. Add a regression test where the
projection contains only the longer identifier and assert that validation raises
CHUNK_STATE_ID_MISSING.
- Around line 36-45: Update changed_paths to be asynchronous and use
asyncio.create_subprocess_exec instead of subprocess.run, awaiting communicate
and preserving the existing changed-path parsing. Convert the checker entry
point to async and update main to run that async entry point.
- Around line 98-115: The outcome validation in the chunk-state checks must stop
using substring matching, which lets values such as “Incomplete” satisfy
“complete.” Update the checks around OUTCOME_WORDS in the chunk-map and
projection validation to match complete tokens or explicitly parse the state
field, while preserving valid outcome handling. Add regression coverage for
“Incomplete” and comparable non-outcome text.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 195d80bd-8841-4e65-b267-c1dc4059b73c

📥 Commits

Reviewing files that changed from the base of the PR and between c31c25f and 86362c6.

📒 Files selected for processing (13)
  • .agent-loop/CURRENT_STATE.md
  • .agent-loop/initiatives/WS-CI-002-deterministic-agent-gates/STATUS.md
  • .agent-loop/initiatives/WS-CI-003-atomic-chunk-state/CHUNK_MAP.md
  • .agent-loop/initiatives/WS-CI-003-atomic-chunk-state/STATUS.md
  • .agent-loop/initiatives/WS-CI-003-atomic-chunk-state/chunks/WS-CI-003-01-atomic-chunk-state.md
  • .agent-loop/templates/PR_TRUST_BUNDLE.md
  • .github/pull_request_template.md
  • .github/workflows/agent-gates.yml
  • AGENTS.md
  • CONTRIBUTING.md
  • scripts/check_chunk_state_sync.py
  • scripts/test_chunk_state_sync.py
  • scripts/test_lightweight_agent_gates.py

Comment on lines +36 to +45
def changed_paths(base_ref: str, head_ref: str = "HEAD") -> list[str]:
"""Return paths changed by the prospective merge."""
result = subprocess.run(
["git", "diff", "--name-only", f"{base_ref}...{head_ref}"],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
)
return [line for line in result.stdout.splitlines() if line]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use async subprocess execution.

changed_paths implements a synchronous-first checker with subprocess.run.

Replace it with asyncio.create_subprocess_exec. Make main run the async entry point.

As per coding guidelines: “Execution is async-first; do not document or implement synchronous-first checkers or jobs.”

🧰 Tools
🪛 ast-grep (0.45.1)

[error] 37-43: Command coming from incoming request
Context: subprocess.run(
["git", "diff", "--name-only", f"{base_ref}...{head_ref}"],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(subprocess-from-request)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check_chunk_state_sync.py` around lines 36 - 45, Update changed_paths
to be asynchronous and use asyncio.create_subprocess_exec instead of
subprocess.run, awaiting communicate and preserving the existing changed-path
parsing. Convert the checker entry point to async and update main to run that
async entry point.

Source: Coding guidelines

Comment thread scripts/check_chunk_state_sync.py
Comment thread scripts/check_chunk_state_sync.py Outdated
@abiorh-claw
abiorh-claw self-requested a review August 11, 2026 17:42
@abiorh-claw
abiorh-claw merged commit 378244b into main Aug 11, 2026
11 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.

2 participants