Skip to content

FE-743: Petri parallel execution with resource pools and per-slice sandboxes#149

Open
kostandinang wants to merge 3 commits into
ka/fe-738-petri-semantic-lanesfrom
ka/fe-743-petri-parallel-execution
Open

FE-743: Petri parallel execution with resource pools and per-slice sandboxes#149
kostandinang wants to merge 3 commits into
ka/fe-738-petri-semantic-lanesfrom
ka/fe-743-petri-parallel-execution

Conversation

@kostandinang
Copy link
Copy Markdown
Contributor

@kostandinang kostandinang commented May 22, 2026

Summary

  • Adds FiringPolicy (serial | parallel) to the Petri interpreter: parallel mode claims all ready transitions and fires them concurrently with Promise.allSettled, subject to pool limits.
  • Introduces shared agent resource places so test-writer and code-writer transitions contend under a configurable global concurrency cap.
  • Isolates each slice in its own sandbox directory under the run tree, which parallel execution and later epic merge depend on.

Context

  • FE-738 separated mechanical and semantic completion lanes; this PR delivers the main structural advantage of Petri over proc: independent slices can advance concurrently when policy and pools allow.
  • Planning decision gate: parallel policy must demonstrate measurable benefit on a multi-slice fixture relative to serial before the frontier is considered complete.
  • Renaming worktreeDir to sandboxDir clarifies that the path is a per-run filesystem root, not necessarily a git worktree (brownfield worktrees land in FE-755).

What changed

  • FiringPolicy: serial preserves prior single-fire behavior; parallel batches independent ready transitions.
  • RunPolicy.agentPoolSize: caps simultaneous agent-backed transitions via pool:test-agent and pool:code-agent places.
  • Per-slice sandboxes: artifacts live under join(sandboxDir, sliceId) so concurrent slices do not stomp the same tree.
  • CLI: removes dead --engine flag; adds --policy=serial|parallel for explicit policy selection at cook time.

Verification

  • Engine contract scenarios exercised under both policies (41 contract tests in this area).
  • Dedicated tests for pool bounds, concurrent firing behavior, and sandbox isolation between slices.
  • npm run verify green.

Out of scope

  • Merging slice sandboxes for epic-level verify-epic (FE-745).
  • Codebase/brownfield cook on real repos (FE-755).

Traceability

  • Requirements 46–50; SPEC §3, §4; frontier petri-parallel-execution in memory/PLAN.md; umbrella H-6476.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 22, 2026

PR Summary

Medium Risk
Touches core orchestration concurrency, token claiming, and filesystem layout; mistakes could cause races, partial net state, or cross-slice artifact clashes, though contract tests cover both policies.

Overview
This PR completes Petri Phase 2 (FE-743) by making the orchestrator actually run independent slices in parallel instead of only serially.

The interpreter gains a parallel FiringPolicy: each step claims tokens for every enabled transition and fires them with Promise.allSettled, rolling the batch back on handler failure. Agent capacity moves from per-slice places into shared pool:test-agent / pool:code-agent places, capped by new RunPolicy.agentPoolSize (default: one token per slice). Filesystem isolation renames the run root to sandboxDir, creates sandboxDir/<sliceId> for slice actions and tests, and keeps verify-epic on the parent sandbox (with a noted follow-up to merge slice dirs for epic verification).

CLI exposes --policy=serial|parallel (replacing the unused --engine help text in server/cli.ts). Contract tests now run under both policies and add concurrency, pool-bound, wall-clock, and per-slice sandbox assertions. memory/PLAN.md marks petri-parallel-execution done and records open Phase 3 constraints (declarative output arcs, epic sandbox merge).

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

@kostandinang kostandinang changed the title plan: petri-parallel-execution in-progress, FE-743 assigned FE-743: Petri parallel execution — concurrent firing, resource pools, worktree-per-slice May 22, 2026
Comment thread src/orchestrator/src/petri-net.ts Outdated
Comment thread src/orchestrator/src/petri-net.ts Outdated
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 22, 2026

🤖 Augment PR Summary

Summary: This PR completes FE-743 by adding true parallel Petri-net execution, shared agent resource pools, and per-slice worktree isolation to reduce wall-clock time on multi-slice plans.

Changes:

  • Extend FiringPolicy to serial | parallel and implement runParallel() using greedy token claiming + Promise.allSettled.
  • Add shared pool:test-agent/pool:code-agent places and RunPolicy.agentPoolSize to cap global agent concurrency.
  • Route action contexts and test runs through join(worktreeDir, sliceId) to isolate slice execution directories.
  • Update brunch cook CLI: retire --engine, add --policy=serial|parallel, default to serial.
  • Expand contract tests to cover both policies and add explicit concurrency/pool/worktree isolation checks.
  • Update memory/PLAN.md to mark petri-parallel-execution done and adjust sequencing.

Technical Notes: Parallel execution aims for serial parity while allowing bounded concurrency via shared pool tokens.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/orchestrator/src/net-compiler.ts Outdated
Comment thread src/orchestrator/src/engine-contract.test.ts Outdated
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from 6ff7563 to d4e9d95 Compare May 22, 2026 13:32
Comment thread src/orchestrator/src/net-compiler.ts
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from d4e9d95 to d43222e Compare May 22, 2026 13:57
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from 8e56a7c to f959557 Compare May 22, 2026 14:14
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from d43222e to 55945f9 Compare May 22, 2026 14:14
Comment thread src/orchestrator/src/net-compiler.ts
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch 3 times, most recently from 13953ca to 386c3cf Compare May 22, 2026 14:31
Comment thread src/orchestrator/src/net-compiler.ts
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from 386c3cf to 0f5cdbf Compare May 22, 2026 14:59
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from f959557 to 1747538 Compare May 22, 2026 14:59
Comment thread src/orchestrator/src/net-compiler.ts
Comment thread src/orchestrator/src/petri-net.ts
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from da2bb0d to 6c4fd65 Compare May 25, 2026 11:02
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch 2 times, most recently from 2f0aba4 to f1ff792 Compare May 25, 2026 11:05
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from 6c4fd65 to c51fdb7 Compare May 25, 2026 11:05
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from f1ff792 to 33a84c1 Compare May 25, 2026 11:17
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from c51fdb7 to e76b68a Compare May 25, 2026 11:17
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from e76b68a to 745c45a Compare May 25, 2026 11:23
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from 33a84c1 to 71a21e2 Compare May 25, 2026 11:23
@kostandinang kostandinang requested a review from lunelson May 26, 2026 07:52
@kostandinang kostandinang self-assigned this May 26, 2026
@kostandinang kostandinang changed the title FE-743: Petri parallel execution — concurrent firing, resource pools, worktree-per-slice FE-743: Petri parallel execution with resource pools and per-slice sandboxes May 27, 2026
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from 745c45a to 78b15a6 Compare May 27, 2026 23:16
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from 71a21e2 to 6f78604 Compare May 27, 2026 23:16
kostandinang and others added 3 commits May 28, 2026 01:20
Parallel firing policy (petri-net.ts):
- FiringPolicy = 'serial' | 'parallel'
- runParallel: greedy token claiming + Promise.allSettled concurrent fire
- Extracted isEnabled() private helper

Shared resource pools (net-compiler.ts):
- pool:test-agent / pool:code-agent replace per-slice agent places
- agentPoolSize on RunPolicy bounds global concurrency
- Worktree-per-slice: join(worktreeDir, sliceId) for all action contexts

CLI (cook-cli.ts):
- Retired dead --engine=proc|petri flag
- Added --policy=serial|parallel wired to createOrchestrator

Tests (engine-contract.test.ts):
- Parallel added to all engines arrays (serial parity)
- Concurrency proof, wall-clock benchmark, pool-bounded tests
- Extracted withConcurrencyTracking() helper
- Worktree isolation adapter test

Decision gate passed: parallel measurably beats serial on wall clock.

Co-authored-by: Amp <amp@ampcode.com>
Deposit fulfilled transition outputs even when a sibling sets ctx.halted in the same batch, matching serial commit semantics while still rolling back on handler rejection.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kostandinang kostandinang force-pushed the ka/fe-738-petri-semantic-lanes branch from 78b15a6 to 78706a2 Compare May 27, 2026 23:21
@kostandinang kostandinang force-pushed the ka/fe-743-petri-parallel-execution branch from 6f78604 to 421f18b Compare May 27, 2026 23:21
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 421f18b. Configure here.

return placeId;
}

type TransitionClaim = { transition: TransitionDef; consumed: Token[] };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale benign-residual entries mask removed per-slice places

Low Severity

BENIGN_RESIDUAL_PLACES still contains 'test-agent' and 'code-agent', but this PR removed per-slice agent places (e.g. slice:X:test-agent) and replaced them with shared pool:test-agent / pool:code-agent places. Pool places are already excluded by the startsWith('pool:') check in hasWorkBearingTokens, so the set entries are now dead code that can never match any place in the compiled net. Keeping them is confusing for anyone reading the deadlock-detection logic, as it implies per-slice agent places still exist.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 421f18b. Configure here.

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.

1 participant