Skip to content

fix(loop-memory): freeze merge-bound evidence#190

Merged
abiorh-claw merged 9 commits into
mainfrom
codex/ws-eng-007-00r3-merge-bound-evidence
Jul 23, 2026
Merged

fix(loop-memory): freeze merge-bound evidence#190
abiorh-claw merged 9 commits into
mainfrom
codex/ws-eng-007-00r3-merge-bound-evidence

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Workstream PR Trust Bundle

Chunk

WS-ENG-007-00R3 — Merge-Bound Evidence Recovery

Merge intent: .agent-loop/merge-intents/WS-ENG-007-00R3.json

Goal

Restore signed reconciliation and explicit starts without allowing mutable
post-merge reruns to rewrite accepted evidence or block unrelated initiatives.

Human-Approved Intent

  • Intent: .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/INTENT.md
  • Chunk contract: .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/chunks/WS-ENG-007-00R3-merge-bound-evidence-recovery.md

What Changed

Why It Changed

Signed memory remained at PR #178 because present-day reruns were re-evaluated
and explicit starts lacked recovery parity. That created a global mutable-history
lock that blocked the unrelated ENG-006 documentation initiative.

Design Chosen

Use immutable merged_at as the evidence cutoff, paginate check evidence
completely, persist exact provenance, consume an exact one-use recovery
certificate, and reconcile in temporary custody before applying authority or
publishing signed state.

Alternatives Rejected

  • Treating CodeRabbit as start or recovery authority.
  • Accepting the latest present-day rerun for an already merged PR.
  • Adding a wildcard or reusable recovery exemption.
  • Maintaining separate merge and explicit-start reducers.

Scope Control

Allowed Files Changed

  • Loop-memory updater/checker, focused workflows, recovery policy, tests,
    operations documentation, initiative artifacts, review evidence, merge intent.

Files Outside Contract

  • None.

Product Behavior

  • No Workstream product behavior changed.

Evidence

Commands Run

PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest -p pytest_cov.plugin -q --cov=scripts.update_post_merge_memory --cov-branch scripts/test_agent_gates.py scripts/test_update_post_merge_memory.py scripts/test_check_loop_memory_state.py
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest -p pytest_cov.plugin -q --cov=scripts.check_loop_memory_state --cov-branch scripts/test_agent_gates.py scripts/test_update_post_merge_memory.py scripts/test_check_loop_memory_state.py
python3 scripts/test_agent_gates.py
PR_HEAD_SHA="$(git rev-parse HEAD)" python3 scripts/check_internal_review_evidence.py
python3 scripts/check_markdown_links.py
python3 scripts/check_stale_workstream_wording.py
git diff --check origin/main...HEAD

Result Summary

Updater: 278 passed; 90.10% branch coverage
Independent checker: 278 passed; 90.41% branch coverage
Standalone Agent Gates: 98 passed
Backend GitHub workflow: passed exact prior PR head; rerunning final head

Acceptance Criteria Proof

  • Post-merge reruns cannot replace merge-bound protected evidence.
  • Eligible failures and malformed evidence fail closed.
  • PR fix(loop-memory): canonicalize trusted check reruns #189 recovery-only evidence is exact and certificate-bound.
  • Recovery is consumed before signing and is non-reusable.
  • Merge and explicit-start workflows use one reducer.
  • ENG-006 and ENG-007 successors remain inactive.

Test Delta

Tests Added

  • Merge-cutoff poisoning and post-merge-only candidates.
  • Paginated collection completeness, overlap, drift, and malformed envelopes.
  • Selected evidence schema, identity, timestamp, digest, and certificate mutations.
  • Schema-v4 policy and shared reconcile/CLI behavior.
  • Exact PR fix(loop-memory): canonicalize trusted check reruns #189-only historical_recovery=True dispatch.

Tests Modified

  • Workflow assertions now require the shared reconcile entry point.
  • Historical recovery transport expectations include exact four-entry v3 transport.

Tests Removed Or Skipped

  • None.

Internal Reviewer Results

Reviewed code SHA: 4a3eee7fdd80970675ae2574542073b8a92e1ef9

Reviewer run IDs: /root/eng006_senior_arch_docs, /root/eng006_qa_ci_tests, /root/eng006_security_ops_reuse, explicitly reassigned to this exact ENG-007 review.

Reviewer Result Blocking Findings Notes
Senior engineering PASS AFTER FIXES None Exact head reapproved.
QA/test PASS AFTER FIXES None 278 tests; literal coverage floors pass.
Security/auth PASS AFTER FIXES None PR #189-only authority preserved.
Product/ops PASS None No product behavior change.
Architecture PASS AFTER FIXES None One shared reducer.
CI integrity PASS AFTER FIXES None No gate weakening.
Docs PASS AFTER FIXES None Runbook and evidence aligned.
Reuse/dedup PASS AFTER FIXES None Duplicated predicate removed.
Test delta PASS AFTER FIXES None No removed or weakened tests.

External Review

External response: .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/reviews/WS-ENG-007-00R3-external-review-response.md

Source Status Notes
CodeRabbit Addressed Two actionable comments and one reuse nitpick fixed.
GitHub checks Running Agent Gates and full backend rerun on final head.

CI And Gate Integrity

  • No workflow weakening.
  • No lint/test/docstring gate weakening.
  • No coverage threshold weakening.
  • No package script weakening.
  • No unpinned new GitHub Action.
  • Checkout credential persistence disabled where checkout is used.

Remaining Risks

An intervening main merge invalidates the exact first-parent bridge and must
fail closed. CodeRabbit availability remains rate-limited and supplementary.

Follow-Up Work

After merge and successful signed reconciliation, dispatch the already-approved
ENG-006 documentation refresh. CI coverage precision hardening requires a
separate workflow-policy chunk; this PR reaches literal coverage above 90%.

Human Review Focus

  • Confirm only exact historical PR fix(loop-memory): canonicalize trusted check reruns #189 receives recovery-only evidence.
  • Confirm the activation PR requires ordinary protected checks.
  • Confirm both workflows invoke the same reducer before authority/publication.
  • Confirm no exemption survives signed state.

Human Merge Ownership

  • I can explain what changed.
  • I can explain why it changed.
  • I know what could break.
  • I accept the remaining risks.
  • The user explicitly approved this specific PR for merge.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces merge-bound protected-check evidence, schema-v4 recovery policies, and a shared atomic reconciliation command used by automatic and explicit-start workflows. Validators, workflows, documentation, policies, and regression tests are updated accordingly.

Changes

Merge-bound evidence recovery

Layer / File(s) Summary
Recovery contract and policy
.agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/*, .agent-loop/merge-intents/*, .agent-loop/policies/*
Adds the 00R3 contract, documents merge-bound evidence requirements, and updates recovery policy metadata to schema v4.
Protected evidence collection and validation
scripts/update_post_merge_memory.py, scripts/check_loop_memory_state.py
Selects successful protected checks at or before merged_at, validates provenance, digests, timestamps, historical certificates, and paginated responses.
Recovery preparation and atomic reconciliation
scripts/update_post_merge_memory.py
Adds schema-v4 recovery validation, historical recovery handling, reconcile_to_main, and the reconcile CLI command.
Workflow integration and operating contract
.github/workflows/*, docs/operations_post_merge_memory.md
Routes automatic and explicit-start workflows through one reconcile invocation and documents validation before signing or publication.
Regression coverage
scripts/test_update_post_merge_memory.py, scripts/test_agent_gates.py
Covers evidence selection, pagination, reconciliation ordering, cutoff enforcement, timestamp canonicalization, recovery certificates, policy fixtures, and workflow command ordering.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MergeWorkflow
  participant ReconcileCommand
  participant GitHubAPI
  participant GeneratedMemory
  MergeWorkflow->>ReconcileCommand: run reconcile for TARGET_SHA
  ReconcileCommand->>GitHubAPI: collect merge-bound check evidence
  GitHubAPI-->>ReconcileCommand: paginated checks and merge records
  ReconcileCommand->>GeneratedMemory: prepare and apply recovery state
  ReconcileCommand->>GeneratedMemory: assert consumption and validate state
  ReconcileCommand-->>MergeWorkflow: complete before signing or publishing
Loading

Possibly related PRs

Suggested reviewers: abiorh-claw

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 is concise and accurately summarizes the main change: freezing merge-bound evidence.
Description check ✅ Passed The description matches the template well and includes the required sections, evidence, test delta, and review details.
✨ 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 codex/ws-eng-007-00r3-merge-bound-evidence

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: 2

🧹 Nitpick comments (1)
scripts/update_post_merge_memory.py (1)

2511-2519: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated historical-recovery gate literal across two call sites.

reconcile_to_main (2512-2515) and the CLI update command (3438-3441) each re-derive the same "is this the R3 historical-recovery merge" boolean from the same hand-typed merge_sha literal and "WS-ENG-007-00R2" chunk-id check. Extracting a single helper (e.g. _is_r3_historical_recovery(merge_sha, exemptions)) would remove the duplication and eliminate the risk of the two checks silently diverging if one site is ever edited without the other.

♻️ Suggested consolidation
+def _is_r3_historical_recovery(merge_sha: str, exemptions: list[dict[str, Any]]) -> bool:
+    """Identify the one-time WS-ENG-007-00R2 recovery-only merge."""
+    return merge_sha == "d3321698fb856f3fac320cdc7bc598f813fe1953" and any(
+        item.get("chunk_id") == "WS-ENG-007-00R2" for item in exemptions
+    )
+
 for merge_sha in planned:
-    historical = (
-        merge_sha == "d3321698fb856f3fac320cdc7bc598f813fe1953"
-        and any(item.get("chunk_id") == "WS-ENG-007-00R2" for item in exemptions)
-    )
+    historical = _is_r3_historical_recovery(merge_sha, exemptions)

Also applies to: 3438-3445

🤖 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/update_post_merge_memory.py` around lines 2511 - 2519, Extract the
duplicated historical-recovery condition into a shared helper such as
_is_r3_historical_recovery(merge_sha, exemptions), including the merge SHA and
WS-ENG-007-00R2 exemption check. Replace the inline boolean logic in both
reconcile_to_main and the CLI update command with this helper while preserving
the existing historical_recovery argument behavior.
🤖 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-ENG-007-concurrent-pr-review-reconciliation/reviews/WS-ENG-007-00R3-internal-review-evidence.md:
- Line 17: Add an explicit statement in the review evidence file that the listed
/root/eng006_* reviewer sessions were reassigned or inherited from ENG-006 for
use in WS-ENG-007. Keep the existing exact-SHA binding and complete
track-to-session mappings unchanged.

In `@scripts/test_update_post_merge_memory.py`:
- Around line 1948-1969: Update
test_shared_reconcile_orders_recovery_and_validates_atomically to include
d3321698fb856f3fac320cdc7bc598f813fe1953 in the planned SHAs and record keyword
arguments in the collect_merge_record mock. Assert that only the collection call
for this recovery SHA receives historical_recovery=True, while other collection
calls do not; preserve the existing event-order assertions.

---

Nitpick comments:
In `@scripts/update_post_merge_memory.py`:
- Around line 2511-2519: Extract the duplicated historical-recovery condition
into a shared helper such as _is_r3_historical_recovery(merge_sha, exemptions),
including the merge SHA and WS-ENG-007-00R2 exemption check. Replace the inline
boolean logic in both reconcile_to_main and the CLI update command with this
helper while preserving the existing historical_recovery argument behavior.
🪄 Autofix (Beta)

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: e6220f04-e93f-49c0-8137-494a943364c1

📥 Commits

Reviewing files that changed from the base of the PR and between d332169 and e357e8f.

📒 Files selected for processing (17)
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/CHUNK_MAP.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/DECISIONS.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/DISCOVERY.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/RISKS.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/STATUS.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/chunks/WS-ENG-007-00R3-merge-bound-evidence-recovery.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/reviews/WS-ENG-007-00R3-internal-review-evidence.md
  • .agent-loop/initiatives/WS-ENG-007-concurrent-pr-review-reconciliation/reviews/WS-ENG-007-00R3-pr-trust-bundle.md
  • .agent-loop/merge-intents/WS-ENG-007-00R3.json
  • .agent-loop/policies/loop-memory-recovery.json
  • .github/workflows/loop-memory-start.yml
  • .github/workflows/loop-memory.yml
  • docs/operations_post_merge_memory.md
  • scripts/check_loop_memory_state.py
  • scripts/test_agent_gates.py
  • scripts/test_update_post_merge_memory.py
  • scripts/update_post_merge_memory.py

Comment thread scripts/test_update_post_merge_memory.py
@abiorh-claw
abiorh-claw self-requested a review July 23, 2026 10:08
@Abiorh001

Copy link
Copy Markdown
Collaborator Author

Addressed the remaining CodeRabbit review: inherited reviewer-session reassignment is explicit, exact PR #189 recovery-only dispatch is now proven, and the duplicated historical predicate is centralized in _is_r3_historical_recovery(). The PR description now contains the full trust bundle. The docstring warning is stale: authoritative Backend preflight passed docstring coverage on the prior exact head and is rerunning on the repaired head.

@abiorh-claw
abiorh-claw merged commit a3eecad into main Jul 23, 2026
10 checks passed
github-actions Bot pushed a commit that referenced this pull request Jul 23, 2026
@abiorh-claw
abiorh-claw deleted the codex/ws-eng-007-00r3-merge-bound-evidence branch July 23, 2026 11:40
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