Skip to content

Commit 2a8cce0

Browse files
authored
fix: seed task runtime home with the worker mise global config (#810)
1 parent 85e6abb commit 2a8cce0

5 files changed

Lines changed: 136 additions & 0 deletions

File tree

apps/worker/src/run-task/__tests__/run-task.test.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/worker/src/run-task/__tests__/zero-integration-gating.test.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/worker/src/run-task/agent-home.test.ts

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/worker/src/run-task/agent-home.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,55 @@ export function activateSkillsFolder({
594594
return true;
595595
}
596596

597+
const MISE_GLOBAL_CONFIG_RELATIVE_PATH = ['.config', 'mise', 'config.toml'];
598+
599+
/**
600+
* Seeds the task runtime HOME with the worker home's global mise config.
601+
*
602+
* Mise shims (node, npx, ...) resolve tool versions from the global config at
603+
* `$HOME/.config/mise/config.toml` when no repo-level mise config applies to
604+
* the process cwd. The task runtime HOME starts empty, so without this seed
605+
* any process spawned with the runtime HOME outside a version-pinned
606+
* repository — including environment-defined stdio MCP servers
607+
* (`npx -y ...`) — fails with "mise ERROR No version is set for shim: node".
608+
*
609+
* An existing runtime-home config (restored from a snapshot, or written by
610+
* the agent via `mise use -g`) is left untouched. Best-effort: returns
611+
* whether the config was seeded.
612+
*/
613+
export function seedRuntimeHomeMiseGlobalConfig({
614+
homeDir,
615+
sourceHomeDir,
616+
}: {
617+
homeDir: string;
618+
sourceHomeDir: string;
619+
}): boolean {
620+
if (!homeDir || !sourceHomeDir || homeDir === sourceHomeDir) {
621+
return false;
622+
}
623+
624+
const sourceConfigPath = path.join(
625+
sourceHomeDir,
626+
...MISE_GLOBAL_CONFIG_RELATIVE_PATH,
627+
);
628+
const targetConfigPath = path.join(
629+
homeDir,
630+
...MISE_GLOBAL_CONFIG_RELATIVE_PATH,
631+
);
632+
633+
try {
634+
if (!fs.existsSync(sourceConfigPath) || fs.existsSync(targetConfigPath)) {
635+
return false;
636+
}
637+
638+
fs.mkdirSync(path.dirname(targetConfigPath), { recursive: true });
639+
fs.copyFileSync(sourceConfigPath, targetConfigPath);
640+
return true;
641+
} catch {
642+
return false;
643+
}
644+
}
645+
597646
interface GenerateOpenCodeConfigOptions {
598647
homeDir: string;
599648
runtimeEnv: Record<string, string>;

apps/worker/src/run-task/run-task.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { TaskCancellationController } from './task-cancellation-controller';
6969
import {
7070
activateSkillsFolder,
7171
resolvePackagedSkillsFolder,
72+
seedRuntimeHomeMiseGlobalConfig,
7273
} from './agent-home';
7374
import { installZeroCli } from '../commands/setup/agent-clis';
7475

@@ -766,6 +767,17 @@ export const runTask = async ({
766767

767768
if (workerHomeDir) {
768769
runtimeEnv.HOME = resolveTaskRuntimeHomeDir(workspacePath);
770+
771+
if (
772+
seedRuntimeHomeMiseGlobalConfig({
773+
homeDir: runtimeEnv.HOME,
774+
sourceHomeDir: workerHomeDir,
775+
})
776+
) {
777+
logger.info(
778+
`[runTask] Seeded runtime home mise global config from ${workerHomeDir}`,
779+
);
780+
}
769781
}
770782

771783
delete runtimeEnv.ROOMOTE_TASK_TERMINAL;

0 commit comments

Comments
 (0)