Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): forceFresh 在 kill 后等待 session 真正终止再重建

yand814813e9688
diff --git a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
index 9cc376c134..0413e8f734 100644
--- a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
@@ -81,6 +81,11 @@ describe('remoteCcQueryFactory cleanup wiring', () => {
ccManagerClientSource.indexOf('const existing =', killFirst),
);
expect(killForFreshBlock).not.toContain('.catch(() => undefined)');
+ // greptile P1 回归②:registry.kill 对 alive session 是异步终止
+ // (consume loop 退出后才移除) — kill 响应后必须轮询 list 确认不再
+ // alive 才放行 start, 否则同撞 ALREADY_EXISTS。
+ expect(killForFreshBlock).toContain('METHODS.SESSION_LIST');
+ expect(killForFreshBlock).toContain('stillAlive');
});
it('clears forced-fresh tracking when the bridge instance is rebuilt', () => {
diff --git a/apps/desktop/src/main/maker-host/cc-manager-client.ts b/apps/desktop/src/main/maker-host/cc-manager-client.ts
index 9550b2019d..1a38d13918 100644
--- a/apps/desktop/src/main/maker-host/cc-manager-client.ts
+++ b/apps/desktop/src/main/maker-host/cc-manager-client.ts
@@ -392,6 +392,26 @@ export async function openCcManagerSession(opts: {
{ sessionId: opts.sessionId },
{ timeoutMs: RPC_REQUEST_TIMEOUT_MS },
);
+ // registry.kill 对 alive session 是异步终止 (interrupt + inputQueue
+ // .end, consume loop 退出后才从注册表移除, 见 maker-cc-manager
+ // session-registry.ts) — kill 响应返回时 session 往往仍 alive,
+ // 立即 start 同样撞 SESSION_ALREADY_EXISTS (greptile P1)。轮询
+ // list 直到不再 alive;超时也上抛, 走同一"重试可恢复"路径。
+ const killWaitDeadline = Date.now() + 5_000;
+ for (;;) {
+ const after = await client.request<SessionListResult>(METHODS.SESSION_LIST, {}, {
+ timeoutMs: RPC_REQUEST_TIMEOUT_MS,
+ });
+ const stillAlive =
+ after.sessions.find((s) => s.sessionId === opts.sessionId)?.alive === true;
+ if (!stillAlive) break;
+ if (Date.now() > killWaitDeadline) {
+ throw new Error(
+ `cc-mgr: session ${opts.sessionId} still alive 5s after kill (forced fresh)`,
+ );
+ }
+ await new Promise((r) => setTimeout(r, 150));
+ }
log.info('cc-mgr: alive session killed for forced fresh start (bridge MCP re-inject)', {
hostId: opts.host.id,
sessionId: opts.sessionId,