Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
54a12e2
feat(core): accept cross-session messages behind an inbound gate
qqqys Aug 20, 2026
93418cb
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 20, 2026
eb1d343
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 21, 2026
5bf7e26
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 21, 2026
5928873
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 21, 2026
97426bc
fix(i18n): translate the /peers description in strict-parity locales
qqqys Aug 21, 2026
b09bded
fix(ipc): close Critical review findings in the cross-session inbox
qwen-code-dev-bot Aug 22, 2026
6dd138d
fix(cli): gate held-message announcements on the held set growing
qwen-code-dev-bot Aug 22, 2026
3ebd83f
fix(ipc): close round-6 Critical findings in the cross-session inbox
qwen-code-dev-bot Aug 23, 2026
e4065a7
Merge remote-tracking branch 'origin/main' into feat/cross-session-in…
qwen-code-dev-bot Aug 23, 2026
0dd9b35
fix(ipc): close round-7 Critical findings in the cross-session inbox
qwen-code-dev-bot Aug 23, 2026
c6e0718
fix(ipc): close round-8 Critical findings in the cross-session inbox
qwen-code-dev-bot Aug 23, 2026
c5ba3f8
Merge remote-tracking branch 'origin/main' into pr-9576-import
yiliang114 Aug 23, 2026
7ca3be7
fix(ipc): close peer messaging lifecycle races
yiliang114 Aug 23, 2026
3a81046
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 23, 2026
3021309
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 24, 2026
9f5a6dd
chore(cli): regenerate the settings schema for the reworded inbound p…
qqqys Aug 24, 2026
02e6300
Merge remote-tracking branch 'upstream/main' into m9576
qqqys Aug 24, 2026
a7595c3
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot Aug 24, 2026
a9d9f14
fix(cli): close peer-inbox admission and decision review gaps (#9576)
qwen-code-dev-bot Aug 24, 2026
5c5a8e0
fix(cli): settle all peer-inbox receipts at teardown (#9576)
qwen-code-dev-bot Aug 25, 2026
8b7af63
fix(cli): restore peer message when its in-flight turn fails delivery…
qwen-code-dev-bot Aug 25, 2026
2e51fbd
fix(cli): retry restored peer envelope once the failed turn settles (…
qwen-code-dev-bot Aug 25, 2026
7602a09
Merge branch 'main' into feat/cross-session-inbox-v2
qqqys Aug 26, 2026
26c364d
Merge branch 'main' into feat/cross-session-inbox-v2
qqqys Aug 26, 2026
ee63683
Merge remote-tracking branch 'upstream/main' into feat/cross-session-…
qqqys Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/cli/src/config/settingsSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ describe('SettingsSchema', () => {
expect(exploreModel.showInDialog).toBe(false);
});

it('should keep cross-session messaging off by default', () => {
// The default is the entire security posture of the feature: shipping
// it flipped on would open every session on the box to peer messages.
const crossSessionMessaging =
getSettingsSchema().agents.properties.crossSessionMessaging;

expect(crossSessionMessaging.type).toBe('boolean');
expect(crossSessionMessaging.default).toBe(false);
expect(crossSessionMessaging.requiresRestart).toBe(true);
expect(crossSessionMessaging.showInDialog).toBe(false);
});

it('should define the inbound cross-session policy as accept/hold/refuse', () => {
const crossSessionInbound =
getSettingsSchema().agents.properties.crossSessionInbound;

expect(crossSessionInbound.type).toBe('enum');
// Unset is not a fourth policy: it means approval-mode parity, which
// the gate derives. A concrete default here would silence that.
expect(crossSessionInbound.default).toBeUndefined();
expect(crossSessionInbound.options).toEqual([
{ value: 'accept', label: 'Accept' },
{ value: 'hold', label: 'Hold for review' },
{ value: 'refuse', label: 'Refuse' },
]);
});

it('should define model grade settings', () => {
const agents = getSettingsSchema().agents.properties;

Expand Down
25 changes: 25 additions & 0 deletions packages/cli/src/config/settingsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,31 @@ const SETTINGS_SCHEMA = {
},
},
},
crossSessionMessaging: {
type: 'boolean',
label: 'Cross-Session Messaging',
category: 'Advanced',
requiresRestart: true,
default: false,
description:
'Experimental. Let Qwen Code sessions on this machine send each other messages over a per-session local socket. Off by default; turning it on both opens this session to peer messages and makes it discoverable to others.',
showInDialog: false,
},
crossSessionInbound: {
type: 'enum',
label: 'Inbound Cross-Session Messages',
category: 'Advanced',
requiresRestart: false,
default: undefined as string | undefined,
description:
'What happens to messages other sessions send this one. "accept" delivers them; "hold" parks them for your review without letting the model act; "refuse" opts this session out. Unset means approval-mode parity: a message auto-delivers unless this session bypasses permission prompts (YOLO) while the sender does not, or does not say — those are held for you to review.',
showInDialog: false,
options: [
{ value: 'accept', label: 'Accept' },
{ value: 'hold', label: 'Hold for review' },
{ value: 'refuse', label: 'Refuse' },
],
},
modelGrades: {
type: 'object',
label: 'Model Grades',
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/peerMessaging/PeerMessagingContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright 2026 Qwen
* SPDX-License-Identifier: Apache-2.0
*/

import { createContext, useContext } from 'react';
import type { PeerMessaging } from './peer-messaging.js';

export const PeerMessagingContext = createContext<PeerMessaging | null>(null);
export const usePeerMessaging = () => useContext(PeerMessagingContext);
260 changes: 260 additions & 0 deletions packages/cli/src/peerMessaging/peer-messaging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
/**
* @license
* Copyright 2026 Qwen
* SPDX-License-Identifier: Apache-2.0
*/

/**
* End-to-end over a real socket: a frame written by the client comes out
* of the gate and lands in the submit function, wrapped and attributed.
*/

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import * as fs from 'node:fs/promises';
import * as os from 'node:os';
import * as path from 'node:path';
import {
ApprovalMode,
buildUserFrame,
sendPeerFrame,
startPeerInbox,
type PeerFrame,
type PeerInbox,
} from '@qwen-code/qwen-code-core';
import { PeerMessaging } from './peer-messaging.js';

const isWindows = process.platform === 'win32';

let tmpDir: string;
let messaging: PeerMessaging | null = null;
/** Stands in for the peer that sent us something, to collect receipts. */
let senderInbox: PeerInbox | null = null;
let receipts: PeerFrame[];

beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'qwen-peer-msg-'));
receipts = [];
});

afterEach(async () => {
await messaging?.close();
messaging = null;
await senderInbox?.close();
senderInbox = null;
await fs.rm(tmpDir, { recursive: true, force: true });
});

async function settle(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 40));
}

async function startSenderInbox(): Promise<PeerInbox> {
const inbox = await startPeerInbox({
socketPath: path.join(tmpDir, 'socks', 'sender.sock'),
onFrame: (frame) => receipts.push(frame),
});
if (!inbox) throw new Error('sender inbox failed to start');
senderInbox = inbox;
return inbox;
}

async function start(
mode: ApprovalMode | null = ApprovalMode.DEFAULT,
): Promise<{
messaging: PeerMessaging;
submitted: Array<{ modelText: string; displayText: string }>;
}> {
const submitted: Array<{ modelText: string; displayText: string }> = [];
const started = await PeerMessaging.start({
socketPath: path.join(tmpDir, 'socks', 'self.sock'),
getApprovalMode: () => mode,
getPolicySetting: () => undefined,
});
if (!started) throw new Error('peer messaging failed to start');
messaging = started;
started.setSubmitFn((modelText, displayText) =>
submitted.push({ modelText, displayText }),
);
return { messaging: started, submitted };
}

describe.skipIf(isWindows)('PeerMessaging', () => {
it('delivers an accepted message wrapped in an envelope', async () => {
const { messaging: m, submitted } = await start(ApprovalMode.DEFAULT);
await sendPeerFrame(
m.socketPath!,
buildUserFrame({
content: 'check the tests over there',
from: '/tmp/peer.sock',
fromName: 'app-ab',
}),
);
await settle();

expect(submitted).toHaveLength(1);
expect(submitted[0].modelText).toContain(
'<cross_session_message from="/tmp/peer.sock" name="app-ab">',
);
expect(submitted[0].modelText).toContain('check the tests over there');
expect(submitted[0].modelText).toContain('permission laundering');
expect(submitted[0].displayText).toContain('app-ab');
});

it('holds a message when the receiver bypasses prompts and the sender says nothing', async () => {
const { messaging: m, submitted } = await start(ApprovalMode.YOLO);
await sendPeerFrame(
m.socketPath!,
buildUserFrame({ content: 'run the deploy', from: '/tmp/peer.sock' }),
);
await settle();

expect(submitted).toHaveLength(0);
expect(m.getHeld()).toHaveLength(1);
expect(m.getHeld()[0].cause).toBe('no-mode-asserted');
});

it('releases a held message when approved', async () => {
const { messaging: m, submitted } = await start(ApprovalMode.YOLO);
await sendPeerFrame(
m.socketPath!,
buildUserFrame({ content: 'run the deploy', from: '/tmp/peer.sock' }),
);
await settle();

const msgId = m.getHeld()[0].frame.msgId;
expect(m.decide(msgId, 'approve')).toBe('done');
expect(submitted).toHaveLength(1);
expect(m.getHeld()).toHaveLength(0);
});

it('buffers a message that arrives before the queue is wired', async () => {
const started = await PeerMessaging.start({
socketPath: path.join(tmpDir, 'socks', 'self.sock'),
getApprovalMode: () => ApprovalMode.DEFAULT,
getPolicySetting: () => undefined,
});
if (!started) throw new Error('peer messaging failed to start');
messaging = started;

await sendPeerFrame(
started.socketPath!,
buildUserFrame({ content: 'early bird', from: '/tmp/peer.sock' }),
);
await settle();

const submitted: string[] = [];
started.setSubmitFn((modelText) => submitted.push(modelText));
expect(submitted).toHaveLength(1);
expect(submitted[0]).toContain('early bird');
});

it('sends a delivery receipt back to the sender', async () => {
const sender = await startSenderInbox();
const { messaging: m } = await start(ApprovalMode.DEFAULT);

const frame = buildUserFrame({
content: 'hi',
from: sender.socketPath,
});
await sendPeerFrame(m.socketPath!, frame);
await settle();

expect(receipts).toHaveLength(1);
expect(receipts[0]).toMatchObject({
type: 'control',
status: 'delivered',
origMsgId: frame.msgId,
});
});

it('reports held, then delivered, as the decision is made', async () => {
const sender = await startSenderInbox();
const { messaging: m } = await start(ApprovalMode.YOLO);

const frame = buildUserFrame({ content: 'hi', from: sender.socketPath });
await sendPeerFrame(m.socketPath!, frame);
await settle();
expect(receipts.map((r) => (r as { status: string }).status)).toEqual([
'held',
]);

m.decide(frame.msgId, 'approve');
await settle();
expect(receipts.map((r) => (r as { status: string }).status)).toEqual([
'held',
'delivered',
]);
});

it('expires held messages on close so the sender is not left waiting', async () => {
const sender = await startSenderInbox();
const { messaging: m } = await start(ApprovalMode.YOLO);

const frame = buildUserFrame({ content: 'hi', from: sender.socketPath });
await sendPeerFrame(m.socketPath!, frame);
await settle();

await m.close();
messaging = null;
await settle();

expect(receipts.at(-1)).toMatchObject({
status: 'expired',
origMsgId: frame.msgId,
});
});

it('does not try to answer a sender that gave no reply address', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred to the follow-up queue — non-blocking per the maintainer's Critical-only scope for this mature PR; verified still present at HEAD. Finding: Wiring coverage gap (7/7) — new wiring exercised only through mocks or not at all. This test is a vacuous oracle: it never calls `startSenderInbox(...

延后至跟进队列——按维护者对本成熟 PR 的仅 Critical 范围要求,此项为非阻断;已在 HEAD 复验仍存在。

const { messaging: m } = await start(ApprovalMode.DEFAULT);
await expect(
sendPeerFrame(m.socketPath!, buildUserFrame({ content: 'anonymous' })),
).resolves.toBeUndefined();
await settle();
expect(receipts).toHaveLength(0);
});

it('ignores an inbound control frame instead of treating it as a message', async () => {
const { messaging: m, submitted } = await start(ApprovalMode.DEFAULT);
await sendPeerFrame(m.socketPath!, {
msgV: 1,
msgId: 'c1',
type: 'control',
action: 'delivery_status',
status: 'delivered',
origMsgId: 'whatever',
});
await settle();
expect(submitted).toHaveLength(0);
});

it('releases held messages when the approval mode changes', async () => {
let mode = ApprovalMode.YOLO;
const submitted: string[] = [];
const started = await PeerMessaging.start({
socketPath: path.join(tmpDir, 'socks', 'self.sock'),
getApprovalMode: () => mode,
getPolicySetting: () => undefined,
});
if (!started) throw new Error('peer messaging failed to start');
messaging = started;
started.setSubmitFn((modelText) => submitted.push(modelText));

await sendPeerFrame(
started.socketPath!,
buildUserFrame({ content: 'later', from: '/tmp/peer.sock' }),
);
await settle();
expect(submitted).toHaveLength(0);

mode = ApprovalMode.DEFAULT;
expect(started.reevaluate('approval-mode-changed')).toBe(1);
expect(submitted).toHaveLength(1);
});

it('is safe to close twice', async () => {
const { messaging: m } = await start();
await m.close();
await expect(m.close()).resolves.toBeUndefined();
messaging = null;
});
});
Loading
Loading