Skip to content

feat(app-server): propagate traces across tasks and core ops#14387

Merged
owenlin0 merged 5 commits intomainfrom
owen/request-trace-lineage2
Mar 12, 2026
Merged

feat(app-server): propagate traces across tasks and core ops#14387
owenlin0 merged 5 commits intomainfrom
owen/request-trace-lineage2

Conversation

@owenlin0
Copy link
Copy Markdown
Collaborator

@owenlin0 owenlin0 commented Mar 11, 2026

Summary

This PR keeps app-server RPC request trace context alive for the full lifetime of the work that request kicks off (e.g. for thread/start, this is app-server rpc handler -> tokio background task -> core op submissions). Previously we lose trace lineage once the request handler returns or hands work off to background tasks.

This approach is especially relevant for thread/start and other RPC handlers that run in a non-blocking way. In the near future we'll most likely want to make all app-server handlers run in a non-blocking way by default, and only queue operations that must operate in order (e.g. thread RPCs per thread?), so we want to make sure tracing in app-server just generally works.

Depends on #14300

Before
image

After
image

What changed

  • Keep request-scoped trace context around until we send the final response or error, or the connection closes.
  • Thread that trace context through detached thread/start work so background startup stays attached to the originating request.
  • Pass request trace context through to downstream core operations, including:
    • thread creation
    • resume/fork flows
    • turn submission
    • review
    • interrupt
    • realtime conversation operations
  • Add tracing tests that verify:
    • remote W3C trace context is preserved for thread/start
    • remote W3C trace context is preserved for turn/start
    • downstream core spans stay under the originating request span
    • request-scoped tracing state is cleaned up correctly
  • Clean up shutdown behavior so detached background tasks and spawned threads are drained before process exit.

@owenlin0 owenlin0 marked this pull request as ready for review March 11, 2026 20:07
@owenlin0 owenlin0 force-pushed the owen/request-trace-lineage2 branch 2 times, most recently from 273b27c to 4a2ec69 Compare March 11, 2026 21:09
@owenlin0
Copy link
Copy Markdown
Collaborator Author

@codex review

@owenlin0 owenlin0 force-pushed the owen/request-trace-lineage2 branch from 4a2ec69 to a4f17b4 Compare March 11, 2026 21:12
Copy link
Copy Markdown
Contributor

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

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: a4f17b4cec

ℹ️ 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".

@owenlin0
Copy link
Copy Markdown
Collaborator Author

@codex review

@owenlin0 owenlin0 force-pushed the owen/request-trace-lineage2 branch from a4f17b4 to cdeed13 Compare March 11, 2026 21:38
@owenlin0 owenlin0 changed the title feat(app-server): keep request traces attached to async work feat(app-server): propagate traces across tasks and core op submissions Mar 11, 2026
@owenlin0 owenlin0 changed the title feat(app-server): propagate traces across tasks and core op submissions feat(app-server): propagate traces across tasks and core ops Mar 11, 2026
Copy link
Copy Markdown
Contributor

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

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: cdeed13284

ℹ️ 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".

@owenlin0 owenlin0 force-pushed the owen/request-trace-lineage2 branch from 533026b to 21448b6 Compare March 11, 2026 21:53
@owenlin0
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown
Contributor

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

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: 89fb20e99d

ℹ️ 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".

@owenlin0
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown
Contributor

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

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: 7ed02aec2b

ℹ️ 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 on lines +1889 to +1895
self.background_tasks.close();
if tokio::time::timeout(Duration::from_secs(10), self.background_tasks.wait())
.await
.is_err()
{
warn!("timed out waiting for background tasks to shut down; proceeding");
}
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.

P1 Badge Cancel timed-out background tasks before thread shutdown

drain_background_tasks only waits 10s, then logs and returns without aborting unfinished tasks. Shutdown then proceeds to shutdown_threads, which snapshots current threads. A still-running thread_start_task can create a new thread after that snapshot, leaving it alive past shutdown (resource leak / orphaned work).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

valid but not worth the complexity atm

@owenlin0 owenlin0 merged commit 5bc82c5 into main Mar 12, 2026
35 of 36 checks passed
@owenlin0 owenlin0 deleted the owen/request-trace-lineage2 branch March 12, 2026 03:18
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants