Skip to content

fix(renderer): publish cycle artifacts atomically - #3996

Merged
kwakayama merged 2 commits into
mainfrom
fix/issue-613-atomic-cycle-artifacts
Aug 22, 2026
Merged

fix(renderer): publish cycle artifacts atomically#3996
kwakayama merged 2 commits into
mainfrom
fix/issue-613-atomic-cycle-artifacts

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

  • Stage graph-content-addressed cycle artifacts under unique sibling paths.
  • Serialize publication by final artifact path and atomically rename only complete bytes into visibility.
  • Reuse an already-published artifact only when its bytes exactly match; fail closed on conflicting content.
  • Leave ordinary non-cycle module persistence unchanged.
  • Expand the original race to eight top-level callers sharing the same production-shaped module cache.

Reachability analysis

A shared moduleCache does not prevent the race. It maps cache keys to completed path strings only. It has no in-flight entry. Two concurrent loadModule calls can both miss, enter separate top-level cycle-manifest transactions, and write one graph-content-addressed root path.

The existing per-source in-flight sharing is scoped to one CycleManifestTransaction, so it cannot coordinate those independent top-level graphs.

Request-wide transform coalescing is not the right fix. It would couple independent cancellation signals and could merge source generations. The shared mutable boundary is artifact publication. Content-addressed graph paths make complete-byte atomic publication the smaller and safer invariant.

Failure mechanism

persistTransformedModule wrote transformed code directly to the final cycle artifact path. A sibling transaction could read that path while the write was incomplete. Its commit then raised either:

  • Cycle manifest root evidence is missing, or
  • Cycle manifest changed after its root was sealed.

Each writer now writes a complete unique staging file. Publication for a final path is serialized. The first writer renames its staged file atomically; later identical writers reuse it. The manifest commit can observe an old complete file or the new complete file, never partial bytes.

Red-green TDD

Red before the implementation:

publishes concurrent cycle artifacts only from complete staged files ... FAILED
AssertionError: cycle writers must stage complete bytes away from the published path

That deterministic test runs eight concurrent writers and records every write and rename. The unchanged source wrote all eight directly to the final path and performed no rename.

The original race now also runs eight simultaneous top-level transforms with one shared moduleCache. All callers still receive the same path, module namespace, cycle namespace, and import.meta identity.

The two corruption guards remain independently reachable and tested:

  • removing sealed root evidence still raises Cycle manifest root evidence is missing;
  • changing root bytes after sealing still raises Cycle manifest changed after its root was sealed.

Verification

  • Race stress: 200 consecutive eight-way runs, zero failures
  • module-persistence.test.ts: 20 steps passed
  • cycle-manifest.test.ts: 10 steps passed
  • index.test.ts: 69 steps passed
  • src/rendering/orchestrator/module-loader: 13 passed / 165 steps
  • src/rendering/orchestrator: 33 passed / 503 steps
  • Node emitted-package test: 20 tests passed
  • Bun emitted-package test: 1 file passed
  • deno task build:npm: passed
  • deno fmt --check: passed
  • deno lint: passed
  • deno check src/index.ts: passed
  • deno task generate:manifests:check: passed
  • git diff --check: passed

Fixes veryfront/veryfront-issue-inbox#613

Concurrent top-level module transforms can share a graph-content-addressed cycle artifact even when they use one shared module cache, because that cache stores only completed paths. Direct writes exposed partial bytes to the sibling transaction during manifest sealing.

Stage each immutable cycle artifact under a unique sibling path, serialize publication by final path, and atomically rename only complete bytes. Later identical writers reuse the durable artifact, while conflicting bytes fail closed. Keep ordinary module persistence unchanged.

Expand the race to eight shared-cache callers, add a deterministic publication regression, retain corruption guards, and pass 200 consecutive stress runs.

Fixes veryfront/veryfront-issue-inbox#613
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 5 minutes

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.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 91bcd58d-9d30-4e3e-8eaa-734adb0bd9fe

📥 Commits

Reviewing files that changed from the base of the PR and between 8f530af and e99d22e.

📒 Files selected for processing (4)
  • src/rendering/orchestrator/module-loader/cycle-manifest.test.ts
  • src/rendering/orchestrator/module-loader/index.test.ts
  • src/rendering/orchestrator/module-loader/module-persistence.test.ts
  • src/rendering/orchestrator/module-loader/module-persistence.ts

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

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 327 1961 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98f44a2942

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/rendering/orchestrator/module-loader/module-persistence.ts
Publishing a cycle artifact stages complete bytes under a unique sibling
path, renames that file into place, and removes the staging file on every
exit path. Nothing covered the removal or the conflict guard, so both
could be deleted without a test noticing.

Assert that a finished publish and a rejected publish each leave no
`.pending-` file behind, and cover the branch that refuses to publish
when the artifact path already holds different bytes.

Both assertions fail on the base commit: the base writes straight to the
artifact path and overwrites conflicting bytes instead of rejecting.
@kwakayama

Copy link
Copy Markdown
Contributor

@codex review

@kwakayama

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: e99d22ec72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kwakayama
kwakayama added this pull request to the merge queue Aug 22, 2026
Merged via the queue into main with commit c43cc40 Aug 22, 2026
39 of 41 checks passed
@kwakayama
kwakayama deleted the fix/issue-613-atomic-cycle-artifacts branch August 22, 2026 23:54
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