Skip to content

fix(deploy): pin exact runtime version in generated sandbox package.json - #262

Merged
khaliqgant merged 1 commit into
mainfrom
fix/deploy-runtime-exact-pin
Jul 15, 2026
Merged

fix(deploy): pin exact runtime version in generated sandbox package.json#262
khaliqgant merged 1 commit into
mainfrom
fix/deploy-runtime-exact-pin

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

  • sandbox mode (BYO / workforce-managed Daytona, modes/sandbox-client.ts) installs the bundle's dependencies with npm install --prefer-offline. The generated package.json pinned "@agentworkforce/runtime": "*" on purpose ("resolves the runtime version from the active workspace" per the old comment) — but a wildcard + --prefer-offline lets the sandbox silently keep whatever version is already cached/pre-baked, with no guarantee it matches what the bundle was actually compiled against. This is the same failure class that crashed daily-ship's --mode cloud redeploy today (missing normalizeCronFire export from a stale runtime) — see cloud PR AgentWorkforce/cloud#2621 for that incident (--mode cloud doesn't consume this field at all; it's server-overwritten, so this PR doesn't fix that specific crash, but closes the same-shaped gap in the sandbox mode path).
  • buildPackageJson now pins the exact @agentworkforce/runtime version this copy of @agentworkforce/deploy resolves via its own installed node_modules copy (workspace:* becomes an exact version at publish time — confirmed via npm view @agentworkforce/deploy@4.1.17 dependencies, which already shows "@agentworkforce/runtime": "4.1.17"). A version mismatch during npm install in the sandbox now either installs the correct exact version or fails loudly, instead of silently keeping a stale one.

Test plan

  • pnpm -r build (full monorepo, all 17 workspace packages) — clean
  • packages/deploynpm test (tsc + node --test): 220/220 pass, including a new assertion that the generated package.json pins the exact installed runtime version (not "*")

🤖 Generated with Claude Code

Review in cubic

The generated bundle's package.json pinned "@agentworkforce/runtime": "*",
deliberately left wildcard so "deploys resolve the runtime version from
the active workspace" per the old comment. In practice this let a
sandbox's `npm install --prefer-offline` (modes/sandbox-client.ts) silently
satisfy the dependency from whatever's already cached/pre-baked, with no
guarantee it matches what the bundle was actually compiled against.

Pin the exact @agentworkforce/runtime version this copy of
@agentworkforce/deploy resolves (its own installed copy's package.json —
workspace:* becomes an exact version at publish time, so this is always
the version the CLI was built/tested with). A version mismatch now either
installs the correct exact version or fails npm install loudly, instead
of silently running a stale runtime.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84cddfd0-35c5-48c7-9db9-eb02048a008f

📥 Commits

Reviewing files that changed from the base of the PR and between aa43063 and ff8a54f.

📒 Files selected for processing (2)
  • packages/deploy/src/bundle.test.ts
  • packages/deploy/src/bundle.ts

📝 Walkthrough

Walkthrough

The deploy bundle now resolves the installed @agentworkforce/runtime version, pins it in generated package.json output, adds runner format version metadata, and verifies the exact dependency in bundle tests.

Changes

Runtime dependency pinning

Layer / File(s) Summary
Resolve and write runtime version
packages/deploy/src/bundle.ts
Bundle staging resolves and validates the installed runtime version, writes it as an exact dependency, and adds runner format version metadata.
Verify generated dependency
packages/deploy/src/bundle.test.ts
Tests confirm the generated runtime dependency matches the installed package version and is not a wildcard.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • AgentWorkforce/cloud#1647 — Replaces the wildcard persona runtime dependency with an exact pinned version in the deploy bundle.

Poem

A bunny packed a bundle tight,
With runtime pinned just right.
No wildcard hops across the floor,
The tested version guards the door.
Format numbers spring with cheer!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: pinning the exact runtime version in generated sandbox package.json.
Description check ✅ Passed The description is directly related to the PR and accurately explains the runtime pinning change and its motivation.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deploy-runtime-exact-pin

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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the bundle stager to pin the exact version of @agentworkforce/runtime that @agentworkforce/deploy was built against in the generated package.json, replacing the previous wildcard (*) dependency. This ensures that the sandbox installs the correct runtime version. Corresponding tests were added to verify this behavior. The feedback suggests caching the resolved runtime version in a module-level variable to avoid redundant disk I/O and resolution overhead during batch deployments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +115 to +131
function resolveRuntimeVersion(): string {
let packageJsonPath: string;
try {
packageJsonPath = require.resolve('@agentworkforce/runtime/package.json');
} catch (err) {
throw new Error(
`bundle: could not resolve @agentworkforce/runtime/package.json to pin an exact version (${
err instanceof Error ? err.message : String(err)
})`
);
}
const pkg = require(packageJsonPath) as { version?: unknown };
if (typeof pkg.version !== 'string' || pkg.version.length === 0) {
throw new Error(`bundle: ${packageJsonPath} has no valid "version" field`);
}
return pkg.version;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since resolveRuntimeVersion performs synchronous resolution and file system read/parse operations, calling it on every stage invocation can be inefficient if multiple bundles are staged in a single process (e.g., during batch deployments). Caching the resolved version in a module-level variable avoids redundant disk I/O and resolution overhead.

let cachedRuntimeVersion: string | undefined;

function resolveRuntimeVersion(): string {
  if (cachedRuntimeVersion !== undefined) {
    return cachedRuntimeVersion;
  }
  let packageJsonPath: string;
  try {
    packageJsonPath = require.resolve('@agentworkforce/runtime/package.json');
  } catch (err) {
    throw new Error(
      `bundle: could not resolve @agentworkforce/runtime/package.json to pin an exact version (${
        err instanceof Error ? err.message : String(err)
      })`
    );
  }
  const pkg = require(packageJsonPath) as { version?: unknown };
  if (typeof pkg.version !== 'string' || pkg.version.length === 0) {
    throw new Error(`bundle: ${packageJsonPath} has no valid "version" field`);
  }
  cachedRuntimeVersion = pkg.version;
  return cachedRuntimeVersion;
}

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@khaliqgant
khaliqgant merged commit 6186b94 into main Jul 15, 2026
3 checks passed
@khaliqgant
khaliqgant deleted the fix/deploy-runtime-exact-pin branch July 15, 2026 08:27
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