Skip to content

fix(H-1): auto-serialize parallel pkg-manager/file-edit steps via inferred resource locks#122

Merged
huberp merged 3 commits into
mainfrom
copilot/fix-package-json-concurrent-mutates
Apr 25, 2026
Merged

fix(H-1): auto-serialize parallel pkg-manager/file-edit steps via inferred resource locks#122
huberp merged 3 commits into
mainfrom
copilot/fix-package-json-concurrent-mutates

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

The scheduler's file-write exclusion mechanism was silently bypassed whenever the planner LLM omitted resources hints — allowing npm install and file-edit package.json to run concurrently and produce an inconsistent manifest/lockfile state.

Changes

src/langgraph/graph.ts — Planner hard constraints

  • Added two explicit rules to BLOCKS_PLANNER_SYSTEM: package-manager commands (npm install, yarn, pnpm, pip install, cargo build, go get, bundle) must declare resources: ["file:WRITE:<manifest>"] and must not be placed in the same parallel block as steps that edit that manifest; file-edit/file-write steps must declare their write targets.

src/langgraph/compiler.ts — Structural safety net

  • inferMissingResources() (exported): detects pkg-manager invocations in description and file-edit/file-write tool use mentioning a known manifest, then produces the missing file:write:<manifest> lock strings.
  • compileBlocksPlanToDag(): merges inferred resources into every compiled step node so the scheduler enforces serialisation regardless of what the planner emitted.
  • detectPkgManifestConflicts() (exported): post-plan scan that identifies parallel branch pairs with a pkg-manager step vs. a file-edit step sharing a manifest without a declared lock; called from planNode to emit a structured warn.

Inference example (H-1 scenario)

// Planner emits these two branches in parallel with no resources declared:
// branch "install":   { description: "npm install @anthropic-ai/sdk@latest", toolsNeeded: [] }
// branch "edit":      { description: "Edit package.json to add ...", toolsNeeded: ["file-edit"] }

// compileBlocksPlanToDag() now auto-adds to both nodes:
//   resources: ["file:write:package.json"]
// → scheduler serialises them via the existing write-exclusion logic

Tests

19 new unit tests covering inferMissingResources (all supported package managers, file-edit+manifest, no-op cases), the H-1 scheduler serialisation scenario end-to-end, and detectPkgManifestConflicts (conflict, sequential, unrelated branches).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • duckduckgo.com
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/agentloop/agentloop/node_modules/jest-worker/build/processChild.js (dns block)
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/agentloop/agentloop/node_modules/jest-worker/build/processChild.js tnet/tools/git git bran�� -v -d &#39;,&#39;x&#39;)}catch(e){} --local user.email /snap/bin/git git s__/�� (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits April 25, 2026 19:05
…ce locks

- Fix 1: Update BLOCKS_PLANNER_SYSTEM with hard constraint that package-manager
  steps (npm install, yarn, pnpm, pip, cargo, go get, etc.) must declare
  file:WRITE:<manifest> resources and must never be parallelised with steps
  that edit the same manifest file. Also requires file-edit/file-write steps
  to declare their file:WRITE resources explicitly.

- Fix 2: Add inferMissingResources() in compiler.ts that auto-infers
  file:write:<manifest> resource locks from step descriptions (matching
  package-manager patterns) and from toolsNeeded (file-edit/file-write tool
  + manifest file name in description). compileBlocksPlanToDag() now merges
  inferred resources into every step node so the scheduler enforces serialisation
  even when the planner omits the resource hints.

- Fix 3: Export detectPkgManifestConflicts() from compiler.ts for post-plan
  validation. planNode in graph.ts calls it after parsePlanOutput and logs a
  structured warning when a parallel branch pair contains a pkg-manager step
  and a file-edit step without proper serialisation.

- 19 new unit tests covering inferMissingResources, compiler inference
  integration, scheduler serialisation of the H-1 scenario, and
  detectPkgManifestConflicts.

Agent-Logs-Url: https://github.com/huberp/agentloop/sessions/9a3f05ac-a1f7-4956-a137-7c0bae9b4d4f

Co-authored-by: huberp <4027454+huberp@users.noreply.github.com>
…malisation comment

Agent-Logs-Url: https://github.com/huberp/agentloop/sessions/9a3f05ac-a1f7-4956-a137-7c0bae9b4d4f

Co-authored-by: huberp <4027454+huberp@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix concurrent mutations of package.json in parallel branches fix(H-1): auto-serialize parallel pkg-manager/file-edit steps via inferred resource locks Apr 25, 2026
Copilot AI requested a review from huberp April 25, 2026 19:08
@huberp huberp marked this pull request as ready for review April 25, 2026 19:17
@huberp huberp merged commit 846b6bf into main Apr 25, 2026
@huberp huberp deleted the copilot/fix-package-json-concurrent-mutates branch April 25, 2026 19:18
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.

H-1 · Parallel Branches s4 + s5 Both Mutate package.json Concurrently Without Resource Locks

2 participants