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 降级方案纠正 + live send 漂移闸门 + worker 远端兼容闸

yan8a66e9f9026c
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 941d63e8d1..2da0aec6e9 100644
--- a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts
@@ -69,7 +69,7 @@ describe('remoteCcQueryFactory cleanup wiring', () => {
const killFirst = ccManagerClientSource.indexOf('killAliveForFresh');
expect(killFirst).toBeGreaterThan(-1);
const existingGuard = ccManagerClientSource.indexOf(
- 'listedSession?.alive && (!killAliveForFresh || !killSettled)',
+ 'listedSession?.alive && !killAliveForFresh',
);
expect(existingGuard).toBeGreaterThan(killFirst);
@@ -120,18 +120,17 @@ describe('remoteCcQueryFactory stale-invalidation freshness (R22 P2)', () => {
});
});
-describe('cc-manager-client forced-fresh kill settle (Greptile R22 P1)', () => {
- it('degrades to attach instead of hard-failing when kill does not settle in time', () => {
- // 固定期限的上抛会让恢复路径死锁 (重试只重复同样的 kill+超时) —
- // 超时必须降级 attach 仍在退出中的 query, 其自然终止后的下次 send
- // 按 dead 条目走正常 fresh start。
+describe('cc-manager-client forced-fresh kill settle (Greptile R22/R23 P1)', () => {
+ it('backs off the settle poll and never attaches to a kill-pending query (input would be silently dropped)', () => {
const client = ccManagerClientSource;
- // 退避轮询存在 (不再固定 150ms / 5s)。
+ // 退避轮询 (150ms→1s), 覆盖 SSH 大 RTT / SDK abort 慢。
expect(client).toContain('pollDelayMs');
- // 超时不再上抛固定期限错误。
- expect(client).not.toContain('still alive 5s after kill');
- // 降级 attach 的实现:killSettled=false 时 existing 仍取 alive 条目。
- expect(client).toContain('killSettled = false');
- expect(client).toContain('(!killAliveForFresh || !killSettled)');
+ // 超时必须上抛:attach 到 inputQueue 已 end 的 query 会静默吞掉用户
+ // 消息 (cc-mgr registry 注释实锤) — 降级 attach 路径不得存在。
+ expect(client).toContain('still alive 30s after kill');
+ expect(client).not.toContain('killSettled');
+ expect(client).not.toContain('still-terminating');
+ // 错误信息必须带可操作指引 (重试 / 重启远端 cc-mgr)。
+ expect(client).toContain('restart the remote');
});
});
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 45a5aaa1fb..1df71172d9 100644
--- a/apps/desktop/src/main/maker-host/cc-manager-client.ts
+++ b/apps/desktop/src/main/maker-host/cc-manager-client.ts
@@ -381,7 +381,6 @@ export async function openCcManagerSession(opts: {
// forceFreshQuery:alive 也 kill + fresh (bridge MCP 重启后首轮注入,
// 见 opts.forceFreshQuery 注释)。
const killAliveForFresh = listedSession?.alive === true && opts.forceFreshQuery === true;
- let killSettled = true;
if (killAliveForFresh) {
// kill 失败不得吞错继续 (greptile P1):旧 session 仍 alive 时 fresh
// start 必撞 SESSION_ALREADY_EXISTS, 且后续重试沿同一路径永久卡死。
@@ -398,12 +397,15 @@ export async function openCcManagerSession(opts: {
// session-registry.ts) — kill 响应返回时 session 往往仍 alive,
// 立即 start 同样撞 SESSION_ALREADY_EXISTS (greptile P1)。轮询
// list 直到不再 alive:退避 (150ms→1s) 覆盖慢退出 (SSH 大 RTT /
- // SDK abort 慢), 总预算 15s。
- // 超时不硬失败 (greptile R22 P1):固定期限的上抛会让恢复路径死锁 —
- // 重试只是重复同样的 kill+超时, 无法加速 consume loop 退出。降级为
- // attach 仍在退出中的 query:其自然终止后的下次 send 会按 dead
- // 条目走正常 fresh start, 恢复可能晚一拍但永不死锁。
- const killWaitDeadline = Date.now() + 15_000;
+ // SDK abort 慢), 总预算 30s。
+ // 超时只能上抛, 不得降级 attach (greptile R22/R23 P1):kill 已 end
+ // 输入队列, AsyncQueue.push 在 end 后静默丢弃 (cc-mgr registry 注释
+ // 实锤) — attach 仍在退出中的 query 会吞掉用户消息。慢退出场景由
+ // 调用方重试自然覆盖 (重试时 query 多已退出);consume loop 永不退出
+ // 是 daemon 病态, 任何客户端策略都无法恢复, 错误信息给出可操作
+ // 指引 (重启远端 cc-mgr)。fresh 状态不提交, 下次重试仍带
+ // forceFreshQuery。
+ const killWaitDeadline = Date.now() + 30_000;
let pollDelayMs = 150;
for (;;) {
const after = await client.request<SessionListResult>(METHODS.SESSION_LIST, {}, {
@@ -413,30 +415,22 @@ export async function openCcManagerSession(opts: {
after.sessions.find((s) => s.sessionId === opts.sessionId)?.alive === true;
if (!stillAlive) break;
if (Date.now() > killWaitDeadline) {
- killSettled = false;
- break;
+ throw new Error(
+ `cc-mgr: session ${opts.sessionId} still alive 30s after kill (forced fresh) — ` +
+ `the daemon's consume loop did not exit; retry shortly, or restart the remote ` +
+ `cc-mgr daemon if it persists (a wedged consume loop cannot be recovered from the client side)`,
+ );
}
await new Promise((r) => setTimeout(r, pollDelayMs));
pollDelayMs = Math.min(pollDelayMs * 2, 1_000);
}
- if (killSettled) {
- log.info('cc-mgr: alive session killed for forced fresh start (bridge MCP re-inject)', {
- hostId: opts.host.id,
- sessionId: opts.sessionId,
- daemonLastSeq: listedSession.lastSeq,
- });
- } else {
- log.warn(
- 'cc-mgr: kill not settled within 15s — attaching to the still-terminating query (fresh start deferred to its natural death)',
- {
- hostId: opts.host.id,
- sessionId: opts.sessionId,
- },
- );
- }
+ log.info('cc-mgr: alive session killed for forced fresh start (bridge MCP re-inject)', {
+ hostId: opts.host.id,
+ sessionId: opts.sessionId,
+ daemonLastSeq: listedSession.lastSeq,
+ });
}
- const existing =
- listedSession?.alive && (!killAliveForFresh || !killSettled) ? listedSession : undefined;
+ const existing = listedSession?.alive && !killAliveForFresh ? listedSession : undefined;
// 对齐 codex 模式: alive → attach live-only, dead/absent → fresh start。
// 不 replay 旧 events,不追踪 cursor。
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index 198ae2d807..8e0f30e4fc 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@ -1637,3 +1637,85 @@ describe('buildNoProviderMessage', () => {
});
});
});
+
+describe('SSH remote worker model/provider compatibility gate (R23 P2)', () => {
+ const remoteLeadRow = {
+ id: 'lead-1',
+ agentKind: 'codex' as const,
+ workingDir: '/srv/repo',
+ model: 'gpt-5.5',
+ effort: 'medium',
+ permissionMode: 'default',
+ fastMode: false,
+ providerId: 'xd',
+ remoteHostId: 'remote-host-1',
+ };
+
+ it('rejects subscription-direct models for a remote lead (they require the local proxy path)', async () => {
+ const { service } = createDeps({
+ getLeadSessionRow: vi.fn(async () => remoteLeadRow),
+ getAvailableModels: vi.fn(() => [
+ { id: 'chatgpt/gpt-5.5', efforts: ['low', 'medium', 'high', 'xhigh'], defaultEffort: 'high', supportsFastMode: true },
+ ]),
+ getProviderRoutingContext: vi.fn(async () => providerRoutingContext({
+ codex: [{ id: 'chatgpt', name: 'ChatGPT Subscription', models: ['chatgpt/gpt-5.5'] }],
+ })),
+ });
+
+ await expect(
+ service.createWorker({
+ leadSessionId: 'lead-1',
+ role: 'reviewer',
+ agent: 'codex',
+ label: 'reviewer',
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'chatgpt',
+ }),
+ ).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message: expect.stringContaining('not available for SSH remote workers'),
+ });
+ });
+
+ it('rejects chat-bridged codex providers for a remote lead (wireProtocol=openai-chat)', async () => {
+ const { service } = createDeps({
+ getLeadSessionRow: vi.fn(async () => remoteLeadRow),
+ getAvailableModels: vi.fn(() => [
+ { id: 'deepseek-v4', efforts: ['low', 'medium', 'high', 'xhigh'], defaultEffort: 'high', supportsFastMode: true },
+ ]),
+ getProviderRoutingContext: vi.fn(async () => providerRoutingContext({
+ codex: [{ id: 'deepseek', name: 'DeepSeek', models: ['deepseek-v4'], chatBridgedCodex: true }],
+ })),
+ });
+
+ await expect(
+ service.createWorker({
+ leadSessionId: 'lead-1',
+ role: 'reviewer',
+ agent: 'codex',
+ label: 'reviewer',
+ model: 'deepseek-v4',
+ providerId: 'deepseek',
+ }),
+ ).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message: expect.stringContaining('not available for SSH remote workers'),
+ });
+ });
+
+ it('still allows SSH-compatible models for a remote lead', async () => {
+ const { service } = createDeps({
+ getLeadSessionRow: vi.fn(async () => remoteLeadRow),
+ });
+ await expect(
+ service.createWorker({
+ leadSessionId: 'lead-1',
+ role: 'reviewer',
+ agent: 'codex',
+ label: 'reviewer',
+ }),
+ ).resolves.toMatchObject({ ok: true });
+ });
+});
diff --git a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
index 6724d47695..cd1788e656 100644
--- a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
+++ b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
@@ -2,6 +2,7 @@ import type { AgentKind } from '@cindy/maker-core';
import type { AuthStrategy } from '@cindy/model-providers';
import { isCredentialModeSwitchBusyError } from '../maker-host/codex-credential-switch.js';
+import { isSubscriptionDirectModel } from '../../shared/subscriptionModels.js';
import type { DispatchWorkerTaskResult, OrcaWorkerEffort, OrcaWorkerStatus } from './orcaTeamService.js';
import type { MakerSessionCreateOpts } from './sessionRequest.js';
@@ -66,6 +67,13 @@ export interface OrcaWorkerProviderSnapshot {
>;
/** true 表示该来源必须写入 session provider store 才能注入自己的 API key/OAuth token。 */
requiresExplicitRoute?: boolean;
+ /**
+ * true 表示 chat-bridged codex 供应商 (wireProtocol=openai-chat, 与
+ * renderer/lib/providerModels.ts 的 isChatBridgedCodexProvider 同语义):
+ * 其 Responses→Chat 翻译只挂在本地 codex-proxy, SSH 远端 worker 不兼容
+ * (codex-connector R23 P2 的拒绝依据)。
+ */
+ chatBridgedCodex?: boolean;
}
/** 自带凭证或明确无鉴权的第三方路由都不能回落到 worker/lead 的默认上游。 */
@@ -628,6 +636,37 @@ export function createOrcaWorkerCreationService(deps: OrcaWorkerCreationDeps): O
};
}
+ // SSH 远端 worker 的模型/来源兼容闸 (codex-connector R23 P2):remote
+ // transport 不经本地 proxy — subscription-direct 模型 (chatgpt/xai) 与
+ // chat-bridged codex 供应商 (wireProtocol=openai-chat, 其 Responses→Chat
+ // 翻译只挂在本地 codex-proxy) 送到远端必失败。ChatInput 对 remoteHostId
+ // 已用 excludeSubscriptionDirect / excludeChatBridgedCodex 隐藏
+ // (renderer/lib/providerModels.ts 同语义), worker 创建 (UI popover 与
+ // MCP 调用) 在此统一拒绝, 失败提前到创建前而非远端运行期。
+ if (lead.remoteHostId) {
+ if (isSubscriptionDirectModel(resolved.model)) {
+ return {
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message:
+ `model "${resolved.model}" is not available for SSH remote workers: ` +
+ 'subscription-direct models require the local proxy path — pick an SSH-compatible model',
+ };
+ }
+ const remoteRouteProvider = resolved.providerId !== null
+ ? agentProviders.find((candidate) => candidate.id === resolved.providerId)
+ : undefined;
+ if (remoteRouteProvider?.chatBridgedCodex === true) {
+ return {
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message:
+ `provider "${remoteRouteProvider.id}" is not available for SSH remote workers: ` +
+ 'chat-bridged Codex providers require the local proxy path — pick an SSH-compatible provider',
+ };
+ }
+ }
+
if (params.model !== undefined && explicitModelDefaultProviderId === null) {
return {
ok: false,
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 4e5651f87f..2b4c499372 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -81,7 +81,8 @@ import {
getBrowserAvailability,
openBrowserForLogin,
} from '../mcp-integrations/browser.js';
-import { shutdownCodexEnvironment } from '../mcp-integrations/codexEnvironment.js';
+import { getActiveCodexBridgeInstanceId, shutdownCodexEnvironment } from '../mcp-integrations/codexEnvironment.js';
+import { getRemoteMcpBridgeToken } from '../mcp-integrations/remoteMcpBridgeToken.js';
import {
checkComputerDriverUpdate,
cancelComputerDriverPermissionGrant,
@@ -255,7 +256,7 @@ import {
saveTurnStartedAtForDeferred,
} from '../messagePersistBroadcaster.js';
import { ensureCcManagerInstalledOrInstall } from '../remote-ssh/cc-manager-install.js';
-import { ensureRemoteCodexMcpBridge } from '../remote-ssh/codex-remote-mcp.js';
+import { ensureRemoteCodexMcpBridge, hasPendingRemoteMcpDrift } from '../remote-ssh/codex-remote-mcp.js';
import { reconcileCodexAgentProxyEnv } from '../remote-ssh/agent-proxy.js';
import { ensureRemoteAgentInstalledOrInstall, ensureRemoteHostReady, getRemoteSshPool, isCcMgrUpgradeInFlight } from '../remote-ssh/index.js';
import {
@@ -5180,6 +5181,22 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
: null,
};
}
+ // idle-live send 前的轻量 MCP 漂移判定 (纯本地, 零远程 RTT):
+ // bridge shutdown strip / token 轮换 / bridge 重建 / 端口重绑后,
+ // live 直发路径原本不经任何 ensure, daemon 会带着死 URL / 空 env
+ // 跑到 turn-done 才恢复 (codex-connector R23 P1)。命中漂移才走完整
+ // remote ensure (含 lazy 重建 bridge), 无漂移零开销。
+ if (
+ live.remoteHostId &&
+ live.agentKind === 'codex' &&
+ hasPendingRemoteMcpDrift(live.remoteHostId, {
+ collabEnabled: getPluginRegistry().isEnabled('collab'),
+ token: getRemoteMcpBridgeToken(),
+ bridgeInstanceId: getActiveCodexBridgeInstanceId(),
+ })
+ ) {
+ await ensureRemoteReadyForSessionStart({ session: live });
+ }
try {
const sendResult = await sendUserMessageWithAwaitedGitBaseline(
live,
@@ -6054,6 +6071,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
requiresExplicitRoute: providerRouteRequiresExplicitSelection(
provider.routing[agent]?.authStrategy,
),
+ // chat-bridged codex 供应商标记 (SSH 远端 worker 兼容闸用,
+ // 见 orcaWorkerCreationService R23 P2 校验;wireProtocol 仅
+ // codex 侧存在, 其他 agent 恒 false)。
+ chatBridgedCodex: agent === 'codex' && provider.routing[agent]?.wireProtocol === 'openai-chat',
};
});
return {
diff --git a/apps/desktop/src/main/mcp-integrations/codexEnvironment.ts b/apps/desktop/src/main/mcp-integrations/codexEnvironment.ts
index 43009d3ea5..958005f765 100644
--- a/apps/desktop/src/main/mcp-integrations/codexEnvironment.ts
+++ b/apps/desktop/src/main/mcp-integrations/codexEnvironment.ts
@@ -87,6 +87,15 @@ export function setCodexEnvironmentShutdownHook(fn: (() => void) | null): void {
shutdownHook = fn;
}
+/**
+ * 当前活跃 bridge 的实例 id (不触发 lazy 启动;未启动 / 已 shutdown 时
+ * null)。live send 的轻量 MCP 漂移判定 (hasPendingRemoteMcpDrift) 用它
+ * 区分「bridge 不在 ⇒ 必 ensure」与「比对实例代际」。
+ */
+export function getActiveCodexBridgeInstanceId(): string | null {
+ return activeBridge?.instanceId ?? null;
+}
+
export async function shutdownCodexEnvironment(): Promise<void> {
const cur = cached;
if (!cur) return;
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 0e983513e2..f3791699da 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
@@ -16,6 +16,7 @@ import {
mergeManagedMcpBlock,
ensureRemoteCodexMcpBridge,
stripRemoteCodexMcpConfig,
+ hasPendingRemoteMcpDrift,
} from '../codex-remote-mcp.js';
// safeStorage 在测试 stub 里 isEncryptionAvailable=false → token 真源恒 null;
@@ -1124,3 +1125,55 @@ describe('codex-connector R21 regressions', () => {
expect(prefsOf('host-strip-shutdown')?.appliedFingerprint).toBeUndefined();
});
});
+
+describe('hasPendingRemoteMcpDrift (R23 P1 lightweight live-send gate)', () => {
+ const base = { collabEnabled: true, token: 'tok', bridgeInstanceId: 'bridge-1' };
+
+ it('is true when the host was never injected (no applied fingerprint)', () => {
+ expect(hasPendingRemoteMcpDrift('host-drift-new', base)).toBe(true);
+ });
+
+ it('is false once the applied fingerprint matches the full desired state', async () => {
+ const { host } = fakeHost('host-drift-match', '');
+ await ensureRemoteCodexMcpBridge(host, {
+ ensureBridgeStarted: async () => ({ port: 38080, serverNames: SERVERS, bridgeInstanceId: 'bridge-1' }),
+ hasLiveTurnOnHost: () => false,
+ });
+ expect(hasPendingRemoteMcpDrift('host-drift-match', {
+ collabEnabled: true,
+ token: 'test-persistent-token',
+ bridgeInstanceId: 'bridge-1',
+ })).toBe(false);
+ expect(hasPendingRemoteMcpDrift('host-drift-match', {
+ collabEnabled: true,
+ token: 'test-persistent-token',
+ bridgeInstanceId: 'bridge-2',
+ })).toBe(true);
+ });
+
+ it('is true after a bridge shutdown strip (applied cleared) when collab stays enabled', async () => {
+ const { host } = fakeHost('host-drift-strip', '');
+ await ensureRemoteCodexMcpBridge(host, {
+ ensureBridgeStarted: async () => ({ port: 38080, serverNames: SERVERS, bridgeInstanceId: 'bridge-1' }),
+ hasLiveTurnOnHost: () => false,
+ });
+ await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => false });
+ expect(hasPendingRemoteMcpDrift('host-drift-strip', {
+ collabEnabled: true,
+ token: 'test-persistent-token',
+ bridgeInstanceId: null,
+ })).toBe(true);
+ });
+
+ it('follows cleanup semantics when collab is disabled or token is missing', async () => {
+ const { host } = fakeHost('host-drift-collab-off', '');
+ await ensureRemoteCodexMcpBridge(host, {
+ ensureBridgeStarted: async () => ({ port: 38080, serverNames: SERVERS, bridgeInstanceId: 'bridge-1' }),
+ hasLiveTurnOnHost: () => false,
+ });
+ expect(hasPendingRemoteMcpDrift('host-drift-collab-off', { ...base, collabEnabled: false })).toBe(true);
+ expect(hasPendingRemoteMcpDrift('host-drift-collab-off', { ...base, token: null })).toBe(true);
+ await stripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: () => false });
+ expect(hasPendingRemoteMcpDrift('host-drift-collab-off', { ...base, collabEnabled: false })).toBe(false);
+ });
+});
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 df7ffd2fc0..c188846c88 100644
--- a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts
+++ b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts
@@ -603,6 +603,45 @@ export function stripRemoteCodexMcpConfig(
});
}
+/**
+ * live send 前的轻量 MCP 漂移判定 (纯本地, 零远程 RTT):「应有状态」与
+ * appliedFingerprint 不一致 ⇒ 需要一次完整 ensure。成分:
+ * - collab 关闭 / token 缺失:applied 存在 = 待清理;
+ * - bridge 不在 (shutdown 后):返回 true — ensure 会触发 lazy 重建并按
+ * collab/token 现状重注入或清理;
+ * - bridge 在:全成分 (token|instanceId|remotePort|servers) 与 applied 比对。
+ * stripRemoteCodexMcpConfig 后 applied 被摘除 ⇒ collab 开时恒 true
+ * (codex-connector R23 P1:strip 后 idle-live 的 send 必须 send 前恢复)。
+ * servers 成分用白名单全集 — collab 开启时 provider 恒注册
+ * (keepOrcaProviderStable), 与 ensure 内 filter 结果一致。
+ */
+export function hasPendingRemoteMcpDrift(
+ hostId: string,
+ opts: {
+ collabEnabled: boolean;
+ token: string | null;
+ bridgeInstanceId: string | null;
+ },
+): boolean {
+ const applied = readPortPrefs()[hostId]?.appliedFingerprint ?? null;
+ if (!opts.collabEnabled || !opts.token) {
+ // 清理语义:applied 存在 = 待清理 (strip / 清理路径未跑过)。
+ return applied !== null;
+ }
+ if (!opts.bridgeInstanceId) {
+ return true;
+ }
+ const remotePort = readPortPrefs()[hostId]?.remotePort ?? DEFAULT_REMOTE_PORT_START;
+ const desired = createHash('sha256')
+ .update(
+ `${opts.token}|${opts.bridgeInstanceId}|${remotePort}|${[...CODEX_REMOTE_MCP_SERVER_NAMES].sort().join(',')}`,
+ 'utf8',
+ )
+ .digest('hex')
+ .slice(0, 12);
+ return desired !== applied;
+}
+
/**
* 确保远端 codex daemon 能用上本机 MCP bridge。幂等,挂在 remote codex
* session 的 start/resume 前置 (ensureRemoteReadyForSessionStart)。