fix(cli-run): set default timeout to 10 minutes and attach immediate .catch() on event processor
DEFAULT_TIMEOUT_MS was 0 (no timeout), causing opencode run to hang forever if the session never completed. Also attached .catch() to processEvents() immediately to prevent unhandled promise rejections before Promise.race.
This commit is contained in:
parent
25c7337fd1
commit
c677042f05
@ -11,7 +11,7 @@ import { pollForCompletion } from "./poll-for-completion"
|
|||||||
|
|
||||||
export { resolveRunAgent }
|
export { resolveRunAgent }
|
||||||
|
|
||||||
const DEFAULT_TIMEOUT_MS = 0
|
const DEFAULT_TIMEOUT_MS = 600_000
|
||||||
|
|
||||||
export async function run(options: RunOptions): Promise<number> {
|
export async function run(options: RunOptions): Promise<number> {
|
||||||
process.env.OPENCODE_CLI_RUN_MODE = "true"
|
process.env.OPENCODE_CLI_RUN_MODE = "true"
|
||||||
@ -67,7 +67,9 @@ export async function run(options: RunOptions): Promise<number> {
|
|||||||
const ctx: RunContext = { client, sessionID, directory, abortController }
|
const ctx: RunContext = { client, sessionID, directory, abortController }
|
||||||
const events = await client.event.subscribe()
|
const events = await client.event.subscribe()
|
||||||
const eventState = createEventState()
|
const eventState = createEventState()
|
||||||
const eventProcessor = processEvents(ctx, events.stream, eventState)
|
const eventProcessor = processEvents(ctx, events.stream, eventState).catch(
|
||||||
|
() => {},
|
||||||
|
)
|
||||||
|
|
||||||
console.log(pc.dim("\nSending prompt..."))
|
console.log(pc.dim("\nSending prompt..."))
|
||||||
await client.session.promptAsync({
|
await client.session.promptAsync({
|
||||||
@ -85,7 +87,7 @@ export async function run(options: RunOptions): Promise<number> {
|
|||||||
// Abort the event stream to stop the processor
|
// Abort the event stream to stop the processor
|
||||||
abortController.abort()
|
abortController.abort()
|
||||||
|
|
||||||
await eventProcessor.catch(() => {})
|
await eventProcessor
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
const durationMs = Date.now() - startTime
|
const durationMs = Date.now() - startTime
|
||||||
@ -126,4 +128,3 @@ export async function run(options: RunOptions): Promise<number> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user