Skip to content

test(control-plane): accept running status in waitForSandboxSpawn#651

Merged
ColeMurray merged 1 commit into
mainfrom
test/wait-for-sandbox-spawn-running
May 17, 2026
Merged

test(control-plane): accept running status in waitForSandboxSpawn#651
ColeMurray merged 1 commit into
mainfrom
test/wait-for-sandbox-spawn-running

Conversation

@ColeMurray
Copy link
Copy Markdown
Owner

@ColeMurray ColeMurray commented May 17, 2026

Summary

Follow-up to #643. The waitForSandboxSpawn helper polls for
status = 'connecting' every 10ms (1s deadline), but with the fetch
mock installed in #643 the createSandbox response resolves
synchronously — so on a fast runner the connecting → running
transition can complete between two polls. The loop would never
observe connecting, then throw "Timed out waiting for sandbox spawn".

This was the residual race I flagged at review time. Broadening the
predicate to accept either connecting or running removes it —
both states indicate the spawn has progressed past init, which is the
actual precondition the cancel test needs before driving
status = 'active'.

-    if (rows[0]?.status === "connecting") {
+    const status = rows[0]?.status;
+    if (status === "connecting" || status === "running") {
       return;
     }

Test plan

  • npm run test:integration -w @open-inspect/control-plane -- test/integration/do-internal-routes.test.ts passes locally.
  • Ran the test file 30 times in a loop — 30/30 green.
  • npm run typecheck -w @open-inspect/control-plane clean.
  • npm run lint -w @open-inspect/control-plane clean.
  • npx prettier --check clean.

Summary by CodeRabbit

  • Tests
    • Improved integration test reliability by updating sandbox readiness detection to recognize additional valid states before proceeding with test execution.

Review Change Stack

The helper polls for status='connecting' every 10ms, but with the
fetch mock installed in #643 the createSandbox response now resolves
synchronously, so the connecting -> running transition can complete
between polls. On a fast runner the loop would never observe
'connecting' and would throw "Timed out waiting for sandbox spawn"
after 1s.

Broaden the predicate to accept either 'connecting' or 'running' —
both indicate the spawn has progressed past init, which is the
precondition the cancel test actually needs.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

This PR updates the sandbox spawn detection logic in an integration test. The waitForSandboxSpawn polling helper is modified to recognize both "connecting" and "running" sandbox states as successful spawn conditions, broadening the readiness criteria before proceeding to cancel a session.

Changes

Sandbox Spawn Detection

Layer / File(s) Summary
Sandbox spawn readiness condition
packages/control-plane/test/integration/do-internal-routes.test.ts
waitForSandboxSpawn polling logic now returns on sandbox status "connecting" or "running" instead of only "connecting", expanding the test's spawn completion criteria.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • ColeMurray/background-agents#643: Earlier PR that introduced the waitForSandboxSpawn polling logic for the cancel integration test; this PR expands its readiness condition to include the "running" state.

Suggested reviewers

  • open-inspect

Poem

🐰 A sandbox that connects or runs with glee,
Now either state will set the test free,
No more waiting in vain for just one way—
Two paths to readiness save the test day! 🎉

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating waitForSandboxSpawn to accept 'running' status in addition to 'connecting', which is the core modification to the polling logic.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/wait-for-sandbox-spawn-running

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 and usage tips.

@github-actions
Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

Copy link
Copy Markdown
Contributor

@open-inspect open-inspect Bot left a comment

Choose a reason for hiding this comment

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

Summary

PR #651, test(control-plane): accept running status in waitForSandboxSpawn, by @ColeMurray updates one control-plane integration test helper to treat both connecting and running sandbox statuses as sufficient progress. The change is narrowly scoped and correctly removes a polling race introduced by the synchronous fetch mock.

Files changed: 1, additions/deletions: +2/-1.

Critical Issues

None.

Suggestions

None.

Nitpicks

None.

Positive Feedback

  • The helper now waits for the actual test precondition: a sandbox spawn that has progressed past initial creation, rather than one transient intermediate status.
  • The change is minimal and keeps the polling logic easy to read.
  • This should reduce integration test flakiness without weakening the cancel-path assertion.

Questions

None.

Verdict

Approve: Ready to merge.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/control-plane/test/integration/do-internal-routes.test.ts (1)

36-36: ⚡ Quick win

Define timeout values as named constants with unit suffixes.

The timeout values 1000 (line 36) and 10 (line 44) are hardcoded literals. As per coding guidelines, TypeScript timeouts should be defined as named constants with millisecond units in the variable name (e.g., TIMEOUT_MS), and each default timeout should be defined exactly once rather than restated.

♻️ Refactor to use named constants

Add constants at the top of the file or in a shared constants module:

+const SANDBOX_SPAWN_TIMEOUT_MS = 1000;
+const SANDBOX_POLL_INTERVAL_MS = 10;
+
 async function waitForSandboxSpawn(stub: DurableObjectStub): Promise<void> {
-  const deadline = Date.now() + 1000;
+  const deadline = Date.now() + SANDBOX_SPAWN_TIMEOUT_MS;

   while (Date.now() < deadline) {
     const rows = await queryDO<{ status: string }>(stub, "SELECT status FROM sandbox LIMIT 1");
     const status = rows[0]?.status;
     if (status === "connecting" || status === "running") {
       return;
     }
-    await new Promise((resolve) => setTimeout(resolve, 10));
+    await new Promise((resolve) => setTimeout(resolve, SANDBOX_POLL_INTERVAL_MS));
   }

As per coding guidelines: "Use seconds for Python timeouts and milliseconds for TypeScript timeouts, encoding the unit in variable names (Python: timeout_seconds, TypeScript: timeoutMs, TIMEOUT_MS)" and "Define each default timeout value exactly once as a named constant and import it everywhere rather than restating literal values".

Also applies to: 44-44

🤖 Prompt for 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.

In `@packages/control-plane/test/integration/do-internal-routes.test.ts` at line
36, Replace the hardcoded numeric timeout literals with named millisecond
constants: introduce a top-level constant like DEFAULT_TIMEOUT_MS = 1000 (or
TIMEOUT_1S_MS) and another constant for the other literal (e.g.,
SHORT_TIMEOUT_MS = 10_000 if that 10 was seconds or SHORT_TIMEOUT_MS = 10 if it
truly is ms) and use those instead of the raw numbers where the test sets
deadline (variable deadline) and the other timeout occurrence (the literal 10).
Update the test to compute deadline using DEFAULT_TIMEOUT_MS (e.g., const
deadline = Date.now() + DEFAULT_TIMEOUT_MS) and replace the other raw 10 with
the corresponding named constant so each default timeout value is defined once
and reused.
🤖 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.

Nitpick comments:
In `@packages/control-plane/test/integration/do-internal-routes.test.ts`:
- Line 36: Replace the hardcoded numeric timeout literals with named millisecond
constants: introduce a top-level constant like DEFAULT_TIMEOUT_MS = 1000 (or
TIMEOUT_1S_MS) and another constant for the other literal (e.g.,
SHORT_TIMEOUT_MS = 10_000 if that 10 was seconds or SHORT_TIMEOUT_MS = 10 if it
truly is ms) and use those instead of the raw numbers where the test sets
deadline (variable deadline) and the other timeout occurrence (the literal 10).
Update the test to compute deadline using DEFAULT_TIMEOUT_MS (e.g., const
deadline = Date.now() + DEFAULT_TIMEOUT_MS) and replace the other raw 10 with
the corresponding named constant so each default timeout value is defined once
and reused.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12996bcb-1589-4c98-9dd8-ecb79792d8ba

📥 Commits

Reviewing files that changed from the base of the PR and between e735131 and 1c1c07a.

📒 Files selected for processing (1)
  • packages/control-plane/test/integration/do-internal-routes.test.ts

@ColeMurray ColeMurray merged commit 1bc52ad into main May 17, 2026
18 checks passed
@ColeMurray ColeMurray deleted the test/wait-for-sandbox-spawn-running branch May 17, 2026 06:06
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