fix(delegate-task): harden child-session fallback bootstrap and cleanup
Capture delegated child-session retry context before the first prompt so fallback recovery still works when session history is empty. Align background and sync launch paths around the same bootstrap contract, clear session-scoped fallback state on every terminal path, and lock the behavior with regression coverage for first-prompt retries, exhaustion, isolation, and cleanup. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { extractSessionMessages } from "./session-messages"
|
||||
import { getDelegatedChildSessionBootstrap } from "../../shared/delegated-child-session-bootstrap"
|
||||
|
||||
export function getLastUserRetryParts(
|
||||
messagesResponse: unknown,
|
||||
sessionID?: string,
|
||||
): Array<{ type: "text"; text: string }> {
|
||||
const messages = extractSessionMessages(messagesResponse)
|
||||
const lastUserMessage = messages?.filter((message) => message.info?.role === "user").pop()
|
||||
@@ -9,7 +11,7 @@ export function getLastUserRetryParts(
|
||||
lastUserMessage?.parts
|
||||
?? (lastUserMessage?.info?.parts as Array<{ type?: string; text?: string }> | undefined)
|
||||
|
||||
return (lastUserParts ?? [])
|
||||
const retryParts = (lastUserParts ?? [])
|
||||
.filter(
|
||||
(part): part is { type: "text"; text: string } =>
|
||||
part.type === "text"
|
||||
@@ -17,4 +19,12 @@ export function getLastUserRetryParts(
|
||||
&& part.text.length > 0,
|
||||
)
|
||||
.map((part) => ({ type: "text" as const, text: part.text }))
|
||||
|
||||
if (retryParts.length > 0) {
|
||||
return retryParts
|
||||
}
|
||||
|
||||
return sessionID
|
||||
? (getDelegatedChildSessionBootstrap(sessionID)?.retryParts ?? [])
|
||||
: []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user