fix: Prevent permission cards from being lost on PromptBar open

- Connect WebSocket BEFORE loading history to catch real-time permissions
- loadHistory() now preserves unresolved intervention cards
- loadPendingPermissions() runs AFTER loadHistory() to avoid race condition
This commit is contained in:
2026-02-16 01:46:10 -06:00
parent 6633a61ee4
commit 5a4192ac2f

View File

@@ -561,6 +561,9 @@ async function loadHistory(sessionId?: string) {
const data = await res.json() const data = await res.json()
activeSessionId.value = data.sessionId || null activeSessionId.value = data.sessionId || null
// Preserve unresolved intervention cards (permissions, questions, plans)
const pendingInterventions = messages.filter(m => m.intervention && !m.intervention.resolved)
messages.length = 0 messages.length = 0
idCounter = 0 idCounter = 0
@@ -575,6 +578,14 @@ async function loadHistory(sessionId?: string) {
}) })
} }
// Re-add preserved intervention cards at the end
for (const intv of pendingInterventions) {
const rid = intv.intervention?.requestId
if (rid && messages.some(m => m.intervention?.requestId === rid)) continue
intv.id = ++idCounter
messages.push(intv)
}
// Extract session stats // Extract session stats
if (data.model || data.stats) { if (data.model || data.stats) {
sessionStats.value = { sessionStats.value = {
@@ -680,18 +691,19 @@ watch(() => props.visible, async (v) => {
console.log('[PromptBar] Opening for agent:', props.agent.id) console.log('[PromptBar] Opening for agent:', props.agent.id)
// Load real conversation history + sessions list + global stats + usage // Connect WebSocket FIRST so real-time permission messages aren't missed
await Promise.all([loadHistory(), fetchSessions(), fetchClaudeStats(), fetchClaudeUsage(), loadPendingPermissions()])
console.log('[PromptBar] Loaded', messages.length, 'messages, sessions:', sessions.value.length)
// Connect WebSocket for real-time updates
connectWs() connectWs()
// Connect agent terminal (lazy)
agentTerminal.connect() agentTerminal.connect()
agentTerminal.checkStatus() agentTerminal.checkStatus()
// Load history + stats (loadHistory preserves any intervention cards added by WS)
await Promise.all([loadHistory(), fetchSessions(), fetchClaudeStats(), fetchClaudeUsage()])
// Load pending permissions AFTER history so they aren't wiped
await loadPendingPermissions()
console.log('[PromptBar] Loaded', messages.length, 'messages, sessions:', sessions.value.length)
await voice.init() await voice.init()
await nextTick() await nextTick()
if (props.startRecording) { if (props.startRecording) {