Skip to content

fix(vm): preserve nested sessions in parallel block invocations (#17) - #178

Open
Adityakk9031 wants to merge 1 commit into
openprose:mainfrom
Adityakk9031:fix/parallel-block-sessions-17
Open

fix(vm): preserve nested sessions in parallel block invocations (#17)#178
Adityakk9031 wants to merge 1 commit into
openprose:mainfrom
Adityakk9031:fix/parallel-block-sessions-17

Conversation

@Adityakk9031

Copy link
Copy Markdown

Summary

Addresses #17 by specifying and standardizing execution semantics for block invocations inside parallel contexts (parallel: or parallel for).

Context & Root Cause

When executing a named block containing sequential session: or call: statements (such as appending start and completion markers to an event ledger before and after work steps) inside a parallel: block or parallel for loop:

block process-item(item_id):
  session: ledger
    prompt: "Append 'phase-1-started' for {item_id}"
  let step1_result = session "Do step 1"
    prompt: "Process step 1 for {item_id}"
  session: ledger
    prompt: "Append 'phase-1-completed' for {item_id}"

Previous VM specifications did not define execution semantics for parallel block invocations. As observed by @MattKotsenas in #17, executing agents and VMs collapsed the block into a single natural-language directive for a subagent (e.g. "process item X through all phases"). This caused:

  1. Collapsed nested sessions: The subagent executed everything in a single turn without dispatching discrete session: or call: child sessions.
  2. Batched state / lost temporal ordering: Ledger appends and intermediate state updates were deferred and written simultaneously at the end with identical timestamps, eliminating observable phase duration and progress.
  3. Unspecified branch isolation: Lack of an explicit convention for scoped execution frames during concurrent block runs.

Key Changes

  1. VM Execution Specification (skills/open-prose/prose.md):
    • Added ### Block Invocation in Parallel Contexts under ### Parallel Execution.
    • Statement-by-statement execution: Mandates sequential statement evaluation for each parallel branch.
    • Session boundary preservation: Strictly forbids collapsing block statements into a single natural-language summary prompt; every session: / call: statement must be spawned as an independent, discrete session with its own prompt and completion barrier.
    • Sub-VM delegation protocol: When parallel branches are delegated to subagents, the coordinator must pass the unsummarized block body and instruct the worker to act as an OpenProse sub-VM executing statements sequentially.
    • Contemporaneous updates: Intermediate state, event ledger appends, and receipt updates must occur contemporaneously when each statement completes, guaranteeing accurate temporal ordering and distinct timestamps.
    • Scoped execution frames: Iterations execute within isolated execution scopes (workspace/{node}/__scope/{execution_id}/).
    • Cross-referenced from #### 4d. Parallel Execution.
  2. Language Reference (skills/open-prose/prosescript.md):
    • Added ### Parallel Block Invocations under ## Parallel Blocks, defining invariants: no statement collapsing, discrete nested sessions, contemporaneous updates, and isolated scope.
    • Updated ## Blocks And 'do' to emphasize that parallel block invocation preserves statement sequences and nested session boundaries.
  3. Authoring Guidance (skills/open-prose/guidance/authoring.md):
    • Added explicit anti-patterns under ## Anti-Patterns:
      • Collapsing block invocations in parallel contexts into a single natural-language subagent task instead of preserving discrete statement-by-statement session execution and scoped checkpoints.
      • Batching intermediate ledger writes or state updates at the end of a parallel block branch instead of committing them contemporaneously after each statement completes.
  4. State & Filesystem Specification (skills/open-prose/state/filesystem.md):
    • Added workspace/{node}/__scope/{execution_id}/* to the canonical directory artifacts table.
    • Documented ## Scoped Execution Frames with per-branch isolation, scratch isolation, and contemporaneous progress progression.
  5. Conformance Tests (tests/open-prose/primitives/parallel-blocks.test.ts):
    • Added 17 automated Vitest tests validating specification sections, invariants, anti-pattern documentation, filesystem layout, and a behavioral simulation demonstrating advancing timestamps and discrete sessions under compliant VM execution vs. identical timestamps in the collapsed anti-pattern.

Verification

  • pnpm vitest run tests/open-prose/primitives/parallel-blocks.test.ts (17/17 passed)
  • pnpm vitest run tests/open-prose/primitives/ (29/29 passed)
  • pnpm vitest run tests/open-prose/state/ tests/open-prose/forme/ tests/open-prose/compiler/ tests/open-prose/concepts/ tests/open-prose/skill-meta/ tests/open-prose/tenets/ (127/127 passed)

Closes #17

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.

Block invocation in parallel contexts appears to break nested sessions

1 participant