Skip to content

refactor: simplify sandbox resource-settings helpers (#693 follow-up)#720

Merged
ColeMurray merged 2 commits into
mainfrom
refactor/sandbox-settings-followup
Jun 9, 2026
Merged

refactor: simplify sandbox resource-settings helpers (#693 follow-up)#720
ColeMurray merged 2 commits into
mainfrom
refactor/sandbox-settings-followup

Conversation

@ColeMurray

@ColeMurray ColeMurray commented Jun 9, 2026

Copy link
Copy Markdown
Owner

What

Follow-up cleanup to #693 (configurable Modal sandbox CPU/memory). Two behavior-preserving changes:

  • web (sandbox-settings.tsx): the cpu/memory override logic was implemented with a heavier, parallel mechanism than the adjacent child-session-limit fields — four helpers including a 7-argument applyResourcePayload and a 3-field intermediate object. Collapsed to two small helpers (resourceDisplayValue, resourcePayloadValue); the inherit / explicit-override / explicit-null (provider-default) tri-state is unchanged.
  • control-plane (integration-settings.test.ts): added a regression test pinning the getResolvedConfig merge-time normalizeSandboxSettings pass.

Why

The resource fields and the child-session-limit fields solve the same inheritance-guard problem; #693 introduced a second, heavier pattern for it. This narrows them and removes the bespoke indirection (net −47 lines).

The regression test closes a gap: the merge-time normalize in getResolvedConfig is the only enforcement of maxConcurrent <= maxTotal when the global defaults and the repo override are each individually valid but the merged result is not. It had no committed test, so a future refactor could silently drop it. The test is mutation-verified (it fails if that normalize pass is removed).

Behavior

No behavior change. The prior !== undefined reasoning relies on stored JSON values never being undefined, so an inherited-only field is skipped and an explicit null override is preserved — exactly as before. Modal's _resource_kwargs mapping and every normalization pass are untouched.

Testing

  • web: 25/25 sandbox-settings tests pass unchanged
  • control-plane: integration-settings unit suite passes, +1 new regression test (mutation-verified)
  • typecheck clean (against real shared types), eslint clean

Summary by CodeRabbit

  • Tests

    • Added a sandbox integration test that verifies config normalization handles cross-field validation after merging defaults and overrides.
    • Ensures invalid inverted concurrent/total limit cases are dropped by the merged configuration.
  • Refactor

    • Improved resource override/inheritance handling for CPU and memory in sandbox settings.
    • Updated editor logic to correctly display values and persist payloads while preserving prior override semantics.

Follow-up cleanup to #693. Two behavior-preserving changes:

- web: the cpu/memory override logic duplicated the inheritance-guard with a
  heavier, parallel mechanism (four helpers incl. a 7-arg function) than the
  adjacent child-session fields. Collapsed to two small helpers; the
  inherit/override/null tri-state is unchanged. All 25 existing sandbox-settings
  tests pass as-is.

- control-plane: added a regression test pinning the getResolvedConfig
  merge-time normalizeSandboxSettings pass -- the only enforcement of
  maxConcurrent <= maxTotal when global and repo settings are each individually
  valid but the merged result is not.

No behavior change. Modal mapping and all normalization passes untouched.
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d97f16e2-5701-405f-af4c-a429838b548a

📥 Commits

Reviewing files that changed from the base of the PR and between 4a60e49 and eb4c418.

📒 Files selected for processing (1)
  • packages/web/src/components/settings/sandbox-settings.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/components/settings/sandbox-settings.tsx

📝 Walkthrough

Walkthrough

This PR adds a regression test for sandbox config normalization and refactors resource (CPU cores, memory) override handling in the settings editor with new semantic helpers distinguishing inheritance (undefined) from explicit defaults (null).

Changes

Config Normalization Test

Layer / File(s) Summary
Normalization violation regression test
packages/control-plane/src/db/integration-settings.test.ts
New sandbox integration test verifies getResolvedConfig normalizes the merged config when global maxConcurrentChildSessions and repo maxTotalChildSessions create an invalid concurrent-exceeds-total state, ensuring only the valid total limit remains.

Resource Override/Inheritance Refactor

Layer / File(s) Summary
Resource display and payload helpers
packages/web/src/components/settings/sandbox-settings.tsx
New helpers (numOrUndef, resourceDisplayValue, resourcePayloadValue) replace prior utilities to compute displayed and persisted resource values, with explicit undefined vs null semantics. Component display values (currentCpuCores, currentMemoryMib) now use the display helper.
Payload persistence and dependency correction
packages/web/src/components/settings/sandbox-settings.tsx
handleSave now builds resource payload via resourcePayloadValue (preserving prior overrides and omitting undefined values), and the hook dependency list now includes repoSettings?.cpuCores and repoSettings?.memoryMib.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ColeMurray/background-agents#670: Both PRs add tests around maxConcurrentChildSessions/maxTotalChildSessions validation and invalid "concurrent > total" case normalization.
  • ColeMurray/background-agents#693: The normalization test validates the normalizeSandboxSettings behavior introduced in that PR's getResolvedConfig logic.

Poem

🐰 I hopped through code to catch a merge-time slip,
A test that finds when limits cross and flip,
Helpers now choose what to show and save,
Omit to inherit, or null if you gave,
I nibble bugs and leave the settings crisp.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: refactoring sandbox resource-settings helpers as a follow-up to a previous PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 refactor/sandbox-settings-followup

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

github-actions Bot commented Jun 9, 2026

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

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

Summary

Reviewed PR #720, refactor: simplify sandbox resource-settings helpers (#693 follow-up) by ColeMurray. The PR changes 2 files with 45 additions and 92 deletions, simplifying the web sandbox resource helper flow and adding a control-plane regression test for merge-time sandbox normalization.

Critical Issues

None found.

Suggestions

None.

Nitpicks

None.

Positive Feedback

The resource helper refactor keeps the repo/global tri-state behavior compact while preserving the important distinction between inherited values, explicit numeric overrides, and explicit null provider-default overrides.

The new control-plane regression test targets a subtle merge-only invariant and clearly documents why the resolve-time normalization pass is necessary.

Targeted verification passed: web sandbox settings tests passed (25/25) and control-plane integration settings tests passed (87/87).

Questions

None.

Verdict

Approve: ready to merge.

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

[deep review] No blocking maintainability findings. This follow-up deletes a heavier resource-settings helper structure without adding new branching, keeps the tri-state repo/global behavior covered by existing tests, and the new control-plane regression test is placed at the merge boundary it is pinning. Focused tests passed locally: npm test -w @open-inspect/web -- sandbox-settings.test.tsx and npm test -w @open-inspect/control-plane -- integration-settings.test.ts sandbox/settings.test.ts.

@github-actions

github-actions Bot commented Jun 9, 2026

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

@ColeMurray ColeMurray merged commit e351684 into main Jun 9, 2026
18 checks passed
@ColeMurray ColeMurray deleted the refactor/sandbox-settings-followup branch June 9, 2026 06:10
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