Skip to content

Commit 8c91ceb

Browse files
committed
Remove unused measureResponseShape helper and its tests
1 parent b17e7fb commit 8c91ceb

2 files changed

Lines changed: 0 additions & 79 deletions

File tree

workers/src/tokenize.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,34 +115,3 @@ export async function measurePayloadShape(
115115
tokenize_ms: tokenizerRan ? tokenize_ms : 0,
116116
};
117117
}
118-
119-
/**
120-
* Measure the byte and token shape of a Request/Response pair using the
121-
* call-site Response object directly. Clones the response so the original
122-
* body flows untouched back to the caller, reads the clone to completion,
123-
* then delegates to `measurePayloadShape`.
124-
*
125-
* No Content-Type filter — the original implementation guessed that MCP
126-
* responses would be `application/json` and recorded zeros for everything
127-
* else. Real MCP traffic uses Streamable HTTP transport which returns
128-
* `text/event-stream`, and the prior filter dropped almost every response.
129-
* Reading the body universally is correct because oddkit's responses are
130-
* always bounded (no long-lived streams), and the SSE protocol overhead
131-
* (~10 bytes per event) is negligible against the actual payload size.
132-
*
133-
* Telemetry must never break MCP requests — clone or read failures fall
134-
* through to an empty `responseText`, which `measurePayloadShape` handles
135-
* by recording `bytes_out=0, tokens_out=0`.
136-
*/
137-
export async function measureResponseShape(
138-
requestText: string,
139-
response: Response,
140-
): Promise<PayloadShape> {
141-
let responseText = "";
142-
try {
143-
responseText = await response.clone().text();
144-
} catch {
145-
// Fall through with empty string; bytes_out / tokens_out will be 0.
146-
}
147-
return measurePayloadShape(requestText, responseText);
148-
}

workers/test/tokenize.test.mjs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -130,53 +130,5 @@ await test("measurePayloadShape handles empty response (SSE skipped)", async ()
130130
assert.ok(s.bytes_in > 0);
131131
});
132132

133-
// ─── measureResponseShape — guards against the prod bug the agent caught ──
134-
135-
const { measureResponseShape } = await import(compiledPath);
136-
137-
await test("measureResponseShape measures application/json responses", async () => {
138-
const body = JSON.stringify({ jsonrpc: "2.0", id: 1, result: { ok: true } });
139-
const res = new Response(body, { headers: { "Content-Type": "application/json" } });
140-
const s = await measureResponseShape("req", res);
141-
assert.ok(s.bytes_out > 0, `bytes_out should be > 0, got ${s.bytes_out}`);
142-
assert.ok(s.tokens_out > 0, `tokens_out should be > 0, got ${s.tokens_out}`);
143-
});
144-
145-
await test("measureResponseShape ALSO measures text/event-stream (the smoke-test bug)", async () => {
146-
// This is the case that the prior implementation got wrong:
147-
// MCP Streamable HTTP transport returns text/event-stream by default,
148-
// and the prior Content-Type filter recorded zeros for every such response.
149-
const sseBody = `data: ${JSON.stringify({ jsonrpc: "2.0", id: 1, result: { content: [{ type: "text", text: "hello world" }] } })}\n\n`;
150-
const res = new Response(sseBody, { headers: { "Content-Type": "text/event-stream" } });
151-
const s = await measureResponseShape("req", res);
152-
assert.ok(s.bytes_out > 50, `bytes_out should reflect SSE body (~80 bytes), got ${s.bytes_out}`);
153-
assert.ok(s.tokens_out > 5, `tokens_out should be > 5, got ${s.tokens_out}`);
154-
console.log(` SSE response: bytes_out=${s.bytes_out} tokens_out=${s.tokens_out}`);
155-
});
156-
157-
await test("measureResponseShape leaves the original response body intact (clone)", async () => {
158-
const body = JSON.stringify({ jsonrpc: "2.0", id: 1, result: { x: 42 } });
159-
const res = new Response(body, { headers: { "Content-Type": "application/json" } });
160-
161-
// Measure first
162-
await measureResponseShape("req", res);
163-
164-
// The original response body MUST still be readable — measurement uses a clone
165-
const originalText = await res.text();
166-
assert.equal(originalText, body, "original response body should be intact after measurement");
167-
});
168-
169-
await test("measureResponseShape handles already-consumed body without throwing", async () => {
170-
const body = JSON.stringify({ ok: true });
171-
const res = new Response(body);
172-
// Drain the original first — this will make .clone() succeed but the cloned body
173-
// won't have data flowing if it was a stream. For a static body this still works,
174-
// but the test ensures no throw under unusual conditions.
175-
await res.text();
176-
// Now ask measureResponseShape to handle this — it must not throw
177-
const s = await measureResponseShape("req", res);
178-
assert.ok(typeof s.bytes_out === "number", "must return a numeric bytes_out");
179-
});
180-
181133
console.log(`\n${pass} passed, ${fail} failed`);
182134
process.exit(fail > 0 ? 1 : 0);

0 commit comments

Comments
 (0)