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(plugins): 隔离跨页回调并补齐未知结果核实入口

nanaead5402f6ba3
diff --git a/apps/desktop/src/main/cindy-brain/runtime/__tests__/ghostSecretCheck.test.ts b/apps/desktop/src/main/cindy-brain/runtime/__tests__/ghostSecretCheck.test.ts
index 299402a1cc..361602c42a 100644
--- a/apps/desktop/src/main/cindy-brain/runtime/__tests__/ghostSecretCheck.test.ts
+++ b/apps/desktop/src/main/cindy-brain/runtime/__tests__/ghostSecretCheck.test.ts
@@ -96,6 +96,18 @@ describe('credential check protocol', () => {
expect(checkSecret).toHaveBeenCalledWith('api_key', value);
expect(vault.store).not.toHaveBeenCalled(); expect(vault.remove).not.toHaveBeenCalled();
});
+ // Exercise the HTTP entry and real projection: short credentials can coincide with
+ // locally generated JSON without reflecting any upstream credential field.
+ it.each([['true', 'fake-token'], ['fake-key', '2033']])('accepts a valid projection with candidate %s and token %s', async (candidate, token) => {
+ const fetch = vi.fn().mockResolvedValueOnce(ok({ session: token }))
+ .mockResolvedValueOnce(ok({ status: 'active', expiresAtMs: 2000000000000, private: candidate }));
+ const store = vi.fn(), remove = vi.fn();
+ const result = await handleGhostSecretsRequest({ ...args, method: 'POST', pathname: '/secrets/api_key/check',
+ vault: { ...vault, store, remove }, readBodyText: async () => JSON.stringify({ value: candidate }),
+ checkSecret: async (_key, input) => run(fetch, undefined, input) });
+ expect(result).toMatchObject({ status: 200, body: '{"valid":true,"expiresAt":"2033-05-18T03:33:20.000Z"}' });
+ expect(store).not.toHaveBeenCalled(); expect(remove).not.toHaveBeenCalled();
+ });
it('keeps unsupported checks separate from the existing save endpoint', async () => {
expect((await handleGhostSecretsRequest({ ...args, checkSecretKeys: [], method: 'POST', pathname: '/secrets/api_key/check' })).status).toBe(404);
vault.store.mockReturnValueOnce(true);
diff --git a/apps/desktop/src/main/cindy-brain/runtime/ghostSecretCheck.ts b/apps/desktop/src/main/cindy-brain/runtime/ghostSecretCheck.ts
index 27248b29a0..31f935877e 100644
--- a/apps/desktop/src/main/cindy-brain/runtime/ghostSecretCheck.ts
+++ b/apps/desktop/src/main/cindy-brain/runtime/ghostSecretCheck.ts
@@ -90,7 +90,8 @@ export async function checkGhostSecret(args: {
}
}
const body = JSON.stringify(result);
- if (body.includes(value) || body.includes(token)) throw new Error('reflection');
+ // Only locally constructed boolean/ISO fields leave this boundary. Substring
+ // matching credentials against that JSON rejects valid short keys (e.g. 'true').
return { status: 200, body };
} catch {
return { status: !isCurrent() ? 403 : controller.signal.aborted ? 504 : 502,
diff --git a/apps/mobile/src/__tests__/pluginNativeViews.test.tsx b/apps/mobile/src/__tests__/pluginNativeViews.test.tsx
index 68ca4cd1b8..6c1435759e 100644
--- a/apps/mobile/src/__tests__/pluginNativeViews.test.tsx
+++ b/apps/mobile/src/__tests__/pluginNativeViews.test.tsx
@@ -1129,3 +1129,25 @@ it.each([PluginDetailView, AndroidDetailView])("limits permission summaries to f
rerender({ ...p, row: { ...row, key: "other-device:other-plugin" }, model: { ...p.model, permissions } });
expect(card().textContent).not.toContain("Full permission title 5");
});
+
+// The normal phone detail must expose recovery independently of its mutation gate
+// on both native renderers; controller identity/replay behavior is covered by pluginsScreen.
+it.each([PluginDetailView, AndroidDetailView])("keeps unknown-result recovery reachable while detail mutations are blocked (%#)", (DetailView) => {
+ const onPress = vi.fn();
+ const managementNotice = { title: "Result unconfirmed", actions: [{ label: "Check result", testID: "check-result", disabled: false, onPress }] };
+ const p = { row, enabled: true, online: true, busy: true, settingsOpen: false,
+ model: { ...pluginDetailModel(row as any, row.item as any, true, false, false), canUseTasks: true }, managementNotice,
+ onEnabledChange: vi.fn(), onOpen: vi.fn(), onNewTask: vi.fn(), onChooseTask: vi.fn(), onResolveStatus: vi.fn() };
+ const { container, rerender } = mount(DetailView, p);
+ expect(container.textContent).toContain("Result unconfirmed");
+ const disabled = (id: string) => {
+ const value = bridge.props.get(id);
+ return value.disabled ?? value.modifiers?.find((m: any) => 'disabled' in m)?.disabled;
+ };
+ expect(disabled("plugins.newTask")).toBe(true);
+ expect(disabled("check-result")).toBe(false);
+ act(() => bridge.props.get("check-result").onPress());
+ expect(onPress).toHaveBeenCalledTimes(1);
+ rerender({ ...p, managementNotice: undefined });
+ expect(container.textContent).not.toContain("Result unconfirmed");
+});
diff --git a/apps/mobile/src/__tests__/pluginSettingsCard.test.tsx b/apps/mobile/src/__tests__/pluginSettingsCard.test.tsx
index 1f060f26c8..746d4300c1 100644
--- a/apps/mobile/src/__tests__/pluginSettingsCard.test.tsx
+++ b/apps/mobile/src/__tests__/pluginSettingsCard.test.tsx
@@ -525,3 +525,62 @@ it.each([false, true])(
expect(state.clients[0].fetch).toHaveBeenCalledTimes(2);
},
);
+
+// Production document lifecycle: late polls retain consumed Host notices but cannot
+// deliver A's broadcasts or prompts to B; pending native answers belong to A too.
+it.each(["poll", "prompt"])("isolates a pending %s across package navigation", async (pending) => {
+ vi.useFakeTimers();
+ (globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
+ let finish!: (value: any) => void;
+ const gate = new Promise<any>((resolve) => { finish = resolve; });
+ const onConfirm = vi.fn(() => gate), onNotice = vi.fn(), onError = vi.fn();
+ const root = createRoot(document.createElement("div"));
+ cleanup = async () => { await act(async () => root.unmount()); };
+ await act(async () => root.render(createElement(PluginSettingsCard, {
+ identity: { deviceId: "host", instanceId: "plugin", expectedInstalledApproval: "approval" },
+ active: true, generation: 1, assertCurrent() {}, invokeTarget: vi.fn(), openSession: vi.fn(), onConfirm, onNotice, onError,
+ })));
+ const old = { events: [{ sequence: 1, channel: "test", data: "old" }], notifications: [{ text: "Saved on Host" }],
+ confirms: [{ id: "first", expiresAt: Date.now() + 60_000 }, { id: "queued", expiresAt: Date.now() + 60_000 }] };
+ state.clients[0].send.mockImplementationOnce(() => pending === "poll" ? gate : Promise.resolve(old));
+ await act(async () => state.web.onLoad());
+ if (pending === "prompt") expect(onConfirm).toHaveBeenCalledTimes(1);
+ await act(async () => state.web.onLoadStart());
+ state.inject.mockClear();
+ await act(async () => finish(pending === "poll" ? old : true));
+ expect(state.inject).not.toHaveBeenCalled();
+ expect(onNotice).toHaveBeenCalledWith("Saved on Host");
+ expect(onConfirm).toHaveBeenCalledTimes(pending === "poll" ? 0 : 1);
+ expect(state.clients[0].send.mock.calls.some(([command]: any[]) => command.kind === "confirm")).toBe(false);
+ // Host repeats unanswered prompts: they must not reappear on B's next poll.
+ state.clients[0].send.mockResolvedValueOnce({ ...old, events: [], notifications: [] });
+ await act(async () => vi.advanceTimersByTimeAsync(800));
+ expect(onConfirm).toHaveBeenCalledTimes(pending === "poll" ? 0 : 1);
+ expect(onError).not.toHaveBeenCalled();
+ expect(onNotice).toHaveBeenCalledTimes(1);
+ onConfirm.mockResolvedValueOnce(true);
+ state.clients[0].send.mockResolvedValueOnce({ events: [], notifications: [], confirms: [{ id: "new-document", expiresAt: Date.now() + 60_000 }] });
+ await act(async () => vi.advanceTimersByTimeAsync(800));
+ expect(state.clients[0].send).toHaveBeenCalledWith({ kind: "confirm", requestId: "new-document", accepted: true });
+});
+
+it("releases old subscriptions before the new document subscribes, including an in-flight subscribe", async () => {
+ (globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
+ const root = createRoot(document.createElement("div"));
+ cleanup = async () => { await act(async () => root.unmount()); };
+ await act(async () => root.render(createElement(PluginSettingsCard, {
+ identity: { deviceId: "host", instanceId: "plugin", expectedInstalledApproval: "approval" },
+ active: true, generation: 1, assertCurrent() {}, invokeTarget: vi.fn(), openSession: vi.fn(),
+ })));
+ let finish!: () => void;
+ state.clients[0].send.mockImplementationOnce(() => new Promise<void>((resolve) => { finish = resolve; }));
+ const subscribe = () => state.web.onMessage({ nativeEvent: { data: JSON.stringify({ settings: "page", id: 1, command: { kind: "subscribe", channels: ["test"] } }) } });
+ await act(async () => subscribe());
+ await act(async () => state.web.onLoadStart());
+ await act(async () => subscribe());
+ expect(state.clients[0].send).toHaveBeenCalledTimes(1);
+ await act(async () => finish());
+ expect(state.clients[0].send.mock.calls.map(([command]: any[]) => command)).toEqual([
+ { kind: "subscribe", channels: ["test"] }, { kind: "unsubscribe", channel: "test" }, { kind: "subscribe", channels: ["test"] },
+ ]);
+});
diff --git a/apps/mobile/src/__tests__/pluginsScreen.test.tsx b/apps/mobile/src/__tests__/pluginsScreen.test.tsx
index 915162ad58..c95c5ba8ae 100644
--- a/apps/mobile/src/__tests__/pluginsScreen.test.tsx
+++ b/apps/mobile/src/__tests__/pluginsScreen.test.tsx
@@ -1051,3 +1051,28 @@ it("refreshes an unknown management result using its original operation without
expect(requests.filter((request) => request?.actionId === "management:begin")).toHaveLength(1);
expect(requests.filter((request) => request?.actionId === "management:operation").map((request) => request.input.operationId)).toEqual(["screen-operation"]);
});
+
+// Narrow detail hides the directory refresh. Recovery must remain reachable while
+// mutations/settings are blocked, and query the same operation rather than replay it.
+it("checks an unknown operation from the phone detail and restores actions", async () => {
+ realManagementHost();
+ const readHost = fixture.wire.getMockImplementation()!;
+ fixture.wire.mockImplementation(async (...args) => {
+ const request = args[2]?.[0];
+ if (request?.actionId === "management:begin") throw new Error("CONNECTION_LOST");
+ if (request?.actionId === "management:operation") return { result: { operationId: request.input.operationId, phase: "succeeded" } };
+ return readHost(...args);
+ });
+ await openDetail();
+ await act(async () => fixture.props.get("header").rightToolbar.props.onAction("uninstall"));
+ await act(async () => fixture.alert.mock.calls.at(-1)![2][1].onPress());
+ const detail = fixture.props.get("detail");
+ expect(detail.busy).toBe(true);
+ expect(detail.managementNotice?.actions?.[0].disabled).toBe(false);
+ await act(async () => detail.managementNotice.actions[0].onPress());
+ const requests = fixture.wire.mock.calls.map((call) => call[2]?.[0]);
+ expect(requests.filter((request) => request?.actionId === "management:begin")).toHaveLength(1);
+ expect(requests.filter((request) => request?.actionId === "management:operation").map((request) => request.input.operationId)).toEqual(["screen-operation"]);
+ expect(fixture.props.get("detail").managementNotice).toBeUndefined();
+ expect(fixture.props.get("detail").busy).toBe(false);
+});
diff --git a/apps/mobile/src/debug/PluginNoticePreview.tsx b/apps/mobile/src/debug/PluginNoticePreview.tsx
index 13661a1ae1..d1e647e24e 100644
--- a/apps/mobile/src/debug/PluginNoticePreview.tsx
+++ b/apps/mobile/src/debug/PluginNoticePreview.tsx
@@ -83,6 +83,7 @@ function NoticeScene({ scenario, settingsOptions }: { scenario: string; settings
</View> : undefined;
return <View style={{ flex: 1 }}>
<PluginDetailView row={row} enabled={enabled} online={online} busy={loading || state.busy || ["running", "confirmation", "unknown"].includes(outcome)} statusRecoveryBusy={loading || state.busy} model={model} settingsOpen={false}
+ managementNotice={outcome === "unknown" ? { testID: "plugins.managementUnknown", title: t("plugins.notice.title.resultUnknown"), icon: "warning", actions: [{ label: t("plugins.management.checkResult"), testID: "plugins.checkManagementResult", disabled: !online || state.busy, onPress: () => { void controller.reconcile(); } }] } : undefined}
previewLabel={`QA fixture · ${scenario}${errorKind ? " · bridge-only failure; no page reply" : ""}${feedback ? " · " + feedback : ""}`} settingsContent={settingsContent}
onEnabledChange={(value) => { setEnabled(value); setFeedback("QA · local switch"); }}
onOpen={() => Alert.alert("QA only", "No Host was opened")}
diff --git a/apps/mobile/src/i18n/locales/en/plugins.json b/apps/mobile/src/i18n/locales/en/plugins.json
index 615b2aa07f..dc6ea2af13 100644
--- a/apps/mobile/src/i18n/locales/en/plugins.json
+++ b/apps/mobile/src/i18n/locales/en/plugins.json
@@ -155,6 +155,7 @@
"mailAttachTooLarge": "Each email attachment must be 16 MB or smaller.",
"mailRemoveAttachment": "Remove {{name}}",
"management": {
+ "checkResult": "Check result",
"manage": "Manage plugin",
"update": "Update",
"uninstall": "Uninstall",
diff --git a/apps/mobile/src/i18n/locales/ja/plugins.json b/apps/mobile/src/i18n/locales/ja/plugins.json
index d4af7d12a7..acd988fc3f 100644
--- a/apps/mobile/src/i18n/locales/ja/plugins.json
+++ b/apps/mobile/src/i18n/locales/ja/plugins.json
@@ -155,6 +155,7 @@
"mailAttachTooLarge": "添付ファイルは1件につき16 MB以下にしてください。",
"mailRemoveAttachment": "{{name}} を削除",
"management": {
+ "checkResult": "結果を確認",
"manage": "プラグインを管理",
"update": "更新",
"uninstall": "アンインストール",
diff --git a/apps/mobile/src/i18n/locales/ko/plugins.json b/apps/mobile/src/i18n/locales/ko/plugins.json
index 79e8af0187..efbc26862e 100644
--- a/apps/mobile/src/i18n/locales/ko/plugins.json
+++ b/apps/mobile/src/i18n/locales/ko/plugins.json
@@ -155,6 +155,7 @@
"mailAttachTooLarge": "메일 첨부 파일 하나의 크기는 16 MB 이하여야 합니다.",
"mailRemoveAttachment": "{{name}} 삭제",
"management": {
+ "checkResult": "결과 확인",
"manage": "플러그인 관리",
"update": "업데이트",
"uninstall": "제거",
diff --git a/apps/mobile/src/i18n/locales/zh-CN/plugins.json b/apps/mobile/src/i18n/locales/zh-CN/plugins.json
index 7efe04f05d..b755ba55d9 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/plugins.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/plugins.json
@@ -155,6 +155,7 @@
"mailAttachTooLarge": "单个邮件附件不能超过 16 MB。",
"mailRemoveAttachment": "移除 {{name}}",
"management": {
+ "checkResult": "核实结果",
"manage": "管理插件",
"update": "升级",
"uninstall": "卸载",
diff --git a/apps/mobile/src/i18n/locales/zh-TW/plugins.json b/apps/mobile/src/i18n/locales/zh-TW/plugins.json
index 86f5b9cb05..a1a44056ad 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/plugins.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/plugins.json
@@ -155,6 +155,7 @@
"mailAttachTooLarge": "單個郵件附件不能超過 16 MB。",
"mailRemoveAttachment": "移除 {{name}}",
"management": {
+ "checkResult": "核實結果",
"manage": "管理插件",
"update": "升級",
"uninstall": "解除安裝",
diff --git a/apps/mobile/src/plugins/PluginDetailView.ios.tsx b/apps/mobile/src/plugins/PluginDetailView.ios.tsx
index 7428efe2fe..5f1f98941f 100644
--- a/apps/mobile/src/plugins/PluginDetailView.ios.tsx
+++ b/apps/mobile/src/plugins/PluginDetailView.ios.tsx
@@ -222,6 +222,11 @@ export function PluginDetailView(p: PluginDetailViewProps) {
</VStack>
) : null}
{status}
+ {p.managementNotice ? (
+ <VStack modifiers={[listRowSeparator("hidden")]}>
+ <PluginNativeNotice {...p.managementNotice} />
+ </VStack>
+ ) : null}
{notices.loading ? (
<VStack
testID="plugins.loading"
diff --git a/apps/mobile/src/plugins/PluginDetailView.tsx b/apps/mobile/src/plugins/PluginDetailView.tsx
index 6ee65ec225..b692acaad2 100644
--- a/apps/mobile/src/plugins/PluginDetailView.tsx
+++ b/apps/mobile/src/plugins/PluginDetailView.tsx
@@ -29,7 +29,7 @@ import type { PluginDetailModel } from "./pluginDetailModel";
import { useMobileKeyboardState } from "@/session/useMobileKeyboardState";
import { PluginPermissionCard } from "./PluginPermissionCard";
import { PluginToolChips } from "./PluginToolChips";
-import { PluginNotice } from "./PluginNotice";
+import { PluginNotice, type PluginNoticeProps } from "./PluginNotice";
import { pluginDetailNotices } from "./pluginDetailNotices";
export interface PluginDetailViewProps {
@@ -43,6 +43,7 @@ export interface PluginDetailViewProps {
settingsOpen: boolean;
previewLabel?: string;
settingsContent?: ReactNode;
+ managementNotice?: PluginNoticeProps;
onEnabledChange(enabled: boolean): void;
onOpen(surface: PluginPageSurface): void;
onNewTask(): void;
@@ -146,6 +147,7 @@ export function PluginDetailView(p: PluginDetailViewProps) {
}
/>
) : null}
+ {p.managementNotice ? <PluginNotice {...p.managementNotice} /> : null}
{notices.loading ? (
<ActivityIndicator
testID="plugins.loading"
diff --git a/apps/mobile/src/plugins/PluginSettingsCard.tsx b/apps/mobile/src/plugins/PluginSettingsCard.tsx
index f18801979a..7411b241a9 100644
--- a/apps/mobile/src/plugins/PluginSettingsCard.tsx
+++ b/apps/mobile/src/plugins/PluginSettingsCard.tsx
@@ -6,6 +6,7 @@ import {
type PluginPageConfirm,
type PluginPagePoll,
type PluginDirectoryRequest,
+ type PluginSettingsCommand,
} from "@cindy/device-link";
import {
motionDuration,
@@ -86,6 +87,10 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
const webview = useRef<WebView>(null);
const clientRef = useRef<PluginSettingsClient | undefined>(undefined);
const documentEpoch = useRef(0);
+ const documentChannels = useRef<{
+ send(command: PluginSettingsCommand, epoch: number): Promise<unknown>;
+ reset(): void;
+ } | undefined>(undefined);
const pollRef = useRef<(() => void) | undefined>(undefined);
const covered = useRef(0);
const openingLink = useRef<object | null>(null);
@@ -155,6 +160,8 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
const abort = new AbortController();
const prompts = new Set<string>();
let promptQueue = Promise.resolve();
+ let channelQueue = Promise.resolve();
+ const channels = new Set<string>();
const check = () => {
if (
disposed ||
@@ -188,10 +195,12 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
const prompt = async (
request: PluginPageConfirm | PluginDirectoryRequest,
directory: boolean,
+ epoch: number,
) => {
let presented = false;
try {
check();
+ if (epoch !== documentEpoch.current) return;
covered.current++;
presented = true;
const answer =
@@ -205,7 +214,7 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
request as PluginPageConfirm,
)) ?? false);
check();
- if (Date.now() >= request.expiresAt) return;
+ if (epoch !== documentEpoch.current || Date.now() >= request.expiresAt) return;
await client!.send(
directory
? {
@@ -220,7 +229,7 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
},
);
} catch (error) {
- report(error);
+ if (epoch === documentEpoch.current) report(error);
} finally {
if (presented && !disposed)
covered.current = Math.max(0, covered.current - 1);
@@ -229,14 +238,21 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
const enqueue = (
request: PluginPageConfirm | PluginDirectoryRequest,
directory: boolean,
+ epoch: number,
) => {
if (prompts.has(request.id)) return;
prompts.add(request.id);
- promptQueue = promptQueue.then(() => prompt(request, directory));
+ promptQueue = promptQueue.then(() => prompt(request, directory, epoch));
};
const poll = async () => {
+ const epoch = documentEpoch.current;
try {
+ await channelQueue;
check();
+ if (epoch !== documentEpoch.current) {
+ timer = setTimeout(() => void poll(), 800);
+ return;
+ }
// Host retains the authorization lease; do not consume notices while the browser owns the UI.
if (!foregroundRef.current || authorizationActive.current) {
timer = setTimeout(() => void poll(), 800);
@@ -254,6 +270,13 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
!Array.isArray(result.notifications)
)
throw new Error("PLUGIN_SETTINGS_INVALID_POLL");
+ if (epoch !== documentEpoch.current) {
+ for (const event of result.events)
+ after = Math.max(after, event.sequence);
+ // Host repeats unanswered prompts; remember these even though A is gone.
+ for (const request of [...result.confirms, ...(result.directories ?? [])])
+ prompts.add(request.id);
+ }
if (!foregroundRef.current || authorizationActive.current) {
// An in-flight poll has already consumed these notices on Host. Keep them across resource reload.
deferredNotices.current = {
@@ -263,17 +286,23 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
timer = setTimeout(() => void poll(), 800);
return;
}
- inject({ kind: "events", events: result.events });
- for (const event of result.events)
- after = Math.max(after, event.sequence);
+ if (epoch === documentEpoch.current) {
+ inject({ kind: "events", events: result.events });
+ for (const event of result.events)
+ after = Math.max(after, event.sequence);
+ }
for (const notice of result.notifications)
latest.current.onNotice?.(notice.text);
for (const confirmation of result.confirms)
- enqueue(confirmation, false);
+ enqueue(confirmation, false, epoch);
for (const directory of result.directories ?? [])
- enqueue(directory, true);
+ enqueue(directory, true, epoch);
if (!disposed) timer = setTimeout(() => void poll(), 800);
} catch (error) {
+ if (!disposed && epoch !== documentEpoch.current) {
+ timer = setTimeout(() => void poll(), 800);
+ return;
+ }
report(error);
if (!disposed) {
void client?.close().catch(() => {});
@@ -310,6 +339,40 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
});
check();
clientRef.current = client;
+ documentChannels.current = {
+ send(command, epoch) {
+ const work = channelQueue.then(async () => {
+ check();
+ if (epoch !== documentEpoch.current) throw new Error("PLUGIN_SETTINGS_CLOSED");
+ // Track before awaiting: a lost acknowledgement can still have subscribed on Host.
+ if (command.kind === "subscribe")
+ for (const channel of command.channels) channels.add(channel);
+ const result = await client!.send(command);
+ if (command.kind === "unsubscribe") channels.delete(command.channel);
+ return result;
+ });
+ channelQueue = work.then(() => {}, () => {});
+ return work;
+ },
+ reset() {
+ // Keep the lease/authorization, but release A's channels before B can subscribe.
+ // Host unsubscribe also removes buffered events for those channels.
+ channelQueue = channelQueue.then(async () => {
+ check();
+ for (const channel of channels) {
+ await client!.send({ kind: "unsubscribe", channel });
+ channels.delete(channel);
+ }
+ });
+ void channelQueue.catch((error) => {
+ report(error);
+ clearTimeout(timer);
+ abort.abort();
+ void client?.close().catch(() => {});
+ if (!disposed) setSource(undefined);
+ });
+ },
+ };
resource = await preparePluginSettingsResources(
client,
themeRef.current,
@@ -338,6 +401,7 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
browserBackground.current = false;
setAuthorizing(false);
pollRef.current = undefined;
+ documentChannels.current = undefined;
if (clientRef.current === client) clientRef.current = undefined;
void resource?.close().catch(() => {});
void client?.close().catch(() => {});
@@ -488,6 +552,7 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
onLoadStart={() => {
if (!pageCurrent()) return;
documentEpoch.current++;
+ documentChannels.current?.reset();
latest.current.onLoading?.(true);
}}
onLoad={() => {
@@ -547,7 +612,7 @@ export function PluginSettingsCard(props: PluginSettingsCardProps) {
: command.kind === "fetch"
? client.fetch(command.path, command.method, command.body)
: ["subscribe", "unsubscribe", "post"].includes(command.kind)
- ? client.send(command)
+ ? documentChannels.current!.send(command, requestDocument)
: Promise.reject(
new Error("PLUGIN_SETTINGS_COMMAND_BLOCKED"),
);
diff --git a/apps/mobile/src/plugins/PluginsScreen.tsx b/apps/mobile/src/plugins/PluginsScreen.tsx
index 50c0511b8c..465e7d4fd7 100644
--- a/apps/mobile/src/plugins/PluginsScreen.tsx
+++ b/apps/mobile/src/plugins/PluginsScreen.tsx
@@ -948,6 +948,17 @@ function PluginDirectory() {
enabled={enabled}
busy={busy || detailLoading || managementPending}
statusRecoveryBusy={busy || detailLoading}
+ managementNotice={management.state?.outcome === "unknown" ? {
+ testID: "plugins.managementUnknown",
+ title: t("plugins.notice.title.resultUnknown"),
+ icon: "warning",
+ actions: [{
+ label: t("plugins.management.checkResult"),
+ testID: "plugins.checkManagementResult",
+ disabled: !online || management.state.busy,
+ onPress: () => { void management.controller?.reconcile(); },
+ }],
+ } : undefined}
online={online}
model={model}
previewLabel={
diff --git a/docs/remote-plugin-oauth.md b/docs/remote-plugin-oauth.md
index 4624e9bce2..8ecf84c67f 100644
--- a/docs/remote-plugin-oauth.md
+++ b/docs/remote-plugin-oauth.md
@@ -265,6 +265,13 @@ remote context 接线一同发布;通用 OAuth capabilities 存在不代表原
包内 HTML 与锚点继续留在设置容器;协议/凭证 URL 被拒绝,目标电脑 loopback 链接明确提示
在电脑打开,不把它当作手机本地服务。回退或切换身份后的迟到确认不打开浏览器。
+包内文档导航保留 Host 租约与授权上下文,但旧文档的轮询事件、排队确认和迟到答案不能进入
+新文档;旧 BroadcastChannel 订阅先释放,再建立新文档订阅。已经从 Host 消费的普通通知
+仍按当前账号、目标与租约投递,不因文档切换丢失。
+
+管理操作回执丢失时,手机详情显示“结果未确认”及“核实结果”入口。查询沿用原 operationId,
+期间保持写操作和配置页停用;不重放 begin,核实终态并读回快照后恢复对应操作。
+
### 原配置页普通凭证校验
可选的 `network.secrets[].check` 固定校验地址、JSON 请求模板和有限响应投影;