subagent: seed inherited policy events at creation
The parent implementation introduced sandboxMode and approvalPolicy as generic SessionHeader fields, then propagated those fields through both persistence backends, session-query indexes, collision checks, policy-specific seed-boundary folds, catalogs, and a broad test matrix. That storage plane is unnecessary: Session already accepts a validated constructor seed, and persistence captures that seed when the session is announced before committing its first batch. Capture each parent override synchronously at delegation, append source-tagged sandbox/mode and approval/policy records after the optional fork prefix, and create the child with that combined seed. Keeping header.seedLength at the original fork-prefix length preserves lineage while ordinary last-event-wins folds make the inherited records outrank stale parent history and remain subordinate to later child switches. Unswitched parents still stamp nothing, so children continue to follow deployment defaults. Remove the generic header fields and every persistence/query/schema branch built around them. Collapse the inheritance suite from ten leaking scenarios to four owned-context cases covering real filesystem confinement, stale fork precedence, delegation-time capture, and the no-override path. The assembled headless snapshot now asserts the persisted inheritance event directly. This keeps the security behavior while restoring policy ownership to the existing event log and deleting the speculative durability machinery that the original tests did not exercise.
This commit is contained in:
@@ -102,17 +102,28 @@ export async function startInProcessRun(
|
||||
subagentDepth: childDepth,
|
||||
}
|
||||
|
||||
// Policy inheritance: capture the parent's sandbox/approval OVERRIDES
|
||||
// synchronously, before the first await — the delegation moment is the
|
||||
// semantic snapshot point, and a parent switch racing the child's
|
||||
// asynchronous creation must belong to the parent's future, not the child.
|
||||
// The captured values ride the child's creation meta into its immutable
|
||||
// header, so the baseline is durable from the moment the session exists —
|
||||
// no first-turn event could survive every crash window (an idle injection
|
||||
// can persist a complete turn before any prompt turn opens). Both services
|
||||
// are consumed opportunistically — without them, delegation is policy-free.
|
||||
// Capture before the first await: a later parent switch belongs to the
|
||||
// parent's future. Appending after the fork prefix makes the captured
|
||||
// values the child's initial overrides without another storage plane.
|
||||
const inheritedMode = parent.ctx.get('sandboxPolicy')?.overrideOf(parent.session)
|
||||
const inheritedPolicy = parent.ctx.get('approval')?.overrideOf(parent.session)
|
||||
const seed: SessionEvent[] = [...options.seed ?? []]
|
||||
if (inheritedMode !== undefined) {
|
||||
seed.push({
|
||||
type: 'sandbox/mode',
|
||||
seq: seed.length,
|
||||
time: Date.now(),
|
||||
data: { mode: inheritedMode, source: 'delegation' },
|
||||
})
|
||||
}
|
||||
if (inheritedPolicy !== undefined) {
|
||||
seed.push({
|
||||
type: 'approval/policy',
|
||||
seq: seed.length,
|
||||
time: Date.now(),
|
||||
data: { policy: inheritedPolicy, source: 'delegation' },
|
||||
})
|
||||
}
|
||||
|
||||
let structured: StructuredAttachment | undefined
|
||||
const setup = (childCtx: Context): void => {
|
||||
@@ -134,10 +145,8 @@ export async function startInProcessRun(
|
||||
// Durable: the recursion budget must survive persistence and resume.
|
||||
delegationDepth: childDepth,
|
||||
...seedLength > 0 ? { seedLength } : {},
|
||||
...inheritedMode !== undefined ? { sandboxMode: inheritedMode } : {},
|
||||
...inheritedPolicy !== undefined ? { approvalPolicy: inheritedPolicy } : {},
|
||||
},
|
||||
...options.seed !== undefined ? { seed: options.seed } : {},
|
||||
...(options.seed !== undefined || seed.length > 0) ? { seed } : {},
|
||||
agentOptions,
|
||||
signal: request.signal,
|
||||
setup,
|
||||
|
||||
Reference in New Issue
Block a user