Skip to content

Switch Codex interactive runner to app-server for real turn/steer #1170

Closed

Description

@currentbits

Parent / related

Decision (this pass)

Do not implement here. The switch is not small. codex exec --json and codex app-server are different protocols. Flipping supportsSteer on the current adapter would lie to the composer.

Keep electron/codex.js runCodex as one-shot JSONL (stdio: ["ignore", ...], handle is { kill } only). Keep workflow / ask / commitmsg on exec --json.

Why exec cannot steer (restated)

Solenta's interactive Codex path is startCodexRun → provider.buildArgs → codex exec --json / exec resume <id> --json → runCodex.

Candidate What it actually is
exec --json stdin One-shot. Prompt is argv (or stdin drained once as the initial prompt / <stdin> block). Solenta ignores stdin.
-i --image, not interactive.
codex queue / app-server thread/queue/add Follow-up after idle = Solenta Queue, not Steer. thread/queue/add is experimental-schema-only on 0.153.4.
Astra send_user_message_async Persist-mode desktop: model → user. Opposite direction.
app-server turn/steer Real mid-turn user channel. Different adapter.

Protocol (Codex CLI 0.153.4)

Generated from codex app-server generate-json-schema / generate-ts (--experimental only needed for queue).

codex app-server itself is still marked [experimental] in CLI help. turn/steer is in the stable ClientRequest schema (not an experimentalFeature). Product risk: the RPC can still move.

Solenta already speaks a slice of this for /usage: electron/providerUsage.js does app-server --listen stdio:// → initialize → initialized → account/rateLimits/read.

Interactive turn loop:

  1. Spawn private codex app-server --listen stdio:// (do not use the user-global app-server daemon; that shares writer lock with Codex Desktop).
  2. initialize + initialized. experimentalApi is not required for turn/steer.
  3. thread/start (fresh) or thread/resume { threadId, excludeTurns: true } (existing Solenta sessionId).
  4. turn/start { threadId, input: [{ type: "text", text }] } → TurnStartResponse.turn.id.
  5. Stream JSON-RPC notifications, not exec JSONL: thread/started, turn/started, item/started, item/agentMessage/delta, item/completed, thread/tokenUsage/updated, turn/completed.
  6. Mid-turn Steer: turn/steer { threadId, expectedTurnId, input }. Fails if expectedTurnId is not the active turn. Review/compact turns are NonSteerableTurnKind.
  7. Stop: turn/interrupt { threadId, turnId } then thread/unsubscribe. killTree remains the fail-closed abort.
  8. Idle follow-up: Solenta Queue → new startRun → thread/resume + turn/start. Do not wire composer Queue to thread/queue/add.

TurnSteerParams.expectedTurnId is required. Composer must not show Steer until that id is known (handshake race vs Claude, which can write stdin immediately).

Live probes (2026-09-09, CLI 0.153.4, no model turn)

Handshake matches /usage. thread/list { sourceKinds: ["exec","appServer","cli"] } returns Solenta exec sessions (status: notLoaded, canAcceptDirectInput: null).

thread/start { ephemeral: true, sandbox: "read-only", approvalPolicy: "never" } → status: idle, canAcceptDirectInput: true. Default source was vscode (clientInfo name was ignored). Set threadSource so new threads are not attributed to VS Code.

thread/resume of exec id 01a085eb-14f7-71f3-a715-f96593249ad6 with excludeTurns: true → same id, source: "exec", idle, canAcceptDirectInput: true, model gpt-6-astra, sandbox workspaceWrite, approvalPolicy: never. thread/unsubscribe → unsubscribed.

Not live-proven: turn/steer against a real in-progress model turn (would spend tokens). Gate with a fake JSON-RPC server.

What would break vs current exec --json

Area Today (startCodexRun + runCodex) App-server
Process / turn end Child exit = turn over Process stays up; turn/completed ends the turn. onExit must not mark failed after a clean completed.
Event parse JSONL item.started / command_execution / agent_message (electron/codex.js) RPC notifications + camelCase ThreadItem (commandExecution, agentMessage). Existing extractors will miss.
Session resume exec resume <sessionId> --json; -m ignored (sessionPinsModel) thread/resume loads the same id (probed). turn/start.model claims it overrides subsequent turns — re-verify before changing sessionPinsModel.
Sandbox -c / --sandbox First exec --sandbox; resume rejects --sandbox (#795). codexWorkspaceWriteArgs splices writable_roots + gh proxy. thread/start.sandbox is SandboxMode; turn/start.sandboxPolicy is a different object. Resume probe had writableRoots: [] even though Solenta injects roots on exec. Re-apply on start/resume config.
MCP getCodexMcpArgs -c mcp_servers.* after exec / exec resume (#846). Bearer tokens in env, never argv. Same values via spawn -c or thread/start.config / thread/resume.config. Wrong placement drops thread_send. SSE still unsupported.
Guardrail overlay Isolated CODEX_HOME + features.hooks=true + --dangerously-bypass-hook-trust Spawn app-server with the same env/flags. ssh/WSL still needs remote overlay (#835).
Usage / context ring token_count / turn.completed JSONL; snapshot vs delta (#317) thread/tokenUsage/updated. Re-map last vs total or the ring double-counts.
Writer-lock Exec holds the writer for one process; classifyWriterLock + parkCodexFromNotice Loaded thread holds the writer until unsubscribe. Prefer per-turn private server: handshake → resume → turn → completed → unsubscribe → kill (steer still works while the turn is live). Do not use the shared daemon.
Approvals No interactive ask; modes map to sandbox + approval_policy=never ServerRequest: execCommandApproval, item/commandExecution/requestApproval, item/fileChange/requestApproval. Keep approvalPolicy: "never" until a later issue. Unanswered requests stall the turn.
Images exec -i UserInput image / localImage.
ssh/WSL wrapCommand one-shot argv; stdin ignored Needs a live stdin RPC. Wrap must keep stdio pipes.
Workflow / ask / commitmsg Same buildArgs exec Leave on exec. They are one-shot and do not need steer.
supportsSteer unset / false; listProviders uses === true; composer Queue-only while busy Set true only after fake-server tests prove steerRun sends turn/steer on the same process/turnId and appends steer: true.

Recommended shape

New module (e.g. electron/codex-appserver.js): JSON-RPC framing, handshake, send(method, params), notification dispatch. Do not overload runCodex.

startCodexRun becomes the app-server turn host. entry.handle.send = turn/steer with stored expectedTurnId (return false until that id exists). steerRun stays provider-gated (supportsSteer === true + handle.send).

First lifetime: per-turn private app-server (closest to today's kill/exit). Not a Claude-style idle LRU (writer held between turns). Not the Desktop daemon.

Keep Queue as Solenta's idle follow-up.

Acceptance

  • Fake app-server: initialize → thread/resume or thread/start → turn/start → notifications drive assistant/tool/thinking/usage the way exec JSONL does today.
  • Fake in-progress turn: steerRun writes turn/steer with that expectedTurnId, does not spawn a second process, appends a steer: true user row on the same runId.
  • steerRun before turn/started rejects (or send returns false); no steer: true row.
  • Review/compact: steer rejected.
  • Exec session id round-trip: stored thread.sessionId resumes; no new Codex thread unless sessionId is missing / ejected / model-pin drop.
  • MCP -c / config still auto-approves first-party servers on resume (Explicit Grok worker forks are impossible when approval policy is never #846).
  • Workspace-write roots + planboard gh proxy still present on start and resume.
  • Writer-lock copy still matches thread-store conflict / already has an active writer; unsubscribe/kill releases for the next turn.
  • listProviders advertises supportsSteer: true for Codex only after the adapter can send turn/steer. Workflow/ask/commitmsg still exec --json.
  • Composer: Steer visible while a Codex run is live; Queue remains the idle default (Steer a running turn instead of only queueing a follow-up #156).

PR plan

  1. JSON-RPC client + fake server tests (no live model).
  2. startCodexRun on app-server; map notifications; process-exit vs turn/completed; stop = interrupt + unsubscribe + kill. supportsSteer still false.
  3. Map MCP, sandbox/workspace-write, hooks/CODEX_HOME, effort, web_search onto start/resume config. Resume existing exec ids.
  4. handle.send → turn/steer; hang-scenario test; then supportsSteer: true.
  5. ssh/WSL stdio wrap + writer-lock/fromNotice regression.

Out of scope

  • Shared app-server daemon / remote-control
  • thread/queue/add for Solenta Queue
  • Interactive ServerRequest approvals (Claude-like ask)
  • Persist-mode / send_user_message_async
  • Killing exec to fake steer
  • Grok/Kimi/Cursor/OpenCode steer

Activity

  1. added
    plan:todo
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Sep 9, 2026
  2. currentbits commented on Sep 10, 2026

    @currentbits
    OwnerAuthor

    Interactive Codex now uses a private per-turn codex app-server (electron/codex-appserver.js). startCodexRun handshakes, thread/start or thread/resume, turn/start; notifications map to the existing JSONL extractors; handle.send is turn/steer with expectedTurnId (false until that id exists). supportsSteer is true for Codex only. Workflow/ask/commitmsg stay on exec --json. Queue remains Solenta idle follow-up. Fake-server tests cover steer, pre-turn reject, review/compact, exec-id resume, MCP/workspace-write/hooks argv, writer-lock, ssh wrap without -n. Live turn/steer against a real in-progress model turn was not spent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions