Skip to content

unify orchestrator v2 execution model under work item terminology - #44

Merged
devzeebo merged 2 commits into
mainfrom
feat/work-item
Jul 4, 2026
Merged

unify orchestrator v2 execution model under work item terminology#44
devzeebo merged 2 commits into
mainfrom
feat/work-item

Conversation

@devzeebo

@devzeebo devzeebo commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

Merge interfaces-task and interfaces-task-source into @bifrost-ai/interfaces-work, replacing the overloaded Task/Script split with a single work item model: dispatched WorkItem instances and registered WorkItemHandlers that receive (workItem, ctx).

Motivation

"Task" meant three different things in orchestrator v2 (orchestrator work unit, runner script, LLM task agent). This refactor unifies the orchestrator work unit and runner executor under work item vocabulary and reserves task for the LLM task agent (kind: "task").

  • Related issue/rune: n/a

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that changes existing behavior)
  • Documentation
  • Refactor / cleanup
  • Test coverage
  • Chore / tooling

Checklist

  • Raw go/npx were not used — everything went through make / npm run
  • make lint passes
  • make test passes
  • make build passes
  • Tests added/updated for new behavior
  • Docs updated where relevant (README / docs)
  • Commit messages are short, lowercase, imperative
  • No force-push to main; rebased on latest main
  • Self-reviewed the diff

Notes for reviewers

Breaking API changes (orchestrator-v2 only):

Before After
Task, TaskSource WorkItem, WorkItemSource
ScriptTaskDefinition, ScriptContext WorkItemHandler, WorkItem + WorkItemExecutionContext
registerAgent(type, handler) registerWorkItemHandler({ kind, name, run })
task.complete / task.fail / task.pause workItem.complete / workItem.fail / workItem.pause
taskSource.setState workItemSource.setState
agentType / agentName / taskId / taskState kind / name / workItemId / state

Validation for this PR was run with vp check and vp test in orchestrator-v2 (40 tests passing).

Made with Cursor

Merge interfaces-task and interfaces-task-source into @bifrost-ai/interfaces-work.
Replace the split Task/Script concepts with WorkItem instances and WorkItemHandlers.
Handlers receive the work item and an execution context separately; RPC methods and
runner registration APIs use the same vocabulary. Reserve "task" for the LLM task
agent (kind: "task").
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@devzeebo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 927ecc75-e622-4d4b-bce4-88ce92fbad4b

📥 Commits

Reviewing files that changed from the base of the PR and between 308bb9a and 9d1d832.

📒 Files selected for processing (10)
  • orchestrator-v2/docs/README.md
  • orchestrator-v2/docs/agent-3-task.md
  • orchestrator-v2/docs/agent-4-workflow.md
  • orchestrator-v2/docs/orchestrator.md
  • orchestrator-v2/docs/runner.md
  • orchestrator-v2/docs/work-items.md
  • orchestrator-v2/packages/orchestrator/src/dispatch-ack-handler.ts
  • orchestrator-v2/packages/runner/README.md
  • orchestrator-v2/packages/runner/src/dispatch-handler.ts
  • orchestrator-v2/packages/runner/src/work-item-execution-context.ts
📝 Walkthrough

Walkthrough

This PR renames the "task/script" execution model to a "work item" model across orchestrator-v2. It replaces interfaces-task/interfaces-task-source with a new interfaces-work package, updates orchestrator, runner, and agent-3-task packages, adjusts build/dependency configs, and revises all related documentation.

Changes

Task → Work Item Rename

Layer / File(s) Summary
Work item contracts
packages/interfaces-work/src/*, packages/interfaces-work/package.json
New WorkItem, WorkItemSource, WorkItemHandler, WorkItemExecutionContext, registries, and validation helpers replace the prior task/script contracts.
Removal of legacy packages
packages/interfaces-task*
interfaces-task and interfaces-task-source packages (types, index, config) are deleted.
Orchestrator dispatch/result/RPC pipeline
packages/orchestrator/src/{types,dispatcher,dispatch-tracker,dispatch-ack-handler,result-handler,rpc-router,orchestrator}.ts, package.json, tsconfig.json
Dispatch tracking, RPC routing, and result handling are rewired from taskId/TaskSource to workItemId/WorkItemSource.
Orchestrator tests
packages/orchestrator/src/{test-helpers,orchestrator.spec}.ts
In-memory source and stub runner behavior, plus spec assertions, updated to work-item lifecycle semantics.
Runner handler registration and execution
packages/runner/src/{runner,dispatch-handler,execute-work-item,work-item-execution-context,index,data-registry,types}.ts
Runner registers WorkItemHandlers, dispatch handler validates/executes work items, and executeScript/script-context.ts are removed in favor of new work-item execution files.
Runner tests
packages/runner/src/runner.spec.ts
Fixtures and assertions rewritten around WorkItemHandler, work item sources, and registerWorkItemHandler.
Agent-3-task and engine context
packages/agent-3-task/src/*, packages/engine/src/{types,test-engine}.ts
createTaskAgent/enrollTaskAgent/runTaskAgent migrated to work-item handler shape; EngineContext fields renamed taskIdworkItemId, taskStatestate.
Build/config wiring
package.json, publish.js, packages/*/tsconfig.json, packages/*/package.json
Dependencies and tsconfig references updated to interfaces-work; publish order adjusted; root devEngines.packageManager pin added.
Documentation
README.md, docs/*.md
README and docs updated to describe work-item terminology, RPC methods, registries, and dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Orchestrator
    participant Dispatcher
    participant Runner
    participant WorkItemSource

    Orchestrator->>Dispatcher: dispatchWorkItem(workItem)
    Dispatcher->>Runner: RPC dispatch(workItem)
    Runner->>Runner: executeWorkItem(handler, workItem, ctx)
    Runner->>Orchestrator: workItem.complete / workItem.fail / workItem.pause
    Runner->>Orchestrator: workItemSource.setState(workItemId, state)
    Orchestrator->>WorkItemSource: completeWorkItem / failWorkItem / pauseWorkItem / setState
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Clearly summarizes the refactor to unify orchestrator v2 around work item terminology.
Description check ✅ Passed The summary and motivation match the changes: merging task interfaces into interfaces-work and renaming APIs to work-item terminology.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 10

🧹 Nitpick comments (2)
orchestrator-v2/packages/runner/src/work-item-execution-context.ts (1)

1-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consolidate duplicate import from the same module.

WorkItem is imported in a separate statement (line 6) right after another import type from the identical module (lines 1-5). Merge into a single import.

♻️ Proposed fix
 import type {
   DataRegistry,
+  WorkItem,
   WorkItemExecutionContext,
   WorkItemHandler,
 } from "`@bifrost-ai/interfaces-work`";
-import type { WorkItem } from "`@bifrost-ai/interfaces-work`";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orchestrator-v2/packages/runner/src/work-item-execution-context.ts` around
lines 1 - 6, The imports in work-item-execution-context are split across two
separate import type statements from the same module, which should be
consolidated. Merge WorkItem into the existing `@bifrost-ai/interfaces-work`
import alongside DataRegistry, WorkItemExecutionContext, and WorkItemHandler so
there is only one type import from that module.
orchestrator-v2/docs/script-tasks.md (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename script-tasks.md to match the work-item terminology

The file content is now entirely about the work-item model, while script-tasks.md still reflects the old naming. Update the links in docs/README.md, docs/agent-3-task.md, docs/agent-4-workflow.md, and docs/runner.md with the rename.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orchestrator-v2/docs/script-tasks.md` at line 1, Rename the documentation
file to use the work-item terminology instead of the old script-task name, and
update every reference to it in docs/README.md, docs/agent-3-task.md,
docs/agent-4-workflow.md, and docs/runner.md. Make sure the links and any
mentions of script-tasks.md now point to the new filename consistently across
the docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@orchestrator-v2/docs/agent-4-workflow.md`:
- Around line 211-213: The Task source reference in the workflow docs points to
a missing page, so update that link to the existing package documentation or
remove the bullet entirely. Fix the markdown in the agent-4-workflow document
near the Task Agent, Script tasks, and Task source list so the Task source entry
targets a valid docs location and no broken link remains.

In `@orchestrator-v2/docs/orchestrator.md`:
- Around line 44-60: The documentation still uses the old task-based names in
the ResultHandler and dispatch-lifecycle sections. Update the orchestrator docs
to rename `task.fail` to `workItem.fail`, `task.pause` to `workItem.pause`, and
`workItemSource.failTask` to `workItemSource.failWorkItem`, keeping the wording
aligned with the existing RPC naming scheme used elsewhere in the repo.
- Line 17: The orchestrator docs still reference the stale WorkItemSource method
name `watchTasks()`. Update the documentation entry that describes streaming
tasks to use the correct symbol `watchWorkItems()` so it matches the actual
`WorkItemSource` API and the README/test-helpers naming consistently.

In `@orchestrator-v2/docs/README.md`:
- Line 22: The architecture diagram node label still mixes old and new task
terminology, so update the Mermaid label in the README to use the same work-item
naming as the RPC methods below. In the diagram entry currently labeled with
completeWorkItem / failTask / pauseTask, rename the latter two parts to
failWorkItem and pauseWorkItem so it matches the workItem.complete / fail /
pause naming and stays consistent with the diagram’s other symbols.
- Around line 68-69: The boundary list in README has duplicate entries for
interfaces-work, so consolidate the two descriptions into a single package row
instead of keeping two lines with the same name. Update the documentation
section that lists package boundaries to reflect one merged interfaces-work
entry covering both the pure types and Task + WorkItemSource contracts, and
remove the redundant duplicate line.
- Around line 78-91: The README still uses stale WorkItem terminology and
duplicates the same package in two status rows. Update the opening description
to reflect WorkItem execution instead of “scripts remotely,” and in the status
table rename the `interfaces-work` entries to match the refactor, using the
appropriate labels for work item types and work item source interface. Keep the
table consistent by removing the old script/task wording wherever it appears.

In `@orchestrator-v2/packages/orchestrator/src/dispatch-ack-handler.ts`:
- Around line 26-45: The handle() method in DispatchAckHandler is ignoring the
promise returned by reject(), which can surface as an unhandled rejection if
failWorkItem() fails. Update the reject call sites in handle() to attach a
.catch(...) handler, or make reject() handle its own failures internally, and
ensure any failure from workItemSource.failWorkItem is safely logged/absorbed
without changing the existing rejection flow.

In `@orchestrator-v2/packages/runner/README.md`:
- Around line 43-53: The registry model table in README still has stale
terminology and needs to match the updated API names. Update the header from
“Script access” to “Handler access”, and change the Agent row’s lookup text to
use the same symbols as the rest of the runner docs:
`kind`/`workItem`/`handlers` instead of `agentType`/`task`/`agents`. Keep the
table aligned with `createRpcWorkItemExecutionContext`,
`registerWorkItemHandler`, and `ctx.handlers.get(...)` so the README reflects
the current naming consistently.
- Around line 78-81: The module map in the runner README lists outdated
filenames, so update the entries for the WorkItemExecutionContext and handler
execution modules to match the current names. Replace the references to
script-context.ts and execute-script.ts with work-item-execution-context.ts and
execute-work-item.ts so the table lines up with the actual files and readers can
locate the right modules.

In `@orchestrator-v2/packages/runner/src/dispatch-handler.ts`:
- Around line 22-25: The fire-and-forget call to handleDispatch in the
peer.subscribe callback can reject and cause an unhandled promise failure.
Update the subscription callback around handleDispatch to explicitly catch
errors from the async path, including rejections coming from executeWorkItem or
rpc.call in the completion/failure/pause flow, and route them to an appropriate
error handler or log instead of letting them escape.

---

Nitpick comments:
In `@orchestrator-v2/docs/script-tasks.md`:
- Line 1: Rename the documentation file to use the work-item terminology instead
of the old script-task name, and update every reference to it in docs/README.md,
docs/agent-3-task.md, docs/agent-4-workflow.md, and docs/runner.md. Make sure
the links and any mentions of script-tasks.md now point to the new filename
consistently across the docs.

In `@orchestrator-v2/packages/runner/src/work-item-execution-context.ts`:
- Around line 1-6: The imports in work-item-execution-context are split across
two separate import type statements from the same module, which should be
consolidated. Merge WorkItem into the existing `@bifrost-ai/interfaces-work`
import alongside DataRegistry, WorkItemExecutionContext, and WorkItemHandler so
there is only one type import from that module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a48c8396-9b93-4eb2-9494-ac0a93580ad3

📥 Commits

Reviewing files that changed from the base of the PR and between 0d9b199 and 308bb9a.

⛔ Files ignored due to path filters (1)
  • orchestrator-v2/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (56)
  • orchestrator-v2/README.md
  • orchestrator-v2/docs/README.md
  • orchestrator-v2/docs/agent-4-workflow.md
  • orchestrator-v2/docs/orchestrator.md
  • orchestrator-v2/docs/protocol.md
  • orchestrator-v2/docs/runner.md
  • orchestrator-v2/docs/script-tasks.md
  • orchestrator-v2/package.json
  • orchestrator-v2/packages/agent-3-task/package.json
  • orchestrator-v2/packages/agent-3-task/src/create-task-agent.ts
  • orchestrator-v2/packages/agent-3-task/src/enroll-task-agent.ts
  • orchestrator-v2/packages/agent-3-task/src/run-task-agent.spec.ts
  • orchestrator-v2/packages/agent-3-task/src/run-task-agent.ts
  • orchestrator-v2/packages/agent-3-task/tsconfig.json
  • orchestrator-v2/packages/engine/src/test-engine.spec.ts
  • orchestrator-v2/packages/engine/src/test-engine.ts
  • orchestrator-v2/packages/engine/src/types.ts
  • orchestrator-v2/packages/interfaces-task-source/README.md
  • orchestrator-v2/packages/interfaces-task-source/src/index.ts
  • orchestrator-v2/packages/interfaces-task-source/src/types.ts
  • orchestrator-v2/packages/interfaces-task/package.json
  • orchestrator-v2/packages/interfaces-task/src/index.ts
  • orchestrator-v2/packages/interfaces-task/src/types.ts
  • orchestrator-v2/packages/interfaces-task/tsconfig.json
  • orchestrator-v2/packages/interfaces-task/vite.config.ts
  • orchestrator-v2/packages/interfaces-work/package.json
  • orchestrator-v2/packages/interfaces-work/src/index.ts
  • orchestrator-v2/packages/interfaces-work/src/types.ts
  • orchestrator-v2/packages/interfaces-work/tsconfig.json
  • orchestrator-v2/packages/interfaces-work/vite.config.ts
  • orchestrator-v2/packages/orchestrator/package.json
  • orchestrator-v2/packages/orchestrator/src/dispatch-ack-handler.ts
  • orchestrator-v2/packages/orchestrator/src/dispatch-tracker.ts
  • orchestrator-v2/packages/orchestrator/src/dispatcher.ts
  • orchestrator-v2/packages/orchestrator/src/orchestrator.spec.ts
  • orchestrator-v2/packages/orchestrator/src/orchestrator.ts
  • orchestrator-v2/packages/orchestrator/src/result-handler.ts
  • orchestrator-v2/packages/orchestrator/src/rpc-router.ts
  • orchestrator-v2/packages/orchestrator/src/test-helpers.ts
  • orchestrator-v2/packages/orchestrator/src/types.ts
  • orchestrator-v2/packages/orchestrator/tsconfig.json
  • orchestrator-v2/packages/runner/README.md
  • orchestrator-v2/packages/runner/package.json
  • orchestrator-v2/packages/runner/src/data-registry.ts
  • orchestrator-v2/packages/runner/src/dispatch-handler.ts
  • orchestrator-v2/packages/runner/src/execute-script.ts
  • orchestrator-v2/packages/runner/src/execute-work-item.ts
  • orchestrator-v2/packages/runner/src/index.ts
  • orchestrator-v2/packages/runner/src/runner.spec.ts
  • orchestrator-v2/packages/runner/src/runner.ts
  • orchestrator-v2/packages/runner/src/script-context.ts
  • orchestrator-v2/packages/runner/src/types.ts
  • orchestrator-v2/packages/runner/src/work-item-execution-context.ts
  • orchestrator-v2/packages/runner/tsconfig.json
  • orchestrator-v2/publish.js
  • orchestrator-v2/tsconfig.json
💤 Files with no reviewable changes (10)
  • orchestrator-v2/packages/interfaces-task-source/README.md
  • orchestrator-v2/packages/interfaces-task/vite.config.ts
  • orchestrator-v2/packages/interfaces-task/src/types.ts
  • orchestrator-v2/packages/interfaces-task/src/index.ts
  • orchestrator-v2/packages/interfaces-task-source/src/index.ts
  • orchestrator-v2/packages/interfaces-task/tsconfig.json
  • orchestrator-v2/packages/runner/src/script-context.ts
  • orchestrator-v2/packages/interfaces-task-source/src/types.ts
  • orchestrator-v2/packages/runner/src/execute-script.ts
  • orchestrator-v2/packages/interfaces-task/package.json

Comment thread orchestrator-v2/docs/agent-4-workflow.md Outdated
Comment thread orchestrator-v2/docs/orchestrator.md Outdated
Comment thread orchestrator-v2/docs/orchestrator.md Outdated
Comment thread orchestrator-v2/docs/README.md Outdated
Comment thread orchestrator-v2/docs/README.md Outdated
Comment thread orchestrator-v2/docs/README.md Outdated
Comment thread orchestrator-v2/packages/orchestrator/src/dispatch-ack-handler.ts Outdated
Comment thread orchestrator-v2/packages/runner/README.md Outdated
Comment thread orchestrator-v2/packages/runner/README.md Outdated
Comment thread orchestrator-v2/packages/runner/src/dispatch-handler.ts
@devzeebo

devzeebo commented Jul 4, 2026

Copy link
Copy Markdown
Owner Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@devzeebo
devzeebo merged commit a411816 into main Jul 4, 2026
1 check passed
matt-wright86 added a commit that referenced this pull request Jul 4, 2026
Rebuilds the agent-3-task Runner augmentation on top of the work-item
unification (#44). registerTaskAgent/registerEngine on Runner.prototype now
target registerWorkItemHandler, and a bare new Runner() lazily creates its
guarded data registry via a new ensure(type, guard) instead of throwing
"Unknown data type".

- ensure(type, guard) on MutableDataRegistry (+ shared ensureRegistry helper)
- ./augment export + a runner dependency on agent-3-task
- regression test for bare-Runner registration

Co-Authored-By: Eric Siebeneich <eric.siebeneich@gmail.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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