@runuai/host 0.9.135 → 0.9.137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -308,6 +308,8 @@ export class CodexSession implements AgentSession {
308
308
  environment: TaskEnvironmentAgentSessionSurface;
309
309
  systemPreamble: string;
310
310
  agentEnv?: Record<string, string>;
311
+ /** ADR-128: `-c key=value` overrides a delegating adapter prepends. */
312
+ cliConfigOverrides?: string[];
311
313
  }) {
312
314
  this.agentId = args.agent.id;
313
315
  this.systemPreamble = args.systemPreamble;
@@ -327,6 +329,9 @@ export class CodexSession implements AgentSession {
327
329
  if (args.agent.effort) {
328
330
  codexArgs.push("-c", `model_reasoning_effort=${args.agent.effort}`);
329
331
  }
332
+ for (const override of args.cliConfigOverrides ?? []) {
333
+ codexArgs.push("-c", override);
334
+ }
330
335
  codexArgs.push("app-server");
331
336
  // ADR-061: the CLI is owned by an in-container runner (durable across
332
337
  // host restarts); legacy pipes behind UAI_DURABLE_SESSIONS=0. Codex
@@ -187,5 +187,9 @@ export interface AgentSessionFactory {
187
187
  /** ADR-048: extra per-agent process environment (e.g. this agent's own
188
188
  * UAI_TASK_TOKEN so its `uai` CLI carries only its own permissions). */
189
189
  agentEnv?: Record<string, string>;
190
+ /** ADR-128: engine config overrides a DELEGATING adapter prepends (codex
191
+ * `-c key=value`), e.g. the Uai Managed Engine's model-provider block
192
+ * that points codex at the inference gateway. Never from the roster. */
193
+ cliConfigOverrides?: string[];
190
194
  }): Promise<AgentSession>;
191
195
  }
package/lib/agents/uai.ts CHANGED
@@ -34,6 +34,8 @@ export function uaiGatewayEnv(
34
34
  return {
35
35
  OPENAI_BASE_URL: url,
36
36
  OPENAI_API_KEY: taskToken,
37
+ // Read by the `uai` model provider's `env_key` (see uaiCodexOverrides).
38
+ UAI_INFERENCE_TOKEN: taskToken,
37
39
  };
38
40
  }
39
41
  return {
@@ -47,6 +49,30 @@ export function uaiGatewayEnv(
47
49
  };
48
50
  }
49
51
 
52
+ /**
53
+ * Codex does NOT follow `OPENAI_BASE_URL` / `OPENAI_API_KEY` for its default
54
+ * provider any more: with a ChatGPT login present it opens
55
+ * `wss://api.openai.com/v1/responses` directly and sends no bearer (live
56
+ * 2026-09-12: "401 Missing bearer or basic authentication", five
57
+ * reconnects, turn never answered). A dedicated model provider pins the
58
+ * gateway as the base URL, the HTTP Responses wire (the gateway serves
59
+ * `/v1/responses`, not WebSockets), and the task token via `env_key`;
60
+ * `requires_openai_auth=false` keeps the host's Codex login out of a
61
+ * gateway-billed session. Codex parses `-c` values as TOML, hence the
62
+ * quotes on strings.
63
+ */
64
+ export function uaiCodexOverrides(url: string): string[] {
65
+ const base = `${url.replace(/\/+$/, "")}/v1`;
66
+ return [
67
+ "model_provider=uai",
68
+ 'model_providers.uai.name="Uai Managed Engine"',
69
+ `model_providers.uai.base_url="${base}"`,
70
+ 'model_providers.uai.env_key="UAI_INFERENCE_TOKEN"',
71
+ 'model_providers.uai.wire_api="responses"',
72
+ "model_providers.uai.requires_openai_auth=false",
73
+ ];
74
+ }
75
+
50
76
  const create: AgentSessionFactory["create"] = async (args): Promise<AgentSession> => {
51
77
  const provider = args.agent.uaiProvider === "openai" ? "openai" : "anthropic";
52
78
  const delegateKind = provider === "openai" ? "codex" : "claude";
@@ -69,6 +95,7 @@ const create: AgentSessionFactory["create"] = async (args): Promise<AgentSession
69
95
  ...(args.agentEnv ?? {}),
70
96
  ...uaiGatewayEnv(provider, gatewayUrl(), taskToken),
71
97
  },
98
+ ...(provider === "openai" ? { cliConfigOverrides: uaiCodexOverrides(gatewayUrl()) } : {}),
72
99
  });
73
100
  };
74
101
 
@@ -125,10 +125,40 @@ export function sharedFilesMountPlans(
125
125
  * could not be mounted (the task still starts, like the machine copy path),
126
126
  * null when clean or when there is nothing to mount.
127
127
  */
128
+ /** One mount pass per workspace at a time. Task-up (the cloud's wake) and
129
+ * the sidecar's own resume pass both mount on a runner restart, and the
130
+ * shell's `mountpoint -q` guard is not atomic across two racers: live
131
+ * 2026-09-12 both ran in the same second — /files/org got two stacked
132
+ * mounts and the loser on /files/me failed with "fuse: mountpoint is not
133
+ * empty", surfaced to the human as a warning although the files were
134
+ * mounted. The second pass now waits and finds the healthy mount. */
135
+ const mountPasses = new Map<string, Promise<unknown>>();
136
+
137
+ async function serializedByWorkspace<T>(workspacePath: string, run: () => Promise<T>): Promise<T> {
138
+ const previous = mountPasses.get(workspacePath) ?? Promise.resolve();
139
+ const next = previous.catch(() => undefined).then(run);
140
+ mountPasses.set(workspacePath, next);
141
+ try {
142
+ return await next;
143
+ } finally {
144
+ if (mountPasses.get(workspacePath) === next) mountPasses.delete(workspacePath);
145
+ }
146
+ }
147
+
128
148
  export async function mountSharedFilesFromLease(
129
149
  handle: TaskEnvironmentHandle<unknown>,
130
150
  workspacePath: string,
131
151
  task: { sharedFiles?: string },
152
+ ): Promise<string | null> {
153
+ return serializedByWorkspace(workspacePath, () =>
154
+ mountSharedFilesFromLeaseNow(handle, workspacePath, task),
155
+ );
156
+ }
157
+
158
+ async function mountSharedFilesFromLeaseNow(
159
+ handle: TaskEnvironmentHandle<unknown>,
160
+ workspacePath: string,
161
+ task: { sharedFiles?: string },
132
162
  ): Promise<string | null> {
133
163
  const mode: SharedFilesMode =
134
164
  task.sharedFiles === "rw" ? "rw" : task.sharedFiles === "off" ? "off" : "ro";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runuai/host",
3
- "version": "0.9.135",
3
+ "version": "0.9.137",
4
4
  "description": "Uai host — runs ephemeral AI tasks in containers on a machine you control.",
5
5
  "license": "MIT",
6
6
  "author": "Uai Tech <team@runuai.com>",