Skip to content

✨ feat(flow): Sleep and WaitFor system activities - #189

Merged
roninjin10 merged 9 commits into
mainfrom
flow-system-activities
Aug 13, 2026
Merged

✨ feat(flow): Sleep and WaitFor system activities#189
roninjin10 merged 9 commits into
mainfrom
flow-system-activities

Conversation

@roninjin10

Copy link
Copy Markdown
Contributor

Summary

Sleep and WaitFor as core-shipped declared Activities over the existing DurableClock/DurableDeferred — timers and events become visible, keyed plan nodes instead of invisible engine mechanics. Park classification rides the existing Waiting vocabulary (timer/event); waiting annotations propagate from child attempts into the parent execution.

Decisions taken (review these)

  1. Sleep requires exactly one of millis | until; expired deadlines settle immediately.
  2. Repeated sleeps derive durable identity from the engine's stable dispatch key — no public payload widening; missing dispatch identity fails loudly rather than aliasing timers.
  3. WaitFor requires exactly one of name | token; foreign/malformed tokens are rejected.
  4. Scope expanded into engine/engine-store for two small integration seams (stable per-node timer identity, durable waiting classification) — noted as a deviation, kept minimal.

Note for reviewers: one pre-existing, unrelated platform-node host-contract failure (local jj detection) reproduces with this PR's changes stashed; not addressed here.

Depends-on: #188

Verification

  • Root npm run check passed; check/lint/circular clean in flow, engine, engine-store, flows
  • Full suites at 100% coverage: flow 20/210 · engine 22/164 · engine-store 73/480 · flows 2/151; new Sleep.test.ts (11), WaitFor.test.ts (11), AnnotatedWaiting.test.ts (4)

…Error

The authoring half of the plan: seven closure-free node variants (Succeed,
All, Map, AndThen, FlowCall, ActivityCall, Branch) with digested deferred
functions in out-of-band tables, the Planned<T> branded placeholder whose
proxy throws GraphBuildError on any computation (toPrimitive, valueOf,
toString, toJSON, application), and the GraphBuildError vocabulary.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit 64624ac)
Activity.make gains a string-first overload: a named, schema-typed atom
(payload/success/error/tier/idempotencyKey) whose implementation attaches
separately via .toLayer(execute) through the existing registration and
activity machinery, and whose .call(payload) records an ActivityCall node
for plans. The inline options form is unchanged.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit b883814)
…otations

Flow.make accepts an optional plan-time body (required once the migration
completes), Flow.prototype.call records a FlowCall node, the trampoline
outcome vocabulary lands as pure data (Flow.done / flow.to / Flow.park over
the existing Waiting reasons), and Capabilities / EffectsDeclaration /
Placement join the annotation keys.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
Docs: docs/specs/Concepts/Trampoline Loops.md
(cherry picked from commit ad7df62)
@roninjin10

Copy link
Copy Markdown
Contributor Author

Review round 1 complete (sol + fable, independent). Findings for this PR were fixed and folded into its commit; the full ledger (15 fixes, 6 resolved-as-designed) lives in the stack's review notes. All 14 branches rebased and re-verified: whole-repo check green, all package suites at 100% coverage, rebuilt tip byte-identical to the verified fix tree.

Evaluates a body against its real payload with strict Planned placeholders
for step results, expands branch arms as static topology, splices inline
flow calls with capability intersection, rejects recursive calls with
recursion_requires_boundary, reads effects/capabilities/placement from the
authoring annotations, and emits NodeDrafts that Plan.compile keys directly.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit f8bf150)
Interpreter.layer(flow) registers a generic handler over the FlowRuntime
port: Graph.build against the real payload, dependency-order driving of the
compiled drafts, activity calls through the existing persistence machinery
with declared implementations resolved from an Implementations table, branch
predicates on real values running only the taken arm, Ref-path projection
threading, and journaled replay on execution-id reuse. Bodied flows reject
toLayer; behavior comes from exactly one place.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit 42ee5ce)
(cherry picked from commit 72f9b1e)
A bodied flow's root value settles as Complete (done), Suspended (park,
existing Waiting vocabulary), or the new encoded Handoff (to): the engine
plans the target and runs it as the next round. Rounds chain under one
lineage via parent_run_id with deterministic (lineage, ordinal) execution
ids, the settle-and-create seam is one storage transaction, maxRounds is
declared on the origin flow and enforced at the handoff with a typed
terminal failure, and the root caller's polling follows handoff chains
transparently to the final value.

Docs: docs/specs/Concepts/Trampoline Loops.md
(cherry picked from commit acafd2e)
(cherry picked from commit e1f2cc8)
flow.child(payload) records a non-expanded boundary node whose material
carries the child's tag, payload, and declared envelope. The interpreter
runs it as a genuine child execution with a deterministic id derived from
the parent execution and node address, parent edges and suspension
propagate through the existing machinery, and placement conflicts on
inline .call() now error with placement_requires_boundary directing to
.child().

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit f09bc16)
(cherry picked from commit b4ec945)
The branch move applied to the error channel: Node.catch protects a
subgraph with a failure arm that is plan-visible via an explicit failure
edge reason, filters errors by digested schema (missing filter = the full
typed error channel), never intercepts defects or compensation failures,
and settles the protected node's planned reference with the caught error
so failure-arm payloads consume it without re-running failed work.

Docs: docs/specs/Concepts/Unified Flow Authoring.md
(cherry picked from commit 47ffb00)
(cherry picked from commit 37d8dc2)
(cherry picked from commit 417035e)
(cherry picked from commit dc5ad88)
@roninjin10
roninjin10 force-pushed the flow-system-activities branch from dc5ad88 to 809d444 Compare August 12, 2026 06:51
@roninjin10
roninjin10 changed the base branch from node-catch to main August 13, 2026 01:13
@roninjin10
roninjin10 merged commit 809d444 into main Aug 13, 2026
1 check failed
@roninjin10
roninjin10 deleted the flow-system-activities branch August 13, 2026 01:35
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