Skip to content

Automations (heartbeat & cron) inject a function_call_output without call_id, permanently breaking the target session (400 missing field call_id) #44723

Open

Description

@husongjie521-alt

Component: Codex desktop app (Windows), package 26.903.9818.0 (ChatGPT.exe 152.0.7977.83), bundled codex-cli 0.153.4
Model provider: custom OpenAI-compatible provider in config.toml with wire_api = "responses" (base_url https://api.deepseek.com/)

Summary

When an automation fires (heartbeat or cron), the app appends a synthetic tool-result item to the target session and posts the session history to the Responses endpoint. The item is a function_call_output for the app tool automation_update, but it carries no call_id, so the server rejects the entire request:

Failed to deserialize the JSON body into the target type:
input: missing field `call_id` at line 1 column 851416

Because the item stays in the session history, the session is permanently bricked: every later request fails the same way, including ordinary user messages. Each failed automation run appends yet another bad item. In our case the automation never ran successfully even once, and the failure was silent.

Steps to reproduce

  1. Configure a custom Responses-API provider (wire_api = "responses") in config.toml.

  2. Create a heartbeat automation targeting an existing thread (reproduced), or a cron automation bound to a project (also reproduced).

  3. Wait for the first trigger.

  4. The run ends immediately with the 400 above.

  5. In the session rollout JSONL, the injected trigger item looks like this (no call_id; note the non-standard name/namespace fields and the fco_ id prefix):

    {"type":"function_call_output",
    "id":"fco_01a08cf7-e93a-7641-98bf-75581dc6ad04",
    "name":"automation_update",
    "namespace":"codex_app",
    "output":"\r\n <automation_id>automation</automation_id>\r\n <current_time_iso>2026-09-10T20:17:32.150Z</current_time_iso>\r\n...",
    "internal_chat_message_metadata_passthrough":{"turn_id":"01a08cf7-...","create_time":1789071452.75}}

  6. Send any ordinary message in that same thread: it also fails with the same error.

Evidence

  • Ordinary turns in another thread work fine against the same provider, so the request path itself is healthy - only the automation-delivered item is malformed.
  • All automation failures show the same message with a monotonically growing column, because the session keeps growing (~3 KB per failed run): 839237, 842598, 845959, 849320, 851416.
  • A cron automation reproduced it in a brand-new thread too (column 46888), so this is not heartbeat-specific.
  • Per the Responses API schema, function_call_output items require call_id (see https://developers.openai.com/api/docs/guides/function-calling).

Expected

Automation triggers should be delivered as schema-valid input - e.g. a function_call_output that carries the call_id of the corresponding automation_update function call, or simply as a normal user message. A failed run should not permanently damage the session.

Suggested fix

  1. Populate call_id on the injected item (pair it with the automation's automation_update call), or deliver the trigger as a regular message.
  2. Validate outgoing input items against the Responses schema before sending, and skip/log invalid synthetic items instead of letting the server reject the whole turn.
  3. Make sessions self-healing: do not persist an item the server rejected, or provide a way to drop/repair invalid items from a broken thread.

Impact

  • Scheduled automations are unusable (5 failures / 0 successful runs).
  • The target conversation is permanently broken and cannot be repaired from the UI.
  • Silent monitoring failure: our automation was supposed to watch a live trading loop every 2 hours; it never ran, and nobody noticed until we investigated manually.

Activity

  1. added
    bug
    app
    custom-model
    session
    on Sep 11, 2026
  2. njwangcn commented on Sep 11, 2026

    @njwangcn

    Confirming this on a second install, with one extra data point that matters for the fix: supplying call_id alone is not enough.

    Environment

    • Codex desktop app 26.903.9818.0 (Windows 11 x64), bundled codex-cli 0.153.4
    • Custom provider in config.toml: wire_api = "responses", routed through a local proxy to DeepSeek

    Instance

    A kind = "heartbeat" automation targeting an existing thread (FREQ=DAILY;BYHOUR=21) fired at 2026-09-11T13:00:05.821Z and wrote the malformed item into the thread rollout (ordinal 6972 of that thread's history):

    {"ordinal":6972,"type":"response_item","payload":{"type":"function_call_output","id":"fco_01a0908d-c6e1-7df2-8290-ce0044f70ae0","name":"automation_update","namespace":"codex_app","output":"<heartbeat>\r\n  <automation_id>automation</automation_id>\r\n ...\r\n</heartbeat>\r\n"}}

    Every later turn in that thread failed with input: missing field call_id at line 1 column 6848223 (column grows across retries: 6847678 → 6848223 → 6849746 → 6850308), including ordinary user messages and the heartbeat run itself. Confirms the "permanently bricked, never a successful run" part.

    Extra evidence: call_id alone doesn't fix it

    I probed the same Responses path directly with two synthetic requests:

    input item response
    {"type":"function_call_output","output":"hi"} 400 Failed to deserialize the JSON body into the target type: input: missing field call_id at line 1 column 56
    {"type":"function_call_output","call_id":"call_test_1","output":"hi"} 400 No tool call found for tool output with call_id call_test_1

    So suggestion 1 in the report should be read as "pair the item with the corresponding function_call", not just "populate the field" — otherwise strict providers still reject it with a different 400. Delivering the trigger as a user message (as the heartbeat spec advertises, and as earlier builds did) avoids the whole class of problem.

    For reference, in a rollout written by an earlier build (rollout-2026-08-05T20-39-57-019fd1f0-...jsonl) the same <heartbeat> payload is stored as a response_item of type message with role: "user" and an input_text part — which is what a heartbeat is supposed to be.

    History integrity check

    Scanning that thread's full history: 3146 response_items, exactly one item missing call_id, and 940 function_call / 940 function_call_output with no other orphan on either side. The single injected item is the entire cause, and removing it restores the thread.

    Repair that worked (for anyone stuck)

    1. Back up the rollout JSONL, then delete the offending function_call_output line and its paired event_msg/item_completed line.
    2. Verified afterwards: 0 items missing call_id, tool call/output pairing intact.
    3. Restart the app so it re-reads the rollout; new turns then go through normally.

    Worth noting for triage: the malformed item is written to disk before the request is built, so the same item also gets replayed by any later resume — a client-side validation of outgoing input items (report item 2 in this issue) would stop the bleeding even before the delivery path is changed.

  3. husongjie521-alt commented on Sep 11, 2026

    @husongjie521-alt
    Author
  4. husongjie521-alt commented on Sep 11, 2026

    @husongjie521-alt
    Author
  5. argszero commented on Sep 11, 2026

    @argszero

    Both of these comments are correct, and @njwangcn's correction ("populate call_id" is not a fix) is the important one. Here is the delivery-path change that introduced this, plus two code facts that matter for the repair.

    Where it came from

    The trigger used to arrive as a user message; it now arrives as a standalone tool output. That switch is commit e56e4922eb — "Support standalone tool outputs in turn/start" (#41002), merged 2026-08-26, first released in rust-v0.151.0-alpha.4 and present in 0.151.0+/0.152.x/0.153.x. Older builds predate it, which is exactly the boundary in @njwangcn's comparison rollout: the 2026-08-05 file stores the same <heartbeat> payload as a message with role: "user" because the standalone-output path did not exist yet.

    The producer is the app-server turn/start toolOutput parameter:

    pub struct TurnToolOutput {   // app-server-protocol/src/protocol/v2/turn.rs:155
        pub name: String,
        pub namespace: Option<String>,
        pub output: FunctionCallOutputBody,
    }

    param at turn.rs:176, consumed at app-server/src/request_processors/turn_processor.rs:592-603, which builds ResponseItem::FunctionCallOutput { id: None, call_id: None, name: Some(..), namespace: .. } — literally with call_id: None hardcoded. Note the type: it has no field that could express a pairing. That is the structural reason a "just add the field" fix cannot be made at the delivery layer — the RPC has no way to name the call the output answers, so @njwangcn's synthetic probe (call_id present → No tool call found for tool output) is the expected outcome, not a bug in the probe.

    The fco_… id is then synthesized by Session::assign_missing_response_item_id (core/src/session/mod.rs:3453) through the standalone-output arm of turn input construction (core/src/session/turn_input.rs:684-692). It is the signature of an intentionally standalone output, not a lost call_id.

    Why nothing catches it

    The request path does have an orphan cleaner — remove_orphan_outputs (core/src/context_manager/normalize.rs:155) — but its arm matches call_id: Some(call_id) only (:184-190), so a call_id: None item is skipped by construction. That is deliberate and documented one line above the call site: "every output has a corresponding call entry or names an external tool event" (core/src/context_manager/history.rs:705). Because toolOutput also cannot be combined with a nonempty input (turn_processor.rs:536-541), the injected item becomes an entire turn's input, and history is replayed on every later turn — which is why the thread is bricked rather than merely warned.

    On the sqlite rows (@husongjie521-alt)

    Your observation is right and the repair is right, but the query should not be read as counting malformed items. The projection stores an app-server ThreadItem, and FunctionCallOutputItem (protocol/src/items.rs:89) is { id, name, namespace, output } — there is no call_id field in that schema at all, so item_json not like '%call_id%' excludes nothing; the discriminating part of your query is item_type = 'functionCallOutput' alone. That column's value for this case happens to be rare for an unrelated reason: the row type has exactly one producer (core/src/hook_runtime.rs:748, inside the TurnInput::FunctionCallOutput arm), which is the same standalone-output delivery. So the DB row is the same item as the rollout item, projected — not a second defect.

    It is also not what re-poisons history. Model input is loaded from the rollout, not from this table (thread-store/src/local/model_context.rs:37-76); thread_items backs the list/timeline/UI views (app-server/src/request_processors/thread_processor.rs via deserialize_stored_thread_item). That is why deleting only one of the two leaves an inconsistent state, and why your recipe deletes both.

    One caveat on editing the JSONL in place

    Deleting a line shortens the file, but nothing reconciles the projection's byte cursor. thread_history_projection_state.next_rollout_byte_offset still points past the new end of file, and the next projection attempt returns "durable rollout shrank before projection" (thread-store/src/local/thread_history_materialization.rs:110-113). That error is warn-only (live_writer.rs:353, session/mod.rs:1349), so the sqlite view silently stops advancing. The codebase already contains the right recovery shape — compare the stored cursor against the actual file length and reproject (rollout_migration.rs:1033-1037) — but it is applied only when recovering a pending published migration, not after manual repair. Practically: after a hand edit, expect the sidebar/timeline for that thread to stay frozen until the rollout regrows past the old cursor, and prefer starting a fresh thread where you can.

    The fix direction is the one in the first comment: either deliver the automation trigger as a user turn again, or give toolOutput a way to name the call it pairs with and enforce it at request assembly.

  6. bjdx8j4zm5-source commented on Sep 12, 2026

    @bjdx8j4zm5-source

    Workaround (verified): deliver the trigger the way it was delivered before e56e4922eb

    Same setup as reported here (Windows, Codex Desktop, wire_api = "responses", DeepSeek).
    We hit both halves of the failure: the automation never completed a single run, and the
    target thread became permanently unusable — every later user message returned the same
    HTTP 400.

    As @argszero traced above, the trigger used to arrive as a user message; since
    e56e4922eb it arrives as a standalone function_call_output with no call_id. And as
    @njwangcn pointed out, populating call_id alone is not a fix either — there is no
    matching function_call to pair it with.

    So rather than trying to make the item valid, add a local passthrough proxy that rewrites
    it back into the old form before it reaches the provider:

    # every function_call_output without call_id -> plain user message with the same text
    {"type": "function_call_output", "id": "fco_…", "name": "automation_update",
     "namespace": "codex_app", "output": "<heartbeat>…</heartbeat>"}
    # becomes
    {"type": "message", "role": "user",
     "content": [{"type": "input_text", "text": "<heartbeat>…</heartbeat>"}]}

    Everything else — tool calls, reasoning items, streaming — is forwarded unchanged.

    [model_providers.deepseek]
    base_url = "http://127.0.0.1:19100/"   # local shim -> api.deepseek.com
    wire_api = "responses"

    Verified end to end:

    test result
    request containing an orphan function_call_output, sent directly to api.deepseek.com 400 missing field 'call_id'
    identical request through the shim 200, 27 SSE events, clean response.completed
    real codex exec run with the shim as base_url 200, normal model reply
    GET /models and a non-streaming POST /responses 200

    Outcome: the automation actually runs instead of dying on its first trigger, and no
    malformed item is ever persisted — so the "permanently bricked thread" failure mode
    disappears.

    For threads that are already bricked, the same repo ships a repair script that removes
    the orphan outputs from both the rollout JSONL and thread_history_1.sqlite
    (thread_items), realigns thread_history_projection_state, and backs everything up
    before touching it (dry-run by default). Restart Codex afterwards.

    Code + write-up: https://github.com/bjdx8j4zm5-source/codex-strict-responses-fix

    Caveat: this is a client-side workaround, not an app-server fix. The proper fix is either
    attaching a real call_id with a matching function_call, or going back to
    user-message delivery for injected triggers.


    中文版

    同样的环境(Windows + Codex 桌面版 + wire_api = "responses" + DeepSeek)。我们遇到了这个
    问题的两半:自动化一次都没成功运行过,而且目标会话被永久搞坏——之后每条消息都返回同样的
    HTTP 400。

    正如 @argszero 上面定位的:触发内容以前是以 user 消息下发的;e56e4922eb 之后改成
    独立的 function_call_output,且不带 call_id。而 @njwangcn 说得对:只补 call_id 也
    不行——它没有配对的 function_call。

    所以不去"修正"这条记录,而是加一个本地透传代理,把它改回旧格式再发给服务商:

    # 每个缺 call_id 的 function_call_output -> 内容相同的普通 user 消息
    {"type": "function_call_output", "id": "fco_…", "name": "automation_update",
     "namespace": "codex_app", "output": "<heartbeat>…</heartbeat>"}
    # 变成
    {"type": "message", "role": "user",
     "content": [{"type": "input_text", "text": "<heartbeat>…</heartbeat>"}]}

    其余内容(工具调用、reasoning、流式响应)原样透传。

    [model_providers.deepseek]
    base_url = "http://127.0.0.1:19100/"   # 本地代理 -> api.deepseek.com
    wire_api = "responses"

    端到端验证:

    测试 结果
    含孤儿 function_call_output 的请求,直连 api.deepseek.com 400 missing field 'call_id'
    同一请求走代理 200,27 个 SSE 事件,正常 response.completed
    真实 codex exec 以代理为 base_url 200,模型正常回复
    GET /models 与非流式 POST /responses 200

    结果:自动化能真正跑起来(而不是在第一次触发就死掉),并且不会再写入坏记录,因此
    "会话永久损坏"这个失败模式消失。

    对于已经坏掉的会话,同一个仓库里有修复脚本:从 rollout JSONL 和
    thread_history_1.sqlite(thread_items)里删除孤儿输出、校正
    thread_history_projection_state 偏移,改动前自动备份(默认 dry-run),修完重启
    Codex 即可。

    代码与说明:https://github.com/bjdx8j4zm5-source/codex-strict-responses-fix

    说明:这是客户端绕过方案,不是 app-server 的修复。官方正确修法是:补上真实的 call_id
    并配对 function_call,或让注入的触发内容改回 user 消息投递。

  7. sleep007 commented on Sep 15, 2026

    @sleep007

    Confirming this on macOS with Codex Desktop 26.908.40834 and a custom Responses provider (CodexCN).

    • Automation type: cron
    • Affected jobs: scheduled daily and weekly work reports
    • Configured model: gpt-5.6-sol
    • Provider configuration uses wire_api = "responses"; Responses WebSocket is not supported by this provider.

    The cron task fails immediately after Codex injects the standalone automation_update function_call_output, before the report-generation prompt starts. The provider returns:

    function_call_output requires call_id on HTTP requests; continuation via previous_response_id is only supported on Responses WebSocket v2

    Normal conversations work through the same provider. This confirms the issue is not Windows-specific and affects macOS cron automations as well.

  8. sususu98 commented on Sep 15, 2026

    @sususu98

    Adding another concrete data point directly from official OpenAI /v1/responses (not a third-party custom provider), which confirms the wire-level schema failure, sheds light on the call_id: "" variation, and identifies a second code location that generates this exact pattern.

    1. Official OpenAI Responses API Error

    In our production deployment, a Windows Codex Desktop client hit this exact issue when an automation heartbeat fired at 01:00 AM.

    Unlike third-party providers that report missing field 'call_id', official OpenAI /v1/responses returned HTTP 400 with the following schema validation failure:

    {
      "error": {
        "message": "Invalid 'input[678].call_id': empty string. Expected a string with minimum length 1, but got an empty string instead.",
        "type": "invalid_request_error",
        "param": "input[678].call_id",
        "code": "empty_string"
      }
    }

    The wire payload captured at index 678 was:

    {
      "type": "function_call_output",
      "call_id": "",
      "output": "<heartbeat>\r\n  <automation_id>ais</automation_id>\r\n  <current_time_iso>2026-09-14T17:00:43.899Z</current_time_iso>\r\n  <instructions>\r\n    ...\r\n  </instructions>\r\n</heartbeat>\r\n"
    }

    Because call_id is serialized as "" (empty string) rather than omitted, OpenAI's strict JSON schema validator rejects it under the minLength: 1 rule.

    2. Additional Code Source: stream_events_utils.rs:366

    In addition to the app-server TurnToolOutput delivery path traced by @argszero, there is a second direct producer of call_id: "" in codex-rs/core/src/stream_events_utils.rs:364-378:

    // The tool request should be answered directly (or was denied); push that response into the transcript.
    Err(FunctionCallError::RespondToModel(message)) => {
        let response = ResponseInputItem::FunctionCallOutput {
            call_id: String::new(), // <--- hardcoded empty String
            output: FunctionCallOutputPayload {
                body: FunctionCallOutputBody::Text(message),
                ..Default::default()
            },
        };
        record_completed_response_item(ctx.sess.as_ref(), ctx.turn_context.as_ref(), &item).await;
        if let Some(response_item) = response_input_to_response_item(&response) {
            ctx.sess
                .record_conversation_items(
                    &ctx.turn_context,
                    std::slice::from_ref(&response_item),
                )
                .await;
        }
    
        output.needs_follow_up = true;
    }

    Here, response_input_to_response_item (line 507) converts it into ResponseItem::FunctionCallOutput { call_id: Some("".to_string()), .. }. Because Option::is_none is false, Serde serializes "call_id": "", which immediately gets written to the session's rollout / SQLite database and permanently poisons all future turns against strict OpenAI endpoints.

    3. Verification of the Proposed Fix

    We verified the workaround suggested by @njwangcn and @bjdx8j4zm5-source at the gateway layer:

    • Rewrote input[678] from type: "function_call_output" into a standard user message:
      {
        "type": "message",
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "<heartbeat>...</heartbeat>"
          }
        ]
      }
    • Result: HTTP 200 OK (status: completed). The model smoothly received the heartbeat instructions and resumed the thread without any schema error.

    Delivering automation triggers and synthetic external context as role: "user" messages (or pairing them with a valid function_call when a tool interaction is genuinely intended) is definitely the right architectural fix.

  9. charlescao0417-svg commented on Sep 15, 2026

    @charlescao0417-svg

    Adding a macOS data point confirming this is still present on app-server 0.154.0-alpha.6.2.

    Environment

    • macOS 26.6.2 (25G83)
    • Codex Desktop 26.908.70816 (reproduced earlier on 26.903.71938 and 26.908.40834; updated again 2026-09-15 and the issue persists)
    • app-server bundled with the desktop app: 0.154.0-alpha.6.2
    • Model provider: DeepSeek custom provider, wire_api = "responses", model_provider = deepseek

    Symptom

    Both local cron automations fail on their first turn, roughly 0.3 s after the trigger. No output is produced and there is no retry:

    Failed to deserialize the JSON body into the target type: input: missing field `call_id` at line 1 column 56598
    {"type":"invalid_request_error","param":null,"code":"invalid_request_error"}
    

    Observed trigger times (Asia/Shanghai)

    • 2026-09-11 12:02:08 and 12:32:08
    • 2026-09-14 12:02 and 12:31
    • 2026-09-15 12:02 and 12:31

    All six failed identically. The scheduler itself fires correctly — the failure happens purely at request construction, before inference starts.

    Recorded item

    The injected trigger is persisted as a standalone tool output with no call_id (and, as others noted, no matching function_call to pair it with):

    {"type":"function_call_output","id":"fco_...","name":"automation_update","namespace":"codex_app","output":"Automation: <name> ..."}

    Client-side gate

    The desktop client still gates on the same capability and takes the tool-output branch; the shaping function is unchanged in 26.908.70816:

    return hasCapability(appServerVersion, `turnToolOutput`)
      ? { input: [], toolOutput: { name: `automation_update`, namespace: `codex_app`, output: text } }
      : { input: [{ type: `text`, text, text_elements: [] }] };

    The capability table maps turnToolOutput to 0.151.0-alpha.4, so any app-server at or above that version takes the broken branch.

    Impact

    Both automations have failed every scheduled run since the regression. They only work when re-run manually from a normal chat (i.e. user-message delivery). There is no setting or feature flag that forces the legacy text path — codex features list exposes no relevant toggle, and codex CLI offers no override for the app-server version.

  10. VincentAdamNemessisX commented on Sep 16, 2026

    @VincentAdamNemessisX

    Fresh reproduction on macOS, adding two details not covered above.

    Environment: macOS, ChatGPT.app bundle 152.0.7977.83 (bundled codex 0.154.0-alpha.6.2, originator Codex Desktop), custom provider wire_api = "responses" → OpenCode Go (https://opencode.ai/zen/go/v1, DeepSeek V4.1 Flash), which validates input items strictly.

    Same failure: Failed to deserialize the JSON body into the target type: input: missing field call_id``. Item shape identical (function_call_output, `name: automation_update`, `namespace: codex_app`, no `call_id`, no matching `function_call`).

    Two additions:

    1. The heartbeat is injected at turn start and the automation tick's own request already contains the fresh item, so the run can never succeed on a strict upstream — this is stronger than "the thread is bricked for later messages". With an hourly heartbeat automation (:00/:30, kind = "heartbeat"), every tick appends another malformed item and fails silently until the JSONL rows are repaired by hand. The malformed items are also replayed on every manual turn, so the thread stays unusable in between.

    2. Confirmed the repair constraint reported in Standalone injected function_call_output is rejected by strict Responses providers; adding a call_id is not a sufficient repair #45450: adding only a synthetic call_id moves the error to No tool call found for tool output with call_id …. A strict upstream requires a matching function_call item, or the injection must be delivered as a schema-valid non-tool item.

    Suggested fix (unchanged, now with the pairing requirement explicit): deliver automation/thread-delegation injections as plain message items (role=user), or emit a paired automation_update function_call + function_call_output with call_id. Either would fix both the tick itself and history replay.

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

    appautomationsbugcustom-modelsession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions