fix for session stuck in "Working..."

This commit is contained in:
Dax Raad
2025-08-13 16:29:07 -04:00
parent 703ae49675
commit 796bc390db
4 changed files with 24 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ import { Agent } from "../agent/agent"
import { Permission } from "../permission" import { Permission } from "../permission"
import { Wildcard } from "../util/wildcard" import { Wildcard } from "../util/wildcard"
import { ulid } from "ulid" import { ulid } from "ulid"
import { defer } from "../util/defer"
export namespace Session { export namespace Session {
const log = Log.create({ service: "session" }) const log = Log.create({ service: "session" })
@@ -763,6 +764,11 @@ export namespace Session {
sessionID: input.sessionID, sessionID: input.sessionID,
} }
await updateMessage(assistantMsg) await updateMessage(assistantMsg)
await using _ = defer(async () => {
if (assistantMsg.time.completed) return
await Storage.remove(`session/message/${input.sessionID}/${assistantMsg.id}`)
await Bus.publish(MessageV2.Event.Removed, { sessionID: input.sessionID, messageID: assistantMsg.id })
})
const tools: Record<string, AITool> = {} const tools: Record<string, AITool> = {}
const processor = createProcessor(assistantMsg, model.info) const processor = createProcessor(assistantMsg, model.info)

View File

@@ -0,0 +1,12 @@
export function defer<T extends () => void | Promise<void>>(
fn: T,
): T extends () => Promise<void> ? { [Symbol.asyncDispose]: () => Promise<void> } : { [Symbol.dispose]: () => void } {
return {
[Symbol.dispose]() {
fn()
},
[Symbol.asyncDispose]() {
return Promise.resolve(fn())
},
} as any
}

View File

@@ -631,7 +631,7 @@ func (a *App) IsBusy() bool {
if casted, ok := lastMessage.Info.(opencode.AssistantMessage); ok { if casted, ok := lastMessage.Info.(opencode.AssistantMessage); ok {
return casted.Time.Completed == 0 return casted.Time.Completed == 0
} }
return true return false
} }
func (a *App) SaveState() tea.Cmd { func (a *App) SaveState() tea.Cmd {

View File

@@ -203,6 +203,11 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.Properties.Part.SessionID == m.app.Session.ID { if msg.Properties.Part.SessionID == m.app.Session.ID {
cmds = append(cmds, m.renderView()) cmds = append(cmds, m.renderView())
} }
case opencode.EventListResponseEventMessageRemoved:
if msg.Properties.SessionID == m.app.Session.ID {
m.cache.Clear()
cmds = append(cmds, m.renderView())
}
case opencode.EventListResponseEventMessagePartRemoved: case opencode.EventListResponseEventMessagePartRemoved:
if msg.Properties.SessionID == m.app.Session.ID { if msg.Properties.SessionID == m.app.Session.ID {
// Clear the cache when a part is removed to ensure proper re-rendering // Clear the cache when a part is removed to ensure proper re-rendering