Skip to content

Add runtime-backed strand forks - #795

Merged
flyingrobots merged 2 commits into
mainfrom
v19-runtime-fork
Jul 26, 2026
Merged

Add runtime-backed strand forks#795
flyingrobots merged 2 commits into
mainfrom
v19-runtime-fork

Conversation

@flyingrobots

Copy link
Copy Markdown
Member

Closes #792.

Adds Runtime.fork() with same-runtime ownership, exact captured-frontier persistence, runtime-backed strand writes, and checkpoint-tail bounded strand observations. A first fork establishes a missing checkpoint through the composition root; observations never full-materialize the graph.

Validation: full pre-push gate, 7,338/2 skipped coverage tests at 92.96% lines, consumer/declaration/reference checks, real-Git fork integration, and 27/28 integration files in the aggregate run plus 7/7 on the resource-timed traversal file in isolation.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 33 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 33f92bbe-e907-44a5-868d-6fe5a12c0893

📥 Commits

Reviewing files that changed from the base of the PR and between 96f8995 and 00d9e3e.

📒 Files selected for processing (8)
  • src/application/Runtime.ts
  • src/application/RuntimeLaneAdapter.ts
  • src/domain/WarpStrandOpticBasis.ts
  • src/domain/WarpWorldline.ts
  • src/domain/api/DraftReadingTarget.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • test/unit/application/RuntimeLaneAdapter.test.ts
  • test/unit/domain/services/strand/StrandService.test.ts
📝 Walkthrough

Walkthrough

The PR adds Runtime.fork(source, { name }), runtime ownership checks, strand lane construction, coordinate-aware draft reading, captured frontier propagation, and public API/type-contract coverage.

Changes

Runtime forking and strand lanes

Layer / File(s) Summary
Runtime fork contract and ownership
index.ts, src/application/Runtime.ts, src/domain/api/LaneRuntime.ts, docs/topics/reference.md, test/unit/application/Runtime.test.ts, test/type-check/v19-consumer.ts, test/unit/scripts/v19-public-api-boundary.test.ts
Runtime.fork validates ownership, source kind, options, runtime state, and fork identity; lane bindings carry owner/fork metadata, and RuntimeForkOptions is exported and documented.
Fork coordinates and draft reading infrastructure
src/domain/WarpWorldline.ts, src/domain/api/DraftTimelineRuntime.ts, src/domain/api/TickRuntime.ts, src/domain/api/TimelineRuntime.ts, test/conformance/v18FirstUseOpticsHonesty.test.ts
Fork coordinates flow through draft creation, fork optic preparation, frontier derivation, draft reading targets, ticks, and timeline context bindings.
Strand lane adapter and observation flow
src/application/RuntimeLaneAdapter.ts, test/unit/application/RuntimeLaneAdapter.test.ts
Worldline lanes expose fork operations, forked lanes use draft-backed observers, strand coordinate capture is rejected, and observation receipts support both lane types.
Captured frontier propagation and validation
src/domain/services/controllers/StrandController.ts, src/domain/services/strand/StrandCoordinator.ts, src/domain/services/strand/StrandDescriptorValidation.ts, src/domain/types/StrandDescriptor.ts, test/unit/domain/services/strand/StrandService.test.ts
Strand creation accepts an optional captured frontier, validates and sorts it, copies it into strand state, and reports invalid inputs with field-specific errors.

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

Sequence Diagram(s)

sequenceDiagram
  participant Runtime
  participant WorldlineLane
  participant RuntimeLaneAdapter
  participant DraftTimeline
  participant Observer
  Runtime->>WorldlineLane: fork(name)
  WorldlineLane->>RuntimeLaneAdapter: create strand from fork coordinate
  RuntimeLaneAdapter->>DraftTimeline: create draft reading target
  Observer->>RuntimeLaneAdapter: start observation
  RuntimeLaneAdapter->>DraftTimeline: read using pinned tick
  DraftTimeline-->>Observer: readings and receipt
Loading

Possibly related PRs

Poem

A rabbit hopped along the lane,
And forked a strand through frost and rain.
With ticks held tight and frontiers bright,
Draft readers danced through bounded light.
“New types!” I cheered—and twitched my nose.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. 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 is concise and accurately summarizes the main change: adding runtime-backed strand forks.
Description check ✅ Passed It includes the required issue reference and testing details, but the template sections are not formatted as requested.
Linked Issues check ✅ Passed The changes implement Runtime.fork with same-runtime ownership, strand descriptors, bounded observe/write behavior, and stable error cases required by #792.
Out of Scope Changes check ✅ Passed The added docs, API exports, runtime changes, and tests all support the fork/strand objective; no unrelated scope stands out.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 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 `@src/application/RuntimeLaneAdapter.ts`:
- Around line 94-115: Wrap the body of forkWorldlineLane in the same
activity.run guard used by captureWorldlineCoordinate, so direct lane fork calls
are tracked and reject with E_RUNTIME_CLOSED when the runtime is closing. Ensure
the guard covers createForkTick, createDraftTimeline, and createStrandLane,
while preserving the existing Runtime.fork behavior through idempotent nesting.
- Around line 68-81: Update bindWorldlineLaneRuntime so the fork closure
captures only activity, owner, parent, and timeline, not the full options object
or options.lane. Introduce or reuse a lane-free record for these fields, pass it
to forkWorldlineLane, and narrow forkWorldlineLane’s parameter type accordingly
while keeping bindLaneRuntime associated with the original lane.

In `@src/domain/WarpWorldline.ts`:
- Around line 69-76: Extract WarpStrandOpticBasis from WarpWorldline.ts into a
dedicated src/domain/WarpStrandOpticBasis.ts file and update
DraftTimelineRuntime imports to use it. Also extract DraftReadingTarget from
DraftTimelineRuntime.ts into a dedicated file and update RuntimeLaneAdapter
imports accordingly; remove the original inline exports while preserving both
public type APIs.

In `@test/unit/application/RuntimeLaneAdapter.test.ts`:
- Around line 77-79: In the test using requireLaneRuntime(lane).fork, replace
the non-null assertion after expect(fork).not.toBeNull() with explicit runtime
narrowing, matching the sibling test’s if (fork === null) throw pattern before
invoking fork. Preserve the existing 'try-admin-role' call and assertions.
- Around line 182-190: Replace the nested ternary assertion in the test around
the first and second results with the file’s existing Set-of-tick-ids idiom,
matching the direct pin-check pattern used near lines 279-282. Preserve the
expectation that both yielded values have the same tick ID without rechecking
their done state.

In `@test/unit/domain/services/strand/StrandService.test.ts`:
- Around line 716-730: Replace the Reflect.apply invocation in the malformed
explicit parent frontier test with a direct service.create call preceded by
`@ts-expect-error`, preserving compile-time validation of the invalid input.
Update the second rejection assertion to also require context.field to equal
baseFrontier, matching the stable error contract asserted for the first case.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cc0d264f-85d3-4d45-9b4c-e172fa403a2d

📥 Commits

Reviewing files that changed from the base of the PR and between 614b8b0 and 96f8995.

📒 Files selected for processing (20)
  • docs/topics/reference.md
  • index.ts
  • src/application/Runtime.ts
  • src/application/RuntimeLaneAdapter.ts
  • src/domain/WarpWorldline.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/TickRuntime.ts
  • src/domain/api/TimelineRuntime.ts
  • src/domain/services/controllers/StrandController.ts
  • src/domain/services/strand/StrandCoordinator.ts
  • src/domain/services/strand/StrandDescriptorValidation.ts
  • src/domain/types/StrandDescriptor.ts
  • test/conformance/v18FirstUseOpticsHonesty.test.ts
  • test/integration/application/Runtime.fork.integration.test.ts
  • test/type-check/v19-consumer.ts
  • test/unit/application/Runtime.test.ts
  • test/unit/application/RuntimeLaneAdapter.test.ts
  • test/unit/domain/services/strand/StrandService.test.ts
  • test/unit/scripts/v19-public-api-boundary.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: v19 base/head performance
  • GitHub Check: test-node (22)
  • GitHub Check: preflight
  • GitHub Check: coverage-threshold
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Do not use direct imports from src/infrastructure/** in src/domain/** or src/ports/**; depend on a port instead.
Do not use direct Node built-ins in src/domain/** or src/ports/**; use a port instead.

Files:

  • index.ts
  • test/integration/application/Runtime.fork.integration.test.ts
  • src/domain/api/TickRuntime.ts
  • src/domain/types/StrandDescriptor.ts
  • test/unit/domain/services/strand/StrandService.test.ts
  • src/domain/services/controllers/StrandController.ts
  • test/unit/scripts/v19-public-api-boundary.test.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/TimelineRuntime.ts
  • test/unit/application/RuntimeLaneAdapter.test.ts
  • test/type-check/v19-consumer.ts
  • src/domain/services/strand/StrandCoordinator.ts
  • src/domain/services/strand/StrandDescriptorValidation.ts
  • test/conformance/v18FirstUseOpticsHonesty.test.ts
  • test/unit/application/Runtime.test.ts
  • src/application/Runtime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/WarpWorldline.ts
  • src/application/RuntimeLaneAdapter.ts
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.{ts,tsx,js,jsx}: Do not introduce any, as any, as unknown as, unknown (outside adapters), Record<string, unknown> (outside adapters), *Like placeholder types, JSON.parse/JSON.stringify (outside adapters), fetch (outside adapters), process.env (outside adapters), @ts-ignore, or z.any() in core code; use validated boundary models and ports instead.
Use constructor-injected ports for external capabilities; do not rely on ambient dependencies for I/O, clocks, persistence, or entropy.
Do not create utils.ts, helpers.ts, misc.ts, or common.ts; name files after the actual concept they model.
Prefer one file per class, type, or object; if a file accumulates peer concepts, split it.
Keep helper corridors, fake shape trust, transitional duplication, and compile-time theater out of the codebase; runtime-honest TypeScript must reflect actual behavior.
No enum usage; prefer runtime-backed domain forms and unions.
Do not use boolean trap parameters; prefer named option objects or separate methods.
Avoid magic strings or numbers when a named constant should exist.
Keep domain bytes as Uint8Array; Buffer belongs in infrastructure adapters.

Files:

  • src/domain/api/TickRuntime.ts
  • src/domain/types/StrandDescriptor.ts
  • src/domain/services/controllers/StrandController.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/TimelineRuntime.ts
  • src/domain/services/strand/StrandCoordinator.ts
  • src/domain/services/strand/StrandDescriptorValidation.ts
  • src/application/Runtime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/WarpWorldline.ts
  • src/application/RuntimeLaneAdapter.ts
src/domain/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/domain/**/*.{ts,tsx,js,jsx}: In src/domain/**, do not use Date.now(), new Date(), Date(), performance.now(), Math.random(), crypto.randomUUID(), crypto.getRandomValues(), setTimeout, setInterval, raw new Error(...)/new TypeError(...), or direct imports from Node built-ins; time, entropy, and external capabilities must enter through ports or parameters, and domain errors should extend WarpError.
Construct domain objects only in core when doing so establishes validated runtime truth; do not build infrastructure adapters, host APIs, persistence implementations, wall clocks, or entropy sources inside core.
Prefer discriminated unions and explicit result types instead of boolean-flag bags, and model expected failures as return values rather than exceptions.
src/domain/ must not import host APIs or Node-specific globals; hexagonal architecture boundaries are mandatory.
Domain code must not use the wall clock directly; time must enter through a port or parameter.

Files:

  • src/domain/api/TickRuntime.ts
  • src/domain/types/StrandDescriptor.ts
  • src/domain/services/controllers/StrandController.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/TimelineRuntime.ts
  • src/domain/services/strand/StrandCoordinator.ts
  • src/domain/services/strand/StrandDescriptorValidation.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/WarpWorldline.ts
src/domain/**/!(*.test).{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use explicit domain concepts with validated constructors, Object.freeze, and instanceof dispatch; domain objects should be runtime-backed nouns, not ad hoc shape bags.

Files:

  • src/domain/api/TickRuntime.ts
  • src/domain/types/StrandDescriptor.ts
  • src/domain/services/controllers/StrandController.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/TimelineRuntime.ts
  • src/domain/services/strand/StrandCoordinator.ts
  • src/domain/services/strand/StrandDescriptorValidation.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/WarpWorldline.ts
🔇 Additional comments (30)
src/application/Runtime.ts (4)

1-6: LGTM!


22-42: LGTM!


73-85: LGTM!


96-131: LGTM!

src/domain/api/LaneRuntime.ts (1)

5-8: LGTM!

Also applies to: 19-20

index.ts (1)

14-17: LGTM!

docs/topics/reference.md (1)

42-69: LGTM!

test/unit/application/Runtime.test.ts (4)

22-50: LGTM!

Also applies to: 71-79


105-134: LGTM!


136-158: LGTM!


187-210: LGTM!

test/type-check/v19-consumer.ts (1)

16-16: LGTM!

Also applies to: 27-28, 90-90

src/application/RuntimeLaneAdapter.ts (4)

2-12: LGTM!

Also applies to: 25-28, 40-51


117-156: LGTM!


230-230: LGTM!

Also applies to: 251-251, 274-274, 291-291, 333-333, 350-350, 367-367, 392-392, 415-415, 444-444


185-209: 🩺 Stability & Availability

No change needed. prepareStrandOptic does not surface E_OPTIC_NO_BOUNDED_BASIS; the only bounded-basis failure in createDraftReadingTarget is the null state.forkedAt path, which fork-created draft strands do not reach.

			> Likely an incorrect or invalid review comment.
test/unit/application/RuntimeLaneAdapter.test.ts (1)

136-181: LGTM!

Also applies to: 191-203

src/domain/types/StrandDescriptor.ts (1)

92-97: LGTM!

test/unit/domain/services/strand/StrandService.test.ts (1)

698-714: LGTM!

src/domain/WarpWorldline.ts (2)

18-20: LGTM!

Also applies to: 37-40, 88-90, 107-109, 127-129, 155-162, 192-204, 250-259, 311-318, 327-334, 352-442


336-350: 🩺 Stability & Availability

No change needed: the fork bootstrap is already guarded by the activity queue.

The checkpoint bootstrap retries on E_OPTIC_NO_BOUNDED_BASIS, and concurrent Runtime.fork(...) calls for the same runtime are serialized through RuntimeActivity.run.

			> Likely an incorrect or invalid review comment.
src/domain/api/DraftTimelineRuntime.ts (1)

2-3: LGTM!

Also applies to: 13-16, 26-26, 41-47, 102-103, 120-146, 148-166, 281-298, 300-309

src/domain/api/TickRuntime.ts (1)

23-31: LGTM!

src/domain/api/TimelineRuntime.ts (1)

15-20: LGTM!

Also applies to: 46-63

test/conformance/v18FirstUseOpticsHonesty.test.ts (1)

138-141: LGTM!

test/integration/application/Runtime.fork.integration.test.ts (1)

1-85: LGTM!

src/domain/services/controllers/StrandController.ts (1)

38-38: LGTM!

src/domain/services/strand/StrandCoordinator.ts (1)

17-17: LGTM!

Also applies to: 184-188

src/domain/services/strand/StrandDescriptorValidation.ts (1)

117-161: LGTM!

test/unit/scripts/v19-public-api-boundary.test.ts (1)

29-29: 🎯 Functional Correctness

No action needed for RuntimeForkOptions.

Comment thread src/application/RuntimeLaneAdapter.ts
Comment thread src/application/RuntimeLaneAdapter.ts
Comment thread src/domain/WarpWorldline.ts Outdated
Comment thread test/unit/application/RuntimeLaneAdapter.test.ts Outdated
Comment thread test/unit/application/RuntimeLaneAdapter.test.ts Outdated
Comment thread test/unit/domain/services/strand/StrandService.test.ts
@github-actions

Copy link
Copy Markdown

Release Preflight

  • package version: 18.2.1
  • prerelease: false
  • npm dist-tag on release: latest
  • npm pack dry-run: passed
  • jsr publish dry-run: passed

If this PR is from a release/* branch and merges to main, Main Push Release Branch Check will run final preflight and create v18.2.1. A maintainer who is a JSR @git-stunts scope member must then dispatch the Release workflow manually.

@github-actions

Copy link
Copy Markdown

Release Preflight

  • package version: 18.2.1
  • prerelease: false
  • npm dist-tag on release: latest
  • npm pack dry-run: passed
  • jsr publish dry-run: passed

If this PR is from a release/* branch and merges to main, Main Push Release Branch Check will run final preflight and create v18.2.1. A maintainer who is a JSR @git-stunts scope member must then dispatch the Release workflow manually.

@flyingrobots
flyingrobots merged commit 2d37ffe into main Jul 26, 2026
18 checks passed
@flyingrobots
flyingrobots deleted the v19-runtime-fork branch July 26, 2026 21:45
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.

Add Runtime fork and strand Lane contract

1 participant