Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/opencode/src/cli/cmd/tui/context/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export const { use: useSDK, provider: SDKProvider } = createSimpleContext({
const elapsed = Date.now() - last

if (timer) return
// If we just flushed recently (within 16ms), batch this with future events
// If we just flushed recently (within 50ms), batch this with future events
// Otherwise, process immediately to avoid latency
if (elapsed < 16) {
timer = setTimeout(flush, 16)
if (elapsed < 50) {
timer = setTimeout(flush, 50)
return
}
flush()
Expand Down
4 changes: 3 additions & 1 deletion packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ export namespace MCP {

const toolsResults = await Promise.all(
connectedClients.map(async ([clientName, client]) => {
const toolsResult = await client.listTools().catch((e) => {
const mcpEntry = config[clientName]
const timeout = (isMcpConfigured(mcpEntry) ? mcpEntry.timeout : undefined) ?? defaultTimeout ?? DEFAULT_TIMEOUT
const toolsResult = await withTimeout(client.listTools(), timeout).catch((e) => {
log.error("failed to get tools", { clientName, error: e.message })
const failedStatus = {
status: "failed" as const,
Expand Down
5 changes: 4 additions & 1 deletion packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export namespace SessionProcessor {
try {
let currentText: MessageV2.TextPart | undefined
let reasoningMap: Record<string, MessageV2.ReasoningPart> = {}
let finished = false
const stream = await LLM.stream(streamInput)

for await (const value of stream.fullStream) {
Expand Down Expand Up @@ -337,6 +338,8 @@ export namespace SessionProcessor {
break

case "finish":
log.info("stream finish event received")
finished = true
break

default:
Expand All @@ -345,7 +348,7 @@ export namespace SessionProcessor {
})
continue
}
if (needsCompaction) break
if (needsCompaction || finished) break
}
} catch (e: any) {
log.error("process", {
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/storage/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export namespace Database {
if (err instanceof Context.NotFound) {
const effects: (() => void | Promise<void>)[] = []
const result = ctx.provide({ effects, tx: Client() }, () => callback(Client()))
for (const effect of effects) effect()
for (const effect of effects) Promise.resolve(effect()).catch((e) => log.error("effect failed", { error: e }))
return result
}
throw err
Expand All @@ -146,7 +146,7 @@ export namespace Database {
const result = Client().transaction((tx) => {
return ctx.provide({ tx, effects }, () => callback(tx))
})
for (const effect of effects) effect()
for (const effect of effects) Promise.resolve(effect()).catch((e) => log.error("effect failed", { error: e }))
return result
}
throw err
Expand Down
Loading