Skip to content

Harden RLCR against mainline drift#48

Merged
SihaoLiu merged 1 commit intoPolyArch:devfrom
tastynoob:anti-drift
Mar 29, 2026
Merged

Harden RLCR against mainline drift#48
SihaoLiu merged 1 commit intoPolyArch:devfrom
tastynoob:anti-drift

Conversation

@tastynoob
Copy link
Copy Markdown

PR Description

Summary

This PR hardens the RLCR loop against mainline drift on top of the current dev baseline.

The core change is that RLCR no longer treats every newly discovered issue as the next round's de facto objective. Instead, each round is re-anchored against the original plan and acceptance criteria, and work is explicitly split into:

  • mainline: work that directly advances the planned objective
  • blocking: issues that must be resolved because they block mainline progress or review acceptance
  • queued: non-blocking follow-up work that should be recorded, but must not take over the round

Why

Before this change, later RLCR rounds could gradually drift away from the original plan.

Typical failure mode:

  1. Early rounds followed the plan correctly.
  2. Mid-round implementation introduced smaller bugs or cleanup items.
  3. Those issues were carried into later rounds as if they were the new main task.
  4. The loop slowly turned into "fix the latest issues" instead of "finish the planned objective".

This PR changes the loop to judge success by whether the mainline actually advanced, not by whether the backlog became smaller.

Expected Effect

This PR is expected to make RLCR behavior materially more stable:

  • each round starts from a fresh plan-aligned anchor
  • non-blocking issues no longer automatically hijack the next round
  • review findings are classified instead of blindly promoted into main work
  • queued work can remain as backlog without blocking loop progress
  • repeated non-progress is now surfaced explicitly through a drift / replan state machine

In practice, RLCR should now spend more time advancing the intended ACs and less time getting trapped in local issue-clearing loops.

What Changed

1. Round Re-anchor and Round Contract

  • Added round-N-contract.md as the per-round execution anchor.
  • Round 0, normal next-round flow, review phase, and skip-impl review flow now all use the round contract model.
  • Stop-hook now blocks non-finalize exits when the current round contract is missing.

2. Mainline / Blocking / Queued Semantics

  • Prompt templates now require task and issue classification into mainline, blocking, and queued.
  • Todo / task checking only blocks unfinished mainline and blocking items.
  • queued items are treated as backlog and do not block round completion.

3. Goal Tracker Model

  • goal-tracker.md was updated to reflect:
    • mainline tasks
    • blocking side issues
    • queued side issues
  • After Round 0, only the mutable section may be updated.
  • Validators now protect the immutable section while still allowing controlled tracker maintenance.

4. Drift / Replan State Machine

  • Added mainline_stall_count, last_mainline_verdict, and drift_status to RLCR state.
  • Codex implementation review must now emit:
    • Mainline Progress Verdict: ADVANCED / STALLED / REGRESSED
  • Two consecutive stalled/regressed rounds trigger a drift recovery prompt.
  • Three consecutive stalled/regressed rounds trigger a circuit breaker stop.

5. Skip-impl / Finalize / Contract Protection

  • --skip-impl now stays consistent with the new contract model.
  • Explicit-plan skip-impl mode preserves the original plan anchor instead of degrading to a generic review-only objective.
  • Historical round contracts are protected from being rewritten as if they were current-round files.
  • Finalize phase no longer treats round contracts as active artifacts.

6. Monitor and Operator Visibility

  • Monitor output now distinguishes blocking issues from queued issues.
  • Drift status and recent mainline verdict are surfaced in loop status output.

7. Compatibility with Existing RLCR Features

  • Anti-drift prompts now coexist with BitLesson selection requirements where that flow is enabled.
  • Follow-up prompts still preserve task-routing reminders for coding / analyze execution.
  • Agent Teams mode continues to work for implementation rounds, including drift-recovery rounds.
  • Review-only and finalize flows remain compatible with the newer dev behavior.

Main Files Touched

  • scripts/setup-rlcr-loop.sh
  • hooks/loop-codex-stop-hook.sh
  • hooks/check-todos-from-transcript.py
  • hooks/loop-write-validator.sh
  • hooks/loop-edit-validator.sh
  • hooks/loop-read-validator.sh
  • hooks/loop-bash-validator.sh
  • hooks/lib/loop-common.sh
  • scripts/humanize.sh
  • scripts/lib/monitor-common.sh
  • prompt-template/claude/*
  • prompt-template/codex/*
  • prompt-template/block/*
  • tests/*

Validation

The anti-drift changes were validated after the rebase with the existing regression suite plus targeted coverage for:

  • round contract enforcement
  • task lane parsing
  • skip-impl compatibility
  • finalize phase contract restrictions
  • drift / replan state transitions
  • monitor and tracker parsing updates
  • task-routing / agent-teams compatibility after rebase
  • BitLesson-aware prompt / summary flow compatibility

Full test result at the end of this work:

  • 1553 passed
  • 0 failed

Scope Notes

This PR intentionally focuses on the mainline drift prevention objective.

It does not attempt to clean up every pre-existing repository issue. Non-critical unrelated issues were left out unless they directly weakened the new anti-drift behavior.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b961a8336

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread hooks/lib/loop-common.sh
awk '
/^## IMMUTABLE SECTION[[:space:]]*$/ { capture=1 }
capture && /^## MUTABLE SECTION[[:space:]]*$/ { exit }
capture && /^---[[:space:]]*$/ { exit }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Parse full immutable section before mutable boundary

goal_tracker_mutable_update_allowed relies on extract_goal_tracker_immutable_from_stream, but this extractor exits on any standalone --- after ## IMMUTABLE SECTION; if the immutable content copied from a plan includes a horizontal rule, the comparison truncates early and edits below that line are no longer protected. In that case, Write/Edit validators can incorrectly accept changes to the immutable portion of goal-tracker.md, defeating the round>0 immutability guard.

Useful? React with 👍 / 👎.

@SihaoLiu SihaoLiu merged commit a8f85e8 into PolyArch:dev Mar 29, 2026
4 checks passed
@SihaoLiu SihaoLiu mentioned this pull request Mar 29, 2026
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