fix(session): restore presence when sessions return

This commit is contained in:
creatixchu committed 2026-10-17 16:35:12 +08:00
1 parent eb8efe84e4
commit ca081d5658
7 files changed
+59 -9

No files matched your search

@@ -446,6 +446,7 @@ export class SessionManager {
for (const s of this.summaries) {
const session = this.sessions.get(s.sessionId)
if (session === undefined) continue
session.handlePresence(true)
session.handleBlank(this.effectiveBlank(s))
session.handleRunning(s.running)
}
@@ -667,6 +668,7 @@ export class SessionManager {
handleSessionAdded(summary: SessionSummary): void {
this.mergeSummary(summary)
if (!this.disposed && summary.running) this.engagedSessions.add(summary.sessionId)
this.sessions.get(summary.sessionId)?.handlePresence(true)
this.sessions.get(summary.sessionId)?.handleBlank(this.effectiveBlank(summary))
if (summary.projections !== undefined) this.applyListBlock(summary.sessionId, summary.projections)
}
@@ -706,7 +708,7 @@ export class SessionManager {
? { kind: 'status', sessionId, running: false, agentAvailable: false }
: { kind: 'remove', sessionId })
if (durableSubagent) this.sessions.get(sessionId)?.handleRunning(false)
else this.sessions.get(sessionId)?.handleRemoved()
else this.sessions.get(sessionId)?.handlePresence(false)
const catalog = this.projectionStores.get(sessionId)?.values().subagentCatalog
if (!durableSubagent && (catalog === undefined || catalog.length === 0)) {
this.projectionStores.delete(sessionId)
@@ -577,9 +577,13 @@ export class Session implements SessionFace {
this.notifier.markDirty()
}
/** `api-session/removed` relay: flag the snapshot while retaining the resident instance. */
handleRemoved(): void {
this.removed = true
/**
* Update Host membership while retaining the resident instance and its draft.
* @param present - Whether a current Host event or reconciled list contains this Session.
*/
handlePresence(present: boolean): void {
if (present === !this.removed) return
this.removed = !present
this.notifier.markDirty()
}