Skip to content

FE-743: Petri parallel execution — concurrent firing, resource pools, worktree-per-slice#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 — concurrent firing, resource pools, worktree-per-slice#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

TL;DR. Phase 2 of the Petri orchestrator arc: parallel firing policy with greedy token claiming, shared resource-pool tokens that cap global concurrency, and per-slice worktrees. Decision gate passed — parallel measurably beats serial on multi-slice plans.

What changed

Interpreter (petri-net.ts)

  • FiringPolicy = 'serial' | 'parallel'.
  • runParallel() — greedy token claiming in registration order + Promise.allSettled concurrent fire.
  • Extracted isEnabled() helper (was inlined 3×); removed unused hasTokens().

Compiler (net-compiler.ts)

  • Shared pool:test-agent / pool:code-agent places replace per-slice agent places.
  • agentPoolSize on RunPolicy caps global concurrency (default = slice count = unbounded).
  • Per-slice sandbox dirs via join(sandboxDir, sliceId) for all action contexts.

CLI (cook-cli.ts)

  • Retired dead --engine=proc|petri flag (proc engine deleted in FE-730).
  • Added --policy=serial|parallel wired to createOrchestrator().

Naming

  • Renamed worktreeDirsandboxDir across orchestrator files — disambiguates from git worktrees.

Why now

Parallelism is the primary value claim for Petri over proc. Without it, both engines are serial and proc wins on simplicity. Decision gate: if parallel didn't beat proc on wall clock for a representative multi-slice fixture, the substrate commitment would have paused. It does.

Verification

  • All 41 contract tests pass under both serial and parallel.
  • Concurrency proof — maxConcurrent > 1 under parallel.
  • Wall-clock benchmark — parallel < 85% of serial time.
  • Pool-bound tests — agentPoolSize=1 → 1; =2 → 2; default → 3.
  • Per-slice sandbox isolation adapter test.
  • npm run verify clean.

Traceability

Requirements 46–50; spec §3 (token taxonomy — resource tokens), §4 (canonical slice-net terminal join). Frontier petri-parallel-execution in memory/PLAN.md. Under umbrella H-6476.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 22, 2026

PR Summary

Medium Risk
Changes core orchestrator concurrency and token-pool semantics; risk is mitigated by broad dual-policy contract tests but parallel batch rollback and epic verify sandbox scope remain subtle execution edges.

Overview
Phase 2 (FE-743) delivers parallel Petri execution so independent plan slices can advance concurrently, with shared agent pools and per-slice sandboxes—the decision gate (parallel faster than serial on multi-slice plans) is recorded as passed in memory/PLAN.md.

The interpreter adds FiringPolicy parallel: each step greedily claims tokens for all enabled transitions, runs fires with Promise.allSettled, commits successes, and rolls back the whole batch on handler failure. Serial behavior is unchanged aside from shared claim/deposit helpers.

The compiler moves test-agent / code-agent capacity into global pool:* places (replacing per-slice agent places), with agentPoolSize on RunPolicy capping concurrent agent work (default = slice count). Handlers get sandboxDir per slice (<run>/<sliceId>) with path-escape checks; verify-epic still uses the parent run sandbox (noted TODO for epic-scoped merge).

CLI: brunch cook accepts --policy=serial|parallel (replacing the removed --engine flag); worktreeDir is renamed sandboxDir across the orchestrator. Contract tests now run under both policies, plus concurrency, pool-bound, wall-clock, and sandbox-isolation coverage.

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

Copy link
Copy Markdown
Contributor Author

kostandinang commented May 22, 2026

@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
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 9e6a0e8. Configure here.

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 and others added 3 commits May 25, 2026 13:23
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>
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