Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion orchestrator/routes/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4577,7 +4577,24 @@ def _get_plan_review_criteria() -> str:
"### 7. Completeness\n"
"- Does the plan cover all aspects of the original request?\n"
"- Are documentation updates included where needed?\n"
"- Are there any obvious gaps or missing tasks?\n"
"- Are there any obvious gaps or missing tasks?\n\n"
"### 8. Task Role ↔ Files Alignment (deterministic, see #2527)\n"
"- Task role↔files alignment is enforced **orchestrator-side** at "
"`CONSENSUS_PROPOSE`: a planner proposal whose task `role:` "
"assignments cannot push their `files:` (per "
"`shared/egg_restrictions/patterns.py`, the same blocklist the "
"gateway uses) is rejected with HTTP 400 before this prompt is "
"ever rendered. By the time you see a proposal, structural "
"role↔files alignment is therefore already validated — no manual "
"check is required for this dimension.\n"
"- If you want belt-and-suspenders verification, you can run the "
"validator yourself against the proposed plan: "
'`python3 -c "from egg_contracts.plan_parser import parse_plan_file, '
"validate_task_role_alignment as v; r = parse_plan_file('<plan-path>'); "
"print('\\n'.join(v(r.to_contract_slices())))\"`. "
"Errors here would predict a push-time `403 "
"restricted_path_modified` — NACK the planner and quote the "
"structured errors verbatim if any surface.\n"
)


Expand Down
122 changes: 122 additions & 0 deletions orchestrator/routes/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,123 @@ def _validate_tester_check_coverage(
)


def _validate_planner_role_alignment(
pipeline_id: str, payload: dict[str, Any], repo_path: Path
) -> None:
"""Validate task role↔files alignment for a planner proposal (#2527).

Reads the plan draft at the proposed commit via ``git show`` against
the orchestrator's pipeline worktree and runs
``validate_task_role_alignment``. Raises ``ValueError`` if any task
is assigned to a role that cannot push its files — the caller's
``handle_consensus_propose_signal`` ``except`` block then returns 400
to the planner before the proposal is recorded on the tracker, so no
reviewer cycle is wasted on a structurally-broken plan.

The check mirrors the gateway's push-time blocked-pattern logic
(``gateway/phase_filter.py::FileRestriction.is_file_blocked``), so a
rejection here predicts a push-time ``403 restricted_path_modified``
in the implement phase. Caught here it costs the planner one
re-propose; caught at push time it costs a full producer cycle.

Graceful degradation: when the plan file doesn't exist at the
proposed commit, ``git show`` fails, parsing fails, or the validator
raises, this function returns silently. The push-time gateway check
remains the backstop, and the existing forest-validation pass at
plan-ingestion time still runs.
"""
commit_sha = (payload.get("commit_sha") or "").strip()
if not commit_sha:
return

try:
pipeline = get_state_store(repo_path).load_pipeline(pipeline_id)
except StateStoreError:
return

if not pipeline.branch:
return

# Build the plan draft path. Imported lazily to avoid pulling the
# 16k-line ``routes.pipelines`` module into ``signals`` import time.
try:
from routes.pipelines import _get_draft_path
except ImportError:
try:
from .pipelines import _get_draft_path # type: ignore[no-redef]
except ImportError:
return
plan_rel = _get_draft_path(
"plan",
issue_number=pipeline.issue_number,
pipeline_id=pipeline_id,
mode=getattr(pipeline, "mode", None),
)
if not plan_rel:
return

worktree_path = resolve_worktree_path(pipeline_id, repo_path)

# Read plan content as committed at the proposed SHA so a stale
# local checkout cannot mask a real misassignment. The preceding
# ``_verify_commit_on_branch`` call has already done a ``git fetch``,
# making the commit reachable in the worktree.
try:
result = subprocess.run(
["git", "-C", str(worktree_path), "show", f"{commit_sha}:{plan_rel}"],
capture_output=True,
text=True,
timeout=15,
check=False,
)
if result.returncode != 0:
return # Plan not present at this commit — nothing to validate.
plan_text = result.stdout
except Exception as exc:
logger.warning(
"plan role-alignment validation: git show failed (non-blocking)",
pipeline_id=pipeline_id,
commit_sha=commit_sha,
error=str(exc),
)
return

try:
from egg_contracts.plan_parser import (
parse_plan,
validate_task_role_alignment,
)
except ImportError:
return

try:
parsed = parse_plan(plan_text)
if not parsed.success:
return
slices = parsed.to_contract_slices()
errors = validate_task_role_alignment(slices)
except Exception as exc:
logger.warning(
"plan role-alignment validation: validator raised (non-blocking)",
pipeline_id=pipeline_id,
commit_sha=commit_sha,
error=str(exc),
)
return

if not errors:
return

bullet_list = "\n".join(f" - {e}" for e in errors)
raise ValueError(
"Plan proposal rejected: task role↔files alignment violations.\n"
"The following tasks are assigned to roles whose blocklist "
"forbids their files (would 403 at push time per "
"shared/egg_restrictions/patterns.py). Update the affected "
"tasks' 'role' field and re-propose:\n" + bullet_list
)


def _resolve_pipeline_phase(pipeline_id: str, repo_path: Path) -> str:
"""Resolve the current phase for a pipeline, with graceful fallback.

Expand Down Expand Up @@ -1101,6 +1218,11 @@ def handle_consensus_propose_signal(
# rejected proposals.
if agent_role == "tester":
_validate_tester_check_coverage(pipeline_id, payload, repo_path)
# Validate task_planner proposals don't misassign tasks to roles
# whose blocklist forbids their files (#2527). Same placement
# rule: BEFORE handle_propose so the tracker isn't mutated.
elif agent_role == "task_planner":
_validate_planner_role_alignment(pipeline_id, payload, repo_path)

# Check if this is a re-proposal
changed_artifacts = data.get("changed_artifacts")
Expand Down
Loading
Loading