Skip to content

Commit 372296a

Browse files
hahhforestclaude
andcommitted
fix: 修复集成测试中发现的两个 bug
1. saveToDisk 过滤 bug:新创建的空会话(无 sessionId)被持久化过滤器 跳过,导致 /reset 后重启服务会丢失新会话。改为保存 group 内所有 session。 2. /switch 未释放 persistent executor:切换会话时旧的长驻 Claude 进程 仍在运行,其 sessionId 会覆盖切换后的会话。现在 /switch 和 /session 命令都会调用 releaseExecutor。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9162ea5 commit 372296a

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/bridge/command-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ export class CommandHandler {
459459
}
460460
const success = this.sessionManager.switchSession(chatId, num - 1);
461461
if (success) {
462+
// Release persistent executor so the next message picks up the
463+
// switched session's sessionId instead of the old process's.
464+
try { await this.releaseExecutor(chatId, 'session-switch'); } catch {}
462465
const session = this.sessionManager.getSession(chatId);
463466
const sid = session.sessionId ? `\`${session.sessionId.slice(0, 8)}...\`` : '_new_';
464467
await this.sender.sendTextNotice(chatId, '✅ Switched', `Switched to session ${num} (${sid}).`, 'green');
@@ -477,6 +480,7 @@ export class CommandHandler {
477480
}
478481
const idx = this.sessionManager.switchToSessionByPrefix(chatId, prefix);
479482
if (idx >= 0) {
483+
try { await this.releaseExecutor(chatId, 'session-switch'); } catch {}
480484
const session = this.sessionManager.getSession(chatId);
481485
const sid = session.sessionId ? `\`${session.sessionId.slice(0, 8)}...\`` : '_new_';
482486
await this.sender.sendTextNotice(chatId, '✅ Switched',

src/engines/claude/session-manager.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,16 @@ export class SessionManager {
331331
try {
332332
const data: Record<string, PersistedSessionGroup> = {};
333333
for (const [chatId, group] of this.groups) {
334-
const persistedSessions = group.sessions
335-
.filter(s => s.sessionId || s.model || s.engine || s.activeGoal || s.title)
336-
.map(s => this.sessionToPersisted(s));
337-
if (persistedSessions.length > 0) {
338-
// Recalculate activeIndex after filtering
339-
const activeSession = group.sessions[group.activeIndex];
340-
const newActiveIndex = persistedSessions.findIndex(
341-
ps => ps.sessionId === (activeSession.sessionId || '') && ps.lastUsed === activeSession.lastUsed,
342-
);
334+
// Persist all sessions in a group — even new ones without a sessionId yet.
335+
// The group is the unit of persistence; filtering individual sessions
336+
// would lose newly-created (post-/reset) sessions before their first turn.
337+
const hasContent = group.sessions.some(
338+
s => s.sessionId || s.model || s.engine || s.activeGoal || s.title,
339+
);
340+
if (hasContent || group.sessions.length > 1) {
343341
data[chatId] = {
344-
activeIndex: Math.max(0, newActiveIndex),
345-
sessions: persistedSessions,
342+
activeIndex: group.activeIndex,
343+
sessions: group.sessions.map(s => this.sessionToPersisted(s)),
346344
};
347345
}
348346
}

0 commit comments

Comments
 (0)