Skip to content

Add compute runtime sleep guard package#81

Merged
luanvdw merged 2 commits into
mainfrom
feat/compute-runtime-guard
Jun 11, 2026
Merged

Add compute runtime sleep guard package#81
luanvdw merged 2 commits into
mainfrom
feat/compute-runtime-guard

Conversation

@rtbenfield

Copy link
Copy Markdown
Contributor

Adds @prisma/compute as a publishable runtime utility package for Prisma Compute applications. The first API helps application code keep an instance awake while background work is active, without adding any CLI command surface.

Changes

  • Compute package: Adds packages/compute as an ESM TypeScript library with tsdown build output, package-local verification guidance, and workspace lockfile metadata.
  • Sleep guard utilities: Exposes ScaleToZeroGuard and waitUntil from packages/compute/src/index.ts. Both write paired acquire/release signals to the Prisma Compute runtime endpoint, no-op outside the runtime, and support AbortSignal as a safety bound for dangling guards.
  • Consumer docs and tests: Adds README guidance for human authors and coding agents, plus tests covering signal writes, idempotent release, disposable cleanup, abort-triggered release, unavailable runtime no-op behavior, and waitUntil fire-and-forget semantics.

Why

Prisma Compute can sleep and resume applications from memory snapshots after short idle periods. Request-adjacent background work needs an explicit keep-awake signal so it is not interrupted when the request completes. The guard uses immediate one-byte writes so acquisition and release are ordered with user code, while AbortSignal.timeout(ms) lets callers bound guard lifetime if a code path does not reach release.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 505e59e9-47e9-43b4-9fa6-5caa1d8135aa

📥 Commits

Reviewing files that changed from the base of the PR and between e37fe3f and 6b02c69.

📒 Files selected for processing (3)
  • .github/workflows/preview-cli-package.yml
  • packages/compute/src/scale-to-zero.ts
  • packages/compute/tests/scale-to-zero.test.ts

Summary by CodeRabbit

  • New Features

    • Introduced @prisma/compute with utilities to keep apps awake during background work: waitUntil and ScaleToZeroGuard.
  • Documentation

    • Added user-facing README and developer guidance for the new package and verification steps.
  • Tests

    • Added tests covering guard acquisition/release behavior, abort handling, and waitUntil lifecycle.
  • Chores

    • Added build script and package metadata for the new package; CI preview steps extended to build/test it.

Walkthrough

This PR introduces a new @prisma/compute package to the monorepo with APIs for preventing application hibernation during background work. The package includes a ScaleToZeroGuard class and waitUntil helper that write acquire/release signals to a control file, along with abort signal integration for automatic cleanup. The implementation is thoroughly tested with a Vitest suite covering guard lifecycle, promise integration, signal handling, and edge cases. Consumer documentation explains usage patterns and safety guidelines for the public APIs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 'Add compute runtime sleep guard package' clearly summarizes the main change: introducing a new package with sleep guard utilities for Prisma Compute.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose, implementation details, and rationale for adding the @prisma/compute package.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/compute-runtime-guard
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/compute-runtime-guard

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

@rtbenfield rtbenfield requested a review from luanvdw June 10, 2026 23:49

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

🤖 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 `@packages/compute/src/scale-to-zero.ts`:
- Around line 142-144: The current waitUntil call discards the promise returned
by Promise.resolve(promise).finally(...), which can create an unhandled
rejection; change the flow so the finally-attached promise cannot produce an
unhandled rejection — e.g., after Promise.resolve(promise).finally(() =>
guard.release()) attach a .catch(() => {}) to consume any rejection from the
finalizer chain (or otherwise capture the returned promise) so Node won’t flag
unhandled rejections; update the invocation in waitUntil where promise and
guard.release() are used.
🪄 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

Run ID: 5616e5ab-19b2-4a29-8cde-666a961beaa0

📥 Commits

Reviewing files that changed from the base of the PR and between ee7c648 and e37fe3f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • docs/architecture/package-structure.md
  • package.json
  • packages/compute/AGENTS.md
  • packages/compute/README.md
  • packages/compute/package.json
  • packages/compute/src/index.ts
  • packages/compute/src/scale-to-zero-control.ts
  • packages/compute/src/scale-to-zero.ts
  • packages/compute/tests/scale-to-zero.test.ts
  • packages/compute/tsconfig.json
  • packages/compute/tsdown.config.ts

Comment thread packages/compute/src/scale-to-zero.ts Outdated
@luanvdw

luanvdw commented Jun 11, 2026

Copy link
Copy Markdown
Member

Reviewed with the local code-review. Fixed the waitUntil rejection handling, added a regression test, and made the PR workflow run compute test/build too. Local checks and CI are green.

@luanvdw luanvdw merged commit eb328b4 into main Jun 11, 2026
5 checks passed
@rtbenfield rtbenfield deleted the feat/compute-runtime-guard branch June 11, 2026 09:51
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