Skip to content

FE-1166: Add executor run policy#302

Merged
kostandinang merged 9 commits into
nextfrom
ka/fe-1166-greenfield-executor-harness
Jul 8, 2026
Merged

FE-1166: Add executor run policy#302
kostandinang merged 9 commits into
nextfrom
ka/fe-1166-greenfield-executor-harness

Conversation

@kostandinang

@kostandinang kostandinang commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Why

Greenfield executor runs must not inherit the host repo, host package.json, or host git history by default.

This PR also fixes the failure mode caught by run-mrbs97w9: an empty_dir worktree nested under Brunch could still let npm test walk up to the host package and promotion/preflight resolve against the host git root.

What

  • Adds substrate: "empty_dir" for isolated greenfield run directories.
  • Adds bounded verifyProfile support, currently including npm_test.
  • Preserves run environment policy across superseding replan runs.
  • Initializes empty_dir worktrees as isolated git repos with an empty base commit.
  • Runs npm verification with npm --prefix <worktreeDir> ....
  • Makes run-local promotion and host-promotion preflight/apply fail closed unless the git root is exactly the run worktree.
  • Uses an explicit git identity for run-local promotion commits.

How To Test

  • npx vitest run src/executor/__tests__/worktree.test.ts src/app/__tests__/test-runner-port.test.ts src/app/__tests__/git-land-port.test.ts src/app/__tests__/git-host-promotion-port.test.ts src/executor/__tests__/promotion.test.ts src/executor/__tests__/host-promotion.test.ts src/executor/__tests__/orchestrate.test.ts src/.pi/extensions/__tests__/registry.test.ts
  • npm test

TUI smoke path:

  • Reach execute_launch: ready.
  • Run execute_run_create { runId: "run-empty-1", substrate: "empty_dir", verifyProfile: "npm_test" }.
  • Run execute_orchestrate { runId: "run-empty-1" }.
  • Expect worktree creation to use an isolated empty-dir git repo, not git_worktree_add against the host.
  • Expect verify stream to say npm test started, but execute via npm --prefix <run worktree> test.
  • Expect promotion/preflight to fail closed if git resolves to the host repo instead of the run worktree.

kostandinang commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@kostandinang kostandinang marked this pull request as ready for review July 7, 2026 18:50
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes executor worktree creation, verify invocation, and promotion/preflight git checks—areas where mistakes could touch the host repo or run wrong tests; defaults preserve brownfield behavior and tests assert fail-closed isolation.

Overview
Greenfield executor runs can now declare run environment policy separately from source-copy: substrate: "empty_dir" plus optional verifyProfile (e.g. npm_test) are persisted in run.json via execute_run_create, forwarded through superseding replan runs, and documented for Execute-mode agents.

Worktree creation branches on substrate: default git_worktree is unchanged; empty_dir skips GitWorktreePort, clears/repairs stale paths, and initializes an isolated git repo with an empty base commit so promotion still has a local history without checking out Brunch.

Verification reads verifyTarget from run metadata into ingestTestResult; createTestRunnerPort honors run overrides and runs npm with --prefix <worktreeDir> so nested worktrees cannot walk up to the host package.json.

Safety on git boundaries: createGitLandPort and createGitHostPromotionPort require the worktree’s git root to canonical-match the run directory (fail closed if resolution points at the host); run-local commits use an explicit brunch git identity. Topology, PLAN, and a scoped card capture the frontier; focused tests cover substrate, verify, and isolation. The web runs UI drops replan metadata rows (supersedes / abandon reason) from list and detail.

Reviewed by Cursor Bugbot for commit e300f58. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/executor/worktree.ts
@kostandinang kostandinang changed the base branch from ka/fe-1114-executor-replanning to graphite-base/302 July 7, 2026 21:01
@kostandinang kostandinang requested a review from lunelson July 8, 2026 07:41
Comment thread src/executor/worktree.ts
@kostandinang kostandinang changed the title FE-1166: Add executor run environment policy FE-1166: Add executor run policy Jul 8, 2026
@kostandinang kostandinang force-pushed the ka/fe-1166-greenfield-executor-harness branch from e10205f to 86756d7 Compare July 8, 2026 08:22
@kostandinang kostandinang changed the base branch from graphite-base/302 to ka/fe-1114-executor-replanning July 8, 2026 08:22
Comment thread src/executor/worktree.ts
@kostandinang kostandinang force-pushed the ka/fe-1166-greenfield-executor-harness branch 2 times, most recently from f76437d to f87bfcc Compare July 8, 2026 09:47
Comment thread src/executor/worktree.ts
Comment thread src/executor/worktree.ts
@kostandinang kostandinang force-pushed the ka/fe-1166-greenfield-executor-harness branch from f87bfcc to 047123f Compare July 8, 2026 10:05
Comment thread src/executor/worktree.ts
@kostandinang kostandinang changed the base branch from ka/fe-1114-executor-replanning to graphite-base/302 July 8, 2026 10:38
@kostandinang kostandinang changed the base branch from graphite-base/302 to ka/fe-1114-executor-replanning July 8, 2026 11:15

@lunelson lunelson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the right direction for isolating greenfield runs, and I like that the default path remains compatible.

One boundary concern before this lands: src/executor/worktree.ts now shells out to git init / git commit directly for the empty_dir substrate, while src/executor/TOPOLOGY.md still says executor core does not own subprocess/git effects and that real capabilities enter through app-layer ports. That changes the executor/app port boundary in a way future slices will likely copy.

Can we either move this run-local git initialization behind an injected port, or update the topology/decision to explicitly name this as the allowed exception and why it is not part of the app-layer git capability surface?

Comment thread src/web/routes/runs.tsx
@kostandinang

Copy link
Copy Markdown
Contributor Author

Fixed: removed the web run-policy/replanning metadata from the FE-1166 sidecar surface. Focused run route tests pass.

@kostandinang kostandinang requested a review from lunelson July 8, 2026 12:11
Base automatically changed from ka/fe-1114-executor-replanning to next July 8, 2026 13:27
@kostandinang kostandinang force-pushed the ka/fe-1166-greenfield-executor-harness branch from f689244 to e300f58 Compare July 8, 2026 13:28
@graphite-app

graphite-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

Merge activity

  • Jul 8, 1:28 PM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e300f58. Configure here.

Comment thread src/executor/worktree.ts
metadataPath,
sideEffects: [],
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty dir idempotency stalls orchestration

Medium Severity

For substrate: "empty_dir", when run.json still has status: "created" but already records a valid isolated worktreeDir, createWorktree returns already_created without advancing metadata to worktree_created. drive() treats unchanged runStatus as a halt on worktree_create, so re-orchestration after resetting only status (while keeping worktreeDir) wedges the run.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e300f58. Configure here.

@kostandinang kostandinang merged commit c4e0783 into next Jul 8, 2026
6 checks passed
@kostandinang kostandinang deleted the ka/fe-1166-greenfield-executor-harness branch July 8, 2026 13:45
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