Skip to content

Commit 93a7929

Browse files
feat: add opt-in network response digest
Preserve every network entry and top-level recovery/actionability signal while dropping only verbose per-entry header, body, and raw-log fields at digest response level. Record deterministic output-economy baselines and parity tests. Refs #1186 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 7579026 commit 93a7929

6 files changed

Lines changed: 234 additions & 0 deletions

File tree

‎docs/agents/contract-projection-output-economy-spike.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,33 @@ from those projections, `AgentDeviceCommandClient` derives the five navigation m
9494

9595
Recommendation: #1185 should CONTINUE incrementally, one already-typed closed-contract family at a
9696
time, re-measuring declarations and bundle each step and stopping on any stop condition.
97+
98+
## Digest expansion results (#1186)
99+
100+
Added one conservative, opt-in `network` response view in `src/daemon/response-views.ts`
101+
(registered as `RESPONSE_VIEWS.network`). It acts ONLY at `responseLevel: 'digest'`; `default`
102+
and `full` return the same object reference, so the default wire shape stays byte-identical
103+
(Maestro `.ad` recompare safe) and live metrics remain informational.
104+
105+
Transformation: the entire top-level dump (`path`, `exists`, `active`, `state`, `backend`,
106+
`include`, `scannedLines`, `matchedLines`, `limits`, `notes`, and any additive fields) is
107+
preserved, EVERY entry is preserved (none dropped, capped, or reordered), and only the verbose
108+
per-entry payload fields are removed: `headers`, `requestHeaders`, `responseHeaders`,
109+
`requestBody`, `responseBody`, `raw`. Each entry keeps its actionable identity — `method`, `url`,
110+
`status`, `timestamp`, `durationMs`, `packetId`, `line`, and any additive fields such as
111+
`metadata`.
112+
113+
Measured on the deterministic `selection.network` fixture (`network ... --include all`, 8 entries):
114+
115+
- Output bytes: 26,371 -> 1,665 (24,706 fewer / 93.7% reduction).
116+
- Entries preserved: 8 -> 8 (no follow-up refetch needed; identity intact).
117+
- Follow-up actionability: the failed POST keeps method/url/status/packetId/duration/timestamp and
118+
the top-level recovery note, so the retry path is unchanged (no extra follow-up calls implied).
119+
- Fallback observations: 0 (routine-workflow oracle unchanged).
120+
- Retries: 1 (routine-workflow oracle unchanged).
121+
- Recovery/session fields: preserved (routine-workflow oracle unchanged).
122+
123+
Defaults are unchanged; the digest is strictly opt-in via a non-default response level. Residual
124+
risk: the dropped-field set is intentionally specific to the known verbose network payload fields;
125+
if a backend introduces a new large per-entry field it would remain until added to the drop list
126+
(safe by default — unknown fields are preserved, never silently narrowed).

‎src/daemon/__tests__/response-views.test.ts‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,115 @@ test('resolution digest and settle digest compose independently', () => {
422422
expect((digest.resolution as { alternatives?: unknown[] }).alternatives).toBeUndefined();
423423
expect((digest.settle as { diff?: { lines?: unknown[] } }).diff?.lines).toBeUndefined();
424424
});
425+
426+
const networkView = RESPONSE_VIEWS.network;
427+
428+
const NETWORK_DATA: DaemonResponseData = {
429+
path: '/tmp/app.log',
430+
exists: true,
431+
active: true,
432+
state: 'active',
433+
backend: 'ios-simulator',
434+
include: 'all',
435+
scannedLines: 4000,
436+
matchedLines: 2,
437+
limits: { maxEntries: 25, maxPayloadChars: 2048, maxScanLines: 4000 },
438+
entries: [
439+
{
440+
method: 'POST',
441+
url: 'https://api.example.test/checkout/1',
442+
status: 503,
443+
timestamp: '2026-07-02T12:00:00.000Z',
444+
durationMs: 120,
445+
packetId: 'packet-1',
446+
line: 3900,
447+
metadata: { requestId: 'request-1' },
448+
headers: 'authorization: <redacted>\ncontent-type: application/json',
449+
requestHeaders: { authorization: '<redacted>' },
450+
responseHeaders: { 'x-retry-after-ms': '500' },
451+
requestBody: '{"cartId":"cart-1"}',
452+
responseBody: '{"error":"service unavailable"}',
453+
raw: 'network capture 1: {"error":"service unavailable"}',
454+
},
455+
{
456+
method: 'GET',
457+
url: 'https://api.example.test/checkout/2',
458+
status: 200,
459+
timestamp: '2026-07-02T12:00:01.000Z',
460+
durationMs: 137,
461+
packetId: 'packet-2',
462+
line: 3901,
463+
headers: 'content-type: application/json',
464+
requestBody: '',
465+
responseBody: 'ok',
466+
raw: 'network capture 2: ok',
467+
},
468+
],
469+
notes: ['The first checkout request returned 503. Retry after the service recovery window.'],
470+
warnings: ['Network capture omitted one malformed log line.'],
471+
artifacts: [{ field: 'path', artifactType: 'app-log', artifactId: 'artifact-network-log' }],
472+
};
473+
474+
test('network view is registered', () => {
475+
expect(typeof networkView).toBe('function');
476+
});
477+
478+
test('network digest keeps the whole dump + every entry identity, dropping only payload material', () => {
479+
const digest = networkView!(NETWORK_DATA, 'digest');
480+
// Top-level dump is preserved verbatim.
481+
for (const key of [
482+
'path',
483+
'exists',
484+
'active',
485+
'state',
486+
'backend',
487+
'include',
488+
'scannedLines',
489+
'matchedLines',
490+
'limits',
491+
'notes',
492+
'warnings',
493+
'artifacts',
494+
] as const) {
495+
expect(digest[key]).toEqual(NETWORK_DATA[key]);
496+
}
497+
const entries = digest.entries as Record<string, unknown>[];
498+
// No entry is dropped or reordered.
499+
expect(entries).toHaveLength(2);
500+
// The failed request stays fully diagnosable.
501+
expect(entries[0]).toEqual({
502+
method: 'POST',
503+
url: 'https://api.example.test/checkout/1',
504+
status: 503,
505+
timestamp: '2026-07-02T12:00:00.000Z',
506+
durationMs: 120,
507+
packetId: 'packet-1',
508+
line: 3900,
509+
metadata: { requestId: 'request-1' },
510+
});
511+
// Verbose payload material is gone from every entry.
512+
for (const entry of entries) {
513+
for (const dropped of [
514+
'headers',
515+
'requestHeaders',
516+
'responseHeaders',
517+
'requestBody',
518+
'responseBody',
519+
'raw',
520+
]) {
521+
expect(dropped in entry).toBe(false);
522+
}
523+
}
524+
});
525+
526+
test('network default and full return today’s shape unchanged (same reference)', () => {
527+
expect(networkView!(NETWORK_DATA, 'default')).toBe(NETWORK_DATA);
528+
expect(networkView!(NETWORK_DATA, 'full')).toBe(NETWORK_DATA);
529+
});
530+
531+
test('network digest tolerates a missing/empty entries list', () => {
532+
const empty: DaemonResponseData = { path: '/tmp/app.log', exists: false };
533+
expect(networkView!(empty, 'digest')).toBe(empty);
534+
const emptyList: DaemonResponseData = { path: '/tmp/app.log', entries: [] };
535+
expect(networkView!(emptyList, 'digest')).toEqual({ path: '/tmp/app.log', entries: [] });
536+
});

‎src/daemon/response-views.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,47 @@ function readObjectRecord(value: unknown): Record<string, unknown> | undefined {
215215
: undefined;
216216
}
217217

218+
// Verbose per-entry network payload fields a digest drops. Each is the raw HTTP
219+
// header/body material or the unparsed log line — the dominant token sink in a
220+
// `network ... --include all` dump. Every actionable identity field
221+
// (method/url/status/timestamp/durationMs/packetId/line and any additive field
222+
// such as `metadata`) is kept, so a failed request stays diagnosable.
223+
const NETWORK_DIGEST_DROPPED_ENTRY_FIELDS: readonly string[] = [
224+
'headers',
225+
'requestHeaders',
226+
'responseHeaders',
227+
'requestBody',
228+
'responseBody',
229+
'raw',
230+
];
231+
232+
/**
233+
* Token-cheap network digest (#1186). CONSERVATIVE and opt-in: it acts only at
234+
* `digest` and otherwise returns the data UNCHANGED, so `default` (byte-identical
235+
* wire shape) and `full` are never narrowed. It preserves the ENTIRE top-level
236+
* dump — `path`, `exists`, `active`, `state`, `backend`, `include`,
237+
* `scannedLines`, `matchedLines`, `limits`, `notes`, and any additive fields —
238+
* and EVERY entry, dropping only the verbose per-entry payload material
239+
* (headers/bodies/raw log line). Nothing is capped or reordered.
240+
*/
241+
function networkView(data: DaemonResponseData, level: ResponseLevel): DaemonResponseData {
242+
if (level !== 'digest') return data;
243+
const entries = data.entries;
244+
if (!Array.isArray(entries)) return data;
245+
return { ...data, entries: entries.map(compactNetworkEntry) };
246+
}
247+
248+
function compactNetworkEntry(entry: unknown): unknown {
249+
const record = readObjectRecord(entry);
250+
if (!record) return entry;
251+
const compact: Record<string, unknown> = {};
252+
for (const [key, value] of Object.entries(record)) {
253+
if (NETWORK_DIGEST_DROPPED_ENTRY_FIELDS.includes(key)) continue;
254+
compact[key] = value;
255+
}
256+
return compact;
257+
}
258+
218259
export const RESPONSE_VIEWS: Record<string, ResponseView> = {
219260
snapshot: snapshotView,
220261
screenshot: screenshotView,
@@ -224,4 +265,5 @@ export const RESPONSE_VIEWS: Record<string, ResponseView> = {
224265
click: interactionDigestView,
225266
fill: interactionDigestView,
226267
longpress: interactionDigestView,
268+
network: networkView,
227269
};

‎test/output-economy/output-economy.baseline.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@
118118
"hints": 0,
119119
"shape": "$.active:boolean|$.backend:string|$.entries:array|$.entries[].durationMs:number|$.entries[].headers:string|$.entries[].line:number|$.entries[].method:string|$.entries[].packetId:string|$.entries[].raw:string|$.entries[].requestBody:string|$.entries[].requestHeaders.authorization:string|$.entries[].requestHeaders.content-type:string|$.entries[].requestHeaders.x-request-id:string|$.entries[].requestHeaders:object|$.entries[].responseBody:string|$.entries[].responseHeaders.content-type:string|$.entries[].responseHeaders.x-request-id:string|$.entries[].responseHeaders.x-retry-after-ms:string|$.entries[].responseHeaders:object|$.entries[].status:number|$.entries[].timestamp:string|$.entries[].url:string|$.entries[]:object|$.exists:boolean|$.include:string|$.limits.maxEntries:number|$.limits.maxPayloadChars:number|$.limits.maxScanLines:number|$.limits:object|$.matchedLines:number|$.notes:array|$.notes[]:string|$.path:string|$.scannedLines:number|$.state:string|$:object"
120120
},
121+
"selection.network.digest.json": {
122+
"bytes": 1665,
123+
"lines": 1,
124+
"refs": 0,
125+
"hints": 0,
126+
"shape": "$.active:boolean|$.backend:string|$.entries:array|$.entries[].durationMs:number|$.entries[].line:number|$.entries[].method:string|$.entries[].packetId:string|$.entries[].status:number|$.entries[].timestamp:string|$.entries[].url:string|$.entries[]:object|$.exists:boolean|$.include:string|$.limits.maxEntries:number|$.limits.maxPayloadChars:number|$.limits.maxScanLines:number|$.limits:object|$.matchedLines:number|$.notes:array|$.notes[]:string|$.path:string|$.scannedLines:number|$.state:string|$:object"
127+
},
121128
"selection.events.default.json": {
122129
"bytes": 7686,
123130
"lines": 1,

‎test/output-economy/output-economy.baseline.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ describe('deterministic output-economy baseline', () => {
5858
expect(actual['screenshot.digest.json']!.bytes).toBeLessThan(
5959
actual['screenshot.default.json']!.bytes,
6060
);
61+
expect(actual['selection.network.digest.json']!.bytes).toBeLessThan(
62+
actual['selection.network.default.json']!.bytes,
63+
);
6164
});
6265
});
6366

@@ -131,6 +134,43 @@ describe('actionability and reliability floors', () => {
131134
});
132135
});
133136

137+
test('network digest preserves every entry identity, notes, and follow-up actionability', () => {
138+
const digest = rendered.networkDigest;
139+
const defaultEntries = (
140+
rendered.samples['selection.network.default.json'] as { data: { entries: unknown[] } }
141+
).data.entries;
142+
const digestEntries = digest.entries as Record<string, unknown>[];
143+
// Opt-in digest drops NO entry — every observed request stays present.
144+
expect(digestEntries).toHaveLength(defaultEntries.length);
145+
// The failed request keeps the identity an agent needs to retry it.
146+
expect(digestEntries[0]).toMatchObject({
147+
method: 'POST',
148+
url: 'https://api.example.test/checkout/1',
149+
status: 503,
150+
packetId: 'packet-1',
151+
durationMs: 120,
152+
timestamp: '2026-07-02T12:00:00.000Z',
153+
line: 3900,
154+
});
155+
// Verbose payload material is the only thing removed.
156+
for (const entry of digestEntries) {
157+
for (const dropped of [
158+
'headers',
159+
'requestHeaders',
160+
'responseHeaders',
161+
'requestBody',
162+
'responseBody',
163+
'raw',
164+
]) {
165+
expect(dropped in entry).toBe(false);
166+
}
167+
}
168+
// Recovery guidance (top-level notes) survives, so the retry path is intact.
169+
expect(digest.notes).toEqual([
170+
'The first checkout request returned 503. Retry after the service recovery window.',
171+
]);
172+
});
173+
134174
test('normalized failures keep stable identity, retryability, and next-step guidance', () => {
135175
expect(rendered.error).toMatchObject({
136176
code: 'DEVICE_IN_USE',

‎test/output-economy/render-fixtures.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export async function renderOutputFixtures() {
3838
const selectorDigest = RESPONSE_VIEWS.find!(SELECTOR_READ_RESULT, 'digest');
3939
const screenshotDefault = RESPONSE_VIEWS.screenshot!(SCREENSHOT_RESULT, 'default');
4040
const screenshotDigest = RESPONSE_VIEWS.screenshot!(SCREENSHOT_RESULT, 'digest');
41+
const networkDigest = RESPONSE_VIEWS.network!(NETWORK_SELECTION_RESULT, 'digest');
4142
const error = normalizeError(ACTIONABLE_ERROR);
4243
const errorPolicyNormalized = normalizeError(POLICY_NORMALIZED_ERROR);
4344
const mcpSnapshot = await createCommandToolExecutor({
@@ -54,6 +55,7 @@ export async function renderOutputFixtures() {
5455
selectorDigest,
5556
screenshotDefault,
5657
screenshotDigest,
58+
networkDigest,
5759
error,
5860
errorPolicyNormalized,
5961
mcpSnapshot,
@@ -75,6 +77,7 @@ export async function renderOutputFixtures() {
7577
'error.policy-normalized.json': { data: errorPolicyNormalized },
7678
'mcp.snapshot.default.json': { data: mcpSnapshot },
7779
'selection.network.default.json': { data: NETWORK_SELECTION_RESULT },
80+
'selection.network.digest.json': { data: networkDigest },
7881
'selection.events.default.json': { data: EVENTS_SELECTION_RESULT },
7982
'selection.debug.default.json': { data: DEBUG_SELECTION_RESULT },
8083
'selection.recording.default.json': { data: RECORDING_SELECTION_RESULT },

0 commit comments

Comments
 (0)