Skip to content

codex: desktop OTEL tracing on macOS - #1187

Merged
andy-xu-db merged 1 commit into
mainfrom
andy-xu-db/stack/andy/codex-desktop-tracing-macos
Oct 21, 2026
Merged

andy-xu-db merged 1 commit into
mainfrom
andy-xu-db/stack/andy/codex-desktop-tracing-macos

Conversation

@andy-xu-db

@andy-xu-db andy-xu-db commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


What

#1112 runs ug's OTEL proxy as a login service so Codex desktop traces get a fresh Databricks token, but only on Linux. This adds the same service on macOS: the LaunchAgent com.databricks.ug-codex-otel in ~/Library/LaunchAgents, loaded with launchctl bootstrap gui/<uid>. KeepAlive restarts it after a failure.

The proxy, fixed port, ~/.codex/config.toml exporter, warn-only setup, and removal on disable or ug revert are unchanged. Linux code is untouched: macOS returns early from the shared functions, and the Linux unit and systemctl calls are byte-identical to main. Windows follows in the next PR of this stack.

Notes

  • An unchanged launch leaves a loaded agent alone; a changed plist is reloaded with bootout + bootstrap.
  • The only code shared with the systemd path is _otel_service_env(), the variables the service inherits, so the unit and the plist can't drift apart.

Validation

  • A component test simulates launchctl and checks the plist, an unchanged launch, a workspace change, and removal.
  • A script generates the Linux unit and the systemctl call sequence from this branch and from main: they're identical.
  • just lint passes; tests/test_agent_codex.py passes. The 7 full-suite failures (test_agents_init update prompts, test_e2e_user_agent) fail the same way on main.
  • End to end on a GitHub macos-latest runner, with ug installed by uv tool install, the real Databricks CLI, and Codex's real codex app-server, against a local fake workspace:
    • ug configure writes the exporter and starts the LaunchAgent.
    • App-server sessions export OTLP traces through it to /ai-gateway/otel/v1/traces with the Databricks token, before and after a simulated logout/login (bootout + bootstrap).
    • KeepAlive restarts a killed proxy, and disabling tracing removes the exporter and the agent.

This pull request and its description were written by Isaac.

E2E Test:

Screenshot 2026-10-19 at 4 33 27 PM

@andy-xu-db
andy-xu-db marked this pull request as ready for review October 19, 2026 14:54
@andy-xu-db
andy-xu-db force-pushed the andy-xu-db/stack/andy/codex-desktop-tracing-macos branch from d3d26e0 to f01858e Compare October 19, 2026 20:35
@andy-xu-db
andy-xu-db requested a review from masonc08 October 19, 2026 21:13
Comment thread src/ucode/agents/codex.py
#1112 runs ug's OTEL proxy as a systemd user service so Codex desktop
traces get a fresh Databricks token, but only on Linux. On macOS, run
the same proxy as the LaunchAgent com.databricks.ug-codex-otel, loaded
with `launchctl bootstrap gui/<uid>`; KeepAlive restarts it after a
failure. An unchanged launch leaves a loaded agent alone; a changed
plist is reloaded with bootout + bootstrap.

Co-authored-by: Isaac <no-reply@databricks.com>
@andy-xu-db
andy-xu-db force-pushed the andy-xu-db/stack/andy/codex-desktop-tracing-macos branch from 5b570c9 to 1ef8a4c Compare October 19, 2026 22:35
@andy-xu-db
andy-xu-db enabled auto-merge October 21, 2026 15:44
@andy-xu-db
andy-xu-db added this pull request to the merge queue Oct 21, 2026
@andy-xu-db

Copy link
Copy Markdown
Collaborator Author

/merge

Merged via the queue into main with commit 1fffcd1 Oct 21, 2026
101 of 104 checks passed
@andy-xu-db
andy-xu-db deleted the andy-xu-db/stack/andy/codex-desktop-tracing-macos branch October 21, 2026 15:51
github-merge-queue Bot pushed a commit that referenced this pull request Oct 21, 2026
Follows #1187 (macOS, merged); this PR's diff is the Windows change
only.

## What

Extends the Codex desktop OTEL login service from the previous PR in
this stack to Windows: a per-user logon task
`com.databricks.ug-codex-otel` that needs no admin rights. It runs the
venv's `pythonw.exe -m ucode.cli otel-proxy`, so no console window
appears.

## Notes

- Task Scheduler keeps its own copy of the task, so ug keeps the XML it
registered in `~/.ucode` to track ownership and the port. The file is
UTF-16, the encoding `schtasks` reads, so `write_text_file` gains an
`encoding` argument.
- Like macOS, Windows returns early from the shared functions, so the
Linux and macOS code is untouched; the Linux unit is still
byte-identical to main.
- A changed definition runs `/End` before `/Create /F`, which would
otherwise leave the old proxy running. `IgnoreNew` keeps `/Run` from
starting a second proxy next to a running one.

## Validation

- A component test simulates `schtasks` and checks the task XML, the
UTF-16 file, an unchanged launch, a workspace change, and removal. It
passes in the Windows unit-test CI job.
- `just lint` passes; `tests/test_agent_codex.py` passes. The 7
full-suite failures (`test_agents_init` update prompts,
`test_e2e_user_agent`) fail the same way on main.
- End to end on a GitHub `windows-latest` runner, with ug installed by
`uv tool install`, the real Databricks CLI, and Codex's real `codex
app-server`, against a local fake workspace:
- `ug configure` writes the exporter and registers the task; the proxy
listens within ~2s under windowless `pythonw.exe`.
- App-server sessions export OTLP traces with the Databricks token,
before and after a simulated logout/login (`/End` + `/Run`).
  - Disabling tracing removes the exporter and the task.
- A standard (non-admin) user registered the task as their own `At logon
time` / `Interactive only` task, and removal worked.

## Limits

- Marked `shortcut:` in code: a crashed proxy waits for the next logon
or `ug codex` launch, and the task doesn't get the shell's
`DATABRICKS_*` overrides.
- The non-admin run couldn't start the task because that test user had
no desktop session; a real user configuring from their own session
wasn't tested.
- Not run with a real workspace, a real reboot, or the Codex desktop app
itself (only its app server).

This pull request and its description were written by Isaac.

Co-authored-by: Isaac <no-reply@databricks.com>
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.

2 participants