fix(cline): stop generating proxy task ids (#10279)

Validado no worktree combinado do lote: typecheck:core, lint, gates de qualidade e os 13 testes unitários + 1 de integração (cline-task-id-propagation) todos verdes. Correção legítima de identidade de tarefa fabricada. CI vermelho neste PR é o base-red já rastreado em #9985. Obrigado!
This commit is contained in:
Ara
2026-08-20 22:13:00 -07:00
committed by GitHub
parent fac2a93dbf
commit 967b56a0dc
5 changed files with 98 additions and 17 deletions

View File

@@ -8,8 +8,6 @@
* must route its headers through `buildClineHeaders()`.
*/
import { randomUUID } from "node:crypto";
import { APP_CONFIG } from "../constants/appConfig";
const APP_VERSION = APP_CONFIG.version;
@@ -41,9 +39,11 @@ function getHeaderCaseInsensitive(
return key ? cleanHeaderValue(headers?.[key]) : undefined;
}
/** Keep an inbound Cline task id when supplied; otherwise create one per request. */
export function resolveClineTaskId(clientHeaders?: Record<string, string> | null): string {
return getHeaderCaseInsensitive(clientHeaders, "x-task-id") ?? randomUUID();
/** Keep an inbound Cline task id when supplied; never invent task identity at the proxy layer. */
export function resolveClineTaskId(
clientHeaders?: Record<string, string> | null
): string | undefined {
return getHeaderCaseInsensitive(clientHeaders, "x-task-id");
}
function resolveClineClientType(clientHeaders?: Record<string, string> | null): string | undefined {
@@ -53,18 +53,15 @@ function resolveClineClientType(clientHeaders?: Record<string, string> | null):
}
/**
* Apply the required Cline billing headers with case-insensitive replacement.
* These fields are authoritative in the official client and must win over
* stored/configured header layers.
* Apply Cline billing headers with case-insensitive replacement. Task identity
* is optional and may only come from the request context; stored/configured
* header layers must not fabricate or override it.
*/
export function applyClineProtocolHeaders(
headers: Record<string, string>,
context: ClineHeaderContext = {}
): Record<string, string> {
const taskId =
cleanHeaderValue(context.taskId) ??
getHeaderCaseInsensitive(headers, "x-task-id") ??
randomUUID();
const taskId = cleanHeaderValue(context.taskId);
const clientVersion = cleanHeaderValue(context.clientVersion) ?? APP_VERSION;
const existingClientType = getHeaderCaseInsensitive(headers, "x-client-type");
const clientType =
@@ -82,9 +79,13 @@ export function applyClineProtocolHeaders(
"X-PLATFORM": cleanHeaderValue(context.platform) ?? process.platform ?? "unknown",
"X-PLATFORM-VERSION": cleanHeaderValue(context.platformVersion) ?? process.version ?? "unknown",
"X-CORE-VERSION": cleanHeaderValue(context.coreVersion) ?? APP_VERSION,
"X-Task-ID": taskId,
};
for (const existing of Object.keys(headers)) {
if (existing.toLowerCase() === "x-task-id") delete headers[existing];
}
if (taskId) required["X-Task-ID"] = taskId;
for (const [name, value] of Object.entries(required)) {
for (const existing of Object.keys(headers)) {
if (existing !== name && existing.toLowerCase() === name.toLowerCase()) {