perf(orchestrator): add IP index to sandbox map and remove status sta…#2429
perf(orchestrator): add IP index to sandbox map and remove status sta…#2429
Conversation
…te machine Replace the O(n) linear scan in GetByHostPort with an O(1) lookup via a secondary ipIndex map keyed by host IP string. Remove the SandboxStatus state machine (Starting/Running/Stopping), the status field on Sandbox, and IsRunning(). The map now uses two maps with clear roles: live (running sandboxes for Get/Items/Count) and ipIndex (IP reverse lookups). Remove takes *Sandbox directly through the cleanup closure instead of looking it up by ID. Rename MarkRunning -> Activate, MarkStopping -> Deactivate.
PR SummaryMedium Risk Overview Reviewed by Cursor Bugbot for commit f0c43a6. Bugbot is set up for automated code reviews on this repo. Configure here. |
| s.OnRemove(ctx, sbx) | ||
| }) | ||
| } | ||
| go m.trigger(ctx, func(ctx context.Context, s MapSubscriber) { |
There was a problem hiding this comment.
OnRemove is fired unconditionally, even when neither RemoveCb actually removed the sandbox. Previously guarded with if removed.
If sandbox creation fails between Insert (adds to ipIndex) and Activate (adds to live), cleanup calls Remove and OnRemove fires without a prior OnInsert. Subscribers maintaining paired insert/remove state receive an unmatched OnRemove.
Both RemoveCb calls return bool - the trigger should be conditional on either returning true.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f0c43a6. Configure here.
| } | ||
| go m.trigger(ctx, func(ctx context.Context, s MapSubscriber) { | ||
| s.OnRemove(ctx, sbx) | ||
| }) |
There was a problem hiding this comment.
Remove unconditionally fires OnRemove without checking removal
Medium Severity
Remove unconditionally fires OnRemove subscribers regardless of whether the sandbox was actually found and removed from ipIndex or live. The old code guarded this with if removed { ... }, only notifying subscribers when a removal actually occurred. Now, OnRemove can fire even when both RemoveCb calls are no-ops (pointer identity mismatch or sandbox not present), and can fire without a matching OnInsert (e.g., creation failed before Activate). This breaks the lifecycle contract for MapSubscriber.
Reviewed by Cursor Bugbot for commit f0c43a6. Configure here.


…te machine
Replace the O(n) linear scan in GetByHostPort with an O(1) lookup via a secondary ipIndex map keyed by host IP string.
Remove the SandboxStatus state machine (Starting/Running/Stopping), the status field on Sandbox, and IsRunning(). The map now uses two maps with clear roles: live (running sandboxes for Get/Items/Count) and ipIndex (IP reverse lookups). Remove takes *Sandbox directly through the cleanup closure instead of looking it up by ID.
Rename MarkRunning -> Activate, MarkStopping -> Deactivate.