fix: require explicit agentrun bundle source commit

This commit is contained in:
Codex Agent
2026-06-05 22:18:20 +08:00
parent 8ae0f55463
commit 73d541fd58
3 changed files with 83 additions and 27 deletions
+26 -27
View File
@@ -60,6 +60,7 @@ export function describeAgentRunAdapterAvailability(env = process.env, options =
const blockers = [];
let managerUrl = null;
let repoUrl = null;
let resourceBundleSourceCommit = null;
try {
managerUrl = resolveAgentRunManagerUrl(env);
@@ -71,6 +72,11 @@ export function describeAgentRunAdapterAvailability(env = process.env, options =
} catch (error) {
blockers.push(agentRunAvailabilityBlocker(error, "repo-url"));
}
try {
resourceBundleSourceCommit = requireAgentRunSourceCommit(env);
} catch (error) {
blockers.push(agentRunAvailabilityBlocker(error, "resource-bundle-source-commit"));
}
const providerId = firstNonEmpty(env.HWLAB_CODE_AGENT_AGENTRUN_PROVIDER_ID, env.AGENTRUN_PROVIDER_ID, DEFAULT_PROVIDER_ID);
const runnerNamespace = firstNonEmpty(env.HWLAB_CODE_AGENT_AGENTRUN_RUNNER_NAMESPACE, env.AGENTRUN_RUNTIME_NAMESPACE, DEFAULT_RUNNER_NAMESPACE);
@@ -145,6 +151,7 @@ export function describeAgentRunAdapterAvailability(env = process.env, options =
managerHost,
repoUrl,
repoHost,
resourceBundleSourceCommit,
managerConfigured: Boolean(managerUrl),
repoConfigured: Boolean(repoUrl),
internalServiceDns: managerHost === "agentrun-mgr.agentrun-v01.svc.cluster.local",
@@ -235,6 +242,7 @@ export function initialAgentRunChatResult({ params = {}, options = {}, traceId }
providerId: firstNonEmpty(env.HWLAB_CODE_AGENT_AGENTRUN_PROVIDER_ID, env.AGENTRUN_PROVIDER_ID, DEFAULT_PROVIDER_ID),
managerUrl: resolveAgentRunManagerUrl(env),
repoUrl: resolveAgentRunRepoUrl(env),
resourceBundleSourceCommit: requireAgentRunSourceCommit(env),
valuesPrinted: false
},
valuesPrinted: false
@@ -710,22 +718,20 @@ function newSessionIdAfterEviction(baseSessionId, traceId) {
return baseSessionId + "-reset-" + profile;
}
function buildAgentRunCreateRunInput({ params, env, traceId, backendProfile, sessionId, toolCapabilities = null }) {
const commitId = fullSourceCommit(env);
const commitId = requireAgentRunSourceCommit(env);
const threadId = safeOpaqueId(params.threadId);
const hwlabProjectId = firstNonEmpty(params.projectId);
const toolAliases = filteredResourceToolAliases(toolCapabilities);
const resourceBundleRef = commitId
? {
kind: "git",
repoUrl: resolveAgentRunRepoUrl(env),
commitId,
submodules: false,
lfs: false,
toolAliases,
promptRefs: HWLAB_RESOURCE_PROMPT_REFS,
skillRefs: HWLAB_RESOURCE_SKILL_REFS
}
: null;
const resourceBundleRef = {
kind: "git",
repoUrl: resolveAgentRunRepoUrl(env),
commitId,
submodules: false,
lfs: false,
toolAliases,
promptRefs: HWLAB_RESOURCE_PROMPT_REFS,
skillRefs: HWLAB_RESOURCE_SKILL_REFS
};
return {
tenantId: firstNonEmpty(env.HWLAB_CODE_AGENT_AGENTRUN_TENANT_ID, DEFAULT_TENANT_ID),
projectId: agentRunProjectIdForEnv(env),
@@ -1705,20 +1711,13 @@ function resolveAgentRunRepoUrl(env = process.env) {
return url.toString().replace(/\/+$/u, "");
}
function fullSourceCommit(env) {
for (const value of [
env.HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT,
env.HWLAB_BOOT_COMMIT,
env.HWLAB_GITOPS_SOURCE_COMMIT,
env.HWLAB_COMMIT_ID,
env.HWLAB_GIT_SHA,
env.GIT_COMMIT,
env.HWLAB_REVISION
]) {
const text = String(value ?? "").trim().toLowerCase();
if (/^[0-9a-f]{40}$/u.test(text)) return text;
}
return null;
function requireAgentRunSourceCommit(env) {
const text = String(env.HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT ?? "").trim().toLowerCase();
if (/^[0-9a-f]{40}$/u.test(text)) return text;
throw Object.assign(new Error("HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT must be a full 40-character source commit before AgentRun dispatch"), {
code: "agentrun_bundle_source_commit_invalid",
statusCode: 500
});
}
function modelForBackendProfile(profile, env = process.env) {