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): gate remote Codex detach on daemon rebootstrap

yan6b6e1d747173
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 04efe8670d..1627ffb063 100644
--- a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
@@ -104,6 +104,27 @@ describe('remoteCcQueryFactory cleanup wiring', () => {
});
});
+describe('codex bridge shutdown strip detach gating (Greptile R30 P1)', () => {
+ it('detaches idle remote codex sessions only after strip reboots the daemon', () => {
+ const fnStart = source.indexOf('export function handleCodexEnvironmentShutdownForRemote');
+ expect(fnStart).toBeGreaterThan(-1);
+ const fnEnd = source.indexOf('export async function ensureCodexMcpBridgeStartedForRemote', fnStart);
+ expect(fnEnd).toBeGreaterThan(fnStart);
+ const body = source.slice(fnStart, fnEnd);
+
+ const stripCall = body.indexOf('stripRemoteCodexMcpConfig(host,');
+ expect(stripCall).toBeGreaterThan(-1);
+ const thenBlock = body.indexOf('.then((result) => {', stripCall);
+ expect(thenBlock).toBeGreaterThan(stripCall);
+ const gate = body.indexOf('if (!result.daemonRebootstrapped) return;', thenBlock);
+ expect(gate).toBeGreaterThan(thenBlock);
+ const detach = body.indexOf("detachActiveRemoteCodexSessions(hostId, 'bridge-shutdown-strip')", gate);
+ expect(detach).toBeGreaterThan(gate);
+ const detachCalls = body.match(/detachActiveRemoteCodexSessions\(hostId, 'bridge-shutdown-strip'\)/g) ?? [];
+ expect(detachCalls).toHaveLength(1);
+ });
+});
+
describe('remoteCcQueryFactory stale-invalidation freshness (R22 P2)', () => {
it('forces fresh for invalidated sessions even when nothing is injected this round', () => {
// collab 禁用等场景:invalidate 过的 session 重建时无 server 可注
diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.ts
index 52d219cac2..388acdcc19 100644
--- a/apps/desktop/src/main/maker-host/index.ts
+++ b/apps/desktop/src/main/maker-host/index.ts
@@ -359,11 +359,20 @@ export function handleCodexEnvironmentShutdownForRemote(): void {
if (host?.getStatus() !== 'ready') continue;
void stripRemoteCodexMcpConfig(host, {
hasLiveTurnOnHost: liveTurnChecker ?? undefined,
- });
- // strip 的 bootstrap (清 env 重启 daemon) 同样杀死旧 transport —
- // live-turn 豁免内已在 strip 里跳过, 这里 detach 剩余活跃 session
- // (codex-connector R26 P1 同源)。
- detachActiveRemoteCodexSessions(hostId, 'bridge-shutdown-strip');
+ })
+ .then((result) => {
+ if (!result.daemonRebootstrapped) return;
+ // strip 的 bootstrap (清 env 重启 daemon) 同样杀死旧 transport —
+ // live-turn 豁免内已在 strip 里跳过, 这里 detach 剩余活跃 session
+ // (codex-connector R26 P1 同源)。
+ detachActiveRemoteCodexSessions(hostId, 'bridge-shutdown-strip');
+ })
+ .catch((err) => {
+ desktopMakerLogger.warn('remote codex MCP strip on bridge shutdown failed', {
+ hostId,
+ error: err instanceof Error ? err.message : String(err),
+ });
+ });
}
}
diff --git a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts
index eb2104a5f8..a7374f37dd 100644
--- a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts
+++ b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts
@@ -1111,12 +1111,14 @@ describe('codex-connector R21 regressions', () => {
execCmds.length = 0;
// live turn 中 strip:整体跳过 (不写不重启)。
- await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => true });
+ const liveStrip = await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => true });
+ expect(liveStrip.daemonRebootstrapped).toBe(false);
expect(execCmds.join('\n')).not.toContain('base64 -d');
expect(execCmds.join('\n')).not.toContain('bootstrap');
// idle 后 strip:剥段 + bootstrap 清 env + applied 摘除。
- await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => false });
+ const idleStrip = await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => false });
+ expect(idleStrip.daemonRebootstrapped).toBe(true);
const joined = execCmds.join('\n');
expect(joined).toContain('base64 -d');
expect(joined).toContain('bootstrap');
diff --git a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts
index 2caeb582db..f1347631a9 100644
--- a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts
+++ b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts
@@ -74,6 +74,10 @@ export interface EnsureRemoteCodexMcpResult {
daemonRebootstrapped?: boolean;
}
+export interface StripRemoteCodexMcpConfigResult {
+ daemonRebootstrapped: boolean;
+}
+
// ── per-host 固定 remotePort 与已生效指纹持久化 ─────────────────────────────
type PortPrefs = Record<string, { remotePort: number; appliedFingerprint?: string; bridgeLocalPort?: number }>;
@@ -577,8 +581,8 @@ export function ensureRemoteMcpForward(
export function stripRemoteCodexMcpConfig(
host: RemoteHost,
deps?: { hasLiveTurnOnHost?: (hostId: string) => boolean },
-): Promise<void> {
- return withHostSerial(host.id, () => doStripRemoteCodexMcpConfig(host, deps)).then(() => undefined);
+): Promise<StripRemoteCodexMcpConfigResult> {
+ return withHostSerial(host.id, () => doStripRemoteCodexMcpConfig(host, deps));
}
/**
@@ -589,7 +593,7 @@ export function stripRemoteCodexMcpConfig(
async function doStripRemoteCodexMcpConfig(
host: RemoteHost,
deps?: { hasLiveTurnOnHost?: (hostId: string) => boolean },
-): Promise<{ daemonRebootstrapped: boolean }> {
+): Promise<StripRemoteCodexMcpConfigResult> {
{
try {
if (deps?.hasLiveTurnOnHost?.(host.id)) return { daemonRebootstrapped: false };