Skip to content

porch approve plan-approval fails with 'Plan not found' when plan is in builder worktree #676

@waleedkadous

Description

@waleedkadous

Bug Description

porch approve NNN plan-approval fails with "Plan not found" when run from the main workspace root. The plan file exists in the builder's worktree (.builders/<spir-NNN-slug>/codev/plans/NNN-slug.md), but the plan_exists check looks in cwd/codev/plans/ instead of the resolved project's worktree.

Repro Steps

  1. afx spawn NNN --protocol spir
  2. Builder writes plan to .builders/spir-NNN-slug/codev/plans/NNN-slug.md
  3. Architect runs porch approve NNN plan-approval --a-human-explicitly-approved-this from repo root
  4. Porch prints "CHECKS FAILED. Cannot approve gate." with "Plan not found"
  5. But state.yaml in the worktree sometimes flips to approved anyway

Observed On

At least 3 projects (568, 615, 629) on the Shannon workspace. Behavior is inconsistent — sometimes approval silently goes through, sometimes it doesn't take effect until retry.

Root Cause

The plan_exists check (and likely spec_exists) resolves file paths relative to cwd rather than the project's resolved worktree. porch status NNN correctly resolves the worktree (via findStatusPath which was fixed in PR #674 to search .builders/ first), but the artifact existence checks don't use the same resolution logic.

Additionally, the approve command appears to write the state update BEFORE consulting the check result — so the gate flips to approved even when the check fails. This should be audited: either run checks before the write, or roll back on failure.

Expected Behavior

plan_exists (and any other path-based checks) should resolve the project's worktree from the project ID — same logic porch status uses — and check for the plan file in <worktree>/codev/plans/ instead of cwd/codev/plans/.

Impact

Architects give up on porch CLI for plan approvals and edit status.yaml by hand, which defeats the point of porch.

Reported by Shannon workspace architect session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions