Skip to content

fix(core): prevent automatic turn span nesting - #24809

Closed
fcoury-oai wants to merge 2 commits into
mainfrom
fcoury/fix-nested-turn-spans
Closed

fcoury-oai wants to merge 2 commits into
mainfrom
fcoury/fix-nested-turn-spans

Conversation

@fcoury-oai

@fcoury-oai fcoury-oai commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

Automatic /goal continuation turns are currently started while the completing turn tracing span is still active. The SQLite log store persists full span ancestry in each event body, so successive automatic turns can serialize an increasingly deep turn{...}:turn{...} chain. In #23340, that produced hundreds-of-kilobyte log rows and a 34 GB log database within a day.

This addresses the nested-span amplification. Repeated invalid skill/icon diagnostic warnings remain a separate problem covered by the proposed reopening/follow-up to #21274.

Fixes #23340.

What changed

  • Added an explicit TurnSpanParent policy for task-owned turn spans.
  • Preserved the current tracing parent for externally initiated, interrupted, test-helper, and inter-agent work.
  • Started automatic goal idle-continuation turns, including queued work consumed on that path, with root turn spans.
  • Ensured rooted regular turns publish the fresh task-span trace ID in TurnStarted rather than the completed parent trace.
  • Added regression coverage for both rooted span ancestry and emitted trace correlation while retaining normal-dispatch coverage.

How to Test

Automated verification run:

  • just test -p codex-core spawn_task_turn_span_inherits_dispatch_trace_context
  • just test -p codex-core regular_turn_emits_turn_started_with_trace_id_without_waiting_for_startup_prewarm
  • just test -p codex-core root_task_turn_span_does_not_inherit_current_trace_context
  • just test -p codex-core rooted_regular_turn_does_not_emit_parent_trace_id
  • just fmt
  • just fix -p codex-core

Additional checks attempted:

  • just test -p codex-core currently fails in unrelated existing/environment-sensitive tests: thread_manager::tests::start_thread_uses_all_default_environments_from_codex_home timed out, and suite::user_shell_cmd::user_shell_command_does_not_set_network_sandbox_env_var observes CODEX_SANDBOX_NETWORK_DISABLED=1 in this sandbox.
  • just argument-comment-lint is blocked before checking source by the Bazel LLVM compiler-rt target missing include/sanitizer/*.h; the touched Rust callsites were manually inspected and the introduced opaque literal callsites are annotated.

Manual verification:

  1. Run a goal that schedules several automatic continuation turns.
  2. Inspect the SQLite log feedback bodies for continuation events.
  3. Confirm each automatic turn no longer accumulates nested turn{...} ancestors and its TurnStarted.trace_id names the new task trace, while a directly submitted turn still correlates to its submission trace.

@fcoury-oai
fcoury-oai requested a review from a team as a code owner May 27, 2026 18:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cab71c1911

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tasks/mod.rs Resolved
@fcoury-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/goal long-running loop produces 480 KB single log lines via chain-nested turn{} tracing spans (34 GB log in one day)

1 participant