Skip to content

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.

fix(cli): decrypt question_response, so a device answer reaches the pane

0xdiego253caa51d259f2
diff --git a/cli/src/lib/e2ee/core.test.ts b/cli/src/lib/e2ee/core.test.ts
index d1fa89b99..61e358b9d 100644
--- a/cli/src/lib/e2ee/core.test.ts
+++ b/cli/src/lib/e2ee/core.test.ts
@@ -139,6 +139,24 @@ describe('e2ee core — codes + fingerprint + classification', () => {
expect(C.ENCRYPTED_RPC_RESULT_TYPES.has('models_list_result')).toBe(true)
})
+ it('gates question_response, which the device encrypts', () => {
+ // Regression. The firmware wraps this frame because an AskUserQuestion answer is user content, but the
+ // type was missing from ENCRYPTED_DOWN_TYPES, so dispatchDown never unwrapped it. The failure was
+ // silent in the worst way: no decrypt error, just a payload that still held the {__e2e} envelope, so
+ // requestId/sessionId/answers all read undefined and the answer was discarded as malformed. The device
+ // returned to its tiles believing it had answered, and the CLI sat on question 1 until killed.
+ expect(C.isEncryptedDownType('question_response')).toBe(true)
+
+ const key = seeded(29)(32)
+ const wrapped = C.wrapPayload(key, 'p', 1, 'question_response', undefined, {
+ requestId: 'q_f5809c62', sessionId: 's1', answers: { color: 'Xanh' },
+ })
+ expect(wrapped).not.toHaveProperty('answers') // the answer text must not travel in the clear
+ expect(C.unwrapPayload(key, wrapped.__e2e, 'question_response', undefined)).toEqual({
+ requestId: 'q_f5809c62', sessionId: 's1', answers: { color: 'Xanh' },
+ })
+ })
+
it('round trips runtime catalog request and result only as pairwise ciphertext', () => {
const key = seeded(23)(32)
const request = C.wrapPayload(key, 'p', 1, 'models_list', undefined, { requestId: 'models-1' })
@@ -168,6 +186,6 @@ describe('e2ee core — interop keystone', () => {
it('core.ts still hashes to the pinned value shared with the other implementations', () => {
const here = dirname(fileURLToPath(import.meta.url))
const actual = createHash('sha256').update(readFileSync(join(here, 'core.ts'))).digest('hex')
- expect(actual).toBe('9044aa2e2da62fb4bee401ee06941440daabc6265058f34e941c849661ccf167')
+ expect(actual).toBe('ef9c3f25f41bc4ccece8d082aa9c366037399de9b462d5106c165ce25d0f9bb0')
})
})
diff --git a/cli/src/lib/e2ee/core.ts b/cli/src/lib/e2ee/core.ts
index da82e77d5..dc5c2f587 100644
--- a/cli/src/lib/e2ee/core.ts
+++ b/cli/src/lib/e2ee/core.ts
@@ -354,6 +354,11 @@ export const ENCRYPTED_RPC_RESULT_TYPES = new Set<string>([
/** Client→adapter frames that carry or can trigger adapter-local user data. */
export const ENCRYPTED_DOWN_TYPES = new Set<string>([
'message',
+ // An AskUserQuestion answer is user content, so the firmware wraps it (e2ee_manager.c). Leaving it out
+ // of this set did NOT fail loudly: unwrapDown was simply never called, the payload stayed the raw
+ // {__e2e} envelope, and requestId/sessionId/answers all read back undefined — so the answer was dropped
+ // as "no session/answers", the pane dialog was never keyed, and the CLI waited on question 1 forever.
+ 'question_response',
'agents_list', 'sessions_list', 'session_get', 'models_list',
'agent_create', 'agent_delete', 'agent_recent', 'agent_update', 'agent_files', 'agent_read_file',
'device_e2ee_pair', 'e2ee_pairings_list', 'e2ee_pairing_unpair',
diff --git a/cli/src/lib/e2ee/manager.test.ts b/cli/src/lib/e2ee/manager.test.ts
index 805d0469c..fe12ceae2 100644
--- a/cli/src/lib/e2ee/manager.test.ts
+++ b/cli/src/lib/e2ee/manager.test.ts
@@ -221,6 +221,13 @@ describe('E2eeManager pairing', () => {
const wrapped = C.wrapPayload(web.session!.c2s, 'p', 0, 'message', undefined, { content: 'fix the bug' })
const down = mgr.unwrapDown(conn, { type: 'message', payload: wrapped })
expect((down!.payload as Record<string, unknown>).content).toBe('fix the bug')
+
+ // Same path for an AskUserQuestion answer — the device wraps it, so the answers must survive the trip
+ // intact. When they did not, the CLI dropped the frame and the pane's dialog was never keyed.
+ const qw = C.wrapPayload(web.session!.c2s, 'p', 1, 'question_response', undefined,
+ { requestId: 'q1', sessionId: 'sX', answers: { color: 'Xanh' } })
+ const qdown = mgr.unwrapDown(conn, { type: 'question_response', payload: qw })
+ expect((qdown!.payload as Record<string, unknown>).answers).toEqual({ color: 'Xanh' })
})
it('rejects a wrong code at the confirmation MAC (round 2)', async () => {