Skip to content

Commit 0134c78

Browse files
authored
fix(agents): deliver Codex input choices in Telegram and web chat (#124146)
Mark harness-owned input prompts for source-suppression delivery so Codex choices and secret prompts reach the originating chat during message-tool-only turns. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 94a0661 commit 0134c78

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎src/agents/harness/user-input-bridge.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { markReplyPayloadForSourceSuppressionDelivery } from "../../auto-reply/reply-payload.js";
12
import type { MessagePresentation } from "../../interactive/payload.js";
23
import type { EmbeddedRunAttemptParams } from "../embedded-agent-runner/run/types.js";
34

@@ -79,7 +80,9 @@ export async function deliverAgentHarnessUserInputPrompt(
7980
): Promise<void> {
8081
const text = formatAgentHarnessUserInputPrompt(questions, options);
8182
if (params.onBlockReply) {
82-
await params.onBlockReply({ text, presentation: options.presentation });
83+
await params.onBlockReply(
84+
markReplyPayloadForSourceSuppressionDelivery({ text, presentation: options.presentation }),
85+
);
8386
return;
8487
}
8588
await params.onPartialReply?.({ text });
@@ -159,14 +162,14 @@ export function buildAgentHarnessQuestionPromptPayload(params: {
159162
new Set(normalizedOptionValues).size === candidateOptionValues.length
160163
? candidateOptionValues
161164
: undefined;
162-
return {
165+
return markReplyPayloadForSourceSuppressionDelivery({
163166
text: `${prompt}\n\n${questionReplyGuidance(params.questions)}`,
164167
...(presentation ? { presentation, presentationTextMode: "fallback" as const } : {}),
165168
// Native callbacks need Gateway option order even when presentation controls are reordered.
166169
channelData: {
167170
askUser: { questionId: params.questionId, ...(optionValues ? { optionValues } : {}) },
168171
},
169-
};
172+
});
170173
}
171174

172175
function questionReplyGuidance(questions: readonly AgentHarnessUserInputQuestion[]): string {

‎src/auto-reply/reply/dispatch-from-config.send-policy-routing.test-utils.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Imported by dispatch-from-config.test.ts to keep its mocked suite in one Vitest module graph.
22
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
33
import { registerAgentHarness } from "../../agents/harness/registry.js";
4+
import {
5+
buildAgentHarnessQuestionPromptPayload,
6+
deliverAgentHarnessUserInputPrompt,
7+
} from "../../agents/harness/user-input-bridge.js";
48
import type { OpenClawConfig } from "../../config/config.js";
59
import { settleReplyDispatcher } from "../dispatch-dispatcher.js";
610
import { getReplyPayloadMetadata, setReplyPayloadMetadata } from "../reply-payload.js";
@@ -163,6 +167,54 @@ describe("sendPolicy deny — suppress delivery, not processing (#53328)", () =>
163167
expect(onBlockReplyQueued).not.toHaveBeenCalled();
164168
});
165169

170+
it.each([
171+
{
172+
name: "gateway-backed choice",
173+
deliver: async (onBlockReply: NonNullable<GetReplyOptions["onBlockReply"]>) => {
174+
await onBlockReply(
175+
buildAgentHarnessQuestionPromptPayload({
176+
questionId: "question-owned-by-harness",
177+
questions: [
178+
{
179+
id: "color",
180+
header: "Color",
181+
question: "Choose a color",
182+
options: [{ label: "Red" }, { label: "Blue" }],
183+
},
184+
],
185+
}),
186+
);
187+
},
188+
},
189+
{
190+
name: "plain secret",
191+
deliver: async (onBlockReply: NonNullable<GetReplyOptions["onBlockReply"]>) => {
192+
await deliverAgentHarnessUserInputPrompt({ onBlockReply }, [
193+
{ id: "token", header: "Token", question: "Enter your token", isSecret: true },
194+
]);
195+
},
196+
},
197+
])("delivers $name harness questions in direct message-tool-only turns", async ({ deliver }) => {
198+
setNoAbort();
199+
sessionStoreMocks.currentEntry = { sessionId: "s1", updatedAt: 0, sendPolicy: "allow" };
200+
const dispatcher = createDispatcher();
201+
const replyResolver = vi.fn(async (_ctx: MsgContext, opts?: GetReplyOptions) => {
202+
await deliver(requireBlockReplyHandler(opts?.onBlockReply));
203+
return [];
204+
});
205+
206+
const result = await dispatchReplyFromConfig({
207+
ctx: buildTestCtx({ ChatType: "direct", SessionKey: "test:harness-question" }),
208+
cfg: emptyConfig,
209+
dispatcher,
210+
replyResolver,
211+
replyOptions: { sourceReplyDeliveryMode: "message_tool_only" },
212+
});
213+
214+
expect(result.queuedFinal).toBe(false);
215+
expect(dispatcher.sendBlockReply).toHaveBeenCalledTimes(1);
216+
});
217+
166218
it("keeps hook-cancelled marked blocks out of delivery and queued callbacks", async () => {
167219
setNoAbort();
168220
sessionStoreMocks.currentEntry = {

0 commit comments

Comments
 (0)