Skip to content

Sandbox tier selection and session-to-sandbox affinity in selectPoolSandbox (P6-on-K8s slice 3) #425

Closed

Description

@pdettori

Slice 3 of the P6-on-Kubernetes epic: sandbox tier selection and session-to-sandbox affinity

Part of epic #426. Written so a planner can start it in a fresh session. This is not specific to Kubernetes: the VM path (deploy/vm + deploy/microvm) hits the same limits as soon as it has more than one P4 host or mixes tiers. It is the only slice that changes the harness.

Problem

selectPoolSandbox (harness/src/select-sandbox.ts) selects again on every turn: the least-loaded presence record under the soft cap, from all of the relay's records. Two things follow.

  1. No tier. A record carries only sandboxId, capabilities and capacityMax; session.Config has no labels. Container sandboxes and P4 microVM workers therefore cannot share a relay without a session's turns moving between tiers (deploy/microvm/P4-ON-P6.md, "A P4-only host": "Choosing the tier per session ... is not built").
  2. No affinity. P4 keeps a session's workspace at SH_WORKSPACE_ROOT/<session id> on the worker host (select-sandbox.ts:446-456). With more than one P4 worker, turn N+1 can land on a host with no workspace for that session. So P4 cannot scale horizontally.

Scope (for the design to settle)

  • Tier label on presence records: carried in the worker's Hello (or derived from capabilities), stored by the relay in sh:sandbox:records, and filtered on in selectPoolSandbox.
  • Choosing the tier: a session attribute set at creation (control plane / mocactl), a deployment default, or both. Decide what happens to an existing session when its tier's capacity is gone: wait, 429, or fail.
  • Session-to-sandbox affinity: prefer the sandbox that served the session's previous turn. Decide what happens when it is saturated or gone: queue, 429, or fall back with a recorded workspace loss. Keep concurrent turns of one session consistent (holderId vs sessionId, select-sandbox.ts:384-389). A shared workspace store is the alternative to affinity; compare the two in the design.
  • Leases and records: affinity must survive a relay restart, when every worker reattaches.

Acceptance

  • One relay with both container sandboxes and P4 workers attached: every turn of a P4 session lands on P4, every turn of a container session lands on a container, and nothing silently moves between tiers.
  • Two P4 workers: a session's turn 2 sees turn 1's files across many sessions, and load still spreads across hosts.
  • The "one tier per host" caveat in P4-ON-P6.md and the slice-2 single-host limit are removed or rewritten.

Activity

  1. added
    enhancement
    on Oct 2, 2026
  2. 21 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions