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:
@@ -11,7 +11,7 @@ import { pollForCompletion } from "./poll-for-completion"
|
||||
|
||||
export { resolveRunAgent }
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 0
|
||||
const DEFAULT_TIMEOUT_MS = 600_000
|
||||
|
||||
export async function run(options: RunOptions): Promise<number> {
|
||||
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 events = await client.event.subscribe()
|
||||
const eventState = createEventState()
|
||||
const eventProcessor = processEvents(ctx, events.stream, eventState)
|
||||
const eventProcessor = processEvents(ctx, events.stream, eventState).catch(
|
||||
() => {},
|
||||
)
|
||||
|
||||
console.log(pc.dim("\nSending prompt..."))
|
||||
await client.session.promptAsync({
|
||||
@@ -85,7 +87,7 @@ export async function run(options: RunOptions): Promise<number> {
|
||||
// Abort the event stream to stop the processor
|
||||
abortController.abort()
|
||||
|
||||
await eventProcessor.catch(() => {})
|
||||
await eventProcessor
|
||||
cleanup()
|
||||
|
||||
const durationMs = Date.now() - startTime
|
||||
@@ -126,4 +128,3 @@ export async function run(options: RunOptions): Promise<number> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user