Skip to content

fix(server): allocate sandbox stream buffers lazily and share events - #5408

Open
FrostGod wants to merge 1 commit into
mainfrom
fix/5399-shrink-sandbox-stream-buffers/FrostGod
Open

FrostGod wants to merge 1 commit into
mainfrom
fix/5399-shrink-sandbox-stream-buffers/FrostGod

Conversation

@FrostGod

@FrostGod FrostGod commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Per-sandbox log/event buffers no longer pre-allocate ~3.4 MiB per sandbox. The broadcast channel is created on first subscribe, and events are shared between the channel and the replay tail via Arc.

Related Issue

Closes #5399

Changes

  • PerSandbox.sender is created on first subscribe, not on first publish.
  • The channel and tail store Arc<CursoredEvent> instead of full copies.
  • WatchSandbox unwraps received events with Arc::unwrap_or_clone.

Release Notes

Gateway memory no longer grows by several MiB per sandbox that nobody is watching.

Testing

  • openshell-server fmt, clippy, and unit tests pass
  • Unit tests added/updated
  • E2E tests added/updated (if applicable)

Two create/delete cycles of 20 sandboxes on a single-replica Kubernetes gateway (RSS):

Phase Before After
Baseline 38.0 MiB 30.1 MiB
Cycle 1: 20 created 113.4 MiB (+75.4) 45.2 MiB (+15.1)
Cycle 1: all deleted, +2 min 115.1 MiB 48.0 MiB
Cycle 2: created 146.7 MiB (+31.6 for 8) 48.9 MiB (+0.9 for 20)
Cycle 2: all deleted, +2 min 146.7 MiB 49.7 MiB

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

…5399)

Create the per-sandbox broadcast channel on first subscribe instead of
first publish, and store events as Arc<CursoredEvent> shared by the
channel ring and the replay tail. An unwatched sandbox no longer holds
two pre-allocated 1024-slot rings sized for the full Sandbox payload.

Signed-off-by: divesh <dgude@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

This branch has not been deployed

No deployments
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.

bug(gateway): per-sandbox log/event buffers pre-allocate ~3.4 MiB even when idle

1 participant