Audit identity & trace-id uniqueness — plan
Design: ../specs/2026-07-08-audit-identity-and-trace-uniqueness-design.md.
TDD; pnpm check + agent pytest green before ship; no deploy without go-ahead.
Part 1 — trace-id uniqueness
- native-provider.ts — add
nonce?: () => stringtoNativeProviderConfig
(defaultcrypto.randomUUID); line 77 →`${sessionId}-t${history.length}-${nonce()}`;
reword the CONVENTIONS comment (72–76). - orchestrate.ts — replace
turnRequestIdwith exported
makeTurnTraceId(req, nonce = () => crypto.randomUUID()); exportbuildLlms
(now(req, turnTraceId)) andbuildTools; inrunOrchestratorcompute
const turnTraceId = makeTurnTraceId(req)once and thread through both;
reword comment (38–46). - Tests: update
packages/streams/tests/friendly-errors.test.ts:139; add
packages/streams/tests/native-provider-traceid.test.ts(uniqueness); add
apps/public-web/tests/orchestrator/trace-id.test.ts(sharing + decoupling).
Part 2 — identity (X-User-Id)
- dash/gateway.py (edit internal, copy to public — byte-identical): add
user_id_var;RequestIdMiddlewareseeds it fromx-user-id;
GatewayHeaders._snapshot()injectsX-User-Id. - dash/agents.py (both, comment-only): replace the
# TODO(gateway)block
with the ContextVar explanation. - dash/embedder.py (both, comment-only): note X-User-Id now rides along.
- tools/data.ts — add
userId?param →X-User-Idheader. - orchestrate.ts
buildTools— passreq.sessionIdas the DataTool userId. - auth/actor-id.ts (new) —
opaqueStaffId(email)=staff-<hmac16>. - api/dash-proxy/[...path]/route.ts — read verified session, inject
X-User-Id: opaqueStaffId(email), overriding any client-sent value. - Tests: extend
test_gateway.py(user_id var + middleware); extend
data-tool.test.ts(X-User-Id); addorchestrateidentity assertion; add
internal-webactor-id+dash-proxyidentity tests.
Gate & ship
corepack pnpm check(typecheck + suites + check-conventions).- Agent pytest via scratch venv (
agno==2.4.7,openai==2.16.0). - Completion notes; upload changed
.md. Deploy only on explicit go-ahead.