Skip to content

Add revalidated Runtime settlement plans - #796

Merged
flyingrobots merged 2 commits into
mainfrom
v19-settlement-plans
Jul 26, 2026
Merged

Add revalidated Runtime settlement plans#796
flyingrobots merged 2 commits into
mainfrom
v19-settlement-plans

Conversation

@flyingrobots

Copy link
Copy Markdown
Member

Adds immutable Runtime-issued settlement plans with exact Lane/frontier/law/policy binding, stale-basis revalidation, canonical receipts, and serialized promotion.

Validated by the full pre-push M9 firewall and coverage (7,350 tests; 92.97% lines).

Closes #793

@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: 12 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: c2f5bafc-befe-4622-a1b6-fe2697c8d5f2

📥 Commits

Reviewing files that changed from the base of the PR and between 6a265d9 and bef5d43.

📒 Files selected for processing (10)
  • src/application/RuntimeMutationGate.ts
  • src/application/RuntimeSettlement.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • src/domain/api/SettlementLaneReference.ts
  • src/domain/api/SettlementPreview.ts
  • src/domain/api/SettlementReceipt.ts
  • test/helpers/SettlementHarness.ts
  • test/unit/application/RuntimeSettlement.preview.test.ts
  • test/unit/application/RuntimeSettlement.test.ts
  • test/unit/domain/settlement/SettlementIdentityRuntime.test.ts
📝 Walkthrough

Walkthrough

Adds immutable runtime settlement previews and revalidated settlement execution, with serialized mutations, settlement runtime contracts, canonical receipts, public exports, and integration, unit, type-check, and API-boundary tests.

Changes

Runtime settlement

Layer / File(s) Summary
Settlement contracts and immutable artifacts
src/domain/api/*Settlement*.ts, src/domain/api/LaneRuntime.ts, src/domain/api/PublicReceipt.ts, src/domain/settlement/SettlementPlan.ts
Adds settlement runtime types, immutable plans, previews, receipts, outcomes, evidence bindings, and deterministic settlement identifiers.
Mutation-gated lane wiring
src/application/RuntimeMutationGate.ts, src/application/RuntimeLaneAdapter.ts, src/application/RuntimeStrandLaneBinding.ts, src/application/Runtime.ts
Serializes worldline and strand writes, forks, and settlement promotion through shared mutation gates.
Draft settlement runtime and lane validation
src/domain/api/DraftSettlementRuntime.ts, src/domain/api/DraftTimelineRuntime.ts, src/application/RuntimeSettlementValidation.ts
Captures draft snapshots and digests, promotes drafts, and validates lane ownership, kinds, and parent relationships.
Runtime preview and settlement execution
src/application/RuntimeSettlement.ts, src/application/Runtime.ts
Adds preview and settle methods, basis revalidation, stale-plan obstruction handling, promotion, evidence construction, and receipt creation.
Public API and behavioral validation
index.ts, docs/topics/reference.md, test/integration/application/*, test/unit/application/*, test/unit/domain/settlement/*, test/type-check/*, test/unit/scripts/*
Updates public exports and documentation while testing immutability, concurrency, stale plans, promotion outcomes, type compatibility, and export boundaries.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Runtime
  participant RuntimeSettlement
  participant SourceRuntime
  participant TargetRuntime
  Client->>Runtime: previewSettlement(source, target)
  Runtime->>RuntimeSettlement: prepare settlement plan
  RuntimeSettlement->>SourceRuntime: capture source snapshot and digest
  RuntimeSettlement->>TargetRuntime: capture target basis
  RuntimeSettlement-->>Runtime: immutable SettlementPreview
  Client->>Runtime: settle(preview.plan)
  Runtime->>RuntimeSettlement: revalidate bound plan
  RuntimeSettlement->>SourceRuntime: runExclusive promotion
  SourceRuntime-->>RuntimeSettlement: promotion result
  RuntimeSettlement-->>Runtime: SettlementReceipt
Loading

Possibly related PRs

Poem

A rabbit reviews the plan in the moonlit byte,
Frontiers freeze neatly, all tucked in tight.
Gates queue each mutation in line,
Receipts bloom when outcomes align.
If paths grow stale, we hop back and preview—
Thump-thump, settlement stays true!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the required Summary, Issue, Test plan, and ADR checks template sections. Rewrite the PR description to follow the repository template with Summary, Issue, Test plan, and ADR checks sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: introducing revalidated Runtime settlement plans.
Linked Issues check ✅ Passed The changes implement immutable preview/settle plans, revalidation, canonical receipts, and the required tests for issue #793.
Out of Scope Changes check ✅ Passed The added docs, exports, runtime modules, and tests all align with the settlement-plan work and its required API surface.

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.

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

@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: 5

🤖 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/RuntimeMutationGate.ts`:
- Around line 4-21: Add a concise documentation comment to
RuntimeMutationGate.run warning that invoking run directly or transitively on
the same gate from within an active operation causes a deadlock, and instruct
callers to avoid reentrant use. Keep the existing serialization behavior
unchanged.

In `@src/application/RuntimeSettlement.ts`:
- Around line 394-405: Update outcomeFields to return a runtime-frozen
SettlementOutcomeFields object, matching the Object.freeze behavior of
createSettlementFields while preserving all existing field values.

In `@src/domain/api/SettlementIdentityRuntime.ts`:
- Around line 52-59: Update flattenFrontier to sort writerId values with a
deterministic ordinal/codepoint comparison instead of localeCompare(),
preserving the existing ascending order and flattened [writerId, patchSha]
output used by the frontier digest functions.

In `@src/domain/api/SettlementPreview.ts`:
- Around line 53-70: Extract the duplicated freezeLaneReference helper into a
shared module alongside ReceiptSupport.ts, preserving its validation, error
message/code, and frozen return value. Remove the local helper from
src/domain/api/SettlementPreview.ts lines 53-70 and import the shared helper;
remove the duplicate from src/domain/api/SettlementReceipt.ts lines 74-91 and
import the same helper.

In `@test/unit/application/RuntimeSettlement.preview.test.ts`:
- Line 1: Extract the duplicated settlement setup into a shared test-support
harness, moving settlementHarness, freezeSnapshot, bindTargetLane,
bindSourceLane, createLane, and unavailableCoordinate from
RuntimeSettlement.preview.test.ts and replacing the inline
SettlementSourceRuntime, snapshot, evidence, and bindSettlementPlan setup in
RuntimeSettlement.test.ts. Import and reuse this harness in both suites,
parameterizing only the plural/conflict outcome while preserving each test’s
existing behavior.
🪄 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: 5a5255a6-4c80-4eb1-84a8-849435d7069f

📥 Commits

Reviewing files that changed from the base of the PR and between 2d37ffe and 6a265d9.

📒 Files selected for processing (29)
  • docs/topics/reference.md
  • index.ts
  • src/application/Runtime.ts
  • src/application/RuntimeLaneAdapter.ts
  • src/application/RuntimeMutationGate.ts
  • src/application/RuntimeSettlement.ts
  • src/application/RuntimeSettlementOptions.ts
  • src/application/RuntimeSettlementValidation.ts
  • src/application/RuntimeStrandLaneBinding.ts
  • src/domain/api/DraftSettlementRuntime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/LaneSettlementRuntime.ts
  • src/domain/api/PublicReceipt.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • src/domain/api/SettlementOutcomeRuntime.ts
  • src/domain/api/SettlementPlanRuntime.ts
  • src/domain/api/SettlementPreview.ts
  • src/domain/api/SettlementReceipt.ts
  • src/domain/settlement/SettlementPlan.ts
  • test/integration/application/Runtime.settlement.integration.test.ts
  • test/type-check/v19-consumer.ts
  • test/unit/application/Runtime.test.ts
  • test/unit/application/RuntimeLaneAdapter.test.ts
  • test/unit/application/RuntimeMutationGate.test.ts
  • test/unit/application/RuntimeSettlement.preview.test.ts
  • test/unit/application/RuntimeSettlement.test.ts
  • test/unit/domain/settlement/SettlementPlan.test.ts
  • test/unit/scripts/v19-public-api-boundary.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: test-node (22)
  • GitHub Check: v19 base/head performance
  • GitHub Check: coverage-threshold
  • GitHub Check: preflight
🧰 Additional context used
📓 Path-based instructions (4)
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/PublicReceipt.ts
  • src/application/RuntimeSettlementOptions.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • src/domain/api/LaneSettlementRuntime.ts
  • src/domain/api/SettlementPreview.ts
  • src/application/RuntimeMutationGate.ts
  • src/domain/api/SettlementPlanRuntime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/api/LaneRuntime.ts
  • src/application/RuntimeStrandLaneBinding.ts
  • src/domain/api/SettlementReceipt.ts
  • src/application/RuntimeSettlementValidation.ts
  • src/domain/api/SettlementOutcomeRuntime.ts
  • src/application/RuntimeSettlement.ts
  • src/domain/settlement/SettlementPlan.ts
  • src/domain/api/DraftSettlementRuntime.ts
  • src/application/Runtime.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/PublicReceipt.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • src/domain/api/LaneSettlementRuntime.ts
  • src/domain/api/SettlementPreview.ts
  • src/domain/api/SettlementPlanRuntime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/SettlementReceipt.ts
  • src/domain/api/SettlementOutcomeRuntime.ts
  • src/domain/settlement/SettlementPlan.ts
  • src/domain/api/DraftSettlementRuntime.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/PublicReceipt.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • src/domain/api/LaneSettlementRuntime.ts
  • src/domain/api/SettlementPreview.ts
  • src/domain/api/SettlementPlanRuntime.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • src/domain/api/LaneRuntime.ts
  • src/domain/api/SettlementReceipt.ts
  • src/domain/api/SettlementOutcomeRuntime.ts
  • src/domain/settlement/SettlementPlan.ts
  • src/domain/api/DraftSettlementRuntime.ts
**/*.{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:

  • src/domain/api/PublicReceipt.ts
  • src/application/RuntimeSettlementOptions.ts
  • test/unit/application/RuntimeMutationGate.test.ts
  • src/domain/api/SettlementIdentityRuntime.ts
  • test/unit/application/RuntimeLaneAdapter.test.ts
  • index.ts
  • src/domain/api/LaneSettlementRuntime.ts
  • src/domain/api/SettlementPreview.ts
  • src/application/RuntimeMutationGate.ts
  • src/domain/api/SettlementPlanRuntime.ts
  • test/unit/scripts/v19-public-api-boundary.test.ts
  • src/domain/api/DraftTimelineRuntime.ts
  • test/unit/application/RuntimeSettlement.test.ts
  • test/unit/domain/settlement/SettlementPlan.test.ts
  • src/domain/api/LaneRuntime.ts
  • src/application/RuntimeStrandLaneBinding.ts
  • test/type-check/v19-consumer.ts
  • src/domain/api/SettlementReceipt.ts
  • src/application/RuntimeSettlementValidation.ts
  • test/integration/application/Runtime.settlement.integration.test.ts
  • test/unit/application/Runtime.test.ts
  • test/unit/application/RuntimeSettlement.preview.test.ts
  • src/domain/api/SettlementOutcomeRuntime.ts
  • src/application/RuntimeSettlement.ts
  • src/domain/settlement/SettlementPlan.ts
  • src/domain/api/DraftSettlementRuntime.ts
  • src/application/Runtime.ts
  • src/application/RuntimeLaneAdapter.ts
🔇 Additional comments (30)
index.ts (1)

14-18: LGTM!

Also applies to: 41-43

docs/topics/reference.md (1)

42-73: LGTM!

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

20-239: LGTM!

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

15-21: LGTM!

Also applies to: 55-64, 113-113

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

42-49: LGTM!

Also applies to: 210-210

test/unit/application/RuntimeLaneAdapter.test.ts (1)

138-189: LGTM!

test/unit/application/RuntimeMutationGate.test.ts (1)

1-43: LGTM!

test/unit/application/RuntimeSettlement.preview.test.ts (1)

1-157: LGTM!

test/unit/application/RuntimeSettlement.test.ts (1)

1-14: LGTM!

Also applies to: 96-132

test/unit/domain/settlement/SettlementPlan.test.ts (1)

7-20: LGTM!

Also applies to: 31-34, 56-80

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

31-34: LGTM!

src/application/RuntimeSettlementOptions.ts (1)

1-6: LGTM!

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

1-45: LGTM!

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

1-81: LGTM!

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

21-53: LGTM!

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

23-23: LGTM!

Also applies to: 297-299

src/domain/api/DraftSettlementRuntime.ts (2)

34-39: 🎯 Functional Correctness | ⚡ Quick win

Clarify discarded prepareOpticBasis() result before reading coordinate().

await state.runtime.prepareOpticBasis(); discards its return value and is immediately followed by a separate state.runtime.coordinate() call to get targetCoordinate, which feeds targetFrontierRef used for stale/common-basis comparisons. Every other "prepare" call in this file/DraftTimelineRuntime.ts uses its returned basis. Please confirm this is intentional cache/ref warm-up (and not a spot where the returned basis was meant to be used directly), since an incorrect assumption here would undermine the stale-basis detection this PR is meant to guarantee.


73-157: LGTM!

src/application/RuntimeSettlementValidation.ts (1)

1-105: LGTM!

src/application/RuntimeSettlement.ts (1)

60-393: LGTM!

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

4-10: LGTM!

Also applies to: 23-23

src/domain/settlement/SettlementPlan.ts (1)

1-14: LGTM!

Also applies to: 17-77

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

1-52: LGTM!

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

1-73: LGTM!

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

2-6: LGTM!

src/application/RuntimeLaneAdapter.ts (1)

34-35: LGTM!

Also applies to: 47-71, 73-100, 102-104, 106-128, 141-167, 169-194

src/application/Runtime.ts (3)

46-46: 🚀 Performance & Scalability

Confirm the Runtime-wide single mutation gate is intentional.

#mutations is one RuntimeMutationGate instance shared by every worldline lane opened via lane() and every strand lane forked from them, so all writes and settlement promotions across the entire Runtime now serialize through a single queue rather than per-lane. This is likely correct given git's single-working-tree write constraints, but it's worth confirming this doesn't unexpectedly throttle unrelated concurrent lanes under load.

Also applies to: 55-55, 82-90


108-117: 🩺 Stability & Availability

Verify previewSettlement/settle are safe against concurrent close().

Unlike lane() and fork(), these methods don't wrap themselves in this.#activity.run(...)/.acquire() at the top level. settle()'s actual work is tracked indirectly via runExclusive's nested activity.run(mutations.run(...)), but previewSettlement's prepareSettlement internals live in RuntimeSettlement.ts, which isn't in this review batch — please confirm none of its steps perform I/O outside the granular, activity-tracked capture calls, so Runtime.close() can't complete while a preview/settle call is still doing untracked work.


2-27: LGTM!

src/application/RuntimeStrandLaneBinding.ts (1)

1-57: LGTM!

Comment thread src/application/RuntimeMutationGate.ts
Comment thread src/application/RuntimeSettlement.ts
Comment thread src/domain/api/SettlementIdentityRuntime.ts
Comment thread src/domain/api/SettlementPreview.ts Outdated
Comment thread test/unit/application/RuntimeSettlement.preview.test.ts Outdated
@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 a5d49a6 into main Jul 26, 2026
18 checks passed
@flyingrobots
flyingrobots deleted the v19-settlement-plans branch July 26, 2026 23:53
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 immutable revalidated Runtime settlement plans

1 participant