diff --git a/internal/cloud/code-agent-agentrun-adapter.ts b/internal/cloud/code-agent-agentrun-adapter.ts index d7bd6857..3525a33a 100644 --- a/internal/cloud/code-agent-agentrun-adapter.ts +++ b/internal/cloud/code-agent-agentrun-adapter.ts @@ -2937,12 +2937,18 @@ function withAgentRunRunnerJobCount(mapping = {}) { return mapping; } -function hwlabSessionIdForParams(params = {}, traceId) { - return safeSessionId(params.sessionId) || agentRunSessionId(traceId); +function hwlabSessionIdForParams(params = {}) { + return safeSessionId(params.sessionId) || null; } function scopedAgentRunSessionIdForParams(params = {}, traceId, backendProfile) { const baseSessionId = hwlabSessionIdForParams(params, traceId); + if (!safeSessionId(baseSessionId)) { + throw adapterError( + "agentrun_session_id_required", + "AgentRun persistent session/PVC requires params.sessionId; refusing to derive sessionRef.sessionId from traceId because that would create a new PVC per turn." + ); + } const profile = agentRunSessionProfileToken(backendProfile); const base = String(baseSessionId).replace(/^ses_/u, "").replace(/[^A-Za-z0-9_]+/gu, "_").replace(/^_+|_+$/gu, "") || "session"; return `ses_agentrun_${profile}_${base}`;