Skip to content

porch: status.yaml resolution picks an arbitrary worktree copy — approvals read stale state and can write into sibling worktrees #1235

Open

Description

@waleedkadous

Symptom

porch approve <id> <gate> (and porch status) run from the workspace root can resolve the project's status.yaml to an arbitrary worktree's checked-out copy — a different project's worktree that merely carries the target project's snapshot.

Field report from an adopting workspace (details scrubbed): an architect-side porch approve targeting a project's pr gate read a stale earlier-PR-era approved from the wrong worktree's copy and reported "Gate pr is already approved" while the builder's canonical copy still said pending — the approval silently never landed. The same mis-resolution can write gate approvals into sibling worktrees' files.

Root cause

findStatusPath in packages/codev/src/commands/porch/state.ts searches .builders/*/codev/projects/<id> in readdirSync order and returns the first match, then falls back to the local codev/projects/ copy. The comment says worktrees are searched first because they hold "active, up-to-date state" — but since porch state became a committed artifact (the #532 convention: status.yaml ships to main at the pr gate), every worktree branched from main carries every project's snapshot. First-match is therefore arbitrary (alphabetical worktree order), and almost always a stale copy owned by an unrelated project.

A second manifestation of the same gap hit this repo on 2026-07-22: after a builder worktree was cleaned up, the main-checkout snapshot (frozen mid-protocol at pr-gate time) became the resolved copy, leaving a verify-approval gate mechanically un-approvable (restored manually via PR #1228).

Workaround

env -C <builder-worktree> porch approve … — cwd-pinning resolves the canonical copy.

Suggested fix (from the reporting architect, seconded)

  • Resolve project state via worktree ownership (the spawn registry: project id → its own worktree), never by cwd-relative or first-match search.
  • When multiple differing copies of a project's status.yaml exist and ownership can't be established, hard-error listing the candidates instead of silently picking one.
  • Reconcile the "porch works from any directory" contract in the architect role docs with whatever resolution rule ships.

Repro details available from the reporting workspace on request.

Activity

  1. added
    area/porch
    on Jul 23, 2026
  2. waleedkadous commented on Jul 31, 2026

    @waleedkadous
    ContributorAuthor

    Production confirmation + a new wrong-winner class (from an external workspace, 2026-07-31)

    A production workspace hit this in a new shape worth adding to the design constraints:

    • Their project's OWNING worktree was already cleaned up; the root/main copy of codev/projects/<id>/status.yaml was authoritatively updated (a porch cannot express merged-outside-the-loop: add 'porch reconcile' for evidence-based terminal state repair #1297-style terminal reconcile, commit verified on their integration branch).
    • Yet porch status <id> from the workspace root printed the OLD phase — because two unrelated task builders, spawned after the merge but branched before the reconcile landed, each carry a stale snapshot at .builders/task-*/codev/projects/<id>/status.yaml, and resolution (state.ts:279-299 — .builders/* searched FIRST, first readdir match wins) prefers one of those over the root copy.

    So the failure isn't limited to "the owning worktree vs root": any bystander worktree that merely CONTAINS a stale snapshot of the project can win resolution from the root cwd, and which one wins is directory-order nondeterministic. The search builders first (active, up-to-date state) comment encodes an assumption that's only true for the project's own live worktree — for every other worktree, branch-time snapshots are guaranteed-stale by construction.

    Suggested constraint for the fix (also feeds #1306/#1297's authoritative-copy design): when resolving project <id> from a root cwd, a worktree copy should only be preferred if that worktree actually BELONGS to project <id> (branch/registry match) — bystander worktrees' copies should never outrank the root copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/porch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions