feat(atlas): integrate session origins into background launch tracking
- Update background-launch-session-tracking to track session origins
- Add tests for lineage-aware retry scheduling
- Update tool-execute-after to support new tracking
- Add comprehensive tests for background launch continuation
🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
@@ -19,25 +19,24 @@ export async function syncBackgroundLaunchSessionTracking(input: {
|
||||
return
|
||||
}
|
||||
|
||||
if (toolInput.sessionID && !boulderState.session_ids.includes(toolInput.sessionID)) {
|
||||
appendSessionId(ctx.directory, toolInput.sessionID)
|
||||
}
|
||||
|
||||
const extractedSessionId = metadataSessionId ?? extractSessionIdFromOutput(toolOutput.output)
|
||||
const lineageSessionIDs = toolInput.sessionID && !boulderState.session_ids.includes(toolInput.sessionID)
|
||||
? [...boulderState.session_ids, toolInput.sessionID]
|
||||
: boulderState.session_ids
|
||||
const lineageSessionIDs = boulderState.session_ids
|
||||
const subagentSessionId = await validateSubagentSessionId({
|
||||
client: ctx.client,
|
||||
sessionID: extractedSessionId,
|
||||
lineageSessionIDs,
|
||||
})
|
||||
|
||||
if (!subagentSessionId) {
|
||||
const trackedSessionId = subagentSessionId ?? await resolveFallbackTrackedSessionId({
|
||||
ctx,
|
||||
extractedSessionId,
|
||||
lineageSessionIDs,
|
||||
})
|
||||
if (!trackedSessionId) {
|
||||
return
|
||||
}
|
||||
|
||||
appendSessionId(ctx.directory, subagentSessionId)
|
||||
appendSessionId(ctx.directory, trackedSessionId, "appended")
|
||||
|
||||
const { currentTask, shouldSkipTaskSessionUpdate } = resolveTaskContext(
|
||||
pendingTaskRef,
|
||||
@@ -49,7 +48,7 @@ export async function syncBackgroundLaunchSessionTracking(input: {
|
||||
taskKey: currentTask.key,
|
||||
taskLabel: currentTask.label,
|
||||
taskTitle: currentTask.title,
|
||||
sessionId: subagentSessionId,
|
||||
sessionId: trackedSessionId,
|
||||
agent: typeof toolOutput.metadata?.agent === "string" ? toolOutput.metadata.agent : undefined,
|
||||
category: typeof toolOutput.metadata?.category === "string" ? toolOutput.metadata.category : undefined,
|
||||
})
|
||||
@@ -57,7 +56,42 @@ export async function syncBackgroundLaunchSessionTracking(input: {
|
||||
|
||||
log(`[${HOOK_NAME}] Background launch session tracked`, {
|
||||
sessionID: toolInput.sessionID,
|
||||
subagentSessionId,
|
||||
subagentSessionId: trackedSessionId,
|
||||
taskKey: currentTask?.key,
|
||||
})
|
||||
}
|
||||
|
||||
async function resolveFallbackTrackedSessionId(input: {
|
||||
ctx: PluginInput
|
||||
extractedSessionId?: string
|
||||
lineageSessionIDs: string[]
|
||||
}): Promise<string | undefined> {
|
||||
if (!input.extractedSessionId) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
try {
|
||||
const session = await input.ctx.client.session.get({ path: { id: input.extractedSessionId } })
|
||||
const parentSessionId = session.data?.parentID
|
||||
if (typeof parentSessionId === "string" && input.lineageSessionIDs.includes(parentSessionId)) {
|
||||
return input.extractedSessionId
|
||||
}
|
||||
return undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveSessionOrigin(
|
||||
ctx: PluginInput,
|
||||
sessionID: string,
|
||||
): Promise<"direct" | "appended"> {
|
||||
try {
|
||||
const session = await ctx.client.session.get({ path: { id: sessionID } })
|
||||
return typeof session.data?.parentID === "string" && session.data.parentID.length > 0
|
||||
? "appended"
|
||||
: "direct"
|
||||
} catch {
|
||||
return "appended"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user