Skip to content
10 changes: 6 additions & 4 deletions packages/cli/src/commands/channel/daemon-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function stubProcessSend(send: NodeJS.Process['send'] | undefined): () => void {
}

describe('createDaemonSessionFactory', () => {
it('tags created channel sessions without changing loaded sessions', async () => {
it('tags created and resumed channel sessions', async () => {
const sdk = createSdk();
const factory = createDaemonSessionFactory({
client: sdk.client,
Expand Down Expand Up @@ -444,6 +444,7 @@ describe('createDaemonSessionFactory', () => {
workspaceCwd: '/workspace',
modelServiceId: 'qwen-plus',
sessionScope: 'thread',
sourceType: 'channel',
},
'qwen-channel-worker',
);
Expand Down Expand Up @@ -484,12 +485,13 @@ describe('createDaemonSessionFactory', () => {
workspaceCwd: '/workspace',
approvalMode: 'yolo',
sessionScope: 'thread',
sourceType: 'channel',
},
'qwen-channel-worker',
);
});

it('stamps channel sourceId on created sessions only', async () => {
it('stamps channel sourceId on created and resumed sessions', async () => {
const sdk = createSdk();
const factory = createDaemonSessionFactory({
client: sdk.client,
Expand All @@ -514,14 +516,14 @@ describe('createDaemonSessionFactory', () => {
},
'qwen-channel-worker',
);
// The load branch never re-stamps creation attribution: no sourceId in the
// load request even when the factory request carried one.
expect(sdk.DaemonSessionClient.resume).toHaveBeenCalledWith(
sdk.client,
'existing-session',
{
workspaceCwd: '/workspace',
sessionScope: 'thread',
sourceType: 'channel',
sourceId: 'dingtalk-main',
},
'qwen-channel-worker',
);
Expand Down
18 changes: 8 additions & 10 deletions packages/cli/src/commands/channel/daemon-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ interface DaemonSessionClientStaticLike {
modelServiceId?: string;
sessionScope: 'thread';
approvalMode?: string;
sourceType?: string;
sourceId?: string;
},
clientId?: string,
): Promise<DaemonChannelSessionClient>;
Expand Down Expand Up @@ -209,6 +211,11 @@ export function createDaemonSessionFactory({
// sessions remain thread-scoped so different channels never share the
// daemon's default single session.
sessionScope: 'thread' as const,
sourceType: 'channel',
// sourceId = channel instance name (e.g. feishu-main): distinguishes
// channel instances on the daemon data plane; the channel kind
// (dingtalk/feishu) is derivable from the name via the channel config.
...(req.sourceId ? { sourceId: req.sourceId } : {}),
};
if (req.sessionId) {
return await DaemonSessionClient.resume(
Expand All @@ -220,16 +227,7 @@ export function createDaemonSessionFactory({
}
return await DaemonSessionClient.createOrAttach(
client,
{
...daemonReq,
sourceType: 'channel',
// sourceId = channel instance name (e.g. feishu-main): distinguishes
// channel instances on the daemon data plane; the channel kind
// (dingtalk/feishu) is derivable from the name via the channel config.
// The load branch above deliberately omits it: loading never re-stamps
// creation attribution.
...(req.sourceId ? { sourceId: req.sourceId } : {}),
},
daemonReq,
clientId,
);
};
Expand Down
Loading