Skip to content

feat(sdk): add durable child-flow dispatch - #588

Merged
khaliqgant merged 4 commits into
mainfrom
feat/child-flow-dispatch
Sep 29, 2026
Merged

khaliqgant merged 4 commits into
mainfrom
feat/child-flow-dispatch

Conversation

@miyaontherelay

@miyaontherelay miyaontherelay commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add durable f.dispatch(name, input) for direct static use children
  • keep descendants in one run tree with qualified step identities, shared root budget/worker capacity, bounded depth, cycle/name checks, and capability attenuation
  • mirror child journals plus authored labels/dependencies so Cloud can render the complete connected DAG live and after completion
  • document the deliberately narrower authored-child contract and its remaining public Flow Tool gaps

Verification

$ cd packages/sdk
$ npm run build && npm run typecheck:tests && RELAYFLOWD_BIN=/Users/khaliqgant/Projects/AgentWorkforce/flows/kernel/target/debug/relayflowd node node_modules/vitest/vitest.mjs run tests/authored-use-loader.test.ts tests/authored-flow.test.ts tests/authored-dispatch-live.test.ts tests/cloud-mirror-live.test.ts

Test Files  4 passed (4)
Tests       46 passed (46)
$ npm run build --prefix packages/surface
> @relayflows/surface@2.0.33 build
> tsc -p tsconfig.json
$ git diff --check
# no output

Safety boundaries

  • dispatch targets must be direct use children and names must be unambiguous
  • depth is capped at three and load-time use cycles are rejected
  • child provider/MCP capabilities may not exceed the parent's declarations
  • descendants share the root budget and worker pool; child-local budgets are refused until budget intersection exists
  • child human approvals are refused so approval authority stays with the root

Cloud follow-up

The corresponding Cloud schema/storage/graph/UI change is prepared separately. It will pin the released Flows package after this PR is merged and published.


Note

Medium Risk
Nested execution touches budgeting, worker admission, journal DAG edges, and Cloud mirror projection; mistakes could affect replay, concurrency, or dashboard graphs, though guards and live tests target those paths.

Overview
Adds durable f.dispatch(name, input) for children declared in a flow’s static use header, replacing the previous unsupported_verb stub.

Child runs stay in one journal-backed run tree: qualified step ids (dispatch-2--run-1), shared root budget and worker capacity (scoped slots), depth cap of 3, load-time cycle / duplicate-path / ambiguous name checks, and capability attenuation (MCP/helpers; no child budgets or f.human). Successful dispatch returns a journaled DispatchResult; non-success child verdicts fail the parent step.

Cloud mirror folds parent and child journals into one connected DAG (labels/depends_on), hides internal complete-N receipts, and onRunReceipt covers fast runs that finish before watched journal events. Docs and RFC text are updated to describe this narrower authored composition vs future public Flow Tools.

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

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a3a1fd4b-294d-43af-a783-910514a19e44

📥 Commits

Reviewing files that changed from the base of the PR and between f79a8ab and 6eff9d7.

📒 Files selected for processing (8)
  • packages/sdk/src/authored-dispatch.ts
  • packages/sdk/src/authored-flow-executor.ts
  • packages/sdk/src/cli.ts
  • packages/sdk/src/cli/run.ts
  • packages/sdk/tests/authored-dispatch-live.test.ts
  • packages/sdk/tests/authored-flow.test.ts
  • packages/sdk/tests/authored-node-runtime.test.ts
  • packages/sdk/tests/cli.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8b90fedd-bf43-413c-83bc-2e970cc29524

📥 Commits

Reviewing files that changed from the base of the PR and between 86967b0 and f79a8ab.

📒 Files selected for processing (22)
  • docs/CLOUD.md
  • docs/EVENT-AWAIT.md
  • docs/RFC-0002-callable-flow-tools.md
  • docs/SURFACE.md
  • packages/sdk/src/authored-dispatch.ts
  • packages/sdk/src/authored-flow-error.ts
  • packages/sdk/src/authored-flow-executor.ts
  • packages/sdk/src/authored-flow-loader.ts
  • packages/sdk/src/authored-node-entry.ts
  • packages/sdk/src/authored-root.ts
  • packages/sdk/src/authored-worker-step.ts
  • packages/sdk/src/cli/run.ts
  • packages/sdk/src/cloud-mirror-step.ts
  • packages/sdk/src/cloud-mirror.ts
  • packages/sdk/src/worker-slots.ts
  • packages/sdk/tests/authored-dispatch-live.test.ts
  • packages/sdk/tests/authored-flow.test.ts
  • packages/sdk/tests/authored-use-loader.test.ts
  • packages/sdk/tests/cloud-mirror-live.test.ts
  • packages/sdk/tests/worker-slots.test.ts
  • packages/surface/src/context.ts
  • packages/surface/src/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Authored flows can now dispatch direct children declared with use. The executor validates child declarations, shares root execution resources, and records successful dispatch receipts. Cloud mirroring presents composed runs as connected graphs and omits internal completion receipts from displayed work nodes.

Changes

Authored Child-Flow Dispatch

Layer / File(s) Summary
Dispatch contract and graph validation
packages/surface/src/context.ts, packages/surface/src/index.ts, packages/sdk/src/authored-flow-error.ts, packages/sdk/src/authored-flow-loader.ts, packages/sdk/src/authored-dispatch.ts, packages/sdk/tests/authored-use-loader.test.ts, packages/sdk/tests/authored-flow.test.ts
Ctx.dispatch returns a success receipt as a journal-backed step. The loader rejects duplicate direct child names. The resolver checks child names, depth, budgets, and capabilities. Tests cover these checks and dispatch error codes.
Durable child execution and shared resources
packages/sdk/src/authored-flow-executor.ts, packages/sdk/src/worker-slots.ts, packages/sdk/src/authored-worker-step.ts, packages/sdk/src/authored-node-entry.ts, packages/sdk/src/authored-root.ts, packages/sdk/src/cli/run.ts, packages/sdk/tests/authored-dispatch-live.test.ts, packages/sdk/tests/authored-flow.test.ts, packages/sdk/tests/worker-slots.test.ts, docs/EVENT-AWAIT.md, docs/RFC-0002-callable-flow-tools.md, docs/SURFACE.md
The executor runs dispatched children with prefixed operation IDs, inherited dependencies, shared budgets, and shared worker capacity. Child flows cannot call f.human. Tests cover nested execution, gates, hooks, resource scopes, and resume. Documentation describes the dispatch contract and current limits.
Composed run mirroring
packages/sdk/src/cloud-mirror-step.ts, packages/sdk/src/cloud-mirror.ts, packages/sdk/tests/cloud-mirror-live.test.ts, docs/CLOUD.md
The mirror tracks authored completion receipts as hidden steps and excludes them from live and final step data. The end-to-end test checks the composed run’s step names and dependency graph.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ParentFlow
  participant AuthoredFlowExecutor
  participant LoadedFlowGraph
  participant ChildJournal
  ParentFlow->>AuthoredFlowExecutor: Dispatch declared child with input
  AuthoredFlowExecutor->>LoadedFlowGraph: Resolve direct child name
  LoadedFlowGraph-->>AuthoredFlowExecutor: Return child definition
  AuthoredFlowExecutor->>ChildJournal: Record child operations and receipt
  ChildJournal-->>AuthoredFlowExecutor: Return completion data
  AuthoredFlowExecutor-->>ParentFlow: Return dispatch receipt
Loading

Merge Risk: ⚪ Minimal · up to f79a8

This change adds durable child-flow dispatch with depth, capability, and budget checks, plus connected Cloud graph mirroring. No specific merge-blocking issue was identified. Normal pre-merge checks apply.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to f79a8

Dispatch is limited to declared children and shares the parent’s execution limits, but the promised limit on child integration capabilities is not fully enforced at the helper call. The effect depends on which integrations are mounted and which child flows are invoked.

Retained concerns

  • Medium · security · inferred: A dispatched child can reach a mounted helper provider without either flow declaring that provider, so declaration-level child attenuation does not establish effective helper authority.
Security review details

Security Blast Radius

  • inferred — Effective exposure is bounded to statically loaded children and integrations available in the executing environment, but a child’s helper effect can use the process’s mounted provider authority despite absent parent and child tool declarations.

Security Findings and Attack Paths

  • inferred — If an invoked child uses a helper and the provider is mounted, the new dispatch path can perform that integration effect without a corresponding declared grant. The helper sink’s lack of a declaration check predates this PR; the new reachability is the change under assessment, not a verified remote exploit.

Trust Boundaries and Controls

  • observed — Direct-child selection, depth, declared capability comparison, child-budget refusal, checked MCP inventory, and refusal of child human approval constrain the new path. They do not establish tenant identity or effective helper authority at every downstream sink.

Resilience and Maintainability Implications

  • inferred — Stable admission identities and durable admitted-state records support retry inspection, but the inspected path does not establish who cancels or reconciles an already admitted descendant after parent interruption or process death. This remains a lifecycle proof gap, not a demonstrated orphaned run.

Hardening Proposals

  • proposed — Enforce the effective parent-and-child helper grant at invocation or the provider sink, rather than relying on declared-tool comparison and provider credential checks separately.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 18 files. (4 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: durable child-flow dispatch in the SDK.
Description check ✅ Passed The description directly explains durable child-flow dispatch, its safeguards, Cloud mirroring, documentation updates, and verification results.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 18 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

I’m a rabbit with a journal to chart,
I hop through a child flow’s start.
A receipt marks success on the way,
Shared roots keep the steps in play.
Hidden markers stay out of the show,
While connected DAG branches grow.

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

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Pull request base or head changed.

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.

@cursor cursor Bot left a comment •

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 Bugbot comment from a previous run.

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
✅ 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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 using high effort 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 f79a8ab. Configure here.

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

Verification at head 6eff9d7:

Command:
cd packages/sdk
npm run build && npm run typecheck:tests && RELAYFLOWD_BIN=/Users/khaliqgant/Projects/AgentWorkforce/flows/kernel/target/debug/relayflowd node node_modules/vitest/vitest.mjs run tests/authored-flow.test.ts tests/authored-dispatch-live.test.ts tests/worker-slots.test.ts tests/cloud-mirror-live.test.ts tests/observer-link.test.ts tests/cli.test.ts && git diff --check

Captured output:
Test Files 6 passed (6)
Tests 165 passed (165)

The standalone Bun 1.4.0 boundary was also rerun after the CI-reported stale test was updated:

Command:
FLOWS_BUILD_BUN=/Users/khaliqgant/.local/share/mise/installs/bun/1.4.0/bin/bun RELAYFLOWD_BIN=/Users/khaliqgant/Projects/AgentWorkforce/flows/kernel/target/debug/relayflowd node node_modules/vitest/vitest.mjs run tests/authored-node-runtime.test.ts

Captured output:
Test Files 1 passed (1)
Tests 14 passed (14)

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

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.

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

Ready for authorized human merge at exact head 6eff9d7. All repository checks are green (Linux artifact included), Cursor Bugbot is green, and all five review threads are resolved. Per AGENTS.md, an agent may not merge this PR; @khaliqgant please review and merge so the coordinated release, Cloud dependency pin, runtime artifact rollout, and production dashboard proof can continue.

@miyaontherelay

Copy link
Copy Markdown
Contributor Author

Follow-on authoring guidance is ready in AgentWorkforce/relay#1867 and explicitly depends on this PR. All checks at this exact head are green and all review threads are resolved. Per this repository's constitution I cannot perform the merge; once a human merges #588, I can publish the coordinated package release and continue the Cloud dependency/runtime pin rollout.

@khaliqgant
khaliqgant merged commit 73e4634 into main Sep 29, 2026
9 checks passed
@khaliqgant
khaliqgant deleted the feat/child-flow-dispatch branch September 29, 2026 16:50
AgentRelayBot pushed a commit that referenced this pull request Sep 30, 2026
…shot per subscription

Main's durable child-flow dispatch (#588) runs a child body in the same root
run with a fresh AuthoredActivities, so a child's f.on() would reuse the
root-scoped ordinal activity-1 and collide with the parent's subscription.
Refuse it with dispatch_invalid before journal contact, matching f.human.

Add a kernel test pinning that subscription.inspect reports exactly one
snapshot per subscription id across prepared -> active -> closed and restart;
Cloud's lifecycle mirroring relies on it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Sep 30, 2026
* ops: add event-await overnight implementation flow

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* feat(surface): add bounded event activities

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record event activity surface slice

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* fix(sdk): open activities before body work

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): add activity opening fix

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* feat(kernel): add durable event activities

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record event activity kernel slice

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* fix(daemon): restrict activity close reasons

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record activity close boundary

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* fix(daemon): reserve subscription streams

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record reserved stream boundary

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* feat(event-await): integrate local activity ingress

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record event await local slice

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* test(event-await): pin unread lifetime accounting

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): update event await acceptance capture

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* fix(event-await): preserve durable activity wake recovery

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record event-await audit commit

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* fix(event-await): retain normal wakes until acknowledged

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(evidence): record event-await audit pass 2

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* feat: add durable event await suspension protocol

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* feat: report immutable prepared event subscription facts

Session-Id: 01a09c40-ce3b-7f11-a7df-b6b7ccab6fd9

* docs(events): replace stale handoff claims with captured CLI evidence

* fix(events): isolate subscription waits and record cancellation correctly

* fix(events): preserve body failures before subscription activation

* fix(events): fail closed when replaying corrupt journal data

Reject malformed pending ranges, malformed stream entries, and missing frames. Remove the unused one-off implementation driver; the current runtime probe remains the acceptance fixture.

* docs(events): specify stable call-order subscription identity

* fix(cli): load activity compiler only for authored checks

* feat(events): fence router delivery and expose durable subscription metadata

* fix(events): integrate main and verify subscription reporting boundaries

* test(events): pin recovery of torn overflow fences

* fix(sdk): attach local workers to declared agent streams

* test(sdk): select the step_failed diagnostic rather than the last one

The merged tree's run-report boundary appends a trailing protocol_error
diagnostic when durable subscriptions cannot be inspected, so `at(-1)`
no longer names the step failure the test means to pin.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(event-await): use authored failure verdict in CLI probe

Session-Id: 01a0d51d-44ff-76b3-924f-83afe48f4b4f

* docs(event-await): record authored verdict proof and Cloud blockers

Session-Id: 01a0d51d-44ff-76b3-924f-83afe48f4b4f

* fix(sdk): refuse f.on in dispatched child flows; pin one inspect snapshot per subscription

Main's durable child-flow dispatch (#588) runs a child body in the same root
run with a fresh AuthoredActivities, so a child's f.on() would reuse the
root-scoped ordinal activity-1 and collide with the parent's subscription.
Refuse it with dispatch_invalid before journal contact, matching f.human.

Add a kernel test pinning that subscription.inspect reports exactly one
snapshot per subscription id across prepared -> active -> closed and restart;
Cloud's lifecycle mirroring relies on it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(kernel): report closed for canceled pulls; close prepared bindings at terminal

A close over an outstanding subscription.next settles its wait as
{closed:true}. Live next and ordinal replay decoded that ready completion as
an event wake and failed with "lacks from_offset" instead of the defined
closed refusal. wake_from_completed now reports the subscription as closed.
(Cursor Bugbot, state.rs:229)

A binding still prepared when the run becomes terminal never got a
subscription.closed entry, so Cloud's prepared row had no terminal signal and
inspect kept reporting it prepared. The terminal boundary now closes prepared
ids too, and inspect reports them closed with their completion reason.
(CodeRabbit, subscriptions/mod.rs:101)

Both regressions are covered by kernel tests that fail without the change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(sdk): check f.on through the body's actual context; drop stray SDK bun.lock

flows check matched only calls on an identifier literally named f, so
async (ctx) => ctx.on(source, {}) or a destructured { on } skipped the
unbounded_subscription preflight. Resolve the context parameter of each
authored body (the last function argument of flow(...) and the default
export, inline or by same-file name) and track a destructured on alias.
Other .on calls, such as event emitters, are still ignored. None of the
repo's 39 .flow.ts files is refused. (Codex, cli/check-activities.ts:49)

packages/sdk/bun.lock came in with an earlier merge of this branch. It pins
@relayflows/surface 2.0.30 against the manifest's 2.0.35, and main has no
SDK bun.lock; CI installs the SDK with npm ci. Remove it rather than
maintaining a second lockfile. (Codex, packages/sdk/bun.lock:11)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(sdk): scope the f.on preflight to authored bodies and respect shadowing

c297b16 collected context parameter names file-wide, so a helper outside the
body such as function wire(ctx) { ctx.on('data', h) }, or an imported
node:events on, was refused as an unbounded activity. Check only inside the
resolved body functions, and drop a context name inside a nested function
that rebinds it. Each case is covered by a test that fails when the scoping
or the shadowing is removed. (Independent review of c297b16)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(sdk): preflight f.on inside flow(...).on(trigger, body) handlers

Trigger handlers registered on a flow handle are authored bodies that receive
the same Ctx.on, but the scoped checker only resolved flow(...)'s last
argument and the default export. Also resolve .on(trigger, body) on a flow
handle, whether chained or stored in a variable. (Cursor Bugbot,
cli/check-activities.ts:90)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: khaliqgant <khaliqgant@gmail.com>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Relayflow Lead <lead@relayflows.local>
Co-authored-by: Claude Opus 5.5 (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.

2 participants