add stable request ids for replays
This commit is contained in:
@@ -459,6 +459,77 @@ async function run() {
|
||||
recoveredEntry?.request_body_bytes === Buffer.byteLength(recoveredPayload),
|
||||
`请求体大小记录异常: ${recoveredEntry?.request_body_bytes}`,
|
||||
);
|
||||
assert(recoveredEntry?.request_id, "请求记录未生成 request_id");
|
||||
|
||||
const sameRequestPayload = JSON.stringify({ test_reasoning_tokens: 128, test_request_id_marker: "same" });
|
||||
const sameRequestFirstResponse = await fetch(`http://127.0.0.1:${gatewayPort}/responses`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: sameRequestPayload,
|
||||
});
|
||||
assert(sameRequestFirstResponse.status === 200, `相同请求首次发送失败: ${sameRequestFirstResponse.status}`);
|
||||
await sameRequestFirstResponse.json();
|
||||
|
||||
const sameRequestSecondResponse = await fetch(`http://127.0.0.1:${gatewayPort}/responses`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: sameRequestPayload,
|
||||
});
|
||||
assert(sameRequestSecondResponse.status === 200, `相同请求二次发送失败: ${sameRequestSecondResponse.status}`);
|
||||
await sameRequestSecondResponse.json();
|
||||
|
||||
const differentBodyPayload = JSON.stringify({ test_reasoning_tokens: 128, test_request_id_marker: "different" });
|
||||
const differentBodyResponse = await fetch(`http://127.0.0.1:${gatewayPort}/responses`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: differentBodyPayload,
|
||||
});
|
||||
assert(differentBodyResponse.status === 200, `不同请求体发送失败: ${differentBodyResponse.status}`);
|
||||
await differentBodyResponse.json();
|
||||
|
||||
const differentPathResponse = await fetch(`http://127.0.0.1:${gatewayPort}/v1/responses`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: sameRequestPayload,
|
||||
});
|
||||
assert(differentPathResponse.status === 200, `不同路径发送失败: ${differentPathResponse.status}`);
|
||||
await differentPathResponse.json();
|
||||
|
||||
const requestIdRequestsResponse = await fetch(`http://127.0.0.1:${gatewayPort}/__codex_retry_gateway/api/requests?limit=40`);
|
||||
const requestIdRequestsPayload = await requestIdRequestsResponse.json();
|
||||
const sameRequestEntries = (requestIdRequestsPayload?.entries || []).filter(
|
||||
(entry) => entry.path === "/responses" && entry.request_body_bytes === Buffer.byteLength(sameRequestPayload),
|
||||
);
|
||||
assert(sameRequestEntries.length >= 2, "未找到两条相同请求记录");
|
||||
const [sameRequestEntryA, sameRequestEntryB] = sameRequestEntries;
|
||||
assert(sameRequestEntryA.request_id, "相同请求记录缺少 request_id");
|
||||
assert(sameRequestEntryA.request_id === sameRequestEntryB.request_id, "相同请求未复用 request_id");
|
||||
assert(sameRequestEntryA.seq !== sameRequestEntryB.seq, "相同请求不应复用 seq");
|
||||
|
||||
const differentBodyEntry = (requestIdRequestsPayload?.entries || []).find(
|
||||
(entry) =>
|
||||
entry.path === "/responses" &&
|
||||
entry.request_body_bytes !== Buffer.byteLength(sameRequestPayload) &&
|
||||
entry.request_body_bytes === Buffer.byteLength(differentBodyPayload),
|
||||
);
|
||||
assert(differentBodyEntry?.request_id, "不同请求体记录缺少 request_id");
|
||||
assert(differentBodyEntry.request_id !== sameRequestEntryA.request_id, "不同请求体错误复用 request_id");
|
||||
|
||||
const differentPathEntry = (requestIdRequestsPayload?.entries || []).find(
|
||||
(entry) => entry.path === "/v1/responses" && entry.request_body_bytes === Buffer.byteLength(sameRequestPayload),
|
||||
);
|
||||
assert(differentPathEntry?.request_id, "不同路径记录缺少 request_id");
|
||||
assert(differentPathEntry.request_id !== sameRequestEntryA.request_id, "不同路径错误复用 request_id");
|
||||
|
||||
const requestIdQueryResponse = await fetch(
|
||||
`http://127.0.0.1:${gatewayPort}/__codex_retry_gateway/api/requests?query=${encodeURIComponent(sameRequestEntryA.request_id)}`,
|
||||
);
|
||||
const requestIdQueryPayload = await requestIdQueryResponse.json();
|
||||
assert(requestIdQueryResponse.status === 200, `request_id 搜索失败: ${requestIdQueryResponse.status}`);
|
||||
assert(
|
||||
(requestIdQueryPayload?.entries || []).some((entry) => entry.request_id === sameRequestEntryA.request_id),
|
||||
"request_id 搜索未命中对应记录",
|
||||
);
|
||||
|
||||
const capacityResponse = await fetch(`http://127.0.0.1:${gatewayPort}/responses`, {
|
||||
method: "POST",
|
||||
@@ -510,6 +581,7 @@ async function run() {
|
||||
(entry) => entry.path === "/responses" && entry.status_code === 200 && entry.upstream_attempt_count >= 3,
|
||||
);
|
||||
assert(capacityRecoveredEntry, "capacity 抖动恢复后的请求记录未保留重试次数");
|
||||
assert(capacityRecoveredEntry.request_id, "capacity 恢复后的请求记录缺少 request_id");
|
||||
|
||||
const capacityStatus200RecoveredResponse = await fetch(`http://127.0.0.1:${gatewayPort}/responses`, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user