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(browser): recheck the plugin instance after startup; refuse networkidle on older extensions; unique targetIds per connection

Dashc83d97d84835
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
index 7ecdd398b7..797a91221e 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
@@ -397,6 +397,21 @@ describe('browserExtensionSlot · 管子上行', () => {
expect(installs).toBe(2);
});
+ // Review 2026-10-30 (Codex P1): a request that waited for startup must not act after the plugin went away.
+ it('等待启动期间插件被停用时,旧请求不再执行', async () => {
+ let finishStart: () => void = () => undefined;
+ const { slot, bridges, settle, ghosts } = await makeSlot();
+ slot.reconcile(ghosts);
+ await vi.waitFor(() => expect(bridges).toHaveLength(1));
+ bridges[0].start = () => new Promise<void>((resolve) => (finishStart = resolve));
+ await settle();
+ const pending = slot.handleRequest('_root__my-browser', { kind: 'setTrustedClients', clients: [] });
+ slot.reconcile([]);
+ finishStart();
+ expect(await pending).toMatchObject({ ok: false, errorCode: 'HOST_NOT_READY' });
+ expect(bridges[0].calls.some(([name]) => name === 'setTrustedClients')).toBe(false);
+ });
+
// Review 2026-10-30 (Codex P2): a failed startup is rebuilt by the next request instead of staying failed.
it('启动失败后下一次请求重建整套启动流程', async () => {
const { slot, bridges, natives, settle, ghosts } = await makeSlot();
diff --git a/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts b/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
index c6acea96c2..7327dd2e25 100644
--- a/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
+++ b/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
@@ -375,6 +375,10 @@ export class GhostBrowserExtensionSlot {
const req = payload as Record<string, unknown>;
const { entry } = gate;
await entry.ready;
+ // The plugin may have been disabled, removed or replaced while the bridge was starting: a request
+ // that began before that must not act (re-pair, reinstall the native binding) on the old instance.
+ if (entry.closing || this.entries.get(entry.instanceId) !== entry)
+ return fail('HOST_NOT_READY', '浏览器扩展桥接已重建;稍后重试');
if (entry.startFailed) {
// A failed startup would otherwise stay failed for good (no pairing request, no native binding)
// even after the cause, such as busy ports, is gone. Rebuild it from the same request path the
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
index 4f23dd0d09..6bd04109ce 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
@@ -332,6 +332,9 @@ describe('UserBrowserBackend · 读取与动作', () => {
expect(
await call(b, { action: 'act', targetId: 't1', request: { kind: 'wait', selector: '.ready', timeMs: 500 } }),
).toMatchObject({ ok: false, message: expect.stringContaining('组合') });
+ expect(
+ await call(b, { action: 'act', targetId: 't1', request: { kind: 'wait', loadState: 'networkidle' } }),
+ ).toMatchObject({ ok: false, message: expect.stringContaining('networkidle') });
// Review 2026-10-30 (Codex P2): a loadState wait on an older extension must not navigate the tab.
fake.responses.set('tabs', () => ({ ok: true, tabs: [{ id: 7, url: 'https://example.test/a', status: 'complete' }] }));
const navigatesBefore = fake.jobs.filter(([name]) => name === 'navigate').length;
@@ -716,6 +719,23 @@ describe('UserBrowserBackend · 读取与动作', () => {
expect(evaluations).toBe(2);
});
+ // Review 2026-10-30 (Codex P2): connections whose ids share a prefix must not share targetIds.
+ it('前缀相同的两个连接各有自己的 targetId', async () => {
+ const fake = fakeControl({
+ version: '0.3.9',
+ clients: ['abcdefgh-1111', 'abcdefgh-2222'],
+ tabs: {
+ 'abcdefgh-1111': [{ id: 1, url: 'https://a.test/' }],
+ 'abcdefgh-2222': [{ id: 1, url: 'https://b.test/' }],
+ },
+ });
+ const b = backend(fake.control);
+ const listed = (await call(b, { action: 'tabs' })) as { data?: { tabs?: Array<{ targetId?: string; url?: string }> } };
+ const tabs = listed.data?.tabs ?? [];
+ expect(tabs).toHaveLength(2);
+ expect(new Set(tabs.map((t) => t.targetId)).size).toBe(2);
+ });
+
// Review 2026-10-30 (Codex P1): every action that names a tab refuses a profile of another connection.
it('act 的 targetId 与 profile 不属于同一连接时拒绝', async () => {
const fake = fakeControl({
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
index 9d0a453486..dd3963f1b9 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
@@ -490,7 +490,15 @@ export class UserBrowserBackend implements BrowserBackend {
// The browser launch is part of the handle: after a restart the same tab number is a different
// tab, and an old handle the agent still holds must not resolve to it.
const boot = this.clientBoots.get(clientId);
- return `${clientId.slice(0, 8)}${boot ? '.' + boot.slice(0, 8) : ''}:${tabId}`;
+ const suffix = `${boot ? '.' + boot.slice(0, 8) : ''}:${tabId}`;
+ // Shown abbreviated, but never shared between connections: if another connection already holds the
+ // key, the connection part grows until it is unique.
+ for (let n = 8; n < clientId.length; n++) {
+ const key = clientId.slice(0, n) + suffix;
+ const holder = this.targets.get(key);
+ if (!holder || holder.clientId === clientId) return key;
+ }
+ return clientId + suffix;
}
private register(
@@ -1425,6 +1433,8 @@ export class UserBrowserBackend implements BrowserBackend {
waitedMs: (this.opts.now ?? Date.now)() - started,
});
}
+ if (request.loadState === 'networkidle')
+ return unsupported(req.action, 'wait.loadState=networkidle(旧版扩展只能确认页面 load 完成)');
if (request.loadState) {
// Older extensions cannot wait inside the page: poll the tab's own load state. (Navigating to
// the recorded address here would reload a page that was just submitted.)