Skip to content

Commit 83d5304

Browse files
RomneyDavincentkoc
andauthored
fix(channels): route commentary through one progress owner (#121009)
* fix(slack): keep commentary progress on draft lane * fix(channels): route commentary through one progress owner Keep non-verbose commentary in Slack and Discord draft lanes while preserving one durable commentary payload when verbose progress makes those drafts yield. Freeze that owner decision for the turn so session changes apply on the next turn. Co-authored-by: Dallin Romney <[email protected]> Punchcard-Session: amber-workshop-workshop-36 * fix(channels): refresh queued commentary owner Recompute the frozen draft-versus-durable commentary owner for every queued follow-up turn and carry that decision into final payload projection. Punchcard-Session: amber-workshop-workshop-36 * fix(channels): clarify commentary owner opt-in * fix(channels): preserve queued draft preambles * fix(channels): require explicit queued progress ownership * refactor(channels): record commentary progress owner * fix(telegram): tolerate unscoped queued updates * test(discord): use canonical draft fixture after rebase --------- Co-authored-by: Vincent Koc <[email protected]>
1 parent ecaeb8c commit 83d5304

20 files changed

Lines changed: 474 additions & 60 deletions

‎docs/plugins/sdk-channel-plugins.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ update occurred. Existing synchronous and asynchronous callbacks that return `vo
8585
backward-compatible and are treated as visible; new acceptance-aware implementations should use
8686
an explicit boolean.
8787

88+
### Commentary delivery ownership
89+
90+
Set `commentaryPayloadsEnabled: true` when the channel supports durable commentary messages.
91+
Channels that normally render commentary in one evolving progress draft can also provide
92+
`shouldDeliverCommentaryPayloads`. Core freezes verbose visibility for the turn, registers that
93+
getter through `onVerboseProgressVisibility`, evaluates the delivery callback once before
94+
dispatch, and snapshots that result for the whole turn. Session changes apply on the next turn.
95+
The callback is inert unless `commentaryPayloadsEnabled` is also `true`; without that static
96+
opt-in, core neither evaluates the callback nor freezes the registered visibility getter.
97+
98+
Return `false` while the draft owns normal progress and `true` when verbose progress makes that
99+
draft yield to durable commentary. Keep the callback synchronous and read only channel-owned,
100+
already prepared state. Omitting it preserves durable delivery for existing plugins that use the
101+
static opt-in. The callback does not control reasoning, partial replies, tool progress, or final
102+
answers.
103+
88104
Inbound receivers that defer platform acknowledgements should declare
89105
`message.receive.defaultAckPolicy` and `supportedAckPolicies` instead of hiding
90106
ack timing in monitor-local state. Cover every declared policy with

‎extensions/discord/src/monitor/message-handler.process-progress.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export function createDiscordMessageProgressRuntime(params: {
125125
commentaryPayloadsEnabled: draftPreview.isProgressMode
126126
? draftPreview.commentaryProgressEnabled
127127
: undefined,
128+
shouldDeliverCommentaryPayloads:
129+
draftPreview.isProgressMode && draftPreview.commentaryProgressEnabled
130+
? () => shouldYieldDraftCommentary()
131+
: undefined,
128132
reasoningPayloadsEnabled: reasoningDurableEnabled,
129133
onVerboseProgressVisibility: (isActive) => {
130134
shouldYieldDraftCommentary = isActive;

‎extensions/discord/src/monitor/message-handler.process.draft-progress.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ describe("processDiscordMessage draft streaming progress", () => {
293293
const draftStream = createMockDraftStreamForTest();
294294

295295
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
296+
expect(params?.replyOptions?.commentaryPayloadsEnabled).toBe(true);
297+
expect(params?.replyOptions?.shouldDeliverCommentaryPayloads?.()).toBe(false);
296298
params?.replyOptions?.onVerboseProgressVisibility?.(() => durableLaneActive);
299+
expect(params?.replyOptions?.shouldDeliverCommentaryPayloads?.()).toBe(durableLaneActive);
297300
await params?.replyOptions?.onItemEvent?.({
298301
itemId: "preamble-1",
299302
kind: "preamble",
@@ -328,6 +331,25 @@ describe("processDiscordMessage draft streaming progress", () => {
328331
},
329332
);
330333

334+
it("omits the durable commentary owner when Discord commentary progress is disabled", async () => {
335+
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
336+
expect(params?.replyOptions?.commentaryPayloadsEnabled).toBe(false);
337+
expect(params?.replyOptions?.shouldDeliverCommentaryPayloads).toBeUndefined();
338+
return createNoQueuedDispatchResult();
339+
});
340+
341+
const ctx = await createAutomaticDraftContext({
342+
discordConfig: {
343+
streaming: {
344+
mode: "progress",
345+
progress: { commentary: false },
346+
},
347+
},
348+
});
349+
350+
await runProcessDiscordMessage(ctx);
351+
});
352+
331353
it.each([
332354
["active", true],
333355
["inactive", false],

‎extensions/discord/src/monitor/message-handler.process.test-harness.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export type DispatchInboundParams = {
184184
isProgressDraftVisible?: () => boolean;
185185
progressPreambleEnabled?: boolean;
186186
narrationHideCommandText?: boolean;
187+
commentaryPayloadsEnabled?: boolean;
188+
shouldDeliverCommentaryPayloads?: () => boolean;
187189
onVerboseProgressVisibility?: (isActive: () => boolean) => void;
188190
onPlanUpdate?: (payload: {
189191
phase?: string;

‎extensions/slack/src/monitor/message-handler/dispatch.preview-fallback.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,12 +4092,15 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
40924092
);
40934093

40944094
expect(capturedReplyOptions?.commentaryProgressEnabled).toBe(true);
4095+
expect(capturedReplyOptions?.commentaryPayloadsEnabled).toBe(true);
4096+
expect(capturedReplyOptions?.shouldDeliverCommentaryPayloads?.()).toBe(false);
40954097
expect(capturedReplyOptions?.suppressDefaultToolProgressMessages).toBe(true);
40964098
expectLastDraftUpdateText(draftStream, "_Preparing the smallest fix_");
40974099
expect(draftUpdateTexts(draftStream).join("\n")).not.toContain("pnpm test");
40984100

40994101
const updateCount = draftStream.update.mock.calls.length;
41004102
capturedReplyOptions?.onVerboseProgressVisibility?.(() => true);
4103+
expect(capturedReplyOptions?.shouldDeliverCommentaryPayloads?.()).toBe(true);
41014104
await requireCapturedItemEventHandler()({
41024105
kind: "preamble",
41034106
itemId: "preamble-3",
@@ -4305,6 +4308,8 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
43054308
);
43064309

43074310
expect(capturedReplyOptions?.commentaryProgressEnabled).toBeUndefined();
4311+
expect(capturedReplyOptions?.commentaryPayloadsEnabled).toBeUndefined();
4312+
expect(capturedReplyOptions?.shouldDeliverCommentaryPayloads).toBeUndefined();
43084313
expect(capturedReplyOptions?.onVerboseProgressVisibility).toBeUndefined();
43094314
expect(capturedReplyOptions?.progressPreambleEnabled).toBe(true);
43104315
expectLastDraftUpdateText(draftStream, "Keeping the released behavior\n\n• pnpm test");

‎extensions/slack/src/monitor/message-handler/dispatch.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
496496
progressPreambleEnabled:
497497
progress.progressDraftActive && slackStreaming.mode === "progress" ? true : undefined,
498498
commentaryPayloadsEnabled: progress.commentaryProgressEnabled ? true : undefined,
499+
shouldDeliverCommentaryPayloads: progress.commentaryProgressEnabled
500+
? progress.shouldYieldDraftProgress
501+
: undefined,
499502
onVerboseProgressVisibility: progress.commentaryProgressEnabled
500503
? (isActive) => {
501504
progress.setShouldYieldDraftProgress(isActive);

‎extensions/telegram/src/bot-message-dispatch.progress-summary.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ describeTelegramDispatch("dispatchTelegramMessage progress-summary", () => {
320320
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
321321
async ({ dispatcherOptions, replyOptions }) => {
322322
expect(replyOptions?.commentaryPayloadsEnabled).toBe(true);
323+
expect(replyOptions?.shouldDeliverCommentaryPayloads).toBeUndefined();
323324
await replyOptions?.onItemEvent?.({
324325
kind: "preamble",
325326
itemId: "commentary-1",

‎extensions/telegram/src/progress-draft-preview.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe("renderTelegramProgressDraftPreview", () => {
2626
for (const name of ["Bash", "bash", "exec"]) {
2727
const rendered = renderToolLine(name);
2828
expect(rendered.match(/🛠️/gu) ?? []).toHaveLength(1);
29-
expect(rendered).toContain("print text");
3029
}
3130
});
3231

‎extensions/telegram/src/sequential-key.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ describe("getTelegramSequentialKey", () => {
398398
])("resolves key %#", (input, expected) => {
399399
expect(getTelegramSequentialKey(input)).toEqual(expected);
400400
});
401+
402+
it("keeps malformed message updates on the unknown lane", () => {
403+
expect(getTelegramSequentialKey({ message: {} as Message })).toBe("telegram:unknown");
404+
});
401405
});
402406

403407
describe("getTelegramSequentialConstraints", () => {

‎src/auto-reply/get-reply-options.types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ export type GetReplyOptions = {
265265
reasoningPayloadsEnabled?: boolean;
266266
/** Deliver durable commentary (💬) payloads to channels that own a separate commentary lane. */
267267
commentaryPayloadsEnabled?: boolean;
268+
/** Optional turn-frozen commentary owner; visibility is live by default.
269+
* With the static opt-in and this callback, core freezes, evaluates once, and snapshots. */
270+
shouldDeliverCommentaryPayloads?: () => boolean;
268271
/** Called when the agent emits a structured plan update. */
269272
onPlanUpdate?: (payload: {
270273
phase?: string;

0 commit comments

Comments
 (0)