The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
The answer to a question Codex 0.160 asks without stopping reads as the answer, not its wrapper (#868)
Deed3146e4ed723
diff --git a/cli/e2e/harness/fakeEngine.mjs b/cli/e2e/harness/fakeEngine.mjsindex e770a9eb6..2b0c9234b 100644--- a/cli/e2e/harness/fakeEngine.mjs+++ b/cli/e2e/harness/fakeEngine.mjs@@ -1198,6 +1198,20 @@ export async function run(engine, config = {}, { native = false } = {}) {await finish(`you chose ${choice}${notes ? ` (notes: ${notes})` : ''}`)return}+ if (engine === 'codex' && directive?.[1] === 'askasync') {+ // Codex 0.160's question that does not stop the turn (shape measured on real rollouts): the call, its+ // `{"accepted":true}` at once, and later the person's answer as a user message wrapped in+ // `<send_user_message_question_reply>`. Only the transcript is faked: the answer is written as if+ // given at once, with no dialog drawn, since 0.160's panel for it was not recorded.+ const id = `call_${turn}_qa`+ const question = 'Which database should the service use?'+ codex('response_item', { type: 'function_call', name: 'request_user_input_async', call_id: id, arguments: JSON.stringify({ questions: [{ title: question, options: ['Postgres', 'SQLite'] }] }) })+ codex('event_msg', { type: 'item_completed', turn_id: open, item: { type: 'AgentMessage', content: [{ type: 'Text', text: 'Asked which database to use.' }], phase: 'commentary' } })+ codex('response_item', { type: 'function_call_output', call_id: id, output: JSON.stringify({ accepted: true }) })+ const answer = `<send_user_message_question_reply>\n${JSON.stringify([{ answer: directive[2] || 'Postgres', question, questionItemId: JSON.stringify([id]) }])}\n</send_user_message_question_reply>`+ codex('response_item', { type: 'message', role: 'user', content: [{ type: 'input_text', text: answer }] })+ codex('event_msg', { type: 'item_completed', turn_id: open, item: { type: 'UserMessage', id: `${id}-reply`, content: [{ type: 'text', text: answer, text_elements: [] }] } })+ }if (directive?.[1] === 'version') { await finish(versionLine); return }if (engine === 'codex' && directive?.[1] === 'goal') {bottom = goalBottom(directive[2] === 'done' ? 'Goal achieved (1m)' : 'Pursuing goal (1m)')diff --git a/cli/e2e/questions.e2e.ts b/cli/e2e/questions.e2e.tsindex 69e257373..612994340 100644--- a/cli/e2e/questions.e2e.ts+++ b/cli/e2e/questions.e2e.ts@@ -201,4 +201,24 @@ describe('an agent asks a question', () => {await sentclient.close()})++ it('codex: the answer to a question Codex 0.160 asks without stopping reads as the answer, not its wrapper, live and in the history', async () => {+ const d = await fresh()+ const client = await LocalClient.connect(d)+ const agent = await create(d, client, 'codex', 'askasync-codex')+ // The answer comes back as a user message wrapped in <send_user_message_question_reply> around JSON,+ // and was the person's words exactly so: in the live turn, the history, the recap and search.+ const readable = 'Which database should the service use? → SQLite'+ const since = client.frames.length+ client.send('message', { agentId: agent.id, content: '!askasync SQLite' })+ const started = await client.waitFor((frame) => isTurn('turn_started', agent.id)(frame) && frame.payload?.userMessage !== '!askasync SQLite', 45_000, 'the answer\'s turn', since)+ expect(started.payload?.userMessage).toBe(readable)+ await client.waitFor(isTurn('turn_ended', agent.id), 45_000, 'the answer\'s turn to end', client.frames.indexOf(started) + 1)+ const page = await client.request<{ events?: Array<{ type: string; payload: Record<string, any> }>; error?: string }>(+ 'session_get', { sessionId: agent.sessionId, limit: 200 }, 30_000)+ expect(page.error).toBeUndefined()+ const said = (page.events ?? []).filter((event) => event.type === 'user_message').map((event) => event.payload.content)+ expect(said).toEqual(['!askasync SQLite', readable])+ client.close()+ })})diff --git a/cli/src/engines/codex/normalizer.spec.ts b/cli/src/engines/codex/normalizer.spec.tsindex 3e5e7f594..ecd232e73 100644--- a/cli/src/engines/codex/normalizer.spec.ts+++ b/cli/src/engines/codex/normalizer.spec.ts@@ -756,3 +756,57 @@ describe('Codex sub-agents — the 0.160 multi-agent v2 vocabulary', () => {expect(events[1].payload).toMatchObject({ id: spawnCall, isError: false, output: 'There are 12 fixtures.', subagent: { agentId: '/root/scout' } })})})++/**+ * Codex 0.160's non-blocking question (`request_user_input_async`, answered `{"accepted":true}` at once):+ * the person's answer comes back later as a user message, wrapped (shape measured on real 0.160.0 rollouts;+ * text invented):+ *+ * <send_user_message_question_reply>+ * [{"answer":"…","question":"…","questionItemId":"…"}]+ * </send_user_message_question_reply>+ *+ * Read as typed text, that wrapper and its JSON were the person's message: in the live turn, the history,+ * the recap and search.+ */+describe('Codex 0.160 — the answer to a non-blocking question', () => {+ const reply = (answers: Array<Record<string, string>>) =>+ `<send_user_message_question_reply>\n${JSON.stringify(answers)}\n</send_user_message_question_reply>`+ const answered = reply([{ answer: 'Postgres', question: 'Which database should the service use?', questionItemId: '["q-1"]' }])+ const userItem = (text: string) => line('event_msg', { type: 'item_completed', item: { type: 'UserMessage', id: 'u2', client_id: 'c2', content: [{ type: 'text', text, text_elements: [] }] } })+ const fixture = [+ line('event_msg', { type: 'task_started', turn_id: 'turn-1' }),+ userItem('Set up the service'),+ line('response_item', { type: 'function_call', name: 'request_user_input_async', call_id: 'call_q1', arguments: JSON.stringify({ questions: [{ title: 'Which database should the service use?', options: ['Postgres', 'SQLite'] }] }) }),+ line('response_item', { type: 'function_call_output', call_id: 'call_q1', output: JSON.stringify({ accepted: true }) }),+ line('response_item', { type: 'message', role: 'user', content: [{ type: 'input_text', text: answered }] }),+ userItem(answered),+ line('event_msg', { type: 'item_completed', item: { type: 'AgentMessage', content: [{ type: 'Text', text: 'Using Postgres.' }], phase: 'final_answer' } }),+ line('event_msg', { type: 'task_complete', turn_id: 'turn-1' }),+ ]++ it('reads as the question and the answer, live', () => {+ const normalizer = new CodexNormalizer('live')+ const starts = fixture.flatMap((raw) => normalizer.ingest(raw)).filter((event) => event.type === 'turn_started')+ expect(starts.map((event) => event.payload.userMessage)).toEqual(['Set up the service', 'Which database should the service use? → Postgres'])+ })++ it('reads the same in the history and the recap', () => {+ const history = codexMessagesToEvents(fixture).filter((event) => event.type === 'user_message')+ expect(history.map((event) => event.payload.content)).toEqual(['Set up the service', 'Which database should the service use? → Postgres'])+ expect(lastCodexTurnText(fixture)).toEqual({ userMessage: 'Which database should the service use? → Postgres', assistantText: 'Using Postgres.' })+ })++ it('puts several answers one to a line, and an answer without its question as just the answer', () => {+ const normalizer = new CodexNormalizer('live')+ const text = reply([{ answer: 'Postgres', question: 'Database?' }, { answer: 'Yes' }, { question: 'Skipped?', answer: ' ' }])+ expect(normalizer.ingest(userItem(text))).toEqual([{ type: 'turn_started', payload: { userMessage: 'Database? → Postgres\nYes' } }])+ })++ it('keeps what is inside a wrapper it cannot read, without the wrapper', () => {+ const normalizer = new CodexNormalizer('live')+ const text = '<send_user_message_question_reply>\nnot json\n</send_user_message_question_reply>'+ expect(normalizer.ingest(userItem(text))).toEqual([{ type: 'turn_started', payload: { userMessage: 'not json' } }])+ expect(new CodexNormalizer('live').ingest(userItem(reply([])))).toEqual([{ type: 'turn_started', payload: { userMessage: '[]' } }])+ })+})diff --git a/cli/src/engines/codex/normalizer.ts b/cli/src/engines/codex/normalizer.tsindex cae406d40..abcefd4e7 100644--- a/cli/src/engines/codex/normalizer.ts+++ b/cli/src/engines/codex/normalizer.ts@@ -109,6 +109,24 @@ function messageText(item: JsonObject): string {return string(item.message) || textContent(item)}+/**+ * What the person said. Codex 0.160's answer to a question that does not stop the turn+ * (`request_user_input_async`) is a user message wrapping JSON `[{answer, question, questionItemId}]` in+ * `<send_user_message_question_reply>`, and was read as typed, wrapper and all (real 0.160 rollouts).+ */+function userText(item: JsonObject): string {+ const text = messageText(item)+ const body = /^\s*<send_user_message_question_reply>\s*([\s\S]*?)\s*(?:<\/send_user_message_question_reply>\s*)?$/.exec(text)?.[1]+ if (body === undefined) return text+ let replies: unknown+ try { replies = JSON.parse(body) } catch { return body }+ const lines = (Array.isArray(replies) ? replies : []).map(object).flatMap((entry) => {+ const [answer, question] = [string(entry?.answer).trim(), string(entry?.question).trim()]+ return answer ? [question ? `${question} → ${answer}` : answer] : []+ })+ return lines.join('\n') || body+}+function parseInput(value: unknown): unknown {if (typeof value !== 'string') return value ?? {}try { return JSON.parse(value) } catch { return value }@@ -322,7 +340,7 @@ export class CodexNormalizer implements EngineNormalizer {}if (USER_TURN_TYPES.has(type)) {- const message = messageText(item)+ const message = userText(item)if (!message) return []if (this.mode === 'replay') return [{ type: 'user_message', payload: { content: message } }]const events: LiveEvent[] = []@@ -620,7 +638,7 @@ export function selectCodexRecapLine(line: string): 'keep' | 'skip' | 'stop' {if (raw.type === 'response_item' && string(item.type) === 'message') return goalObjective(item) ? 'stop' : 'skip'if (raw.type !== 'event_msg') return 'skip'const itemType = string(item.type)- if (USER_TURN_TYPES.has(itemType) && messageText(item)) return 'stop'+ if (USER_TURN_TYPES.has(itemType) && userText(item)) return 'stop'return AGENT_TEXT_TYPES.has(itemType) ? 'keep' : 'skip'}@@ -635,7 +653,7 @@ export function startsCodexTurn(line: string): boolean {const item = payload(raw)if (!item) return falseconst type = string(item.type)- if (raw.type === 'event_msg') return USER_TURN_TYPES.has(type) && !!messageText(item)+ if (raw.type === 'event_msg') return USER_TURN_TYPES.has(type) && !!userText(item)return raw.type === 'response_item' && type === 'message' && goalObjective(item) !== null}@@ -692,7 +710,7 @@ export function lastCodexTurnText(rawLines: string[]): LastTurnText | null {if (raw.type !== 'event_msg') continueconst itemType = string(item.type)if (USER_TURN_TYPES.has(itemType)) {- const message = messageText(item)+ const message = userText(item)if (message) { userMessage = message; assistantText = ''; finalText = ''; sawPhase = false }} else if (AGENT_TEXT_TYPES.has(itemType)) {const message = messageText(item)