diff --git a/internal/cloud/code-agent-agentrun-adapter.ts b/internal/cloud/code-agent-agentrun-adapter.ts index 9e4a6860..e0fa2fea 100644 --- a/internal/cloud/code-agent-agentrun-adapter.ts +++ b/internal/cloud/code-agent-agentrun-adapter.ts @@ -50,6 +50,8 @@ import { agentRunResultSyncDeferred, buildAgentRunProjectionEventsFetchPlan, bui import { codeAgentOtelTraceFields, codeAgentOtelTraceContext, emitCodeAgentOtelSpan } from "./otel-trace.ts"; const ADAPTER_ID = "agentrun-v01"; +const ADAPTER_IDS = new Set([ADAPTER_ID, "agentrun-v02"]); +const ADAPTER_ALIASES = new Set(["agentrun", "agentrun-v0.1", "agentrun-v0.2"]); const DEFAULT_TENANT_ID = "hwlab"; const DEFAULT_PROJECT_ID = "pikasTech/HWLAB"; const DEFAULT_RUNNER_NAMESPACE = "agentrun-v01"; @@ -73,7 +75,7 @@ const HWLAB_RESOURCE_PROMPT_REFS = Object.freeze([ export function codeAgentAgentRunAdapterEnabled(env = process.env) { const value = String(env.HWLAB_CODE_AGENT_ADAPTER ?? env.HWLAB_CODE_AGENT_PROVIDER ?? "").trim().toLowerCase(); - return value === ADAPTER_ID || value === "agentrun" || value === "agentrun-v0.1"; + return ADAPTER_IDS.has(value) || ADAPTER_ALIASES.has(value); } export function describeAgentRunAdapterAvailability(env = process.env, options = {}) { diff --git a/internal/cloud/server-code-agent-http.ts b/internal/cloud/server-code-agent-http.ts index 5242a020..10eaf152 100644 --- a/internal/cloud/server-code-agent-http.ts +++ b/internal/cloud/server-code-agent-http.ts @@ -785,10 +785,27 @@ function firstNonEmptyValue(...values) { return null; } +function safeOtelConfigText(value) { + const text = firstNonEmptyValue(value); + return text === null ? null : text.slice(0, 120); +} + +function safeOtelUrlHost(value) { + const text = firstNonEmptyValue(value); + if (text === null) return null; + try { + return new URL(text).host.slice(0, 120); + } catch { + return null; + } +} + async function submitCodeAgentChatTurn({ params, options, traceId }) { const traceStore = options.traceStore ?? defaultCodeAgentTraceStore; const results = options.codeAgentChatResults ?? createCodeAgentChatResultStore(); const timestamp = new Date().toISOString(); + const runtimeEnv = options.env ?? process.env; + const adapterEnabled = codeAgentAgentRunAdapterEnabled(runtimeEnv); const acceptedPayload = { accepted: true, status: "running", @@ -803,7 +820,18 @@ async function submitCodeAgentChatTurn({ params, options, traceId }) { }; await recordCodeAgentTurnAdmission({ payload: acceptedPayload, params, options, traceId }); results.set(traceId, annotateOwner(acceptedPayload, params)); - if (codeAgentAgentRunAdapterEnabled(options.env ?? process.env)) { + void emitCodeAgentOtelSpan("provider_decision", traceId, runtimeEnv, { + attributes: { + adapterEnabled, + adapter: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_ADAPTER ?? runtimeEnv.HWLAB_CODE_AGENT_PROVIDER), + provider: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_PROVIDER), + defaultProviderProfile: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_DEFAULT_PROVIDER_PROFILE), + agentRunManagerHost: safeOtelUrlHost(runtimeEnv.AGENTRUN_MGR_URL ?? runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_MGR_URL), + agentRunRunnerNamespace: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_RUNNER_NAMESPACE ?? runtimeEnv.AGENTRUN_RUNTIME_NAMESPACE), + agentRunSourceCommitPresent: Boolean(firstNonEmptyValue(runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT)) + } + }); + if (adapterEnabled) { const run = async () => { let initial = null; let executionOptions = options; diff --git a/internal/cloud/server-health.test.ts b/internal/cloud/server-health.test.ts index e60e877d..016567e9 100644 --- a/internal/cloud/server-health.test.ts +++ b/internal/cloud/server-health.test.ts @@ -1101,6 +1101,15 @@ test("AgentRun adapter does not initialize repo-owned Codex stdio runtime defaul assert.equal(env.CODEX_HOME, undefined); assert.equal(env.HWLAB_PREINSTALLED_SKILLS_DIR, "/app/skills"); assert.equal(env.HWLAB_USER_SKILLS_DIR, "/data/user-skills"); + + const v02Env = { + HWLAB_CODE_AGENT_ADAPTER: "agentrun-v02" + }; + ensureCodeAgentRuntimeBase(v02Env); + assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_STDIO_ENABLED, undefined); + assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_STDIO_SUPERVISOR, undefined); + assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_WORKSPACE, undefined); + assert.equal(v02Env.CODEX_HOME, undefined); }); test("explicit Codex stdio mode keeps local runtime defaults available", () => {