fix: wait for session idle after abort
Agent CI/CD / docker-image (push) Successful in 11s
Agent CI/CD / deploy-fallback-log (push) Has been skipped

This commit is contained in:
2026-05-20 17:17:26 +08:00
parent 0b5004fc2c
commit 6c53e12962
3 changed files with 48 additions and 0 deletions
+26
View File
@@ -92,6 +92,26 @@ export class OpencodeRuntimeAdapter {
return requireData(response.data, "session.abort");
}
async waitForSessionIdle(sessionId: string, timeoutMs = config.OPENCODE_TIMEOUT_MS) {
const client = await this.ensureClient();
const startedAt = Date.now();
while (Date.now() - startedAt < timeoutMs) {
const response = await client.session.status({});
const statuses = requireData(response.data, "session.status");
const status = statuses[sessionId];
if (!status || status.type === "idle") {
return;
}
await delay(100);
}
logger.warn(
{ sessionId, timeoutMs },
"timed out waiting for opencode session to become idle",
);
}
async subscribeEvents() {
const client = await this.ensureClient();
const response = await client.event.subscribe();
@@ -180,3 +200,9 @@ function requireData<T>(data: T | undefined, operation: string): T {
}
return data;
}
function delay(ms: number) {
return new Promise<void>((resolve) => {
setTimeout(resolve, ms);
});
}