fix(cli): treat missing session status as idle in run completion
This commit is contained in:
@@ -235,6 +235,27 @@ describe("pollForCompletion", () => {
|
|||||||
expect(result).toBe(0)
|
expect(result).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("treats missing main session status as idle when status API omits idle sessions", async () => {
|
||||||
|
//#given - latest opencode omits idle sessions from the status map
|
||||||
|
const ctx = createMockContext({
|
||||||
|
statuses: {},
|
||||||
|
})
|
||||||
|
const eventState = createEventState()
|
||||||
|
eventState.mainSessionIdle = false
|
||||||
|
eventState.hasReceivedMeaningfulWork = true
|
||||||
|
const abortController = new AbortController()
|
||||||
|
|
||||||
|
//#when
|
||||||
|
const result = await pollForCompletion(ctx, eventState, abortController, {
|
||||||
|
pollIntervalMs: 10,
|
||||||
|
requiredConsecutive: 2,
|
||||||
|
minStabilizationMs: 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
//#then - missing entry is treated as idle instead of hanging forever
|
||||||
|
expect(result).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
it("allows silent completion after stabilization when no meaningful work is received", async () => {
|
it("allows silent completion after stabilization when no meaningful work is received", async () => {
|
||||||
//#given - session is idle and stable but no assistant message/tool event arrived
|
//#given - session is idle and stable but no assistant message/tool event arrived
|
||||||
const ctx = createMockContext()
|
const ctx = createMockContext()
|
||||||
|
|||||||
@@ -193,6 +193,9 @@ async function getMainSessionStatus(
|
|||||||
statusesRes,
|
statusesRes,
|
||||||
{} as Record<string, { type?: string }>
|
{} as Record<string, { type?: string }>
|
||||||
)
|
)
|
||||||
|
if (!(ctx.sessionID in statuses)) {
|
||||||
|
return "idle"
|
||||||
|
}
|
||||||
const status = statuses[ctx.sessionID]?.type
|
const status = statuses[ctx.sessionID]?.type
|
||||||
if (status === "idle" || status === "busy" || status === "retry") {
|
if (status === "idle" || status === "busy" || status === "retry") {
|
||||||
return status
|
return status
|
||||||
|
|||||||
Reference in New Issue
Block a user