Skip to content

Codex native runtime has very high latency for trivial turns and docs disagree on recommended model prefix #78947

Closed as not planned

Description

@yu381792

Summary

On OpenClaw 2026.5.6, a dedicated Codex agent using the native Codex runtime is much slower than the native Codex App/CLI experience on the same machine. Even a fresh, explicit --agent codex session that only replies OK took 25.9s and sent about 33k prompt tokens.

This makes the OpenClaw Codex harness feel unusable for interactive chat compared with Codex App/CLI. I previously switched back to PI for this reason, and after retesting on 2026.5.6 the issue still reproduces.

There is also a documentation mismatch: the public docs page currently shows codex/gpt-* in the quick config, while the installed 2026.5.6 docs say new native Codex configs should use openai/gpt-* + agentRuntime.id: "codex" and that codex/gpt-* is a legacy alias.

Environment

  • OpenClaw version: 2026.5.6
  • Platform: macOS 26.4.1, arm64
  • Gateway: LaunchAgent, local gateway on 127.0.0.1:18789
  • Codex auth: local Codex/Codex OAuth is available; direct Codex App/CLI is much faster on the same machine/account
  • Workspace: existing OpenClaw workspace with Feishu, Weixin, memory-core/gbrain enabled

Config tested

Dedicated codex agent, leaving main on PI:

{
  "id": "codex",
  "name": "小K Codex",
  "workspace": "/Users/yu/.openclaw/workspace",
  "model": {
    "primary": "openai/gpt-5.5",
    "fallbacks": ["openai/gpt-5.4-mini"]
  },
  "agentRuntime": {
    "id": "codex"
  }
}

main was kept on PI:

{
  "id": "main",
  "model": {
    "primary": "openai-codex/gpt-5.5",
    "fallbacks": ["openai-codex/gpt-5.4-mini"]
  },
  "agentRuntime": {
    "id": "pi"
  }
}

Reproduction

Run a clean explicit Codex-agent session:

openclaw agent \
  --agent codex \
  --session-id codex-native-smoke-$(date +%s) \
  --message '[local diagnostic] 只回复 OK,用于确认独立 codex agent native runtime。' \
  --thinking off \
  --json \
  --timeout 90

Observed result

The request succeeds, but latency is very high:

{
  "status": "ok",
  "result": {
    "meta": {
      "durationMs": 25908,
      "agentMeta": {
        "provider": "openai",
        "model": "gpt-5.5",
        "contextTokens": 272000,
        "agentHarnessId": "codex",
        "usage": {
          "input": 29779,
          "output": 17,
          "cacheRead": 3456,
          "total": 33252
        },
        "promptTokens": 33235
      },
      "executionTrace": {
        "winnerProvider": "openai",
        "winnerModel": "gpt-5.5",
        "attempts": [
          {
            "provider": "openai",
            "model": "gpt-5.5",
            "result": "success",
            "stage": "assistant"
          }
        ],
        "fallbackUsed": false,
        "runner": "embedded"
      },
      "requestShaping": {
        "thinking": "off"
      }
    }
  }
}

Status after the run shows the same:

agentId: codex
runtime: OpenAI Codex
model: gpt-5.5
inputTokens: 29779
outputTokens: 17
totalTokens: 33235

There was no fallback. The route appears to be the native Codex runtime, but the trivial turn still takes ~26 seconds.

Expected result

For a fresh Codex agent session with thinking: off and a trivial reply OK prompt, OpenClaw native Codex runtime should be much closer to Codex App/CLI latency on the same machine. If OpenClaw must inject ~30k tokens of tool/channel/workspace context into every fresh native Codex runtime turn, there should be a documented way to run a lean Codex agent profile for interactive use.

Additional observations

  1. Setting lower bootstrap budgets did not materially reduce the native Codex runtime prompt size. The prompt remained around ~33k tokens, suggesting the dominant cost is the OpenClaw tool/runtime/channel context rather than workspace bootstrap files.
  2. PI remains faster/more usable for day-to-day OpenClaw chat on this setup, even though it still carries a large prompt.
  3. Related but not identical: [Feature]: Split /fast for openai-codex/* into latency-only vs aggressive profiles #45570 discusses /fast behavior for openai-codex/*; this issue is specifically about the native Codex runtime path (agentRuntime.id: "codex") on a dedicated agent.

Documentation mismatch

The public docs page at:

https://docs.openclaw.ai/plugins/codex-harness#quick-config

currently shows quick config using codex/gpt-5.4 and embeddedHarness.runtime: "codex".

The installed docs in the 2026.5.6 package say:

  • new native Codex runtime configs should use openai/gpt-* with agentRuntime.id: "codex"
  • codex/gpt-* refs are legacy compatibility aliases
  • openai-codex/gpt-* is the PI Codex OAuth/subscription path

It would help to clarify which config shape is canonical for 2026.5.6+, and whether embeddedHarness vs agentRuntime is current or legacy naming.

Request

Could you please clarify whether this latency is expected for the native Codex runtime, and whether there is a supported lean profile or config knob to reduce the per-turn prompt/tool schema overhead for a dedicated Codex agent?

Activity

  1. clawsweeper commented on May 7, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Summary
    Keep open: current main and hosted docs now agree on the canonical Codex model/runtime shape, but there is still no current-main proof that trivial native Codex turns are fast enough or that OpenClaw has a documented lean interactive profile.

    Reproducibility: no. high-confidence current-main live reproduction was established. The reporter and commenter provided concrete 2026.5.6 timing data, and current source still shows the relevant context/tool assembly path, but a fresh native Codex OAuth smoke is still needed.

    Next step
    Needs maintainer performance/product judgment and a real current-main native Codex OAuth smoke before a safe fix boundary is clear.

    Review details

    Best possible solution:

    Measure a fresh native Codex smoke on current main, then either document the existing knobs as the supported lean recipe with tradeoffs or design a first-class lean Codex profile.

    Do we have a high-confidence way to reproduce the issue?

    No high-confidence current-main live reproduction was established. The reporter and commenter provided concrete 2026.5.6 timing data, and current source still shows the relevant context/tool assembly path, but a fresh native Codex OAuth smoke is still needed.

    Is this the best way to solve the issue?

    No, closing as implemented would only cover the docs-prefix portion. The maintainable path is to decide, with measurements, whether existing codexDynamicToolsExclude/serviceTier behavior is sufficient or whether a named lean profile is needed.

    Acceptance criteria:

    • Run a fresh native Codex smoke on current main with openclaw agent --agent codex --session-id codex-native-smoke-$(date +%s) --message '[local diagnostic] reply exactly OK' --thinking off --json --timeout 90 and record latency plus prompt-token totals.
    • If changing Codex dynamic-tool/profile behavior, run node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.test.ts extensions/codex/src/app-server/dynamic-tools.test.ts.
    • If changing docs only, verify the public docs page and run the repo docs sanity path appropriate for the changed docs files.

    What I checked:

    • issue-live-context: The issue body reports OpenClaw 2026.5.6 native Codex runtime taking 25.9s and about 33k prompt tokens for a trivial OK turn, and a later commenter reported the same general 22s Codex latency during a live 2026.5.6 smoke.
    • docs-prefix-now-current: Current source docs now recommend canonical openai/gpt-* model refs, say not to configure openai-codex/gpt-*, and describe agentRuntime.id: "codex" as the runtime selector, which resolves the original docs-prefix mismatch. Public docs: docs/plugins/codex-harness.md. (docs/plugins/codex-harness.md:19, ea16a5e9e10c)
    • hosted-docs-match-source: The hosted docs page currently renders the same canonical openai/gpt-* and agentRuntime.id: "codex" guidance and no longer shows the stale quick-config shape from the report.
    • codex-runtime-still-assembles-context: Current Codex app-server attempts still build OpenClaw dynamic tools, create the Codex dynamic tool bridge, read mirrored history, and build workspace bootstrap/developer instructions before starting the turn, so the relevant context/tool assembly path remains active. (extensions/codex/src/app-server/run-attempt.ts:534, ea16a5e9e10c)
    • existing-tool-knobs-are-partial: Current docs and source default Codex dynamic tools to searchable loading and expose codexDynamicToolsExclude, but they do not define a first-class lean latency profile or target for trivial interactive turns. Public docs: docs/plugins/codex-harness.md. (docs/plugins/codex-harness.md:472, ea16a5e9e10c)
    • canonical-search: Related search found this issue as the canonical native Codex latency thread: the broader 2026.5.12 high-CPU report was closed in favor of this issue, and the older /fast issue was closed because fast mode no longer reduces reasoning quality.

    Likely related people:

    • steipete: Commit history shows steipete introduced the Codex app-server harness and remains a frequent contributor to run-attempt.ts and Codex harness docs near this latency/runtime surface. (role: Codex app-server feature owner / recent area contributor; confidence: high; commits: dd26e8c44d4e, 934fc6ceeb10, 1e31bd2ac29d; files: extensions/codex/src/app-server/run-attempt.ts, docs/plugins/codex-harness.md)
    • pashpashpash: Recent history includes routing OpenAI agents through Codex by default and deferring Codex dynamic tools behind search, both central to the reported runtime/config and prompt-overhead boundary. (role: Codex routing and dynamic-tool contributor; confidence: high; commits: 1c3399010815, 02fe0d8978db, 3f217964d1f9; files: docs/providers/openai.md, extensions/codex/src/app-server/dynamic-tools.ts)
    • sercada: Current blame on the canonical model-prefix docs, dynamic-tool docs, and dynamic-tool filtering helper points to the recent fix(codex): scope user MCP servers by agent work. (role: recent Codex docs/tool-scope contributor; confidence: medium; commits: 472523360d88; files: docs/plugins/codex-harness.md, docs/providers/openai.md, extensions/codex/src/app-server/dynamic-tool-profile.ts)
    • vincentkoc: Recent OpenAI provider history includes model-route and Codex OAuth/auth work adjacent to the config ambiguity in the report. (role: adjacent OpenAI/Codex docs and auth contributor; confidence: medium; commits: f2b01bb7b142, cc95d4dd28eb, 517566e39a10; files: docs/providers/openai.md, extensions/codex/src/app-server)

    Remaining risk / open question:

    • No live current-main native Codex OAuth smoke was run in this read-only review, so the exact latency and token count may differ from the 2026.5.6 reports.
    • Existing dynamic-tool exclusions and service-tier knobs may be enough, but that needs maintainer product/performance judgment and measured proof before this can be closed.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against ea16a5e9e10c.

  2. kesslerio commented on May 7, 2026

    @kesslerio
    Contributor

    I saw the same general Codex latency problem during a 2026.5.6 live test.

    A trivial Codex harness smoke (reply exactly CODEX_OK) using openai-codex/gpt-5.5 completed, but took about 22s. That is much slower than the native Codex CLI/app experience on the same host.

    More importantly, during the live trial the gateway later hit event-loop starvation while channel traffic was active. I would not claim Codex alone caused that, but the Codex harness path is definitely part of the load profile that makes the gateway feel fragile.

  3. crash2kx commented on May 20, 2026

    @crash2kx

    I can add a source-level and timing update from another affected self-hosted setup. This looks like more than model latency or Docker overhead: the Codex app-server client is warm, but the OpenClaw Codex harness still spends several seconds per turn rebuilding auth/startup/tool state before the prompt is submitted.

    Environment:

    • OpenClaw 2026.5.18 / commit 50a2481
    • Linux x64 Docker gateway
    • Provider/model: openai-codex/gpt-5.5
    • Short test prompt, same session, gateway already warm
    • Codex app-server child process remained alive between turns

    Measured warm-turn trace from local instrumentation:

    Total harness send:              ~10.8s
    Prompt submitted at:              ~7.5s
    Actual completion wait:           ~3.1s
    
    Pre-submit overhead:
      auth_cache:                     ~1.5s
      dynamic_tools.build:             ~1.9s
      getSharedCodexAppServerClient:   ~3.4s
        auth_profile.resolve:          ~1.6s
        managed_options.resolve:       ~0.16s
        bridge_options.resolve:        ~1.6s
        key.build:                     ~0.003s
      thread_lifecycle:                ~0.1s
    

    Important detail: the shared Codex app-server client was reused on the warm turn:

    phase=lookup clients=1 hasEntry=true hasClient=true hasPromise=true transport=stdio commandSource=resolved-managed
    phase=return_client reusedClient=true reusedPromise=true clients=1
    

    So in this case the expensive part is not a full app-server cold start. The cache works, but the code appears to do expensive setup before it reaches the cache hit.

    Source review against the current tree matches the trace:

    • extensions/codex/src/app-server/run-attempt.ts
      • around the startup path, resolveCodexAppServerAuthAccountCacheKey(...) is awaited every turn before tool build / startup.
      • buildDynamicTools(...) is also called every turn.
    • extensions/codex/src/app-server/shared-client.ts
      • getSharedCodexAppServerClient(...) resolves authProfileId, resolveManagedCodexAppServerStartOptions(...), and bridgeCodexAppServerStartOptions(...) before looking up the shared-client map.
      • That means a warm shared client still pays auth/profile/start-options cost before discovering it can reuse the existing client.
    • extensions/codex/src/app-server/auth-bridge.ts
      • resolveCodexAppServerAuthProfileIdForAgent(...) calls ensureCodexAppServerAuthProfileStore(...) and resolveAuthProfileOrder(...).
      • bridgeCodexAppServerStartOptions(...) calls ensureCodexAppServerAuthProfileStore(...) again and checks whether inherited OpenAI API-key env should be cleared.

    This also explains why Codex App/CLI on the same account can feel much faster: in the measured OpenClaw warm turn the model/Codex completion was only about 3 seconds, while OpenClaw spent about 7.5 seconds preparing the turn before prompt.submitted.

    Possible fix direction:

    1. Cache/memoize Codex auth profile resolution and auth account cache key by something like agentDir + authProfileId + authProfileStore/config fingerprint, with invalidation when auth/config changes.
    2. Move the shared-client cache lookup earlier or cache the resolved shared-client key/start options so a warm client does not pay auth_profile.resolve and bridge_options.resolve on every turn.
    3. Cache dynamic tool specs for stable agentId/sessionKey/model/tool allowlist/plugin config inputs, or split static tool schema construction from per-turn message/channel context.
    4. Add built-in diagnostics for these stages (auth_cache, dynamic_tools.build, client_factory.pre_lookup, client_factory.cache_hit, prompt.submitted, completion.wait) so operators can distinguish model latency from OpenClaw harness overhead.

    This is related to #84037 and #84662, but this specific measurement is about per-turn warm-path overhead before prompt submission, even when the app-server shared client is already alive and reused.

  4. blurry-clouds commented on May 23, 2026

    @blurry-clouds

    Adding a reproduction from OpenClaw 2026.5.20 (e510042) that seems to fit this issue rather than warranting a separate one.

    I tested a Discord-oriented chat agent using native Codex runtime (openai/gpt-5.5, agentHarnessId: codex). The agent config is intentionally small: thinkingDefault: low, fastModeDefault: true, contextInjection: "never", skills: [], and a messaging-only tool profile.

    Observed behavior:

    • A live long-running Discord diagnostic session still reached very large trivial-turn prompts: roughly 169k input tokens, mostly cached, against a reported 272k Codex context window. This was not a fresh-session baseline; it included accumulated diagnostic history.
    • Fresh/local dry-runs were smaller but still heavy for trivial replies, around 22k-23k prompt tokens.
    • The generated Codex handoff still included OpenClaw dynamic tools, Codex/MCP thread metadata, and context-engine projection despite the lightweight agent intent.
    • contextInjection: "never" appears scoped to workspace bootstrap injection; it does not disable Codex context-engine/tool/MCP projection.

    I tested candidate knobs in temporary configs without mutating the live config:

    1. agents.list[].contextTokens = 8192

      • Config validation passed and openclaw config get showed chat.contextTokens: 8192.
      • OPENCLAW_CONFIG_PATH=$tmp openclaw agent --local --agent chat --message 'Runtime dry-run: reply with exactly OK.' --json still reported meta.agentMeta.contextTokens: 272000 and Codex context-engine projection logs.
      • Local dry-run prompt stayed around 22k-23k tokens.
    2. bootstrapMaxChars = 1 and bootstrapTotalMaxChars = 1

      • Bootstrap injection was visibly reduced/truncated.
      • Codex context-engine projection still ran.
      • Prompt remained around 22k tokens.
    3. agents.list[].experimental.localModelLean = true

      • Schema describes this as local-model-focused tool trimming.
      • Source deny set appears to trim browser, cron, and message.
      • In a Codex dry-run, message disappeared from the tool list, but sessions_list, sessions_history, sessions_send, and session_status remained.
      • meta.agentMeta.contextTokens stayed 272000, and prompt remained around 23k tokens.

    I have not found a documented supported way to run a genuinely lean native Codex chat agent. The available knobs seem to affect bootstrap only, local-model tool trimming only, or session/status context accounting, but not the Codex app-server context-engine/tool/MCP projection envelope.

    Clarifications that would help:

    • Is agents.list[].contextTokens intended to affect native Codex contextTokenBudget / projection sizing?
    • Is agentMeta.contextTokens only the model/runtime context window rather than a configured cap?
    • Is there any supported native Codex equivalent of a lean profile for interactive chat agents?
  5. steipete commented on May 31, 2026

    @steipete
    Contributor

    Thanks for the report. Closing as stale after the canonical route docs and provider unification.

    The docs-prefix disagreement is resolved by using canonical openai/gpt-* refs for Codex runtime. Please file a fresh issue with current-build latency proof if trivial turns are still slow on canonical openai/gpt-* after openclaw doctor --fix.

  6. locked as resolved and limited conversation to collaborators on Jun 3, 2026
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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions