Files
opencode-manager/backend/src/services/session-ancestry.ts
T
Chris Scott b21fdf5b94 feat(sandbox): per-session sandbox VMs with resource settings and provider arbitration
- Sandbox new root sessions by default with a per-session composer toggle;
  child sessions inherit their root session's mode (OM-82)
- Run each sandboxed root session in its own microVM that mounts only the
  session's repository, with per-session CPU/memory overrides, Settings
  defaults, idle stop, and a cap on running VMs (OM-89)
- Arbitrate shell sandboxing with other plugins (opencode-forge) through the
  shared opencode.sandbox-arbiter.v1 registry so exactly one provider
  sandboxes each call regardless of load order; fail closed on claim errors
- Throw when another plugin rewrites a pinned sandbox shell setting
- Tag sandboxed tool results with the owning provider and show it in the badge
- Hint the agent to start Docker inside the VM only when OCM owns the session
2026-10-15 16:53:49 -04:00

43 lines
1.2 KiB
TypeScript

import type { OpenCodeClient } from './opencode/client'
const MAX_PARENT_HOPS = 10
export class SessionAncestry {
private readonly parentBySession = new Map<string, string | null>()
constructor(private readonly openCodeClient: OpenCodeClient) {}
rememberParent(sessionId: string, parentId: string | null | undefined): void {
this.parentBySession.set(sessionId, parentId ?? null)
}
forget(sessionId: string): void {
this.parentBySession.delete(sessionId)
}
async resolveRootSessionId(sessionId: string): Promise<string> {
let current = sessionId
for (let hops = 0; hops < MAX_PARENT_HOPS; hops += 1) {
const parentId = await this.getParentId(current)
if (!parentId) {
return current
}
current = parentId
}
return current
}
private async getParentId(sessionId: string): Promise<string | null> {
if (this.parentBySession.has(sessionId)) {
return this.parentBySession.get(sessionId) ?? null
}
const session = await this.openCodeClient.api.session.get({ sessionID: sessionId })
const parentId = session.parentID ?? null
this.parentBySession.set(sessionId, parentId)
return parentId
}
}