Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): gate MCP-boot paste budget to codex sessions only

Adam Eivyc4be72fe1cff
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1d143bb9e0..ad9334adbe 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -48,7 +48,6 @@
- **CoS agents (notably codex) now open their PR as the gh account that matches the repo owner, not gh's mutable active user.** PortOS's own `createPR` pins `GH_TOKEN` to the logged-in gh account whose login matches the repo owner (avoiding the multi-account "must be a collaborator" failure), but a spawned agent running its *own* `gh pr create` — a codex/Claude/CLI CoS agent finishing `/do:pr` — never received that pinning. TUI agents fared worst: `shell.js`'s `buildSafeEnv` strips `GH_TOKEN` from the inherited env entirely, so their `gh` fell back to whatever `hosts.yml` active user happened to be set. A new best-effort `resolveForgeTokenEnv(dir)` (in `server/services/git.js`) resolves just the owner-matched `GH_TOKEN` overlay and is injected into all three agent-spawn env paths — direct CLI (`spawnDirectly`), TUI shell session (`spawnTuiAgent`), and the CoS runner (`spawnViaRunner`). It's provider-agnostic (no codex special-case), returns `{}` when no owner-matched account exists (so single-account installs and GitLab repos are untouched), and is spread before `provider.envVars` so an explicit provider `GH_TOKEN` override still wins.
- **Codex CoS agents no longer die `paste-not-rendered` while codex boots its MCP servers.** Codex boots any MCP servers configured in the user's global `~/.codex/config.toml` on every headless spawn — including heavyweight interactive ones like `playwright` (fetched via `npx`) or a `node_repl` with `startup_timeout_sec = 120`. That boot can run for tens of seconds up to ~2 minutes, during which codex swallows pastes, renders no `[Pasted Content N chars]` commit marker, and shows only the *tail* of a long paste in its input viewport (never the verified prefix) — so PortOS's paste-verify retry could not confirm delivery and killed the agent after only 3 short attempts (~19s), long before the boot finished (real incident 2026-07-10: `agent-c5a26b40` / `agent-3f4ae3b1`, both on gpt-5.6-sol; the same prompt succeeded days earlier when no MCP servers were configured and codex was ready in <10s). The spawner now detects codex's MCP-boot banner (`Booting MCP server` / `Starting MCP servers`) and extends the paste-retry budget from the fixed 3 attempts to a time budget (150s, covering `node_repl`'s 120s startup plus an `npx` cold download while staying under the idle-reap window), so a slow boot completes and the paste finally lands. If the boot genuinely never finishes, the failure now names the MCP-boot cause and points at the codex config instead of a misleading "still initializing" message. Non-codex TUIs and codex installs without MCP servers are unchanged.
->>>>>>> a2c2ced23 (fix(cos): give codex agents time to boot MCP servers before paste-verify fails)
- **Read-only CoS agents (e.g. reference-watch) on a TUI provider now signal completion via the `.agent-done` sentinel.** The prompt builder's completion decision tree gave every other task shape (reasoning-only, TUI push+PR, CLI) an explicit sentinel instruction, but the `isReadOnly` branch emitted only the bare "Read-Only Task" notice with no sentinel — so a read-only TUI run (reference-watch records its proposals directly in the tracker, then just needs to signal done) never wrote `.agent-done`. The 2s sentinel poll in `spawnTuiAgent` — the primary finalize path and the channel that ingests the run summary — therefore never fired, and the run only completed via the idle-reaper / shell-exit fallback with no clean resolution summary captured. `agentPromptBuilder.js` now routes the read-only branch through a new `buildReadOnlyCompletionSection({ isTui, sentinelPath })` that keeps the do-not-modify guidance and, for TUI agents, appends the write-`.agent-done`-then-stop instruction. CLI/API read-only agents complete on process exit and never poll a sentinel, so they still get the bare notice.
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index 6ea045ec09..eb02fa77fa 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -376,6 +376,16 @@ export async function spawnTuiAgent({
// paste-retry loop below extends its budget to MCP_BOOT_PASTE_DEADLINE_MS so a
// slow boot completes and the paste finally lands, instead of being killed
// `paste-not-rendered` mid-boot (incident 2026-07-10, agent-c5a26b40).
+ //
+ // Gated to codex ONLY (isCodexSession below). The extended budget and the
+ // failure message ("check your ~/.codex config") are codex-specific, and the
+ // claude path never blind-pastes during its own MCP boot — it waits for
+ // claude's positive input-ready signal first (createInputReadyTracker) — so it
+ // can't hit this failure mode. Observing every provider would let an unrelated
+ // TUI whose startup text happened to contain "starting mcp servers" inherit
+ // codex's 150s budget and its misleading codex-config guidance, breaking the
+ // "non-codex TUIs are unchanged" contract (codex review [P2]).
+ const isCodexSession = commandName.toLowerCase().includes('codex');
const mcpBoot = createMcpBootTracker();
// Tracks claude's interactive input-readiness (footer chrome) and its first-run
// folder-trust gate. Gates the prompt paste for the claude TUI so we never
@@ -732,10 +742,13 @@ export async function spawnTuiAgent({
// injected — earlier toggles belong to shell startup and the readiness
// probe, not to claude.
if (!promptSentAt && commandInjected) inputReady.observe(text, stripped);
- // Latch codex's MCP-server boot banner during startup (before the prompt is
- // submitted, so codex's own boot chrome — not the echoed prompt — is what
- // trips it). Gates the extended, boot-aware paste-retry budget below.
- if (!promptSubmittedAt && stripped && !mcpBoot.active) mcpBoot.observe(stripped);
+ // Latch codex's MCP-server boot banner during startup (codex sessions only;
+ // before the prompt is submitted, so codex's own boot chrome — not the
+ // echoed prompt — is what trips it). Gates the extended, boot-aware
+ // paste-retry budget below. Observing until promptSubmittedAt (set only on a
+ // CONFIRMED paste) means a banner that arrives AFTER an early swallowed paste
+ // still latches — the swallowed paste never sets promptSubmittedAt.
+ if (isCodexSession && !promptSubmittedAt && stripped && !mcpBoot.active) mcpBoot.observe(stripped);
const now = Date.now();
// Once the prompt is SUBMITTED (Enter sent — not merely pasted), watch for
// proof the model is actually working. Keying on promptSubmittedAt (not
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index dae0532f95..5761886ac7 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -1057,6 +1057,34 @@ describe('spawnTuiAgent runtime', () => {
);
});
+ it('MCP-boot budget is codex-only: a non-codex TUI emitting the same banner still fails at 3 attempts', async () => {
+ // Regression for codex review [P2]: the boot tracker must not latch for a
+ // non-codex provider, or an unrelated TUI whose startup text contains
+ // "starting mcp servers" would inherit codex's 150s budget and its
+ // codex-specific failure guidance, breaking "non-codex TUIs are unchanged."
+ let resolveComplete;
+ const completeDone = new Promise((r) => { resolveComplete = r; });
+ vi.mocked(agentLifecycle.finalizeAgent).mockImplementation(async () => { resolveComplete(); });
+
+ runSpawn({ tuiConfig: { command: 'gemini', args: [], commandLine: 'gemini', promptDelayMs: 100, idleTimeoutMs: 50 } });
+ await flushMicrotasks();
+ // Same banner text codex prints — but this is a gemini session.
+ await capturedOnData(Buffer.from('Starting MCP servers (0/3): a, b, c\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(2000);
+ await flushMicrotasks();
+
+ // Fails at the fixed 3-attempt cap (~19s), NOT the 150s boot budget.
+ await vi.advanceTimersByTimeAsync(25000);
+ vi.useRealTimers();
+ await completeDone;
+
+ expect(pasteCount()).toBe(3);
+ expect(agentLifecycle.finalizeAgent).toHaveBeenCalledWith(
+ expect.objectContaining({ agentId: 'agent-1', success: false, completionReason: 'paste-not-rendered' })
+ );
+ });
+
// ── 2. Command-not-found path ────────────────────────────────────────────────
it('command-not-found: finalizeAgent called with success:false, exitCode 127, completionReason=command-not-found', async () => {
const spawnPromise = runSpawn();