From 4384e0d402b122006d4635700acb2e4fd86067e8 Mon Sep 17 00:00:00 2001 From: manjunath22466 Date: Sat, 7 Nov 2026 00:39:26 +0530 Subject: [PATCH] test(voice): pin crop-capture throws and defensive skips; tighten reason glosses A throw from the crop capture now has a test that it closes its decision with an error outcome. Direct calls to the crop and image senders pin the channel-closed and pointer-scale-not-useful skips. The docs say a send decision requests an image, and when a pointer snapshot counts as already requested. --- docs/CURRENT-STATE.md | 2 +- src/voice/realtimeViewportPolicy.test.mjs | 42 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 48a113873..39230c3e5 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -5779,7 +5779,7 @@ and unreachable upstream (502/504) separately from road geometry. - **Reliability**: tool-call dedupe (2.5s window across call/item/args keys); response-create queueing that respects active responses and defers follow-ups when the user starts speaking; per-tool follow-up instructions so the agent confirms only what actually happened (zoom confirms only on `ok=true`). - **Aircraft identity honesty:** “What is this aircraft?” reads callsign, operator, registration, type, and route only from the selected contact context. Missing operator, route, or type enrichment is named explicitly rather than silently omitted or inferred from the callsign. - **Diagnostics**: every client/server event is posted to `/api/realtime/debug-log` and appended to `.gev-logs/realtime-conversations.jsonl` (gitignored) with secret/image redaction; last 30 errors persist in `localStorage` (`gev-realtime-errors`); `window.__gevVoiceCommands.getDiagnostics()` in the console. - - **Visual-context escalation** (OpenAI Realtime): when a response's last tool result is a `get_entity_context` answer, a tool output from that response was sent and the data channel is open, it logs one `viewport_context.decision` with `contextId`, `send` and `reason`, plus `viewScale` (absent only for `channel-closed`) and, when `send` is true, `kind` (`viewport` or `crop`). Decision reasons: `structured-identity-sufficient` (structured context made an image unnecessary), `view-scale-not-local`, `structured-identity-missing` (sends a viewport), `pointer-ground-crop` (sends a crop), `pointer-identity-present`, `pointer-missing`, `pointer-scale-not-useful` and `channel-closed`. A send decision is followed by exactly one outcome with the same `contextId` and `kind`: `viewport_context.result` (`sent`, `data-channel-send-failed`), logged as soon as the send returns, or `viewport_context.skipped`. Pointer-crop skips are `pointer-not-fresh` (no snapshot, or a stale one), `pointer-not-ground`, `pointer-off-screen`, `pointer-already-requested` (the same snapshot was already sent, is still being captured, or an earlier attempt for it threw), `pointer-expired`, `pointer-pose-unknown` and `pose-changed`; dropped captures are `capture-unavailable`, `session-reset`, `superseded` (a newer request or turn), `channel-lost` and `frame-stale`; a step that throws before an outcome closes the pair with `error`, and the caller then logs `viewport_context.failed`. The `channel-closed` decision and the `channel-closed` and `pointer-scale-not-useful` skip outcomes are defensive and not expected from the current caller. Decision and outcome are separate records, so the debug-log rate limit can drop one half of a pair. Payloads are static codes only, never image data, tool payloads or user text, and other tool results log nothing here. Gemini Live uses a different gate in `geminiSession.js` (no pointer crop, a 1 s throttle), which is not instrumented. + - **Visual-context escalation** (OpenAI Realtime): when a response's last tool result is a `get_entity_context` answer, a tool output from that response was sent and the data channel is open, it logs one `viewport_context.decision` with `contextId`, `send` and `reason`, plus `viewScale` (absent only for `channel-closed`) and, when `send` is true, `kind` (`viewport` or `crop`). Decision reasons: `structured-identity-sufficient` (structured context made an image unnecessary), `view-scale-not-local`, `structured-identity-missing` (requests a viewport), `pointer-ground-crop` (a pointer answer with no identity at `local` or `city` scale; requests a crop, and the snapshot checks below confirm the target is ground), `pointer-identity-present`, `pointer-missing`, `pointer-scale-not-useful` and `channel-closed`. A send decision is followed by exactly one outcome with the same `contextId` and `kind`: `viewport_context.result` (`sent`, `data-channel-send-failed`), logged as soon as the send returns, or `viewport_context.skipped`. Pointer-crop skips are `pointer-not-fresh` (no snapshot, or a stale one), `pointer-not-ground`, `pointer-off-screen`, `pointer-already-requested` (the most recently requested snapshot again: already sent, still being captured, or an earlier attempt for it threw), `pointer-expired`, `pointer-pose-unknown` and `pose-changed`; dropped captures are `capture-unavailable`, `session-reset`, `superseded` (a newer request or turn), `channel-lost` and `frame-stale`; a step that throws before an outcome closes the pair with `error`, and the caller then logs `viewport_context.failed`. The `channel-closed` decision and the `channel-closed` and `pointer-scale-not-useful` skip outcomes are defensive and not expected from the current caller; direct calls to the crop or image senders log those skips with a null `contextId`. Decision and outcome are separate records, so the debug-log rate limit can drop one half of a pair. Payloads are static codes only, never image data, tool payloads or user text, and other tool results log nothing here. Gemini Live uses a different gate in `geminiSession.js` (no pointer crop, a 1 s throttle), which is not instrumented. - **Counting semantics ("near")** — a CONTRACT; new count-bearing tool work inherits it. Three honest numbers exist for one question: the Contacts cohort (250 km around the subject, what the panel shows), `analyst_query`'s count of _currently-loaded_ records for the requested scope, and the layer-wide loaded total in `coverage.layersQueried[].total`. They diverge legitimately — the flights layer loads by viewport, so after a camera dive the loaded set can hold a fraction of the cohort (field case: panel 42, analyst 8). The contract: 1. **Contacts ACTIVE** → "near / nearby / how many aircraft" means the **Contacts window** — the panel's numbers, spoken verbatim. Mechanism: `contactsWindow` (`{centeredOn, radiusKm, flights, military, vessels, complete}`), carried by both `analyst_query` and `get_current_view_state`, derived by `contactsWindowFromSnapshot()` from the same snapshot the panel renders so the two cannot drift. Voice filtering and follow-up memory use that immutable snapshot too. A cohort whose feed cannot answer reports `'unknown'`, never a confident zero; a cohort at the 20,000-row retention bound reports a lower bound. 2. **Contacts OFF** → "nearby" means **in view**; "near \" means a radius around that place. A radius query with Contacts active and no explicit centre is centred on the **active contact**, not the camera. diff --git a/src/voice/realtimeViewportPolicy.test.mjs b/src/voice/realtimeViewportPolicy.test.mjs index 4ed1c0531..2a90b3795 100644 --- a/src/voice/realtimeViewportPolicy.test.mjs +++ b/src/voice/realtimeViewportPolicy.test.mjs @@ -520,6 +520,15 @@ test('a step that throws still closes its decision, then rethrows', async () => }, }, ], + [ + pointerGround(), + { + readPointer: () => groundSnapshot(), + capturePointer: async () => { + throw new Error('crop boom'); + }, + }, + ], ]) { const { viewport, events } = recordingViewport(extra); await assert.rejects(viewport.sendVisualContextIfUseful(context), /boom/); @@ -537,6 +546,39 @@ test('a step that throws still closes its decision, then rethrows', async () => } }); +test('direct calls log their defensive skips without a decision id', async () => { + const open = recordingViewport(); + assert.equal( + await open.viewport.sendPointerCrop(groundSnapshot(), { + viewScale: 'global', + }), + false, + ); + const closed = recordingViewport({ channel: { readyState: 'closed' } }); + assert.equal( + await closed.viewport.sendPointerCrop(groundSnapshot(), { + viewScale: 'city', + }), + false, + ); + assert.equal( + await closed.viewport.sendRetainedImage( + async () => 'data:image/jpeg;base64,AA==', + 'text', + 'client.viewport_context', + ), + false, + ); + assert.deepEqual( + [...open.events, ...closed.events].map((item) => item.detail), + [ + { contextId: null, kind: 'crop', reason: 'pointer-scale-not-useful' }, + { contextId: null, kind: 'crop', reason: 'channel-closed' }, + { contextId: null, kind: 'viewport', reason: 'channel-closed' }, + ], + ); +}); + test('a throw after a real send still logs it as sent', async () => { let reads = 0; const { viewport, events } = recordingViewport({