Repository navigation
feat(core): accept cross-session messages behind an inbound gate #9576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 93418cb
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot eb1d343
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot 5bf7e26
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot 5928873
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot 97426bc
fix(i18n): translate the /peers description in strict-parity locales
qqqys b09bded
fix(ipc): close Critical review findings in the cross-session inbox
qwen-code-dev-bot 6dd138d
fix(cli): gate held-message announcements on the held set growing
qwen-code-dev-bot 3ebd83f
fix(ipc): close round-6 Critical findings in the cross-session inbox
qwen-code-dev-bot e4065a7
Merge remote-tracking branch 'origin/main' into feat/cross-session-in…
qwen-code-dev-bot 0dd9b35
fix(ipc): close round-7 Critical findings in the cross-session inbox
qwen-code-dev-bot c6e0718
fix(ipc): close round-8 Critical findings in the cross-session inbox
qwen-code-dev-bot c5ba3f8
Merge remote-tracking branch 'origin/main' into pr-9576-import
yiliang114 7ca3be7
fix(ipc): close peer messaging lifecycle races
yiliang114 3a81046
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot 3021309
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot 9f5a6dd
chore(cli): regenerate the settings schema for the reworded inbound p…
qqqys 02e6300
Merge remote-tracking branch 'upstream/main' into m9576
qqqys a7595c3
Merge branch 'main' into feat/cross-session-inbox-v2
qwen-code-dev-bot a9d9f14
fix(cli): close peer-inbox admission and decision review gaps (#9576)
qwen-code-dev-bot 5c5a8e0
fix(cli): settle all peer-inbox receipts at teardown (#9576)
qwen-code-dev-bot 8b7af63
fix(cli): restore peer message when its in-flight turn fails delivery…
qwen-code-dev-bot 2e51fbd
fix(cli): retry restored peer envelope once the failed turn settles (…
qwen-code-dev-bot 7602a09
Merge branch 'main' into feat/cross-session-inbox-v2
qqqys 26c364d
Merge branch 'main' into feat/cross-session-inbox-v2
qqqys ee63683
Merge remote-tracking branch 'upstream/main' into feat/cross-session-…
qqqys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 () => { | ||
| 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; | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 复验仍存在。