Compare commits

...
45 Commits
Author SHA1 Message Date
waozi e948929204 Record that Gitea is primary and builds run on Delta 2026-11-17 21:25:46 -03:00
waozi bb4f279951 Record the GitHub rename to waozixyz/xcode 2026-11-17 18:44:19 -03:00
waozi f2fad5bdc4 Record the exact Sol model IDs for the xcode rename 2026-11-17 18:41:22 -03:00
waozi 1c11446a78 Add the new-model skill with real-turn and remote-install scripts
Adopting GPT-6.2-Sol took about 1.5 hours, mostly avoidable: builds
restarted after a raw cargo run without ZIRAN reran the Ziran build
scripts, two logins turned out to be at their usage limit only after the
build, Omega's 8 s DNS lookups slowed every turn, and Omega and Delta
were installed by hand.

skills/new-model lists the steps in the order that avoids those waits.
scripts/model-turns.py runs a plain answer, a shell call and a patch edit
at each effort and accepts a turn only on its real effect.
scripts/install-xcoder-remote.sh installs the locally installed build on
Omega or Delta (through Omega), renaming each file into place.
2026-11-17 17:27:22 -03:00
waozi 095c9cfa21 Bundle GPT-6.2-Sol first in the model table
The provider now lists gpt-6.2-sol at the top of every account's /models
catalog. When that request fails (it has 5 s, DNS included), Xcoder falls
back to its bundled table, which only knew GPT-6.1-Sol: sessions without a
configured model started on 6.1, and 6.2 ran on fallback metadata
("Model metadata for `gpt-6.2-sol` not found").

Add the provider's own gpt-6.2-sol entry to the bundled table with
priority 0, so it is the default with or without the live catalog. A test
checks that a failed catalog fetch defaults to the newest bundled Sol.
2026-11-17 17:09:17 -03:00
waoziandClaude Opus 5.5 d3bc203a10 Drop Windows support, speed up builds and port diff and git to Ziran
Windows support is removed: the Windows sandbox crates, PowerShell and
cmd shell support, Windows-only code paths, config keys, app-server
requests, TUI prompts, the standalone Windows updater and the Windows CI
and installer scripts.

The TUI header, /status, the exec banner, analytics and turn metadata
show the tracked Codex version (at least 0.169.0) instead of 0.0.0.

Builds:
- Ziran build scripts no longer watch the missing ziran.local.toml;
  Cargo reran them on every build, recompiling most of the workspace.
- The build wrapper no longer caps builds at 2 GiB RAM in its own scope;
  memory comes from the surrounding build queue.
- make builds a `local` profile (no LTO, 16 codegen units, incremental);
  published releases keep `release` (XCODER_CARGO_PROFILE=release in CI).
- codex-protocol depends on a small codex-network-policy crate instead
  of the network proxy, the slowest crate in the build.
- Unused dependencies are removed.
A rebuild after a change in codex-config now takes about 90 s, and the
full local suite builds and passes in under 3 minutes.

Diffs come from the Ziran diff package (codex-utils-text-diff) instead
of similar and diffy, and the git baseline repository and remote URL
sanitizing use the Ziran git package instead of gix and gix-url. All
four remain only as test oracles: similar and diffy on generated edits
and damaged patches, gix-url on 200,000 generated remotes, and the git
CLI checks written objects with fsck --strict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:51:13 -03:00
waoziandClaude Opus 5.5 113ff6b8bc Recognize the apply_patch heredoc form in Ziran
extract_apply_patch_from_bash now runs xcoder_apply_patch_heredoc in
native/apply_patch.zi instead of a tree-sitter query. It accepts the
same two whole-script forms (apply_patch/applypatch <<DELIM ... DELIM,
optionally after `cd <one bare word, "string" or 'string'> &&`) and
returns the same body and cd path. Heredoc bodies end only at a line
that is exactly the delimiter (leading tabs stripped for <<-), as in
Bash: tree-sitter's scanner also ended them at lines that merely start
with the delimiter (EOFX), cutting such patches short. An unterminated
heredoc does not match, as before.

The query stays as the test oracle: on 20,000 generated realistic
scripts Ziran returns the same trimmed body and cd path wherever
tree-sitter's own tree has no errors; new unit tests pin the Bash rules
for look-alike, indented and unterminated delimiters. tree-sitter and
tree-sitter-bash are now dev-dependencies of codex-apply-patch.

Local tests: apply-patch (75 unit, 28 integration), core apply_patch
(29).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 07:34:57 -03:00
waoziandClaude Opus 5.5 26039c321d Find dangerous shell commands with a Ziran scanner
parse_shell_lc_literal_commands, which dangerous-command detection uses
to look at every command in a script, now runs xcoder_literal_commands
in native/shell.zi instead of walking a tree-sitter-bash tree. It
descends into lists, pipelines, subshells, { } groups, if/while/until/
for/select/case and function bodies, $(...), backticks, <(...) and
>(...), double quotes and unquoted heredoc bodies; it drops redirection
targets and leading assignments and keeps only literal words, as the
tree walk did. Words are collected on a stack so commands nested in an
argument never interleave with it, and commands come out in post-order,
which reversed is the tree walk's order. Scripts whose compound commands
or operators do not fit together fail, as Bash refuses to run them.

The tree walk stays as the test oracle. The invariant is about safety:
whenever tree-sitter's commands make a script dangerous, Ziran's must
too, unless Bash itself rejects the script or reads that text as a
heredoc body (checked with bash -n). It holds on 40,000 generated
scripts (32,943 with identical command lists) and on 1,005 real agent
commands, where Ziran additionally flags two scripts whose rm commands
tree-sitter failed to parse.

Local tests: shell-command (195 + corpus), core danger (16) and
safety (15) tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 07:20:07 -03:00
waoziandClaude Opus 5.5 161359a813 Recognize plain shell commands in Ziran
parse_shell_script_into_commands, which exec policy, command
canonicalization, plugin attribution and parse_command use to prove a
script is only plain commands joined by &&, ||, ;, | and newlines, now
runs native/shell.zi instead of walking a tree-sitter-bash parse.

The recognizer is deliberately conservative and is checked against the
tree-sitter walk, kept as the test oracle: it must never accept a script
tree-sitter rejects or return different words. The parity tests found
and pinned tree-sitter's rules for command names (a single bare word,
not a number, not dashes alone, no `=`, not a reserved word even when
followed by punctuation) and for word parts starting with `=`. On
50,000 generated scripts there are no parity problems (3,630 accepted
by both; 1,327 adversarial ones rejected only by Ziran); on 1,005 real
agent commands (local corpus, not committed) the two agree exactly.

tree-sitter-bash still serves the literal-command extraction for
dangerous-command detection, shell snapshots and apply_patch heredocs.

Local tests: shell-command (193 + corpus run), core exec_policy (104)
and command_canonicalization (4).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 07:02:05 -03:00
waoziandClaude Opus 5.5 705f52a5a6 Rebuild apply_patch progress only when a patch line completes
Core turned the streaming patch parser's full snapshot into a progress
event for every delta the model sent: every hunk was cloned and every
update diff reformatted, though most deltas are a few characters and
change nothing. Streaming a long patch was quadratic. The parser now
has feed(), which reports whether a delta completed a line, and
hunks(), which borrows the current snapshot; core skips deltas that
complete no line, so the events it emits are unchanged. push_delta
keeps its API, and the parser splits deltas on newlines instead of
pushing one character at a time.

Local tests: apply-patch (73 unit, 28 integration, including a new
test that feed matches push_delta character by character) and core's
29 apply_patch tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 01:00:15 -03:00
waoziandClaude Opus 5.5 eba5fda3e4 Use a plain shell in the running-executable installer test
The test copied /usr/bin/sleep and /usr/bin/true under other names.
On systems whose coreutils is a multi-call build (uutils, as on
Ubuntu), those copies refuse to run under another file name, so the
test failed before it reached the inode check. It now copies /bin/sh,
whose process stays the running executable while its child sleeps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 00:34:27 -03:00
waoziandClaude Opus 5.5 51cd837786 Parse rules files in Ziran and drop the Starlark interpreter
Exec-policy .rules files were evaluated by a full Starlark interpreter,
but they only ever use a declarative subset. native/execpolicy.zi now
parses that subset into a node tree: top-level calls and NAME = value
assignments over strings (quoted, raw and triple-quoted, with every
Starlark escape), lists, tuples, integers, True/False/None, names and
`+`, with comments, continuations and semicolons. A small Rust
evaluator resolves names and `+` and binds arguments to prefix_rule,
network_rule and host_executable as Starlark did (positional or
keyword, None as omitted, errors for unknown, missing, duplicate or
mistyped parameters); the existing validation is unchanged.

Functions, loops, conditions, load and f-strings are rejected with
their line. Errors keep the `path:line:column: starlark error:` shape
core parses for the location. The starlark crates and about 60
dependencies they pulled in are removed, along with two security
advisory exceptions only they needed.

Local tests: all execpolicy tests plus six new rules-language tests,
and core's 104 exec_policy tests (run with a 16 MiB test stack; one
agent-spawn test overflows the default stack in this debug build).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 23:28:46 -03:00
waoziandClaude Opus 5.5 801a9e1f01 Apply apply_patch updates in Ziran
derive_new_contents_from_chunks now hands the file and its chunks to
xcoder_apply_chunks in native/apply_patch.zi, which splits the file
into line offsets (keeping LF, CRLF and CR endings, the first one
preferred), finds every chunk with the Ziran matcher, collects and
stably sorts the replacements, and writes the new contents once into a
buffer sized up front. Lines are no longer copied into strings several
times. Error messages are formatted in Rust exactly as before.

The Rust pipeline (SourceFile + compute_replacements) remains as the
fallback for text above 2 GiB and as the oracle: results and error
messages match on 3,000 generated patches with mixed endings, context
lines, end-of-file and failing hunks. A 20-hunk update of a 50,000-line
file takes 3.2 ms instead of 7.7 ms (make benchmark-apply-patch).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 23:04:05 -03:00
waoziandClaude Opus 5.5 a82616a888 Match apply_patch hunks with a Ziran matcher
seek_sequence now runs in native/apply_patch.zi behind the same Rust
signature. It borrows the file's and the pattern's lines through
pointer and length tables, compares bytes with memcmp, trims Unicode
White_Space from both ends without rescanning lines, and decodes only
non-ASCII scalars. The four passes (exact, trim_end, trim, trim with
typographic punctuation normalised) and their order are unchanged.

The Rust matcher stays as the fallback for lines above 2 GiB and as
the oracle for parity tests over 4,000 generated cases, edge cases and
a 20,000-line file. On a 50,000-line file (make benchmark-apply-patch):
punctuation-tolerant and failing searches are 4-5x faster (3.9 ms vs
20.5 ms, 3.1 ms vs 16.1 ms); exact and trimmed matches cost 0.4-0.7 ms
more, mostly building the line tables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 22:59:01 -03:00
waoziandClaude Opus 5.5 7af3d41cee Build the packaged binaries before the native tests
`make test` ran `make native-test all`, so the native cell test looked
for build/bin/codex-code-mode-host before `all` had packaged it. Local
runs passed only because an earlier build had left the binary there;
CI failed on every push. Build `all` first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 22:22:51 -03:00
waoziandClaude Opus 5.5 4351f9f80e Retry busy cell executables and detach the version check
Parallel cells could fail with "Text file busy" when another thread
forked while a freshly written cell executable still had a writer
descriptor; spawning now retries ETXTBSY briefly. The upstream Codex
version check runs on a detached thread with its own runtime, so a
stalled network cannot hold up process exit, and the offline CLI tests
and memory benchmark disable it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 22:03:27 -03:00
waoziandClaude Opus 5.5 e5109dea3f Release Xcoder 0.1.0
Report the newest upstream Codex release to the service, separately
from Xcoder's own version. The reported version is the larger of the
built-in 0.169.0 and the latest openai/codex release, which the CLI
checks on GitHub in the background at most every 20 hours and caches in
CODEX_HOME/xcoder-upstream-version.json (XCODER_UPSTREAM_VERSION_CHECK=0
turns the check off). `xcoder --version` now shows Xcoder's own number,
0.1.0.

Fix two regressions found by the local suite:
- Shell commands that ran before the session's shell snapshot existed
  used the login profile's PATH, so a profile's apply_patch could win
  over Xcoder's. The Codex-owned PATH entries are now replayed after
  login startup without a snapshot too.
- Tool cells failed with "unexpected end of file" when they exited,
  because the callback channels a cell never used closed. A clean close
  between requests now retires that channel.

The installer no longer keeps copies of the binaries it replaces. The
validation fixture covers every native test, and the dead --oss
plumbing is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 18:30:53 -03:00
waoziandClaude Opus 5.5 e1ab91cdf9 Release idle memory, prune unused parts and report the upstream version
Idle sessions give their memory back: after XCODER_IDLE_RELEASE_SECONDS
(default 120, 0 disables) a watcher written in Ziran (native/idle.zi)
trims the allocator, pages private memory out to swap and unmaps clean
program pages. Measured with 600 tool calls: 415 MB resident drops to
23 MB, and the next keypress takes 79 ms. The TUI's replay copy of a
finished command keeps only the first and last parts of output above
16 KiB. make benchmark-memory and the scripts/memory allocation tracer
measure this.

Remove what Xcoder never uses under Harmony: the cloud, tcp-tunnel,
responses-api-proxy, exec-server and debug app-server subcommands with
their crates, the Ollama and LM Studio providers with the TUI's
local-provider picker, and the AWS SDK behind Bedrock sign-in. --oss
now stops at startup with an explanation.

Model requests identify as the tracked upstream release (0.169.0) in
their User-Agent and version header, as catalog requests already did.
A fresh ChatGPT-account session refused gpt-6.1-sol while requests
still said 0.0.0. The rule lives in codex_protocol::client_version.

Also carried over from the shared working tree: native Ziran fuzzy
matching and Mermaid adapters, Linux packaging and its workflow, and
Landlock/seccomp cell sandboxing in place of bwrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 14:32:42 -03:00
waozi 79119a9392 Report tracked upstream version for the model catalog
Xcoder keeps upstream's 0.0.0 development workspace version, and the
Codex models endpoint hides newer models such as gpt-6.1-sol from 0.0.0
clients. Catalog requests and cache entries now report the tracked
upstream release, 0.169.0, so the full model list is returned and stale
0.0.0 cache entries are refreshed.
2026-11-13 19:01:20 -03:00
waozi ba9d4a9e84 Replace Codex tool runtime with native Ziran and install Xcoder 2026-11-11 10:02:48 -03:00
trpcic-openai 4dd5f1e70b Limit MCP product attribution to configured REPL-backed calls (#60697)
## Why

MCP request metadata could forward a client-supplied `product_sku` to unrelated servers and connectors.

## What changed

Remove `product_sku` from turn metadata before forwarding it. For Node REPL-backed servers and the browser connector, populate it from the turn's `apps_mcp_product_sku` configuration, mapping unrecognized values to `other` and omitting empty or missing values.

## Testing

Add regression coverage for configured REPL and browser attribution, unrelated servers and connectors, unrecognized or absent configuration, and spoofed client metadata.

GitOrigin-RevId: bc24062526048ea1c1621099e609053cf167602f
2026-11-11 01:47:52 +00:00
tarunoai ac54a05173 Add a Signer Service backend for macOS notarization (#60695)
## What changed

Allow `APPLE_NOTARIZATION_BACKEND=signer-service` to sign Apple notarization JWTs through `grpcurl`, using GitHub OIDC authentication. Validate the returned signing key and algorithm, and redact transport and signing failure details.

Keep Azure Key Vault as the default backend and skip its configuration requirements when Signer Service is selected.

## Testing

Add coverage for JWT refresh with fresh OIDC tokens and for the binary wrapper running without Azure configuration. All six notarization tests pass.

GitOrigin-RevId: e38ea90e94639d87c11ab075c999d85b61b37c17
2026-11-11 00:58:44 +00:00
Joe Savona 87b7bdbf2e Fit composer footer hints to available terminal space (#60683)
## Why

Narrow composer footers can clip hints or crowd out mode indicators and actions.

## What changed

Use a shared layout for navigation, actions, mode indicators, context, and warnings. Shorten or drop whole labels in priority order instead of clipping them. Add a second row when input modes and queue or active side-conversation actions fit separately but not together, keeping navigation and modes above actions.

## Testing

Add coverage for fullscreen and scrollback layouts, narrow Plan mode hints, active side-conversation actions, oversized goal indicators, and warning hit areas.

GitOrigin-RevId: 849a53d45ef1b36b40c52282e329b48ec7d7d12e
2026-11-10 23:36:04 +00:00
Joe Savona 65dbdb5f03 Wrap built-in TUI status lines within the footer row budget (#60682)
## Why

Long built-in status lines were truncated to a single row even when the footer had room for more content.

## What changed

- Wrap status text to the available width and row budget, preserving styles and hyperlink targets across rows.
- Show an unlinked ellipsis when content exceeds the available space.
- Refresh wrapped content when the status text, agent label, or width changes.
- Keep reasoning-effort transitions on one row and restore wrapping after the final animation frame.

## Testing

Add coverage for wrapping and hyperlink boundaries across footer layouts, content and agent-label updates, resizing, and wrapping restoration after an effort transition. Update transcript and startup snapshots for multiline status text.

GitOrigin-RevId: 30e0795c473efd62fc4d0dca4deb6029b625a9e8
2026-11-10 23:35:28 +00:00
Joe Savona 192e2ef3ce Prioritize draft space when allocating composer footer rows (#60681)
## Why

Status content and footer hints need to fit within the composer's height budget while preserving room for editing and active search controls.

## What changed

- Share row allocation between composer measurement and rendering. Cap status and hints at two rows in inline scrollback, and scale the fullscreen cap from two to four rows with the available budget.
- Reserve space for active footer controls, give suggestions and image previews priority over additional status rows, and avoid reserving an empty hints row when status is enabled.
- Keep textarea row counts and scroll offsets as `usize`, saturating only the terminal height so very tall drafts remain scrollable with a visible caret.

## Testing

Add layout and snapshot coverage for constrained height budgets, status and hints, image previews, slash suggestions, and transcript search cursors. Add a regression test for rendering a draft beyond the `u16` row limit.

GitOrigin-RevId: 20fb0384ffc976dfd12e648004763feff0597dda
2026-11-10 23:34:54 +00:00
Joe Savona 8a7a723dcd Keep TUI status content separate from composer hints (#60680)
## Why

Composer hints could replace configured status content, and mode indicators and warnings reduced the width available to status extensions.

## What changed

- Give enabled status content a dedicated area below the composer in both inline and fullscreen layouts, preserving it during transient hint states.
- Keep shortcuts, queue hints, mode indicators, and warnings in the hint row.
- Measure extension status content at the full available width, allowing up to four rows while yielding space to the composer when height is limited.
- Suppress composer hints behind centered dialogs.

## Testing

Update layout assertions and snapshots for status persistence, extension resizing and clipping, warning placement, and reasoning-effort transitions.

GitOrigin-RevId: f11c2e4fb53c35b69c2fbdbe80cef31bb28faca4
2026-11-10 23:33:26 +00:00
Felipe Coury ad3d3521ed Avoid redundant reads and screen clears when switching side chats (#60675)
## Why

A live parent thread continues receiving lifecycle notifications while its side chat has focus, so returning to it does not need another liveness read.

## What changed

- Skip the parent liveness read when returning from a side chat while the parent is still attached and online. Keep the read when reattachment is needed.
- Stop scheduling a deferred screen clear when handling a transcript reset that preserves the screen.

## Testing

Add regression coverage for parent `thread/read` requests with and without reattachment, and assert that side-chat navigation leaves no deferred screen clear.

GitOrigin-RevId: a07f161ec86b0ae51250c5a0156402d328c42bdf
2026-11-10 22:32:59 +00:00
cassirer-openai d4b19eca27 Preserve agent message deliveries in rollout traces (#60673)
## Why

An accepted agent message may never appear in a later inference request or compaction snapshot. Rollout traces need to retain the delivery and its interaction edge even when the receiving agent makes no further request.

## What changed

Capture agent message payloads in `HistoryItemAccepted` events and create conversation items when those receipts are replayed. Reuse each item's ID when it later appears in a request or checkpoint, updating its body to the model-visible representation. Repeated receipts preserve that representation without duplicating the item.

## Testing

Extend the spawn-edge regression test to cover delivery before any child inference, stable item IDs across a later request, and preservation of trimmed content after a repeated receipt.

GitOrigin-RevId: c193d691e8240645800ce004c11f21e3f1c82915
2026-11-10 22:22:35 +00:00
tarunoai 568c592f9c Add sign-only mode and tighten macOS signing verification (#60671)
## What changed

- Add a `sign-only` operation to sign macOS CLI packages without notarization.
- Validate the configured signing certificate before signing both standard and provisioned packages.
- Require the configured team ID for every executable during verification and extend leaf certificate fingerprint checks to standard packages.

## Testing

Add coverage for signing a standard package without notarization and rejecting unexpected signing certificates in both standard and provisioned packages.

GitOrigin-RevId: 0794c7666abfe981b59b47311e3a9108223b8f57
2026-11-10 22:00:40 +00:00
felixxia-oai fad8b3d5bc Initialize Guardian evidence cursors from thread history state (#60670)
## What changed

Expose history initialization and the effective history mode to thread-ready contributors. Add `EvidenceCursor::at_thread_ready` with paginated-history validation:

- Start new or cleared threads at position zero without requiring an existing rollout.
- Start resumed, forked, or supplied-history threads at the durable tail to avoid backfilling existing evidence.
- Skip the initial `SessionMeta` header when capturing evidence from position zero.

## Testing

Extend evidence tests to cover initialization before a rollout exists, capture of the first original record, rejection of resume without a rollout, and exclusion of existing records on resume.

GitOrigin-RevId: 32aa8e2afb71eb4e882b5f1fb107ac8616b33c8e
2026-11-10 22:00:08 +00:00
dhavalkapil-oai 39f422522e Skip submodule worktree scans when checking repository changes (#60669)
## Why

Submodule worktree scans can execute clean filters selected by task-writable Git configuration.

## What changed

Pass `--ignore-submodules=dirty` to `git status` in `get_has_changes_in_repo` to skip uncommitted submodule contents while retaining gitlink changes.

## Testing

Add a regression test that configures a submodule clean filter and verifies the repository change check does not execute it. The test also confirms that `git status` without the option executes the filter.

GitOrigin-RevId: 5330402f0354c3bf9613358575f8bedc9f312886
2026-11-10 21:58:49 +00:00
Channing Conger 733a1cca06 Add a content helper for forwarding MCP blocks in Code Mode (#60665)
## Why

Code Mode needs a way to forward mixed MCP tool results while preserving their content types and order.

## What changed

Add `content(block)` and `content(iterable)` so callers can forward tool output with `content(result.content)`. Text, image, and audio blocks become their corresponding output items; resource links and embedded resources are serialized as text. Invalid blocks and encrypted text are rejected, and iterators are closed when a block is rejected.

Share MCP block conversion and image detail types with the protocol layer, while preserving existing `image()` and `audio()` input handling.

## Testing

Add coverage for mixed content ordering, iterator behavior and cleanup, invalid blocks, image metadata, short audio clips, and output suppression after exit. Add an integration scenario verifying that MCP text and image blocks reach the model in order.

GitOrigin-RevId: 83832ec6c530dd35ea1e3373680627997c6e13c1
2026-11-10 21:28:22 +00:00
viyatb-oai f7aad26f1d Defer exec-server sandbox preparation to the execution host (#60663)
## Why

Remote commands can use workspace paths from a different operating system. Preparing them on the client should preserve those paths and command arguments for the execution host.

## What changed

- Build exec-server requests directly, carrying the native command and sandbox context without applying the client's sandbox transform.
- Resolve workspace permissions and runtime read access in `SandboxManager` on the execution host, including helper binaries and validated managed-network CA bundles.
- Add explicit backend selection and required platform sandbox selection, rejecting launches when the required sandbox is unavailable.

## Testing

Extend request tests to cover foreign workspace paths, Unicode arguments, and empty arguments. Extend the remote process test on Unix to verify that restricted reads allow the sandbox helper and validated CA bundle while denying an untrusted certificate file.

GitOrigin-RevId: 5fc02ac4208912ecefb80a212742389afc14ac05
2026-11-10 21:26:11 +00:00
smurching-oai 45d1f24d79 Support gateway device-code sign-in in headless TUI sessions (#60662)
## Why

Gateway sign-in needs a way to complete authentication over SSH or when no local browser is available.

## What changed

- Prefer device authentication for gateways that support it in SSH sessions, headless Linux environments, or when no browser handler is available.
- Check the selected session's provider and complete required gateway sign-in before requesting models, including when resuming a thread.
- Display the verification URL, one-time code, and cancellation instructions. Handle sign-in results, cancellation, and connection failures while the prompt is open.
- Skip device login for older servers that do not support it while preserving errors from current servers.

## Testing

Add protocol tests for early sign-in completion, connection loss, provider selection, resumed threads, and legacy-server compatibility, plus snapshots of the device prompt and gateway sign-in loading text.

GitOrigin-RevId: 4f3675ab2fc7fccafbad17796c72a7736ebb86b5
2026-11-10 21:09:59 +00:00
sayan-oai c9bbed2dae Support environment updates in app-server settings APIs (#60655)
## What changed

Add experimental `environments` fields to `turn/settings/update` and `thread/settings/update`. Turn updates apply to later steps of the running turn; thread updates apply to future turns. Omission or `null` preserves the selection, while `[]` clears it. Providing `cwd` in a thread update without an environment list selects the defaults for that directory.

Include the ordered environment selection in `thread/settings/updated`. Wait for Core to accept thread settings updates before returning success, and return rejections as request errors.

## Testing

Add integration coverage for attaching, replacing, preserving, and clearing environments; rejected updates; and the distinction between later steps and future turns.

GitOrigin-RevId: bfebeda57c676be94427aeb0c567c0b94fd9c387
2026-11-10 20:35:28 +00:00
Benjamin Carlsson 82e6bacb9c Enable model and reasoning effort selection for Cloud conversations (#60651)
## Why

Cloud conversations previously used the model returned on activation without exposing model discovery or supporting model changes from the TUI.

## What changed

- Fetch the account-scoped Cloud catalog on demand through `/v2/models`, independently of the submission and attachment queue.
- Let users stage a supported model and reasoning effort for the next new turn in the current conversation. Send these settings with the user message and show acceptance after successful admission.
- Show a loading picker when the catalog is empty, preserve compatibility with Cloud servers that lack discovery, and discard stale catalog results and selections when the account changes.

## Testing

Add coverage for catalog request parameters and queue bypass, deferred discovery and compatibility, model and effort serialization, admission outcomes, account invalidation, and opening the picker after discovery.

GitOrigin-RevId: 2cd0e7fe5f760d4da9258eefe9f0dcbcd23f9b07
2026-11-10 19:52:49 +00:00
zm-oai a92eae0891 Restore PowerShell's working directory in the MXC sandbox (#60647)
## Why

When a workspace has an unreadable ancestor, PowerShell can start with `$PWD` unset and its filesystem drive at the root, breaking relative paths.

## What changed

Prefix PowerShell commands in the MXC sandbox with a guarded workaround that restores the location from the process working directory when `$PWD` is unset. Preserve locations already initialized by startup or a profile.

## Testing

Extend the MXC PowerShell integration test to cover an unreadable ancestor, checking that `$PWD` matches the process working directory, relative file access works, and the parent and sibling file remain inaccessible.

GitOrigin-RevId: 4fb067db52a7f3c6e819169016fe6bd104a277a1
2026-11-10 19:40:10 +00:00
Won Park a2b7c4a655 Use trusted Guardian templates for managed policies (#60646)
## Why

User-configured model catalogs can supply Guardian prompt templates that omit policy slots or add conflicting instructions. Managed rules need a trusted template to reach the reviewer.

## What changed

- Use the bundled Guardian policy template when managed policy or additional rules are present, while preserving explicit host-provided templates.
- Remove `auto_review.extra_policy` and `auto_review.experimental_policy_template` from configuration and the schema. Warn when they are used, directing additional rules to `guardian_extra_policy` in managed `requirements.toml`.

## Testing

Add regression coverage for managed rules with user-supplied catalog templates, explicit host templates, and migration warnings for the removed settings.

GitOrigin-RevId: 7f00bfaa85051272ed70ceb2fcb64ffc297b8755
2026-11-10 19:30:21 +00:00
Andrew Ambrosino 2c2d99f0e3 Update the safety consent test for the current dialog (#60645)
Pass `can_save: true` when opening the consent dialog and assert that the
popup displays “Include logs and session history?”.

GitOrigin-RevId: d6035a9a1b3e5114a6e92a6fd31547f02c4980fc
2026-11-10 19:26:46 +00:00
rhan-oai 30b42cb802 Keep interrupts responsive during host service-tier updates (#60644)
## Why

Waiting for host acceptance of a service-tier update in the submission loop can block interrupts while the host receipt is pending.

## What changed

Move the host acceptance wait out of the submission loop while keeping explicit thread settings replies pending until acceptance completes. Report handoff failures to the caller while preserving the locally committed settings, and allow a subsequent explicit request for the same tier to retry a failed handoff.

## Testing

Add a WebSocket regression test covering interrupts with pending host receipts, failure reporting, same-tier retries, and continued thread operation after startup caller cancellation.

GitOrigin-RevId: 1b27d156eba3ebb47e717a987f41f4f595635be8
2026-11-10 19:13:55 +00:00
Dmitriy Kovalenko 3f797555cd Refresh Apps tools outside the MCP runtime gate (#60639)
## Why

Holding the session MCP gate during `tools/list` blocks other runtime access. Releasing it requires preventing stale refresh results from publishing after configuration or authentication changes.

## What changed

- Capture the Apps client under the session gate, then release the gate before fetching tools.
- Validate runtime and authentication state before publishing the shared cache and client catalog; retry a superseded refresh once.
- Wait for in-flight Apps refreshes before capturing model tools, preparing Apps calls, or shutting down the runtime.

## Testing

Add regression coverage for stale refreshes after runtime invalidation or logout, publication validation after call preparation drains, and a model step that waits for refreshed Apps tools while MCP status queries remain available.

GitOrigin-RevId: 42d4be8c4a9218933f8e3d07fc7f32f2da9cbd9d
2026-11-10 18:33:49 +00:00
cazhang-oai 057d9140a8 Honor read-only MCP tool hints in automatic approval (#60638)
## Why

MCP tools marked with `readOnlyHint: true` could still require approval in automatic mode when `destructiveHint` was also true.

## What changed

Give `readOnlyHint` precedence over `destructiveHint` and `openWorldHint` when deciding whether annotations require approval. Explicit prompt mode and strict automatic review continue to require their respective approval checks.

## Testing

Update unit tests for conflicting annotations, prompt mode, and strict automatic review. Extend app integration coverage to verify that read-only calls proceed while writes prompt in both automatic and writes approval modes.

GitOrigin-RevId: 11a930b857886bf41d09fd54c3a38607ae3d1b4e
2026-11-10 18:33:19 +00:00
Felipe Coury 4a784f63e8 Show pending key chords in a shared floating shortcut guide (#60637)
## What changed

- Replace footer chord hints with a floating guide that shows available completions after a 350 ms delay, including custom prefixes.
- Share guide rendering across conversations, transcript overlays, the session picker, startup drafts, hook review, and daemon recovery. Preserve workspace-specific pane labels and filter startup drafts to supported actions.
- Adapt the guide to short inline viewports, retain `Esc` cancellation, and redraw when pending chords clear. Consume clicks on the guide so they do not activate controls beneath it.

## Testing

Extend tests and snapshots for delayed reveal, timeout, custom prefixes, compact and inline layouts, startup-safe completions, and picker redraws after chord completion or cancellation.

GitOrigin-RevId: afa2fe3ae1b5fbea4cd871c17d35206e749c842c
2026-11-10 18:32:00 +00:00
Benjamin Carlsson df82e2fe0a Support archiving and restoring cloud threads (#60635)
## What changed

- Add cloud archive and unarchive requests and support listing archived threads.
- Detach successfully archived threads and emit archive notifications. Report loaded cloud threads from live attachments rather than cached resume metadata, including after archive failures.
- Scope resume picker archive state and transcript previews by backend and thread so archiving a cloud session preserves a local session with the same ID.
- Limit cloud task archive cleanup to the selected thread, preserving child agents and their active session state, and update the confirmation text accordingly.

## Testing

Add regression coverage for archive acknowledgments, archived-thread discovery and restoration, attachment state after archive failures, same-ID sessions across backends, and preservation of attached child agents.

GitOrigin-RevId: bd155be85ee911375d4d326b18f9b5abe8e82b3d
2026-11-10 18:19:11 +00:00
malsamiri-oai 627b579219 Preserve script quotes in Windows sandbox cmd invocations (#60624)
## Why

CRT argument escaping adds literal backslashes before quotes in `cmd.exe /c` scripts, breaking quoted paths and executable names.

## What changed

Serialize single-script `cmd /c` invocations with `/s /c` and an outer quote pair, preserving the script's quotes. Share this handling across Windows sandbox process creation, ConPTY, and MXC execution requests.

## Testing

Add a regression test for `certutil -hashfile` with a quoted path containing spaces, and update the command-line test for a quoted PowerShell executable.

GitOrigin-RevId: 32b4b7b55f6af4dba206813eac150310f37ae1d4
2026-11-10 16:58:06 +00:00
1730 changed files with 32931 additions and 130528 deletions

No files matched your search

@@ -1,33 +0,0 @@
name: Set up Windows Bazel build tools
description: Prepare MSVC and verified native dependencies for Windows Bazel builds.
inputs:
target:
description: Native Windows target triple
required: true
windows-tools:
description: Directory containing the public Windows voice bootstrap
default: .github/scripts
runs:
using: composite
steps:
- uses: ./.github/actions/setup-msvc-env
with:
target: ${{ inputs.target }}
- name: Install verified public Windows tools
shell: pwsh
env:
WINDOWS_TOOLS: ${{ inputs.windows-tools }}
TARGET: ${{ inputs.target }}
run: |
./.github/scripts/compute-bazel-windows-path.ps1
$manifest = Get-Content -Raw "$env:WINDOWS_TOOLS/voice-cygwin-snapshot.json" | ConvertFrom-Json
$pin = $manifest.archive
$archive = Join-Path $env:RUNNER_TEMP $pin.name
Invoke-WebRequest "https://github.com/openai/codex/releases/download/$($pin.tag)/$($pin.name)" -OutFile $archive
& "$env:WINDOWS_TOOLS/setup-voice-windows.ps1" -Target $env:TARGET -SnapshotArchive $archive
if (-not $env:SystemRoot) { throw "Windows SystemRoot is required" }
"VOICE_WINDOWS_SYSTEM_ROOT=$env:SystemRoot" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
$hostArch = $env:PROCESSOR_ARCHITEW6432
if (-not $hostArch) { $hostArch = $env:PROCESSOR_ARCHITECTURE }
if (-not $hostArch) { throw "Windows host architecture is required" }
"VOICE_WINDOWS_HOST_ARCH=$hostArch" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
-20
View File
@@ -1,20 +0,0 @@
name: setup-msvc-env
description: Expose an MSVC developer environment for the requested Windows target.
inputs:
target:
description: Rust target triple that will be built on this Windows runner.
required: true
host-arch:
description: Optional Visual Studio host architecture override.
required: false
default: ""
runs:
using: composite
steps:
- name: Expose MSVC SDK environment
shell: pwsh
env:
HOST_ARCH: ${{ inputs.host-arch }}
TARGET: ${{ inputs.target }}
run: '& "$env:GITHUB_ACTION_PATH/setup-msvc-env.ps1" -Target "$env:TARGET" -HostArch "$env:HOST_ARCH"'
@@ -1,257 +0,0 @@
param(
[Parameter(Mandatory = $true)]
[string]$Target,
[string]$HostArch = ""
)
# Cargo can cross-compile the Rust code for Windows ARM64 on a Windows x64
# runner, but rustup alone does not expose the matching MSVC/UCRT include and
# library paths. Ask Visual Studio for the target-specific developer
# environment, then persist the relevant variables through GITHUB_ENV so the
# later Cargo step sees the same environment as a normal VsDevCmd shell.
switch ($Target) {
"x86_64-pc-windows-msvc" {
$TargetArch = "x64"
$RequiredComponent = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
}
"aarch64-pc-windows-msvc" {
$TargetArch = "arm64"
$RequiredComponent = "Microsoft.VisualStudio.Component.VC.Tools.ARM64"
}
default {
throw "Unsupported Windows MSVC target: $Target"
}
}
# VsDevCmd needs both sides of the cross compile: the architecture of the
# machine running the tools and the architecture of the binaries being linked.
# Infer the host from the runner unless a caller needs to override it.
if (-not $HostArch) {
$HostArch = if ($env:PROCESSOR_ARCHITEW6432 -eq "ARM64" -or $env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
"arm64"
} else {
"x64"
}
}
$VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $VsWhere)) {
throw "vswhere.exe not found"
}
# Require the target VC tools component, not merely any Visual Studio install,
# so an x64 archive producer cannot silently link ARM64 tests with the wrong
# SDK/toolchain layout.
$InstallPath = & $VsWhere -latest -products * -requires $RequiredComponent -property installationPath 2>$null
if (-not $InstallPath) {
throw "Could not locate a Visual Studio installation with component $RequiredComponent"
}
$VsDevCmd = Join-Path $InstallPath "Common7\Tools\VsDevCmd.bat"
if (-not (Test-Path $VsDevCmd)) {
throw "VsDevCmd.bat not found at $VsDevCmd"
}
$VarsToExport = @(
"INCLUDE",
"LIB",
"LIBPATH",
"PATH",
"UCRTVersion",
"UniversalCRTSdkDir",
"VCINSTALLDIR",
"VCToolsInstallDir",
"WindowsLibPath",
"WindowsSdkBinPath",
"WindowsSdkDir",
"WindowsSDKLibVersion",
"WindowsSDKVersion"
)
# Run VsDevCmd inside cmd.exe because it is a batch file, then copy just the
# variables Cargo/rustc need into the GitHub Actions environment file. PowerShell
# cannot mutate the parent composite-action environment directly.
$EnvLines = & cmd.exe /c ('"{0}" -no_logo -arch={1} -host_arch={2} >nul && set' -f $VsDevCmd, $TargetArch, $HostArch)
$VcToolsInstallDir = $null
foreach ($Line in $EnvLines) {
if ($Line -notmatch "^(.*?)=(.*)$") {
continue
}
$Name = $Matches[1]
$Value = $Matches[2]
if ($VarsToExport -contains $Name) {
if ($Name -ieq "Path") {
$Name = "PATH"
}
if ($Name -eq "VCToolsInstallDir") {
$VcToolsInstallDir = $Value
}
"$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
}
if (-not $VcToolsInstallDir) {
throw "VCToolsInstallDir was not exported by VsDevCmd.bat"
}
# Prefer Rust's bundled linker when rustup provides one, then Visual Studio's
# LLVM linker, and finally MSVC link.exe. This keeps the cross-compile path close
# to Rust's normal Windows MSVC behavior while still working on runner images
# where one of those linkers is absent.
$Linker = $null
$Rustc = Get-Command rustc -ErrorAction SilentlyContinue
if ($Rustc) {
$Sysroot = (& rustc --print sysroot 2>$null).Trim()
$RustHost = & rustc -vV 2>$null | Select-String "^host: " | ForEach-Object { $_.Line.Substring(6) }
if ($RustHost) {
$RustHost = $RustHost.Trim()
}
if ($Sysroot -and $RustHost) {
$RustLld = Join-Path $Sysroot "lib\rustlib\$RustHost\bin\rust-lld.exe"
if (Test-Path $RustLld) {
$Linker = $RustLld
}
}
}
if (-not $Linker) {
$Linker = Join-Path $InstallPath "VC\Tools\Llvm\x64\bin\lld-link.exe"
}
if (-not (Test-Path $Linker)) {
$Linker = Join-Path $VcToolsInstallDir "bin\Host${HostArch}\${TargetArch}\link.exe"
}
if (-not (Test-Path $Linker)) {
throw "Windows linker not found at $Linker"
}
# rustc passes `/arm64hazardfree` for ARM64 MSVC links. The lld variants on our
# Windows x64 archive producers reject that flag, including when rustc places it
# inside a response file. Compile a tiny forwarding wrapper that strips only
# that unsupported flag, then delegate every other argument to the real linker.
if ($TargetArch -eq "arm64" -and (Split-Path -Leaf $Linker) -match "lld") {
$WrapperDir = Join-Path $env:RUNNER_TEMP "msvc-lld-wrapper"
New-Item -Path $WrapperDir -ItemType Directory -Force | Out-Null
$WrapperPath = Join-Path $WrapperDir "lld-link-wrapper.exe"
$WrapperSource = @'
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
internal static class Program
{
private static int Main(string[] args)
{
var linker = Environment.GetEnvironmentVariable("MSVC_REAL_LINKER");
if (string.IsNullOrEmpty(linker))
{
Console.Error.WriteLine("MSVC_REAL_LINKER is not set");
return 1;
}
var startInfo = new ProcessStartInfo(linker)
{
UseShellExecute = false,
};
var filteredArgs = new List<string> { "-flavor", "link", "/defaultlib:ucrt", "/nodefaultlib:libucrt" };
foreach (var arg in args)
{
if (!string.Equals(arg, "/arm64hazardfree", StringComparison.OrdinalIgnoreCase))
{
filteredArgs.Add(QuoteArgument(FilterResponseFile(arg)));
}
}
startInfo.Arguments = string.Join(" ", filteredArgs);
using var process = Process.Start(startInfo);
if (process is null)
{
Console.Error.WriteLine($"Failed to start linker: {linker}");
return 1;
}
process.WaitForExit();
return process.ExitCode;
}
private static string FilterResponseFile(string argument)
{
if (argument.Length < 2 || argument[0] != '@')
{
return argument;
}
var responsePath = argument.Substring(1);
if (!File.Exists(responsePath))
{
return argument;
}
var filteredResponsePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".rsp");
var responseContents = Regex.Replace(
File.ReadAllText(responsePath),
"/arm64hazardfree",
string.Empty,
RegexOptions.IgnoreCase);
File.WriteAllText(filteredResponsePath, responseContents);
return "@" + filteredResponsePath;
}
private static string QuoteArgument(string argument)
{
if (argument.Length == 0)
{
return "\"\"";
}
if (argument.IndexOfAny(new[] { ' ', '\t', '"' }) < 0)
{
return argument;
}
var quoted = new StringBuilder("\"");
var backslashes = 0;
foreach (var character in argument)
{
if (character == '\\')
{
backslashes++;
continue;
}
if (character == '"')
{
quoted.Append('\\', (backslashes * 2) + 1);
quoted.Append(character);
backslashes = 0;
continue;
}
quoted.Append('\\', backslashes);
backslashes = 0;
quoted.Append(character);
}
quoted.Append('\\', backslashes * 2);
quoted.Append('"');
return quoted.ToString();
}
}
'@
$WrapperSourcePath = Join-Path $WrapperDir "lld-link-wrapper.cs"
$WrapperSource | Out-File -FilePath $WrapperSourcePath -Encoding utf8
$Csc = Join-Path $InstallPath "MSBuild\Current\Bin\Roslyn\csc.exe"
if (-not (Test-Path $Csc)) {
throw "csc.exe not found at $Csc"
}
& $Csc /nologo /target:exe /out:$WrapperPath $WrapperSourcePath
if ($LASTEXITCODE -ne 0) {
throw "Failed to compile lld-link wrapper"
}
"MSVC_REAL_LINKER=$Linker" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
$Linker = $WrapperPath
}
Write-Output "Using Windows linker: $Linker"
$CargoTarget = $Target.ToUpperInvariant().Replace("-", "_")
"CARGO_TARGET_${CargoTarget}_LINKER=$Linker" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@@ -1,80 +0,0 @@
name: windows-code-sign
description: Sign Windows release files with Azure Trusted Signing.
inputs:
target:
description: Target triple for the artifacts to sign.
required: true
binaries:
description: Space-delimited binary basenames to sign.
default: "codex codex-responses-api-proxy codex-windows-sandbox-setup codex-command-runner"
additional-files:
description: Newline-delimited absolute paths to additional files to sign.
default: ""
client-id:
description: Azure Trusted Signing client ID.
required: true
tenant-id:
description: Azure tenant ID for Trusted Signing.
required: true
subscription-id:
description: Azure subscription ID for Trusted Signing.
required: true
endpoint:
description: Azure Trusted Signing endpoint.
required: true
account-name:
description: Azure Trusted Signing account name.
required: true
certificate-profile-name:
description: Certificate profile name for signing.
required: true
runs:
using: composite
steps:
- name: Azure login for Trusted Signing (OIDC)
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
with:
client-id: ${{ inputs.client-id }}
tenant-id: ${{ inputs.tenant-id }}
subscription-id: ${{ inputs.subscription-id }}
- name: Prepare file list
id: prepare
shell: bash
env:
TARGET: ${{ inputs.target }}
BINARIES: ${{ inputs.binaries }}
ADDITIONAL_FILES: ${{ inputs.additional-files }}
run: |
set -euo pipefail
{
echo "files<<EOF"
for binary in ${BINARIES}; do
echo "${CARGO_TARGET_DIR}/${TARGET}/release/${binary}.exe"
done
if [[ -n "$ADDITIONAL_FILES" ]]; then
printf '%s\n' "$ADDITIONAL_FILES"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Sign Windows release files with Azure Trusted Signing
uses: azure/trusted-signing-action@1d365fec12862c4aa68fcac418143d73f0cea293 # v0.5.11
with:
endpoint: ${{ inputs.endpoint }}
trusted-signing-account-name: ${{ inputs.account-name }}
certificate-profile-name: ${{ inputs.certificate-profile-name }}
exclude-environment-credential: true
exclude-workload-identity-credential: true
exclude-managed-identity-credential: true
exclude-shared-token-cache-credential: true
exclude-visual-studio-credential: true
exclude-visual-studio-code-credential: true
exclude-azure-cli-credential: false
exclude-azure-powershell-credential: true
exclude-azure-developer-cli-credential: true
exclude-interactive-browser-credential: true
cache-dependencies: false
files: ${{ steps.prepare.outputs.files }}
@@ -1,113 +0,0 @@
<#
BuildBuddy cache keys include the action and test environment, so Bazel should
not inherit the full hosted-runner PATH on Windows. That PATH includes volatile
tool entries, such as Maven, that can change independently of this repo and
cause avoidable cache misses.
This script derives a smaller, cache-stable PATH that keeps the Windows
toolchain entries Bazel-backed CI tasks need: MSVC and Windows SDK paths,
MinGW runtime DLL paths for gnullvm-built tests, Git, PowerShell, Node, Python,
DotSlash, and the standard Windows system directories.
`prepare-bazel-ci` runs this after exporting the MSVC environment, and the script
publishes the result via `GITHUB_ENV` as `CODEX_BAZEL_WINDOWS_PATH` so later
steps can pass that explicit PATH to Bazel.
#>
$stablePathEntries = New-Object System.Collections.Generic.List[string]
$seenEntries = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
$windowsAppsPath = if ([string]::IsNullOrWhiteSpace($env:LOCALAPPDATA)) {
$null
} else {
"$($env:LOCALAPPDATA)\Microsoft\WindowsApps"
}
$windowsDir = if ($env:WINDIR) {
$env:WINDIR
} elseif ($env:SystemRoot) {
$env:SystemRoot
} else {
$null
}
function Add-StablePathEntry {
param([string]$PathEntry)
if ([string]::IsNullOrWhiteSpace($PathEntry)) {
return
}
if ($seenEntries.Add($PathEntry)) {
[void]$stablePathEntries.Add($PathEntry)
}
}
foreach ($pathEntry in ($env:PATH -split ';')) {
if ([string]::IsNullOrWhiteSpace($pathEntry)) {
continue
}
if (
$pathEntry -like '*Microsoft Visual Studio*' -or
$pathEntry -like '*Windows Kits*' -or
$pathEntry -like '*Microsoft SDKs*' -or
$pathEntry -eq 'C:\mingw64\bin' -or
$pathEntry -like 'C:\msys64\*\bin' -or
$pathEntry -like 'C:\Program Files\Git\*' -or
$pathEntry -like 'C:\Program Files\PowerShell\*' -or
$pathEntry -like 'C:\hostedtoolcache\windows\node\*' -or
$pathEntry -like 'C:\hostedtoolcache\windows\Python\*' -or
$pathEntry -eq 'D:\a\_temp\install-dotslash\bin' -or
($windowsDir -and ($pathEntry -eq $windowsDir -or $pathEntry -like "${windowsDir}\*"))
) {
Add-StablePathEntry $pathEntry
}
}
$gitCommand = Get-Command git -ErrorAction SilentlyContinue
if ($gitCommand) {
Add-StablePathEntry (Split-Path $gitCommand.Source -Parent)
}
$nodeCommand = Get-Command node -ErrorAction SilentlyContinue
if ($nodeCommand) {
Add-StablePathEntry (Split-Path $nodeCommand.Source -Parent)
}
$python3Command = Get-Command python3 -ErrorAction SilentlyContinue
if ($python3Command) {
Add-StablePathEntry (Split-Path $python3Command.Source -Parent)
}
$pythonCommand = Get-Command python -ErrorAction SilentlyContinue
if ($pythonCommand) {
Add-StablePathEntry (Split-Path $pythonCommand.Source -Parent)
}
$pwshCommand = Get-Command pwsh -ErrorAction SilentlyContinue
if ($pwshCommand) {
Add-StablePathEntry (Split-Path $pwshCommand.Source -Parent)
}
foreach ($mingwPath in @('C:\mingw64\bin', 'C:\msys64\mingw64\bin', 'C:\msys64\ucrt64\bin')) {
if (Test-Path $mingwPath) {
Add-StablePathEntry $mingwPath
}
}
if ($windowsAppsPath) {
Add-StablePathEntry $windowsAppsPath
}
if ($stablePathEntries.Count -eq 0) {
throw 'Failed to derive cache-stable Windows PATH.'
}
if ([string]::IsNullOrWhiteSpace($env:GITHUB_ENV)) {
throw 'GITHUB_ENV must be set.'
}
$stablePath = $stablePathEntries -join ';'
Write-Host 'Derived CODEX_BAZEL_WINDOWS_PATH entries:'
foreach ($pathEntry in $stablePathEntries) {
Write-Host " $pathEntry"
}
"CODEX_BAZEL_WINDOWS_PATH=$stablePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@@ -68,19 +68,21 @@ for command_name in python3 zip; do
fi
done
missing_environment=0
for variable_name in \
APPLE_NOTARIZATION_AKV_KEY_NAME \
AZURE_KEYVAULT_NAME
do
if [[ -z "${!variable_name:-}" ]]; then
echo "$variable_name must be configured before notarizing a binary." >&2
missing_environment=1
fi
done
if [[ "${APPLE_NOTARIZATION_BACKEND:-akv}" != signer-service ]]; then
missing_environment=0
for variable_name in \
APPLE_NOTARIZATION_AKV_KEY_NAME \
AZURE_KEYVAULT_NAME
do
if [[ -z "${!variable_name:-}" ]]; then
echo "$variable_name must be configured before notarizing a binary." >&2
missing_environment=1
fi
done
if [[ "$missing_environment" -ne 0 ]]; then
exit 2
if [[ "$missing_environment" -ne 0 ]]; then
exit 2
fi
fi
mkdir -p "$report_dir"
@@ -15,6 +15,7 @@ import time
import urllib.error
import urllib.parse
import urllib.request
import uuid
from dataclasses import dataclass
from pathlib import Path
from typing import Any
@@ -165,14 +166,22 @@ def base64url_decode(value: str) -> bytes:
def create_apple_jwt(
configuration: NotarizationConfiguration, *, issued_at: int
configuration: NotarizationConfiguration | None, *, issued_at: int
) -> str:
"""Create an authentication token for notarization requests."""
"""Create Apple's JWT; a None configuration selects Signer Service."""
header = {"alg": "ES256", "kid": configuration.apple_key_id, "typ": "JWT"}
header = {
"alg": "ES256",
"kid": configuration.apple_key_id
if configuration
else os.environ["APPLE_NOTARIZATION_KEY_ID"],
"typ": "JWT",
}
# Restrict the token to notarization requests.
claims = {
"iss": configuration.issuer_id,
"iss": configuration.issuer_id
if configuration
else os.environ["APPLE_NOTARIZATION_ISSUER_ID"],
"iat": issued_at,
"exp": issued_at + JWT_LIFETIME_SECONDS,
"aud": "appstoreconnect-v1",
@@ -186,6 +195,9 @@ def create_apple_jwt(
)
signing_input = f"{encoded_header}.{encoded_claims}"
digest = hashlib.sha256(signing_input.encode("ascii")).digest()
if configuration is None:
signature = sign_digest_with_signer_service(digest)
return f"{signing_input}.{base64url_encode(signature)}"
key_url = configuration.versioned_key_id
request_body = json.dumps({"alg": "ES256", "value": base64url_encode(digest)})
@@ -240,6 +252,87 @@ def create_apple_jwt(
return f"{signing_input}.{base64url_encode(signature)}"
def sign_digest_with_signer_service(digest: bytes) -> bytes:
"""Sign the Apple JWT digest with the configured Signer Service key."""
endpoint = os.environ["APPLE_NOTARIZATION_SIGNER_ENDPOINT"]
url = urllib.parse.urlsplit(os.environ["ACTIONS_ID_TOKEN_REQUEST_URL"])
query = dict(urllib.parse.parse_qsl(url.query), audience=endpoint)
request = urllib.request.Request(
urllib.parse.urlunsplit(url._replace(query=urllib.parse.urlencode(query))),
headers={
"Authorization": "Bearer " + os.environ["ACTIONS_ID_TOKEN_REQUEST_TOKEN"]
},
)
try:
with urllib.request.urlopen(request, timeout=30) as response:
token = json.load(response)["value"]
except urllib.error.HTTPError as error:
raise NotarizationError(
f"GitHub OIDC request returned HTTP {error.code}"
) from None
except OSError:
raise NotarizationError(
"GitHub OIDC request failed; transport details redacted"
) from None
except (ValueError, KeyError, TypeError):
raise NotarizationError(
"GitHub OIDC returned an invalid token response"
) from None
proto = Path(os.environ["APPLE_NOTARIZATION_SIGNER_PROTO"])
try:
result = subprocess.run(
[
"grpcurl",
"-import-path",
str(proto.parent),
"-proto",
proto.name,
"-max-time",
"30",
"-expand-headers",
"-rpc-header",
"authorization: Bearer ${NOTARIZATION_OIDC_TOKEN}",
"-rpc-header",
f"x-openai-route-key: {uuid.uuid4()}",
"-d",
"@",
urllib.parse.urlsplit(endpoint).netloc + ":443",
"oaiproto.security.signer.v1.SignerService/Sign",
],
input=json.dumps(
{
"purpose": os.environ["APPLE_NOTARIZATION_SIGNER_PURPOSE"],
"digest": base64.b64encode(digest).decode(),
}
),
env={**os.environ, "NOTARIZATION_OIDC_TOKEN": token},
check=True,
capture_output=True,
text=True,
)
except (OSError, subprocess.CalledProcessError):
# grpcurl errors may contain authorization headers or response bodies.
raise NotarizationError(
"Signer Service signing request failed; details redacted"
) from None
try:
result = json.loads(result.stdout)
key_id, algorithm = result["keyId"], result["algorithm"]
signature = base64.b64decode(result["signature"], validate=True)
except (ValueError, KeyError, TypeError):
raise NotarizationError(
"Signer Service returned an invalid signing response"
) from None
if key_id != os.environ["APPLE_NOTARIZATION_SIGNER_KEY_ID"]:
raise NotarizationError("Signer Service returned an unexpected signing key")
if algorithm != "SIGNING_ALGORITHM_ECDSA_P256_SHA256":
raise NotarizationError(
"Signer Service returned an unexpected signing algorithm"
)
return signature
def json_request(
url: str, token: str, *, body: dict[str, Any] | None = None
) -> dict[str, Any]:
@@ -416,12 +509,12 @@ def write_developer_log(
def notarize(
path: Path,
configuration: NotarizationConfiguration,
configuration: NotarizationConfiguration | None,
*,
max_wait_seconds: int,
report_log: Path | None,
) -> str:
"""Submit an artifact, upload it to Apple, and wait for a terminal result."""
"""Submit an artifact and await Apple's result; None selects Signer Service."""
issued_at = int(time.time())
token = create_apple_jwt(configuration, issued_at=issued_at)
@@ -503,13 +596,24 @@ def main() -> int:
raise NotarizationError("--max-wait-seconds must be non-negative")
if arguments.report_log is not None:
arguments.report_log.parent.mkdir(parents=True, exist_ok=True)
backend = os.environ.get("APPLE_NOTARIZATION_BACKEND", "akv")
if backend not in {"akv", "signer-service"}:
raise NotarizationError(
"APPLE_NOTARIZATION_BACKEND must be akv or signer-service"
)
configuration = (
NotarizationConfiguration.from_environment() if backend == "akv" else None
)
notarize(
arguments.file,
NotarizationConfiguration.from_environment(),
configuration,
max_wait_seconds=arguments.max_wait_seconds,
report_log=arguments.report_log,
)
except NotarizationError as error:
except KeyError as error:
print(f"Missing notarization configuration: {error.args[0]}", file=sys.stderr)
return 1
except (NotarizationError, OSError) as error:
print(f"Notarization failed: {error}", file=sys.stderr)
return 1
return 0
@@ -188,15 +188,20 @@ def verify(package, reports, expected_target, configuration: ProfileConfiguratio
binary = package / relative
target = package / APP if relative == EXECUTABLE else binary
prefix = reports / f"{binary.name}-cert-"
subprocess.run(
["codesign", "-d", f"--extract-certificates={prefix}", str(target)],
check=True,
)
if (
hashlib.sha256(Path(f"{prefix}0").read_bytes()).hexdigest()
!= configuration.certificate_sha256
):
raise ValueError(f"Unexpected signing certificate: {relative}")
verify_certificate(target, prefix, configuration)
def verify_certificate(target, prefix, configuration: ProfileConfiguration):
"""Require the independently approved leaf certificate for each signed executable."""
subprocess.run(
["codesign", "-d", f"--extract-certificates={prefix}", str(target)],
check=True,
)
if (
hashlib.sha256(Path(f"{prefix}0").read_bytes()).hexdigest()
!= configuration.certificate_sha256
):
raise ValueError(f"Unexpected signing certificate: {target}")
def parse_profile_args(parser, configuration: ProfileConfiguration | None):
@@ -12,7 +12,7 @@ import provisioned_macos_cli_package as bundle
def main(configuration: bundle.ProfileConfiguration | None = None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("operation", choices=("sign", "verify"))
parser.add_argument("operation", choices=("sign", "sign-only", "verify"))
parser.add_argument("package", type=Path)
args, configuration = bundle.parse_profile_args(parser, configuration)
package = args.package.resolve(strict=True)
@@ -24,11 +24,13 @@ def main(configuration: bundle.ProfileConfiguration | None = None):
reports = Path(repo_root) / "signing-verification"
reports.mkdir(parents=True, exist_ok=True)
provisioned = os.environ.get("PROVISIONED_MACOS", "false") == "true"
signing = args.operation in ("sign", "sign-only")
if signing:
configuration.validate_signing_certificate(
Path(os.environ["OAI_AKV_SIGNING_CERTIFICATE_PEM"])
)
if provisioned:
if args.operation == "sign":
configuration.validate_signing_certificate(
Path(os.environ["OAI_AKV_SIGNING_CERTIFICATE_PEM"])
)
if signing:
bundle.prepare(package, reports, configuration)
else:
bundle.verify(package, reports, os.environ["TARGET"], configuration)
@@ -44,7 +46,7 @@ def main(configuration: bundle.ProfileConfiguration | None = None):
target = package / bundle.APP
identifier = bundle.CODE_SIGNING_ID
entitlements = reports / "codex-provisioned-entitlements.plist"
if args.operation == "sign":
if signing:
command = [
"bash",
str(bundle.SIGNING / "sign_macos_code.sh"),
@@ -72,7 +74,7 @@ def main(configuration: bundle.ProfileConfiguration | None = None):
stdout=output,
check=True,
)
if not provisioned:
if args.operation == "sign" and not provisioned:
subprocess.run(
[
"bash",
@@ -103,11 +105,11 @@ def main(configuration: bundle.ProfileConfiguration | None = None):
" and certificate 1[field.1.2.840.113635.100.6.2.6] exists"
" and certificate leaf[field.1.2.840.113635.100.6.1.13] exists"
)
requirement += (
f' and certificate leaf[subject.OU] = "{configuration.team_id}"'
)
if provisioned and relative == "bin/codex":
requirement += (
f' and identifier "{bundle.CODE_SIGNING_ID}"'
f' and certificate leaf[subject.OU] = "{configuration.team_id}"'
)
requirement += f' and identifier "{bundle.CODE_SIGNING_ID}"'
subprocess.run(
[
"codesign",
@@ -120,6 +122,10 @@ def main(configuration: bundle.ProfileConfiguration | None = None):
],
check=True,
)
if not provisioned:
bundle.verify_certificate(
target, reports / f"{name}-cert-", configuration
)
signature = reports / f"{name}-signature.txt"
with signature.open("wb") as output:
subprocess.run(
@@ -1,3 +1,4 @@
import base64
import contextlib
import hashlib
import io
@@ -148,6 +149,73 @@ class NotarizationTest(unittest.TestCase):
):
notary.create_apple_jwt(CONFIGURATION, issued_at=1)
def test_signer_service_refreshes_tokens_without_azure(self):
environment = {
"APPLE_NOTARIZATION_BACKEND": "signer-service",
"APPLE_NOTARIZATION_ISSUER_ID": CONFIGURATION.issuer_id,
"APPLE_NOTARIZATION_KEY_ID": CONFIGURATION.apple_key_id,
"APPLE_NOTARIZATION_SIGNER_ENDPOINT": "https://signer.example.com",
"APPLE_NOTARIZATION_SIGNER_PURPOSE": "test-notarization",
"APPLE_NOTARIZATION_SIGNER_KEY_ID": "expected-key",
"APPLE_NOTARIZATION_SIGNER_PROTO": "/tmp/notarization_signer.proto",
"ACTIONS_ID_TOKEN_REQUEST_URL": "https://pipelines.actions.githubusercontent.com/token",
"ACTIONS_ID_TOKEN_REQUEST_TOKEN": "request-secret",
}
with (
tempfile.NamedTemporaryFile() as artifact,
patch.dict(os.environ, environment, clear=True),
patch.object(
sys, "argv", ["notarize_with_akv.py", "--file", artifact.name]
),
patch.object(notary.time, "time", side_effect=[1, 900, 900]),
patch.object(
notary,
"json_request",
side_effect=[
{"data": {"id": "submission-1", "attributes": CREDENTIALS}},
{"data": {"attributes": {"status": "Accepted"}}},
],
) as request,
patch.object(notary, "upload_to_apple_s3"),
patch.object(
notary.urllib.request,
"urlopen",
side_effect=[
response({"value": "first-oidc"}),
response({"value": "fresh-oidc"}),
],
),
patch.object(
notary.subprocess,
"run",
return_value=azure_response(
{
"keyId": "expected-key",
"algorithm": "SIGNING_ALGORITHM_ECDSA_P256_SHA256",
"signature": base64.b64encode(bytes(64)).decode(),
}
),
) as sign,
):
self.assertEqual(notary.main(), 0)
self.assertEqual(
[
json.loads(notary.base64url_decode(entry.args[1].split(".")[1]))["iat"]
for entry in request.call_args_list
],
[1, 900],
)
self.assertEqual(
[entry.args[0][0] for entry in sign.call_args_list], ["grpcurl", "grpcurl"]
)
self.assertEqual(
[
entry.kwargs["env"]["NOTARIZATION_OIDC_TOKEN"]
for entry in sign.call_args_list
],
["first-oidc", "fresh-oidc"],
)
def test_uploads_polls_and_retains_sanitized_apple_diagnostics(self) -> None:
signature = azure_response(
{
@@ -224,8 +292,17 @@ class NotarizationWrapperTest(unittest.TestCase):
f"#!/usr/bin/env bash\nset -euo pipefail\n{body}\n"
)
executable.chmod(0o755)
for kind in ("binary", "dmg"):
with self.subTest(kind=kind):
for kind, backend in (
("binary", "akv"),
("dmg", "akv"),
("binary", "signer-service"),
):
selected_environment = dict(environment)
if backend == "signer-service":
selected_environment["APPLE_NOTARIZATION_BACKEND"] = backend
for name in ENVIRONMENT:
selected_environment.pop(name, None)
with self.subTest(kind=kind, backend=backend):
artifact = root / ("codex.dmg" if kind == "dmg" else "codex")
artifact.write_bytes(b"signed release artifact")
subprocess.run(
@@ -238,7 +315,7 @@ class NotarizationWrapperTest(unittest.TestCase):
"--report-dir",
str(root / "report"),
],
env=environment,
env=selected_environment,
check=True,
capture_output=True,
text=True,
@@ -26,7 +26,7 @@ with open(os.environ["CALL_LOG"], "a") as log:
if name == "codesign":
for arg in args:
if arg.startswith("--extract-certificates="):
Path(arg.split("=", 1)[1] + "0").write_bytes(Path(os.environ["MOCK_CERTIFICATE"]).read_bytes())
Path(arg.split("=", 1)[1] + "0").write_bytes(b"wrong certificate" if os.environ.get("MOCK_WRONG_CERTIFICATE") else Path(os.environ["MOCK_CERTIFICATE"]).read_bytes())
if "--test-requirement" in args and os.environ.get("MOCK_WRONG_SIGNING_IDENTITY"):
print("code failed to satisfy specified code requirement(s)", file=sys.stderr)
sys.exit(1)
@@ -149,6 +149,26 @@ class MacosSigningTests(ProvisioningTestCase):
check=False,
)
def test_sign_only_signs_standard_package_without_notarization(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory).resolve()
package, driver, env = self.fixture(root, False, "aarch64-apple-darwin")
result = self.run_driver(driver, "sign-only", package, env)
self.assertEqual(result.returncode, 0, result.stderr)
calls = [
json.loads(line)
for line in (root / "calls.jsonl").read_text().splitlines()
]
self.assertEqual(
[
call[call.index("--target") + 1]
for call in calls
if call[0] == "sign_macos_code.sh"
],
[str(package / path) for path in ("bin/codex", *bundle.HELPERS)],
)
self.assertFalse(any(call[0].startswith("notarize") for call in calls))
def test_standard_and_provisioned_signing_and_verification(self):
for provisioned, target, omit_empty in itertools.product(
(False, True),
@@ -333,6 +353,7 @@ class MacosSigningTests(ProvisioningTestCase):
(
"MOCK_WRONG_SIGNING_IDENTITY",
"MOCK_WRONG_ENTITLEMENTS",
"MOCK_WRONG_CERTIFICATE",
"MOCK_EXECUTOR_ENTITLEMENTS",
),
):
@@ -353,6 +374,8 @@ class MacosSigningTests(ProvisioningTestCase):
"code failed to satisfy specified code requirement(s)",
result.stderr,
)
elif failure == "MOCK_WRONG_CERTIFICATE":
self.assertIn("Unexpected signing certificate", result.stderr)
else:
self.assertIn("unexpected", result.stdout)
@@ -1,103 +0,0 @@
#!/usr/bin/env python3
"""Assign Windows Bazel test targets using checked-in duration estimates."""
import argparse
import sys
from pathlib import Path
DEFAULT_DURATION_SECONDS = 1
DURATIONS_PATH = Path(__file__).with_name("windows_bazel_test_durations.tsv")
def read_durations(path: Path) -> dict[str, int]:
durations = {}
for line_number, line in enumerate(
path.read_text(encoding="utf-8").splitlines(), 1
):
if not line.strip() or line.lstrip().startswith("#"):
continue
fields = line.split("\t")
if len(fields) != 2 or not fields[0] or not fields[1].isdecimal():
raise ValueError(
f"{path}:{line_number}: expected target<TAB>positive integer"
)
target, duration_text = fields
duration = int(duration_text)
if duration < 1:
raise ValueError(f"{path}:{line_number}: duration must be positive")
if target in durations:
raise ValueError(f"{path}:{line_number}: duplicate target {target}")
durations[target] = duration
return durations
def assign_targets(
targets: list[str], durations: dict[str, int], shard_count: int
) -> tuple[list[list[str]], list[int]]:
if shard_count < 1:
raise ValueError("shard count must be positive")
if not targets:
raise ValueError("no Bazel test targets were provided")
if any(not target.strip() for target in targets):
raise ValueError("Bazel test target labels must not be empty")
if len(targets) != len(set(targets)):
raise ValueError("duplicate Bazel test target labels were provided")
assignments: list[list[str]] = [[] for _ in range(shard_count)]
loads = [0] * shard_count
# Place the longest targets first, breaking ties by label and shard number.
for target in sorted(
targets,
key=lambda target: (-durations.get(target, DEFAULT_DURATION_SECONDS), target),
):
shard = min(range(shard_count), key=lambda shard: (loads[shard], shard))
assignments[shard].append(target)
loads[shard] += durations.get(target, DEFAULT_DURATION_SECONDS)
for assignment in assignments:
assignment.sort()
return assignments, loads
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--shard", required=True, type=int)
parser.add_argument("--shard-count", required=True, type=int)
parser.add_argument(
"--durations",
type=Path,
default=DURATIONS_PATH,
help="use this timing file instead of the checked-in default",
)
args = parser.parse_args()
if not 1 <= args.shard <= args.shard_count:
parser.error("shard must be between 1 and shard count")
try:
durations = read_durations(args.durations)
targets = sys.stdin.read().splitlines()
assignments, loads = assign_targets(targets, durations, args.shard_count)
except (OSError, ValueError) as error:
parser.error(str(error))
selected_targets = assignments[args.shard - 1]
if not selected_targets:
parser.error(
f"no Bazel test targets selected for shard {args.shard}/{args.shard_count}"
)
target_set = set(targets)
print(
f"Windows Bazel shards: targets={[len(assignment) for assignment in assignments]}, "
f"estimated test-seconds={loads}, default weights={len(target_set - durations.keys())}, "
f"unused weights={len(durations.keys() - target_set)}. "
f"Selected shard {args.shard}/{args.shard_count}.",
file=sys.stderr,
)
# Keep LF delimiters when native Windows Python feeds Git Bash mapfile.
sys.stdout.buffer.write(("\n".join(selected_targets) + "\n").encode("utf-8"))
if __name__ == "__main__":
main()
-63
View File
@@ -1,63 +0,0 @@
# Configure a fast drive for Windows CI jobs.
#
# GitHub-hosted Windows runners do not always expose a secondary D: volume. When
# they do not, create a Dev Drive VHD. CI depends on this path for its
# build directories where CI spends significant time doing I/O, so fail the
# job if no real Dev Drive is available.
function Test-DevDrive {
param([string]$Drive)
& fsutil devdrv query $Drive *> $null
return $LASTEXITCODE -eq 0
}
function Invoke-BestEffort {
param([scriptblock]$Script, [string]$Description)
try {
& $Script
} catch {
Write-Warning "$Description failed: $($_.Exception.Message)"
}
}
if ((Test-Path "D:\") -and (Test-DevDrive "D:")) {
Write-Output "Using existing Dev Drive at D:"
$Drive = "D:"
} else {
if (Test-Path "D:\") {
Write-Output "Existing D: volume is not a Dev Drive; provisioning a new Dev Drive VHD."
}
try {
$VhdPath = Join-Path $env:RUNNER_TEMP "codex-dev-drive.vhdx"
$SizeBytes = 64GB
if (Test-Path $VhdPath) {
Remove-Item -Path $VhdPath -Force
}
New-VHD -Path $VhdPath -SizeBytes $SizeBytes -Dynamic -ErrorAction Stop | Out-Null
$Mounted = Mount-VHD -Path $VhdPath -Passthru -ErrorAction Stop
$Disk = $Mounted | Get-Disk -ErrorAction Stop
$Disk | Initialize-Disk -PartitionStyle GPT -ErrorAction Stop
$Partition = $Disk | New-Partition -AssignDriveLetter -UseMaximumSize -ErrorAction Stop
$Volume = $Partition | Format-Volume -FileSystem ReFS -NewFileSystemLabel "CodexDevDrive" -DevDrive -Confirm:$false -Force -ErrorAction Stop
$Drive = "$($Volume.DriveLetter):"
if (-not (Test-DevDrive $Drive)) {
throw "Provisioned volume at $Drive did not pass Dev Drive verification."
}
Invoke-BestEffort { fsutil devdrv trust $Drive } "Trusting Dev Drive $Drive"
Invoke-BestEffort { fsutil devdrv enable /disallowAv } "Disabling AV filter attachment for Dev Drives"
Write-Output "Using Dev Drive at $Drive"
} catch {
throw "Failed to create Dev Drive: $($_.Exception.Message)"
}
}
"CI_BUILD_ROOT=$Drive" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
-96
View File
@@ -1,96 +0,0 @@
# CI-only prerequisites. Never install these tools into a Codex package.
param(
[Parameter(Mandatory = $true)][string]$Target,
[Parameter(Mandatory = $true)][string]$SnapshotArchive
)
$ErrorActionPreference = "Stop"
$PkgHashes = @{
"x86_64-pc-windows-msvc" = @("x64", "5604cf25ef38bb6a09520cff25ae9f0ecd8c2443053b15e40df4ad1eae0e4405")
"aarch64-pc-windows-msvc" = @("arm64", "d5752ce2ac2296c8abb91fb12c12e75ee99ba8a18b52ce5febf325847b6f062b")
}
if (-not $PkgHashes.ContainsKey($Target)) { throw "Unsupported target: $Target" }
$Root = Join-Path $env:RUNNER_TEMP "voice-windows-build-tools"
$Evidence = Join-Path $Root "evidence"
$Cygwin = Join-Path $Root "cygwin"
$Cache = Join-Path $Root "cache"
New-Item -ItemType Directory -Path $Root, $Evidence | Out-Null
$ManifestPath = Join-Path $PSScriptRoot "voice-cygwin-snapshot.json"
$Manifest = Get-Content -Raw $ManifestPath | ConvertFrom-Json
$SnapshotTool = Join-Path $PSScriptRoot "voice-cygwin-inputs.py"
& python $SnapshotTool extract --archive $SnapshotArchive --directory (Join-Path $Cache $Manifest.cacheDirectory)
if ($LASTEXITCODE -ne 0) { throw "Cygwin snapshot could not be verified and extracted" }
Copy-Item $ManifestPath (Join-Path $Evidence "cygwin-snapshot.json")
# Official https://cygwin.com/setup/sha512.sum and pkgconf release asset digests.
# The complete package closure is pinned separately in cygwin-snapshot.json.
$Inputs = @(
@{
url = "https://cygwin.com/setup/setup-2.937.x86_64.exe"
file = "setup.exe"
algorithm = "SHA512"
digest = "6acea47c59781c9e7f544a18d53935d59df6e44d5d52ac95ee165671b8e388820455eebf30ccc7d254b00c3d0eb694269a0f8dc84b17944c1f355dac9c5aafcc"
},
@{
url = "https://github.com/pkgconf/pkgconf/releases/download/pkgconf-3.0.6/pkgconf-$($PkgHashes[$Target][0])-3.0.6.msi"
file = "pkgconf.msi"
algorithm = "SHA256"
digest = $PkgHashes[$Target][1]
}
)
foreach ($InputFile in $Inputs) {
$Destination = Join-Path $Root $InputFile.file
Invoke-WebRequest -Uri $InputFile.url -OutFile $Destination
$Actual = (Get-FileHash -Path $Destination -Algorithm $InputFile.algorithm).Hash.ToLowerInvariant()
if ($Actual -ne $InputFile.digest) { throw "Build input digest mismatch: $($InputFile.file)" }
}
$Inputs | ConvertTo-Json | Set-Content (Join-Path $Evidence "bootstrap-inputs.json")
$Packages = $Manifest.requestedPackages -join ","
# Only setup.xz + setup.xz.sig are present: local mode still verifies that
# signature. Never substitute an unsigned setup.ini or enable a network fallback.
$Setup = Start-Process -FilePath (Join-Path $Root "setup.exe") -Wait -PassThru -ArgumentList @(
"--quiet-mode", "--no-admin", "--no-shortcuts", "--only-site",
"--local-install", "--no-version-check",
"--root", "`"$Cygwin`"", "--local-package-dir", "`"$Cache`"",
"--packages", $Packages
)
if ($Setup.ExitCode -ne 0) { throw "Cygwin setup failed: $($Setup.ExitCode)" }
Copy-Item (Join-Path $Cygwin "var/log/setup.log*") $Evidence
Copy-Item (Join-Path $Cygwin "etc/setup/installed.db") $Evidence
& (Join-Path $Cygwin "bin/cygcheck.exe") -cd | Set-Content (Join-Path $Evidence "packages.txt")
if ($LASTEXITCODE -ne 0) { throw "Cannot inventory Cygwin packages" }
& python $SnapshotTool check-installed --inventory (Join-Path $Evidence "packages.txt")
if ($LASTEXITCODE -ne 0) { throw "Installed Cygwin package set differs from the snapshot" }
Get-ChildItem $Cache -File -Recurse | ForEach-Object {
@{ file = [IO.Path]::GetRelativePath($Cache, $_.FullName); bytes = $_.Length;
sha512 = (Get-FileHash $_.FullName -Algorithm SHA512).Hash.ToLowerInvariant() }
} | ConvertTo-Json | Set-Content (Join-Path $Evidence "package-cache.json")
# Administrative extraction uses TARGETDIR, not a normal MSI installation:
# no product registration or system PATH modification. Fail rather than fall
# back to an ambient executable or ordinary installer if the payload is absent.
$Image = Join-Path $Root "pkgconf-image"
$Extract = Start-Process msiexec.exe -Wait -PassThru -ArgumentList @(
"/a", "`"$(Join-Path $Root 'pkgconf.msi')`"", "/qn", "/norestart",
"TARGETDIR=`"$Image`"", "/L*v", "`"$(Join-Path $Evidence 'pkgconf-extract.log')`""
)
if ($Extract.ExitCode -ne 0) { throw "pkgconf extraction failed: $($Extract.ExitCode)" }
$Candidates = @(Get-ChildItem $Image -Filter pkgconf.exe -File -Recurse)
if ($Candidates.Count -ne 1) { throw "Expected exactly one native pkgconf executable" }
# Bazel shell-quotes execpaths containing spaces; Cargo executes PKG_CONFIG
# directly. Keep the executable and its support files at a space-free execpath.
$Native = Join-Path $Image "native"
if (Test-Path $Native) { throw "Native pkgconf destination must be fresh" }
Move-Item -LiteralPath $Candidates[0].Directory.FullName -Destination $Native
$PkgConfig = Join-Path $Native "pkgconf.exe"
$Version = & $PkgConfig --version
if ($LASTEXITCODE -ne 0 -or $Version -ne "3.0.6") { throw "Unexpected native pkgconf version" }
@{ target = $Target; cygwin_root = $Cygwin; pkg_config = $PkgConfig;
pkgconf_version = $Version; requested_packages = $Packages } |
ConvertTo-Json | Set-Content (Join-Path $Evidence "tools.json")
# Declare complete installed support trees only after snapshot and tool checks.
& python (Join-Path $PSScriptRoot "voice_windows_tools.py") --root $Root --target $Target --pkg-config $PkgConfig
if ($LASTEXITCODE -ne 0) { throw "Cannot declare Windows Bazel tool inputs" }
"VOICE_WINDOWS_BAZEL_REPOSITORY=$Root" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
"VOICE_CYGWIN_ROOT=$Cygwin" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
"VOICE_PKG_CONFIG=$PkgConfig" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
@@ -1,147 +0,0 @@
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from select_windows_bazel_targets import DURATIONS_PATH
from select_windows_bazel_targets import assign_targets
from select_windows_bazel_targets import read_durations
class SelectWindowsBazelTargetsTest(unittest.TestCase):
def test_balances_targets_with_complete_deterministic_coverage(self) -> None:
durations = {
f"//test:{name}": duration
for name, duration in zip("abcdefgh", range(8, 0, -1))
}
targets = list(durations)
assignments, loads = assign_targets(targets, durations, 4)
self.assertEqual(loads, [9, 9, 9, 9])
self.assertEqual(
sorted(target for shard in assignments for target in shard), sorted(targets)
)
self.assertEqual(
assign_targets(list(reversed(targets)), durations, 4), (assignments, loads)
)
self.assertTrue(all(shard == sorted(shard) for shard in assignments))
def test_missing_weights_use_one_and_unused_weights_do_not_create_targets(
self,
) -> None:
targets = ["//test:c", "//test:a", "//test:b"]
assignments, loads = assign_targets(targets, {"//test:stale": 100}, 2)
self.assertEqual(assignments, [["//test:a", "//test:c"], ["//test:b"]])
self.assertEqual(loads, [2, 1])
def test_rejects_empty_or_duplicate_target_input(self) -> None:
for targets in ([], [""], ["//test:a", "//test:a"]):
with self.subTest(targets=targets), self.assertRaises(ValueError):
assign_targets(targets, {}, 4)
def test_reads_duration_file_and_rejects_invalid_weights(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "durations.tsv"
path.write_text(
"# comment\n\n//test:a\t12\n//test:b\t1\n", encoding="utf-8"
)
self.assertEqual(read_durations(path), {"//test:a": 12, "//test:b": 1})
for contents in (
"//test:a 12\n",
"//test:a\t0\n",
"//test:a\t-1\n",
"//test:a\t1.5\n",
"//test:a\t1\n//test:a\t2\n",
):
with self.subTest(contents=contents), self.assertRaises(ValueError):
path.write_text(contents, encoding="utf-8")
read_durations(path)
def test_cli_uses_checked_in_weights_and_writes_only_lf_delimited_targets(
self,
) -> None:
durations = read_durations(DURATIONS_PATH)
known = sorted(durations, key=lambda target: (-durations[target], target))[:4]
self.assertEqual(len(known), 4)
targets = [*known, "//test:new-target"]
expected, _ = assign_targets(targets, durations, 4)
script = DURATIONS_PATH.with_name("select_windows_bazel_targets.py")
for shard, assignment in enumerate(expected, 1):
command = [
sys.executable,
str(script),
"--shard",
str(shard),
"--shard-count",
"4",
]
for ordered_targets in (targets, list(reversed(targets))):
with self.subTest(shard=shard, ordered_targets=ordered_targets):
result = subprocess.run(
command,
input=("\r\n".join(ordered_targets) + "\r\n").encode(),
capture_output=True,
check=True,
)
self.assertEqual(
result.stdout, ("\n".join(assignment) + "\n").encode()
)
self.assertIn(b"default weights=1", result.stderr)
def test_cli_uses_only_the_requested_duration_file(self) -> None:
script = DURATIONS_PATH.with_name("select_windows_bazel_targets.py").resolve()
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "durations.tsv"
path.write_text("//test:a\t1\n//test:b\t9\n", encoding="utf-8")
command = [sys.executable, str(script), "--shard-count", "2"]
for shard, expected in ((1, b"//test:b\n"), (2, b"//test:a\n//test:c\n")):
with self.subTest(shard=shard):
result = subprocess.run(
[*command, "--shard", str(shard), "--durations", path.name],
input=b"//test:a\n//test:b\n//test:c\n",
cwd=temp_dir,
capture_output=True,
check=True,
)
self.assertEqual(result.stdout, expected)
self.assertIn(b"estimated test-seconds=[9, 2]", result.stderr)
self.assertIn(b"unused weights=0", result.stderr)
result = subprocess.run(
[*command, "--shard", "1", "--durations", "missing.tsv"],
input=b"//test:a\n",
cwd=temp_dir,
capture_output=True,
check=False,
)
self.assertNotEqual(result.returncode, 0)
self.assertEqual(result.stdout, b"")
self.assertIn(b"missing.tsv", result.stderr)
def test_cli_rejects_bad_or_empty_selection_without_partial_output(self) -> None:
script = DURATIONS_PATH.with_name("select_windows_bazel_targets.py")
for targets, error in (
(b"", b"no Bazel test targets were provided"),
(b"//test:a\n//test:a\n", b"duplicate Bazel test target labels"),
(b"//test:a\n", b"no Bazel test targets selected for shard 2/2"),
):
with self.subTest(targets=targets):
result = subprocess.run(
[sys.executable, str(script), "--shard", "2", "--shard-count", "2"],
input=targets,
capture_output=True,
check=False,
)
self.assertNotEqual(result.returncode, 0)
self.assertEqual(result.stdout, b"")
self.assertIn(error, result.stderr)
if __name__ == "__main__":
unittest.main()
-83
View File
@@ -1,83 +0,0 @@
"""Expose verified Windows build-tool installations as local Bazel inputs.
This declares the installed support trees; the caller authenticates their
inputs and verifies the installed package inventory first.
"""
import argparse
import itertools
import json
from pathlib import Path
import stat
def export_repository(root: Path, target: str, pkg_config: Path):
if target not in ("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"):
raise ValueError("unsupported Windows target")
root = root.resolve(strict=True)
pkg_config = pkg_config.resolve(strict=True)
names = {
"shell": "cygwin/bin/bash.exe",
"make": "cygwin/bin/make.exe",
"cygpath": "cygwin/bin/cygpath.exe",
"automake": "cygwin/bin/automake-1.18",
"pkg_config": pkg_config.relative_to(root).as_posix(),
}
if not names["pkg_config"].startswith("pkgconf-image/"):
raise ValueError("pkg-config must belong to the extracted image")
outputs = ("BUILD.bazel", "MODULE.bazel", "voice-tools.json")
if any((root / name).exists() for name in outputs):
raise ValueError("Bazel tool repository outputs must be fresh")
# A nested package boundary would silently remove files from Bazel's glob.
# Reparse points could escape the installation or hide support directories.
for directory in ("cygwin", "pkgconf-image"):
tree = root / directory
if not tree.is_dir():
raise ValueError(f"missing tool tree: {directory}")
for path in itertools.chain((tree,), tree.rglob("*")):
info = path.lstat()
if (
stat.S_ISLNK(info.st_mode)
or getattr(info, "st_file_attributes", 0)
& stat.FILE_ATTRIBUTE_REPARSE_POINT
or not (stat.S_ISDIR(info.st_mode) or stat.S_ISREG(info.st_mode))
or path.name.casefold() in ("build", "build.bazel")
):
raise ValueError(f"unsupported tool-tree entry: {path}")
if any(not (root / name).is_file() for name in names.values()):
raise ValueError("required Windows build tool missing")
definitions = [
'package(default_visibility = ["//visibility:public"])',
# Cygwin records installation timestamps in this unused Java truststore.
# Exclude it so reinstalling the same tools preserves action cache keys.
'filegroup(name = "cygwin", srcs = glob(["cygwin/**"], '
'exclude = ["cygwin/etc/pki/ca-trust/extracted/java/cacerts"], allow_empty = False))',
'filegroup(name = "pkgconf", srcs = glob(["pkgconf-image/**"], allow_empty = False))',
'filegroup(name = "tools", srcs = [":cygwin", ":pkgconf", "voice-tools.json"])',
]
definitions.extend(
f"filegroup(name = {json.dumps(name)}, srcs = [{json.dumps(path)}])"
for name, path in names.items()
)
metadata = {
"schemaVersion": 1,
"target": target,
"cygwinArchitecture": "x86_64",
"tools": names,
}
for name, contents in (
("BUILD.bazel", "\n".join(definitions) + "\n"),
("MODULE.bazel", 'module(name = "voice_windows_tools")\n'),
("voice-tools.json", json.dumps(metadata, indent=2) + "\n"),
):
with (root / name).open("x", encoding="utf-8") as output:
output.write(contents)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--root", type=Path, required=True)
parser.add_argument("--target", required=True)
parser.add_argument("--pkg-config", type=Path, required=True)
args = parser.parse_args()
export_repository(args.root, args.target, args.pkg_config)
@@ -1,251 +0,0 @@
# Windows Bazel duration weights; columns: target<TAB>seconds.
# Seeded from 24 successful public openai/codex Windows job logs across six main
# runs, September 21-23, 2026. Public GitHub Actions run IDs:
# 35638529858, 35665540272, 35694732932, 35912411800, 35919297566, 35924169500.
# To refresh, take the median summed inner-run time (N * average) from clean,
# uncached PASSED summaries, excluding partial cache hits and FLAKY results.
# Round up to positive integer seconds. These weights exclude build/download time.
# Every queried target is assigned; missing weights default to 1 and stale entries are ignored.
//codex-rs/agent-graph-store:agent-graph-store-unit-tests 76
//codex-rs/agent-identity:agent-identity-unit-tests 66
//codex-rs/agent-roles:agent-roles-unit-tests 48
//codex-rs/analytics:analytics-unit-tests 29
//codex-rs/app-server-client:app-server-client-unit-tests 51
//codex-rs/app-server-daemon:app-server-daemon-unit-tests 4
//codex-rs/app-server-protocol:app-server-protocol-unit-tests 19
//codex-rs/app-server-test-client:app-server-test-client-unit-tests 25
//codex-rs/app-server-test-client:codex-app-server-test-client-bin-unit-tests 1
//codex-rs/app-server-transport:app-server-transport-unit-tests 65
//codex-rs/app-server/tests/common:common-unit-tests 26
//codex-rs/app-server:app-server-all-test-windows-cross 2835
//codex-rs/app-server:app-server-unit-tests 399
//codex-rs/app-server:codex-app-server-bin-unit-tests 48
//codex-rs/app-server:codex-app-server-test-notify-capture-bin-unit-tests 1
//codex-rs/app-server:exec-server-bin-unit-tests 1
//codex-rs/app-server:test_notify_capture-bin-unit-tests 1
//codex-rs/apply-patch:apply-patch-all-test-windows-cross 50
//codex-rs/apply-patch:apply-patch-unit-tests 48
//codex-rs/apply-patch:apply_patch-bin-unit-tests 24
//codex-rs/arg0:arg0-unit-tests 24
//codex-rs/backend-client:backend-client-unit-tests 41
//codex-rs/chatgpt:chatgpt-all-test-windows-cross 26
//codex-rs/chatgpt:chatgpt-unit-tests 27
//codex-rs/cli:cli-app_server-test-windows-cross 3
//codex-rs/cli:cli-app_server_daemon-test-windows-cross 1
//codex-rs/cli:cli-cloud_auth-test-windows-cross 47
//codex-rs/cli:cli-cloud_config-test-windows-cross 3
//codex-rs/cli:cli-daemon_startup-test-windows-cross 4
//codex-rs/cli:cli-daemon_telemetry-test-windows-cross 1
//codex-rs/cli:cli-debug_clear_memories-test-windows-cross 4
//codex-rs/cli:cli-debug_models-test-windows-cross 2
//codex-rs/cli:cli-delete-test-windows-cross 2
//codex-rs/cli:cli-doctor_enterprise_network-test-windows-cross 3
//codex-rs/cli:cli-doctor_path_safety-test-windows-cross 47
//codex-rs/cli:cli-exec_server-test-windows-cross 39
//codex-rs/cli:cli-exec_server_websocket_auth-test-windows-cross 4
//codex-rs/cli:cli-execpolicy-test-windows-cross 2
//codex-rs/cli:cli-features-test-windows-cross 3
//codex-rs/cli:cli-login-test-windows-cross 4
//codex-rs/cli:cli-marketplace_add-test-windows-cross 2
//codex-rs/cli:cli-marketplace_remove-test-windows-cross 1
//codex-rs/cli:cli-marketplace_upgrade-test-windows-cross 2
//codex-rs/cli:cli-mcp_add_remove-test-windows-cross 3
//codex-rs/cli:cli-mcp_list-test-windows-cross 2
//codex-rs/cli:cli-mcp_login-test-windows-cross 2
//codex-rs/cli:cli-plugin_cli-test-windows-cross 7
//codex-rs/cli:cli-queue-test-windows-cross 1
//codex-rs/cli:cli-sandbox_cloud_config-test-windows-cross 48
//codex-rs/cli:cli-sandbox_network_proxy-test-windows-cross 1
//codex-rs/cli:cli-sandbox_tty-test-windows-cross 1
//codex-rs/cli:cli-unit-tests 2
//codex-rs/cli:cli-update-test-windows-cross 47
//codex-rs/cli:cli-worktree-test-windows-cross 12
//codex-rs/cli:codex-bin-unit-tests 60
//codex-rs/cli:logs_client-bin-unit-tests 1
//codex-rs/cloud-config:cloud-config-unit-tests 47
//codex-rs/cloud-tasks-client:cloud-tasks-client-unit-tests 35
//codex-rs/cloud-tasks-mock-client:cloud-tasks-mock-client-unit-tests 59
//codex-rs/cloud-tasks:cloud-tasks-env_filter-test-windows-cross 1
//codex-rs/cloud-tasks:cloud-tasks-unit-tests 1
//codex-rs/code-mode-host:code-mode-host-grpc-test-windows-cross 28
//codex-rs/code-mode-host:code-mode-host-grpc_notifications-test-windows-cross 25
//codex-rs/code-mode-host:code-mode-host-grpc_tcp-test-windows-cross 1
//codex-rs/code-mode-host:code-mode-host-grpc_timing-test-windows-cross 7
//codex-rs/code-mode-host:code-mode-host-stdio-test-windows-cross 11
//codex-rs/code-mode-host:code-mode-host-unit-tests 2
//codex-rs/code-mode-host:codex-code-mode-host-bin-unit-tests 1
//codex-rs/code-mode-protocol:code-mode-protocol-unit-tests 62
//codex-rs/code-mode-runtime:code-mode-runtime-array_sort-test-windows-cross 24
//codex-rs/code-mode-runtime:code-mode-runtime-jit-test-windows-cross 1
//codex-rs/code-mode-runtime:code-mode-runtime-unit-tests 7
//codex-rs/code-mode:code-mode-unit-tests 49
//codex-rs/codex-api:codex-api-clients-test-windows-cross 75
//codex-rs/codex-api:codex-api-models_integration-test-windows-cross 66
//codex-rs/codex-api:codex-api-realtime_websocket_e2e-test-windows-cross 63
//codex-rs/codex-api:codex-api-realtime_websocket_tls-test-windows-cross 66
//codex-rs/codex-api:codex-api-sse_end_to_end-test-windows-cross 48
//codex-rs/codex-api:codex-api-unit-tests 60
//codex-rs/codex-home:codex-home-unit-tests 13
//codex-rs/codex-mcp:codex-mcp-unit-tests 61
//codex-rs/config-schema:codex-write-config-schema-bin-unit-tests 48
//codex-rs/config:config-unit-tests 75
//codex-rs/connectors:connectors-unit-tests 39
//codex-rs/context-fragments:context-fragments-unit-tests 59
//codex-rs/core-api:core-api-unit-tests 1
//codex-rs/core-plugins:core-plugins-unit-tests 20
//codex-rs/core/tests/common:common-unit-tests 48
//codex-rs/core:core-all-test-windows-cross 3162
//codex-rs/core:core-mcp_trace_propagation-test-windows-cross 2
//codex-rs/core:core-responses_headers-test-windows-cross 5
//codex-rs/core:core-unit-tests 251
//codex-rs/exec-server-protocol:exec-server-protocol-unit-tests 48
//codex-rs/exec-server/tests/support:support-unit-tests 48
//codex-rs/exec-server:exec-server-accepted_websocket-test-windows-cross 1
//codex-rs/exec-server:exec-server-capability_discovery-test-windows-cross 1
//codex-rs/exec-server:exec-server-chatgpt_cloudflare_affinity-test-windows-cross 1
//codex-rs/exec-server:exec-server-deferred_environment-test-windows-cross 1
//codex-rs/exec-server:exec-server-environment-test-windows-cross 10
//codex-rs/exec-server:exec-server-environment_config-test-windows-cross 1
//codex-rs/exec-server:exec-server-exec_process-test-windows-cross 1
//codex-rs/exec-server:exec-server-file_stream-test-windows-cross 1
//codex-rs/exec-server:exec-server-file_system_unix-test-windows-cross 1
//codex-rs/exec-server:exec-server-file_system_windows-test-windows-cross 11
//codex-rs/exec-server:exec-server-forward-test-windows-cross 10
//codex-rs/exec-server:exec-server-health-test-windows-cross 1
//codex-rs/exec-server:exec-server-http_client-test-windows-cross 2
//codex-rs/exec-server:exec-server-http_request-test-windows-cross 1
//codex-rs/exec-server:exec-server-http_request_logging-test-windows-cross 3
//codex-rs/exec-server:exec-server-initialize-test-windows-cross 1
//codex-rs/exec-server:exec-server-macos_fs_spawn-test-windows-cross 1
//codex-rs/exec-server:exec-server-process-test-windows-cross 4
//codex-rs/exec-server:exec-server-relay-test-windows-cross 8
//codex-rs/exec-server:exec-server-selected_capability_roots-test-windows-cross 1
//codex-rs/exec-server:exec-server-unit-tests 116
//codex-rs/exec-server:exec-server-websocket-test-windows-cross 1
//codex-rs/exec:codex-exec-bin-unit-tests 1
//codex-rs/exec:exec-all-test-windows-cross 331
//codex-rs/exec:exec-event_processor_with_json_output-test-windows-cross 1
//codex-rs/exec:exec-unit-tests 47
//codex-rs/message-board:message-board-local_board-test-windows-cross 46
//codex-rs/ext/agent-message-board:agent-message-board-unit-tests 30
//codex-rs/ext/agent:agent-agent_service-test-windows-cross 3
//codex-rs/ext/agent:agent-unit-tests 1
//codex-rs/ext/connectors:connectors-unit-tests 47
//codex-rs/ext/extension-api:extension-api-capabilities-test-windows-cross 14
//codex-rs/ext/extension-api:extension-api-registry-test-windows-cross 31
//codex-rs/ext/extension-api:extension-api-state-test-windows-cross 57
//codex-rs/ext/extension-api:extension-api-unit-tests 35
//codex-rs/ext/git-attribution:git-attribution-unit-tests 30
//codex-rs/ext/goal:goal-accounting-test-windows-cross 1
//codex-rs/ext/goal:goal-goal_extension_backend-test-windows-cross 9
//codex-rs/ext/goal:goal-steering-test-windows-cross 1
//codex-rs/ext/goal:goal-unit-tests 47
//codex-rs/ext/guardian-reviewer:guardian-reviewer-unit-tests 36
//codex-rs/ext/guardian-v2:guardian-v2-unit-tests 50
//codex-rs/ext/history-notes:history-notes-history_notes_extension-test-windows-cross 1
//codex-rs/ext/history-notes:history-notes-image_model_input-test-windows-cross 2
//codex-rs/ext/history-notes:history-notes-unit-tests 1
//codex-rs/ext/image-generation:image-generation-unit-tests 47
//codex-rs/ext/mcp:mcp-hosted_apps_mcp-test-windows-cross 26
//codex-rs/ext/mcp:mcp-plugin_mcp-test-windows-cross 5
//codex-rs/ext/mcp:mcp-unit-tests 48
//codex-rs/ext/memories:memories-unit-tests 28
//codex-rs/ext/queue:queue-queue_service-test-windows-cross 9
//codex-rs/ext/queue:queue-unit-tests 25
//codex-rs/ext/skills:skills-executor_file_system_authority-test-windows-cross 36
//codex-rs/ext/skills:skills-skills_extension-test-windows-cross 7
//codex-rs/ext/skills:skills-unit-tests 8
//codex-rs/ext/web-search:web-search-unit-tests 1
//codex-rs/external-agent-migration:external-agent-migration-unit-tests 4
//codex-rs/features:features-unit-tests 47
//codex-rs/feedback:feedback-unit-tests 77
//codex-rs/file-system:file-system-unit-tests 48
//codex-rs/git-utils:git-utils-unit-tests 83
//codex-rs/guardian-context:guardian-context-cache_prefix-test-windows-cross 66
//codex-rs/guardian-context:guardian-context-unit-tests 67
//codex-rs/history:history-unit-tests 59
//codex-rs/hooks:hooks-unit-tests 16
//codex-rs/hooks:write_hooks_schema_fixtures-bin-unit-tests 48
//codex-rs/lmstudio:lmstudio-unit-tests 1
//codex-rs/login:login-all-test-windows-cross 5
//codex-rs/login:login-unit-tests 320
//codex-rs/memories/read:read-unit-tests 62
//codex-rs/memories/write:write-unit-tests 20
//codex-rs/message-history:message-history-unit-tests 74
//codex-rs/model-provider-info:model-provider-info-unit-tests 63
//codex-rs/model-provider:model-provider-unit-tests 64
//codex-rs/models-manager:models-manager-unit-tests 35
//codex-rs/mxc-sandbox:mxc-sandbox-unit-tests 36
//codex-rs/network-proxy:codex-network-proxy-bin-unit-tests 48
//codex-rs/network-proxy:network-proxy-unit-tests 85
//codex-rs/network-proxy:network-proxy-windows_stable_ingress-test-windows-cross 37
//codex-rs/ollama:ollama-unit-tests 1
//codex-rs/otel:otel-tests-test-windows-cross 17
//codex-rs/otel:otel-unit-tests 48
//codex-rs/plugin:plugin-unit-tests 74
//codex-rs/prompts:prompts-unit-tests 62
//codex-rs/protocol:protocol-unit-tests 67
//codex-rs/response-debug-context:response-debug-context-unit-tests 66
//codex-rs/rmcp-client:rmcp-client-foreign_stdio_cwd-test-windows-cross 48
//codex-rs/rmcp-client:rmcp-client-mcp_2026_discovery-test-windows-cross 4
//codex-rs/rmcp-client:rmcp-client-mcp_2026_message_limits-test-windows-cross 4
//codex-rs/rmcp-client:rmcp-client-mcp_2026_mrtr-test-windows-cross 2
//codex-rs/rmcp-client:rmcp-client-mcp_2026_oauth_discovery-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-mcp_2026_sse_discovery-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-mcp_2026_stdio-test-windows-cross 39
//codex-rs/rmcp-client:rmcp-client-mcp_2026_stdio_discovery-test-windows-cross 2
//codex-rs/rmcp-client:rmcp-client-mcp_events-test-windows-cross 2
//codex-rs/rmcp-client:rmcp-client-process_group_cleanup-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-resources-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-stdio_descriptor_boundary-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-stdio_message_limits-test-windows-cross 3
//codex-rs/rmcp-client:rmcp-client-stdio_stderr_cleanup-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_startup-test-windows-cross 6
//codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_store_pinning-test-windows-cross 38
//codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_tool_call-test-windows-cross 2
//codex-rs/rmcp-client:rmcp-client-streamable_http_recovery-test-windows-cross 51
//codex-rs/rmcp-client:rmcp-client-streamable_http_remote-test-windows-cross 3
//codex-rs/rmcp-client:rmcp-client-streamable_http_test_support-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-streamable_http_user_agent-test-windows-cross 1
//codex-rs/rmcp-client:rmcp-client-unit-tests 50
//codex-rs/rmcp-client:rmcp_test_server-bin-unit-tests 39
//codex-rs/rmcp-client:test_mcp_2026_discovery_stdio_server-bin-unit-tests 43
//codex-rs/rmcp-client:test_mcp_2026_stdio_server-bin-unit-tests 25
//codex-rs/rmcp-client:test_stdio_server-bin-unit-tests 41
//codex-rs/rmcp-client:test_streamable_http_server-bin-unit-tests 40
//codex-rs/rollout-trace:rollout-trace-unit-tests 76
//codex-rs/rollout:rollout-unit-tests 56
//codex-rs/sandboxing:sandboxing-unit-tests 74
//codex-rs/secrets:secrets-unit-tests 57
//codex-rs/shell-command:shell-command-unit-tests 60
//codex-rs/skills:skills-unit-tests 59
//codex-rs/state:state-unit-tests 242
//codex-rs/test-binary-support:test-binary-support-unit-tests 48
//codex-rs/thread-manager-sample:codex-thread-manager-sample-bin-unit-tests 47
//codex-rs/thread-store:thread-store-unit-tests 95
//codex-rs/tools:tools-json_schema_policy_fixtures-test-windows-cross 34
//codex-rs/tools:tools-unit-tests 37
//codex-rs/tui:codex-tui-bin-unit-tests 2
//codex-rs/tui:md-events-bin-unit-tests 1
//codex-rs/tui:tui-all-test-windows-cross 36
//codex-rs/tui:tui-manager_dependency_regression-test-windows-cross 2
//codex-rs/tui:tui-test_backend-test-windows-cross 25
//codex-rs/tui:tui-unit-tests 1003
//codex-rs/utils/approval-presets:approval-presets-unit-tests 66
//codex-rs/utils/audio:audio-unit-tests 76
//codex-rs/utils/cli:cli-unit-tests 64
//codex-rs/utils/git-discovery:git-discovery-unit-tests 59
//codex-rs/utils/oss:oss-unit-tests 1
//codex-rs/utils/output-truncation:output-truncation-unit-tests 60
//codex-rs/utils/plugins:plugins-unit-tests 36
//codex-rs/utils/sandbox-summary:sandbox-summary-unit-tests 66
//codex-rs/windows-sandbox-rs:codex-command-runner-bin-unit-tests 1
//codex-rs/windows-sandbox-rs:codex-windows-managed-deny-probe-bin-unit-tests 1
//codex-rs/windows-sandbox-rs:codex-windows-sandbox-setup-bin-unit-tests 1
//codex-rs/windows-sandbox-rs:windows-sandbox-rs-helper_manifest-test-windows-cross 1
//codex-rs/windows-sandbox-rs:windows-sandbox-rs-unit-tests 23
//codex-rs/windows-sandbox-service:codex-windows-sandbox-service-bin-unit-tests 46
//codex-rs/windows-sandbox-service:windows-sandbox-service-unit-tests 12
//codex-rs/worktree:worktree-settings-test-windows-cross 59
//codex-rs/worktree:worktree-unit-tests 76
//codex-rs/worktree:worktree-worktree-test-windows-cross 92
1 # Windows Bazel duration weights; columns: target<TAB>seconds.
2 # Seeded from 24 successful public openai/codex Windows job logs across six main
3 # runs, September 21-23, 2026. Public GitHub Actions run IDs:
4 # 35638529858, 35665540272, 35694732932, 35912411800, 35919297566, 35924169500.
5 # To refresh, take the median summed inner-run time (N * average) from clean,
6 # uncached PASSED summaries, excluding partial cache hits and FLAKY results.
7 # Round up to positive integer seconds. These weights exclude build/download time.
8 # Every queried target is assigned; missing weights default to 1 and stale entries are ignored.
9 //codex-rs/agent-graph-store:agent-graph-store-unit-tests 76
10 //codex-rs/agent-identity:agent-identity-unit-tests 66
11 //codex-rs/agent-roles:agent-roles-unit-tests 48
12 //codex-rs/analytics:analytics-unit-tests 29
13 //codex-rs/app-server-client:app-server-client-unit-tests 51
14 //codex-rs/app-server-daemon:app-server-daemon-unit-tests 4
15 //codex-rs/app-server-protocol:app-server-protocol-unit-tests 19
16 //codex-rs/app-server-test-client:app-server-test-client-unit-tests 25
17 //codex-rs/app-server-test-client:codex-app-server-test-client-bin-unit-tests 1
18 //codex-rs/app-server-transport:app-server-transport-unit-tests 65
19 //codex-rs/app-server/tests/common:common-unit-tests 26
20 //codex-rs/app-server:app-server-all-test-windows-cross 2835
21 //codex-rs/app-server:app-server-unit-tests 399
22 //codex-rs/app-server:codex-app-server-bin-unit-tests 48
23 //codex-rs/app-server:codex-app-server-test-notify-capture-bin-unit-tests 1
24 //codex-rs/app-server:exec-server-bin-unit-tests 1
25 //codex-rs/app-server:test_notify_capture-bin-unit-tests 1
26 //codex-rs/apply-patch:apply-patch-all-test-windows-cross 50
27 //codex-rs/apply-patch:apply-patch-unit-tests 48
28 //codex-rs/apply-patch:apply_patch-bin-unit-tests 24
29 //codex-rs/arg0:arg0-unit-tests 24
30 //codex-rs/backend-client:backend-client-unit-tests 41
31 //codex-rs/chatgpt:chatgpt-all-test-windows-cross 26
32 //codex-rs/chatgpt:chatgpt-unit-tests 27
33 //codex-rs/cli:cli-app_server-test-windows-cross 3
34 //codex-rs/cli:cli-app_server_daemon-test-windows-cross 1
35 //codex-rs/cli:cli-cloud_auth-test-windows-cross 47
36 //codex-rs/cli:cli-cloud_config-test-windows-cross 3
37 //codex-rs/cli:cli-daemon_startup-test-windows-cross 4
38 //codex-rs/cli:cli-daemon_telemetry-test-windows-cross 1
39 //codex-rs/cli:cli-debug_clear_memories-test-windows-cross 4
40 //codex-rs/cli:cli-debug_models-test-windows-cross 2
41 //codex-rs/cli:cli-delete-test-windows-cross 2
42 //codex-rs/cli:cli-doctor_enterprise_network-test-windows-cross 3
43 //codex-rs/cli:cli-doctor_path_safety-test-windows-cross 47
44 //codex-rs/cli:cli-exec_server-test-windows-cross 39
45 //codex-rs/cli:cli-exec_server_websocket_auth-test-windows-cross 4
46 //codex-rs/cli:cli-execpolicy-test-windows-cross 2
47 //codex-rs/cli:cli-features-test-windows-cross 3
48 //codex-rs/cli:cli-login-test-windows-cross 4
49 //codex-rs/cli:cli-marketplace_add-test-windows-cross 2
50 //codex-rs/cli:cli-marketplace_remove-test-windows-cross 1
51 //codex-rs/cli:cli-marketplace_upgrade-test-windows-cross 2
52 //codex-rs/cli:cli-mcp_add_remove-test-windows-cross 3
53 //codex-rs/cli:cli-mcp_list-test-windows-cross 2
54 //codex-rs/cli:cli-mcp_login-test-windows-cross 2
55 //codex-rs/cli:cli-plugin_cli-test-windows-cross 7
56 //codex-rs/cli:cli-queue-test-windows-cross 1
57 //codex-rs/cli:cli-sandbox_cloud_config-test-windows-cross 48
58 //codex-rs/cli:cli-sandbox_network_proxy-test-windows-cross 1
59 //codex-rs/cli:cli-sandbox_tty-test-windows-cross 1
60 //codex-rs/cli:cli-unit-tests 2
61 //codex-rs/cli:cli-update-test-windows-cross 47
62 //codex-rs/cli:cli-worktree-test-windows-cross 12
63 //codex-rs/cli:codex-bin-unit-tests 60
64 //codex-rs/cli:logs_client-bin-unit-tests 1
65 //codex-rs/cloud-config:cloud-config-unit-tests 47
66 //codex-rs/cloud-tasks-client:cloud-tasks-client-unit-tests 35
67 //codex-rs/cloud-tasks-mock-client:cloud-tasks-mock-client-unit-tests 59
68 //codex-rs/cloud-tasks:cloud-tasks-env_filter-test-windows-cross 1
69 //codex-rs/cloud-tasks:cloud-tasks-unit-tests 1
70 //codex-rs/code-mode-host:code-mode-host-grpc-test-windows-cross 28
71 //codex-rs/code-mode-host:code-mode-host-grpc_notifications-test-windows-cross 25
72 //codex-rs/code-mode-host:code-mode-host-grpc_tcp-test-windows-cross 1
73 //codex-rs/code-mode-host:code-mode-host-grpc_timing-test-windows-cross 7
74 //codex-rs/code-mode-host:code-mode-host-stdio-test-windows-cross 11
75 //codex-rs/code-mode-host:code-mode-host-unit-tests 2
76 //codex-rs/code-mode-host:codex-code-mode-host-bin-unit-tests 1
77 //codex-rs/code-mode-protocol:code-mode-protocol-unit-tests 62
78 //codex-rs/code-mode-runtime:code-mode-runtime-array_sort-test-windows-cross 24
79 //codex-rs/code-mode-runtime:code-mode-runtime-jit-test-windows-cross 1
80 //codex-rs/code-mode-runtime:code-mode-runtime-unit-tests 7
81 //codex-rs/code-mode:code-mode-unit-tests 49
82 //codex-rs/codex-api:codex-api-clients-test-windows-cross 75
83 //codex-rs/codex-api:codex-api-models_integration-test-windows-cross 66
84 //codex-rs/codex-api:codex-api-realtime_websocket_e2e-test-windows-cross 63
85 //codex-rs/codex-api:codex-api-realtime_websocket_tls-test-windows-cross 66
86 //codex-rs/codex-api:codex-api-sse_end_to_end-test-windows-cross 48
87 //codex-rs/codex-api:codex-api-unit-tests 60
88 //codex-rs/codex-home:codex-home-unit-tests 13
89 //codex-rs/codex-mcp:codex-mcp-unit-tests 61
90 //codex-rs/config-schema:codex-write-config-schema-bin-unit-tests 48
91 //codex-rs/config:config-unit-tests 75
92 //codex-rs/connectors:connectors-unit-tests 39
93 //codex-rs/context-fragments:context-fragments-unit-tests 59
94 //codex-rs/core-api:core-api-unit-tests 1
95 //codex-rs/core-plugins:core-plugins-unit-tests 20
96 //codex-rs/core/tests/common:common-unit-tests 48
97 //codex-rs/core:core-all-test-windows-cross 3162
98 //codex-rs/core:core-mcp_trace_propagation-test-windows-cross 2
99 //codex-rs/core:core-responses_headers-test-windows-cross 5
100 //codex-rs/core:core-unit-tests 251
101 //codex-rs/exec-server-protocol:exec-server-protocol-unit-tests 48
102 //codex-rs/exec-server/tests/support:support-unit-tests 48
103 //codex-rs/exec-server:exec-server-accepted_websocket-test-windows-cross 1
104 //codex-rs/exec-server:exec-server-capability_discovery-test-windows-cross 1
105 //codex-rs/exec-server:exec-server-chatgpt_cloudflare_affinity-test-windows-cross 1
106 //codex-rs/exec-server:exec-server-deferred_environment-test-windows-cross 1
107 //codex-rs/exec-server:exec-server-environment-test-windows-cross 10
108 //codex-rs/exec-server:exec-server-environment_config-test-windows-cross 1
109 //codex-rs/exec-server:exec-server-exec_process-test-windows-cross 1
110 //codex-rs/exec-server:exec-server-file_stream-test-windows-cross 1
111 //codex-rs/exec-server:exec-server-file_system_unix-test-windows-cross 1
112 //codex-rs/exec-server:exec-server-file_system_windows-test-windows-cross 11
113 //codex-rs/exec-server:exec-server-forward-test-windows-cross 10
114 //codex-rs/exec-server:exec-server-health-test-windows-cross 1
115 //codex-rs/exec-server:exec-server-http_client-test-windows-cross 2
116 //codex-rs/exec-server:exec-server-http_request-test-windows-cross 1
117 //codex-rs/exec-server:exec-server-http_request_logging-test-windows-cross 3
118 //codex-rs/exec-server:exec-server-initialize-test-windows-cross 1
119 //codex-rs/exec-server:exec-server-macos_fs_spawn-test-windows-cross 1
120 //codex-rs/exec-server:exec-server-process-test-windows-cross 4
121 //codex-rs/exec-server:exec-server-relay-test-windows-cross 8
122 //codex-rs/exec-server:exec-server-selected_capability_roots-test-windows-cross 1
123 //codex-rs/exec-server:exec-server-unit-tests 116
124 //codex-rs/exec-server:exec-server-websocket-test-windows-cross 1
125 //codex-rs/exec:codex-exec-bin-unit-tests 1
126 //codex-rs/exec:exec-all-test-windows-cross 331
127 //codex-rs/exec:exec-event_processor_with_json_output-test-windows-cross 1
128 //codex-rs/exec:exec-unit-tests 47
129 //codex-rs/message-board:message-board-local_board-test-windows-cross 46
130 //codex-rs/ext/agent-message-board:agent-message-board-unit-tests 30
131 //codex-rs/ext/agent:agent-agent_service-test-windows-cross 3
132 //codex-rs/ext/agent:agent-unit-tests 1
133 //codex-rs/ext/connectors:connectors-unit-tests 47
134 //codex-rs/ext/extension-api:extension-api-capabilities-test-windows-cross 14
135 //codex-rs/ext/extension-api:extension-api-registry-test-windows-cross 31
136 //codex-rs/ext/extension-api:extension-api-state-test-windows-cross 57
137 //codex-rs/ext/extension-api:extension-api-unit-tests 35
138 //codex-rs/ext/git-attribution:git-attribution-unit-tests 30
139 //codex-rs/ext/goal:goal-accounting-test-windows-cross 1
140 //codex-rs/ext/goal:goal-goal_extension_backend-test-windows-cross 9
141 //codex-rs/ext/goal:goal-steering-test-windows-cross 1
142 //codex-rs/ext/goal:goal-unit-tests 47
143 //codex-rs/ext/guardian-reviewer:guardian-reviewer-unit-tests 36
144 //codex-rs/ext/guardian-v2:guardian-v2-unit-tests 50
145 //codex-rs/ext/history-notes:history-notes-history_notes_extension-test-windows-cross 1
146 //codex-rs/ext/history-notes:history-notes-image_model_input-test-windows-cross 2
147 //codex-rs/ext/history-notes:history-notes-unit-tests 1
148 //codex-rs/ext/image-generation:image-generation-unit-tests 47
149 //codex-rs/ext/mcp:mcp-hosted_apps_mcp-test-windows-cross 26
150 //codex-rs/ext/mcp:mcp-plugin_mcp-test-windows-cross 5
151 //codex-rs/ext/mcp:mcp-unit-tests 48
152 //codex-rs/ext/memories:memories-unit-tests 28
153 //codex-rs/ext/queue:queue-queue_service-test-windows-cross 9
154 //codex-rs/ext/queue:queue-unit-tests 25
155 //codex-rs/ext/skills:skills-executor_file_system_authority-test-windows-cross 36
156 //codex-rs/ext/skills:skills-skills_extension-test-windows-cross 7
157 //codex-rs/ext/skills:skills-unit-tests 8
158 //codex-rs/ext/web-search:web-search-unit-tests 1
159 //codex-rs/external-agent-migration:external-agent-migration-unit-tests 4
160 //codex-rs/features:features-unit-tests 47
161 //codex-rs/feedback:feedback-unit-tests 77
162 //codex-rs/file-system:file-system-unit-tests 48
163 //codex-rs/git-utils:git-utils-unit-tests 83
164 //codex-rs/guardian-context:guardian-context-cache_prefix-test-windows-cross 66
165 //codex-rs/guardian-context:guardian-context-unit-tests 67
166 //codex-rs/history:history-unit-tests 59
167 //codex-rs/hooks:hooks-unit-tests 16
168 //codex-rs/hooks:write_hooks_schema_fixtures-bin-unit-tests 48
169 //codex-rs/lmstudio:lmstudio-unit-tests 1
170 //codex-rs/login:login-all-test-windows-cross 5
171 //codex-rs/login:login-unit-tests 320
172 //codex-rs/memories/read:read-unit-tests 62
173 //codex-rs/memories/write:write-unit-tests 20
174 //codex-rs/message-history:message-history-unit-tests 74
175 //codex-rs/model-provider-info:model-provider-info-unit-tests 63
176 //codex-rs/model-provider:model-provider-unit-tests 64
177 //codex-rs/models-manager:models-manager-unit-tests 35
178 //codex-rs/mxc-sandbox:mxc-sandbox-unit-tests 36
179 //codex-rs/network-proxy:codex-network-proxy-bin-unit-tests 48
180 //codex-rs/network-proxy:network-proxy-unit-tests 85
181 //codex-rs/network-proxy:network-proxy-windows_stable_ingress-test-windows-cross 37
182 //codex-rs/ollama:ollama-unit-tests 1
183 //codex-rs/otel:otel-tests-test-windows-cross 17
184 //codex-rs/otel:otel-unit-tests 48
185 //codex-rs/plugin:plugin-unit-tests 74
186 //codex-rs/prompts:prompts-unit-tests 62
187 //codex-rs/protocol:protocol-unit-tests 67
188 //codex-rs/response-debug-context:response-debug-context-unit-tests 66
189 //codex-rs/rmcp-client:rmcp-client-foreign_stdio_cwd-test-windows-cross 48
190 //codex-rs/rmcp-client:rmcp-client-mcp_2026_discovery-test-windows-cross 4
191 //codex-rs/rmcp-client:rmcp-client-mcp_2026_message_limits-test-windows-cross 4
192 //codex-rs/rmcp-client:rmcp-client-mcp_2026_mrtr-test-windows-cross 2
193 //codex-rs/rmcp-client:rmcp-client-mcp_2026_oauth_discovery-test-windows-cross 1
194 //codex-rs/rmcp-client:rmcp-client-mcp_2026_sse_discovery-test-windows-cross 1
195 //codex-rs/rmcp-client:rmcp-client-mcp_2026_stdio-test-windows-cross 39
196 //codex-rs/rmcp-client:rmcp-client-mcp_2026_stdio_discovery-test-windows-cross 2
197 //codex-rs/rmcp-client:rmcp-client-mcp_events-test-windows-cross 2
198 //codex-rs/rmcp-client:rmcp-client-process_group_cleanup-test-windows-cross 1
199 //codex-rs/rmcp-client:rmcp-client-resources-test-windows-cross 1
200 //codex-rs/rmcp-client:rmcp-client-stdio_descriptor_boundary-test-windows-cross 1
201 //codex-rs/rmcp-client:rmcp-client-stdio_message_limits-test-windows-cross 3
202 //codex-rs/rmcp-client:rmcp-client-stdio_stderr_cleanup-test-windows-cross 1
203 //codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_startup-test-windows-cross 6
204 //codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_store_pinning-test-windows-cross 38
205 //codex-rs/rmcp-client:rmcp-client-streamable_http_oauth_tool_call-test-windows-cross 2
206 //codex-rs/rmcp-client:rmcp-client-streamable_http_recovery-test-windows-cross 51
207 //codex-rs/rmcp-client:rmcp-client-streamable_http_remote-test-windows-cross 3
208 //codex-rs/rmcp-client:rmcp-client-streamable_http_test_support-test-windows-cross 1
209 //codex-rs/rmcp-client:rmcp-client-streamable_http_user_agent-test-windows-cross 1
210 //codex-rs/rmcp-client:rmcp-client-unit-tests 50
211 //codex-rs/rmcp-client:rmcp_test_server-bin-unit-tests 39
212 //codex-rs/rmcp-client:test_mcp_2026_discovery_stdio_server-bin-unit-tests 43
213 //codex-rs/rmcp-client:test_mcp_2026_stdio_server-bin-unit-tests 25
214 //codex-rs/rmcp-client:test_stdio_server-bin-unit-tests 41
215 //codex-rs/rmcp-client:test_streamable_http_server-bin-unit-tests 40
216 //codex-rs/rollout-trace:rollout-trace-unit-tests 76
217 //codex-rs/rollout:rollout-unit-tests 56
218 //codex-rs/sandboxing:sandboxing-unit-tests 74
219 //codex-rs/secrets:secrets-unit-tests 57
220 //codex-rs/shell-command:shell-command-unit-tests 60
221 //codex-rs/skills:skills-unit-tests 59
222 //codex-rs/state:state-unit-tests 242
223 //codex-rs/test-binary-support:test-binary-support-unit-tests 48
224 //codex-rs/thread-manager-sample:codex-thread-manager-sample-bin-unit-tests 47
225 //codex-rs/thread-store:thread-store-unit-tests 95
226 //codex-rs/tools:tools-json_schema_policy_fixtures-test-windows-cross 34
227 //codex-rs/tools:tools-unit-tests 37
228 //codex-rs/tui:codex-tui-bin-unit-tests 2
229 //codex-rs/tui:md-events-bin-unit-tests 1
230 //codex-rs/tui:tui-all-test-windows-cross 36
231 //codex-rs/tui:tui-manager_dependency_regression-test-windows-cross 2
232 //codex-rs/tui:tui-test_backend-test-windows-cross 25
233 //codex-rs/tui:tui-unit-tests 1003
234 //codex-rs/utils/approval-presets:approval-presets-unit-tests 66
235 //codex-rs/utils/audio:audio-unit-tests 76
236 //codex-rs/utils/cli:cli-unit-tests 64
237 //codex-rs/utils/git-discovery:git-discovery-unit-tests 59
238 //codex-rs/utils/oss:oss-unit-tests 1
239 //codex-rs/utils/output-truncation:output-truncation-unit-tests 60
240 //codex-rs/utils/plugins:plugins-unit-tests 36
241 //codex-rs/utils/sandbox-summary:sandbox-summary-unit-tests 66
242 //codex-rs/windows-sandbox-rs:codex-command-runner-bin-unit-tests 1
243 //codex-rs/windows-sandbox-rs:codex-windows-managed-deny-probe-bin-unit-tests 1
244 //codex-rs/windows-sandbox-rs:codex-windows-sandbox-setup-bin-unit-tests 1
245 //codex-rs/windows-sandbox-rs:windows-sandbox-rs-helper_manifest-test-windows-cross 1
246 //codex-rs/windows-sandbox-rs:windows-sandbox-rs-unit-tests 23
247 //codex-rs/windows-sandbox-service:codex-windows-sandbox-service-bin-unit-tests 46
248 //codex-rs/windows-sandbox-service:windows-sandbox-service-unit-tests 12
249 //codex-rs/worktree:worktree-settings-test-windows-cross 59
250 //codex-rs/worktree:worktree-unit-tests 76
251 //codex-rs/worktree:worktree-worktree-test-windows-cross 92
-722
View File
@@ -1,722 +0,0 @@
name: rust-release-windows
on:
workflow_call:
env:
WINDOWS_BINARIES: "codex codex-code-mode-host codex-exec-server codex-responses-api-proxy codex-windows-sandbox-setup codex-windows-sandbox-service codex-command-runner codex-app-server"
jobs:
build-windows-binaries:
name: Build Windows binaries - ${{ matrix.runner }} - ${{ matrix.target }} - ${{ matrix.bundle }} - ${{ matrix.build-system }}
# Release Cargo artifacts only while Bazel releases are disabled.
runs-on: ${{ matrix.runs_on }}
environment:
name: bazel
deployment: false
# Temporary increase from 90 minutes while Cargo and Bazel build paths coexist.
# Reassess after the transition using Bazel release build timings.
timeout-minutes: 120
permissions:
contents: read
defaults:
run:
working-directory: codex-rs
env:
# Preserve Cargo names while teams opt into the additional Bazel artifacts.
ARTIFACT_SUFFIX: ${{ matrix.build-system == 'bazel' && '-bazel' || '' }}
strategy:
fail-fast: false
matrix:
build-system: [cargo] # Bazel releases are disabled while the BuildBuddy key is revoked.
target:
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
bundle: [primary, helpers, app-server]
include:
- runner: windows-x64
target: x86_64-pc-windows-msvc
bundle: primary
binaries: "codex codex-code-mode-host codex-exec-server codex-responses-api-proxy"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
- runner: windows-arm64
target: aarch64-pc-windows-msvc
bundle: primary
binaries: "codex codex-code-mode-host codex-exec-server codex-responses-api-proxy"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-arm64
- runner: windows-x64
target: x86_64-pc-windows-msvc
bundle: helpers
binaries: "codex-windows-sandbox-setup codex-windows-sandbox-service codex-command-runner"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
- runner: windows-arm64
target: aarch64-pc-windows-msvc
bundle: helpers
binaries: "codex-windows-sandbox-setup codex-windows-sandbox-service codex-command-runner"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-arm64
- runner: windows-x64
target: x86_64-pc-windows-msvc
bundle: app-server
binaries: "codex-app-server codex-code-mode-host codex-exec-server"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
- runner: windows-arm64
target: aarch64-pc-windows-msvc
bundle: app-server
binaries: "codex-app-server codex-code-mode-host codex-exec-server"
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-arm64
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: ./.github/actions/setup-ci
if: matrix.build-system == 'cargo'
- name: Print runner specs (Windows)
shell: powershell
run: |
$computer = Get-CimInstance Win32_ComputerSystem
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
$ramGiB = [math]::Round($computer.TotalPhysicalMemory / 1GB, 1)
Write-Host "Runner: $env:RUNNER_NAME"
Write-Host "OS: $([System.Environment]::OSVersion.VersionString)"
Write-Host "CPU: $($cpu.Name)"
Write-Host "Logical CPUs: $($computer.NumberOfLogicalProcessors)"
Write-Host "Physical CPUs: $($computer.NumberOfProcessors)"
Write-Host "Total RAM: $ramGiB GiB"
Write-Host "Disk usage:"
Get-PSDrive -PSProvider FileSystem | Format-Table -AutoSize Name, @{Name='Size(GB)';Expression={[math]::Round(($_.Used + $_.Free) / 1GB, 1)}}, @{Name='Free(GB)';Expression={[math]::Round($_.Free / 1GB, 1)}}
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
with:
targets: ${{ matrix.build-system == 'cargo' && matrix.target || '' }}
- name: Prepare Bazel release build
if: ${{ matrix.build-system == 'bazel' }}
uses: ./.github/actions/prepare-bazel-ci
with:
target: ${{ matrix.target }}
cache-scope: bazel-release-${{ matrix.bundle }}
- name: Configure rusty_v8 artifact overrides and verify checksums
if: matrix.build-system == 'cargo'
uses: ./.github/actions/setup-rusty-v8
with:
target: ${{ matrix.target }}
- name: Configure MSVC environment
uses: ./.github/actions/setup-msvc-env
with:
target: ${{ matrix.target }}
- name: Build Bazel release binaries and symbols
if: ${{ matrix.build-system == 'bazel' }}
uses: ./.github/actions/build-bazel-release
with:
target: ${{ matrix.target }}
bundle: ${{ matrix.bundle }}
release-dir: ${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release
- name: Cargo build (Windows binaries)
if: ${{ matrix.build-system == 'cargo' }}
shell: bash
run: |
target="${{ matrix.target }}"
if [[ "$target" == "x86_64-pc-windows-msvc" ]]; then
export LIBSQLITE3_FLAGS=SQLITE_DISABLE_INTRINSIC
fi
build_args=()
for binary in ${{ matrix.binaries }}; do
build_args+=(--bin "$binary")
done
STABLE_GIT_COMMIT="$(git rev-parse HEAD)"
export STABLE_GIT_COMMIT
cargo build --target "$target" --release --timings "${build_args[@]}"
- name: Stage Windows binaries
shell: bash
run: |
release_dir="$CARGO_TARGET_DIR/${{ matrix.target }}/release"
output_dir="$release_dir/staged-${{ matrix.bundle }}"
mkdir -p "$output_dir"
for binary in ${{ matrix.binaries }}; do
pdb_name="${binary//-/_}"
pdb_path="$release_dir/${pdb_name}.pdb"
if [[ ! -f "$pdb_path" ]]; then
pdb_path="$release_dir/${binary}.pdb"
fi
if [[ ! -f "$pdb_path" ]]; then
echo "PDB for $binary not found at $release_dir/${pdb_name}.pdb or $release_dir/${binary}.pdb" >&2
exit 1
fi
cp "$release_dir/${binary}.exe" "$output_dir/${binary}.exe"
cp "$pdb_path" "$output_dir/${binary}.pdb"
done
- name: Upload Windows binaries
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: windows-binaries-${{ matrix.target }}-${{ matrix.bundle }}${{ env.ARTIFACT_SUFFIX }}
path: |
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release/staged-${{ matrix.bundle }}/*
build-windows-voice:
name: Build Windows voice - ${{ matrix.target }}
runs-on: ${{ matrix.runs_on }}
environment:
name: bazel
deployment: false
timeout-minutes: 120
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-msvc
arch: x86_64
python_arch: x64
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
- target: aarch64-pc-windows-msvc
arch: aarch64
python_arch: arm64
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-arm64
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
architecture: ${{ matrix.python_arch }}
- name: Prepare Bazel CI
uses: ./.github/actions/prepare-bazel-ci
with:
target: ${{ matrix.target }}
cache-scope: release-voice-windows
- uses: ./.github/actions/setup-msvc-env
with:
target: ${{ matrix.target }}
- name: Refresh Bazel PATH for the selected MSVC target
shell: pwsh
run: ./.github/scripts/compute-bazel-windows-path.ps1
- name: Download pinned Windows build inputs
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$manifest = Get-Content -Raw .github/scripts/voice-cygwin-snapshot.json | ConvertFrom-Json
$pin = $manifest.archive
$source = $manifest.sourceArchive
$directory = Join-Path $env:RUNNER_TEMP "voice-cygwin-snapshot"
New-Item -ItemType Directory -Path $directory | Out-Null
gh release download $pin.tag --repo "${{ github.repository }}" --pattern $pin.name --pattern $source.name --dir $directory
if ($LASTEXITCODE -ne 0) { throw "Cannot obtain the public Cygwin inputs and source" }
$sourceFile = Join-Path $directory $source.name
if ((Get-Item $sourceFile).Length -ne $source.bytes -or
(Get-FileHash $sourceFile -Algorithm SHA256).Hash.ToLowerInvariant() -ne $source.sha256) {
throw "Public Cygwin source archive mismatch"
}
"VOICE_CYGWIN_ARCHIVE=$(Join-Path $directory $pin.name)" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
- name: Verify and install pinned public build tools
shell: pwsh
run: |
& ./.github/scripts/setup-voice-windows.ps1 -Target "${{ matrix.target }}" -SnapshotArchive $env:VOICE_CYGWIN_ARCHIVE
if (-not $env:SystemRoot) { throw "Windows SystemRoot is required for native audio actions" }
"VOICE_WINDOWS_SYSTEM_ROOT=$env:SystemRoot" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
$hostArch = $env:PROCESSOR_ARCHITEW6432
if (-not $hostArch) { $hostArch = $env:PROCESSOR_ARCHITECTURE }
if (-not $hostArch) { throw "Windows host architecture is required" }
"VOICE_WINDOWS_HOST_ARCH=$hostArch" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build same-commit native runtime and helper
shell: bash
env:
ARCH: ${{ matrix.arch }}
VOICE_ARCH: ${{ matrix.arch }}
# Use local Bazel while BuildBuddy credentials are unavailable.
run: |
(cd codex-rs && cargo update --workspace)
python .github/scripts/watch_voice_bazel.py "$(cygpath -w "$BASH")" ./.github/scripts/run-bazel-ci.sh \
--remote-download-toplevel \
--print-failed-action-summary \
--windows-msvc-host-platform \
-- \
test --config=release \
--platforms=//:local_windows_msvc \
--extra_toolchains=//third_party/voice:windows_pkg_config_toolchain,//third_party/voice:windows_cmake_toolchain \
--repo_env=BAZEL_MSVC_RUNTIME_VISUAL_STUDIO_EULA=1 \
--inject_repository="voice_windows_tools=$VOICE_WINDOWS_BAZEL_REPOSITORY" \
--//third_party/voice:windows_installed_tools=@voice_windows_tools//:tools \
--action_env="SystemRoot=$VOICE_WINDOWS_SYSTEM_ROOT" \
--host_action_env="SystemRoot=$VOICE_WINDOWS_SYSTEM_ROOT" \
--action_env="PROCESSOR_ARCHITECTURE=$VOICE_WINDOWS_HOST_ARCH" \
--host_action_env="PROCESSOR_ARCHITECTURE=$VOICE_WINDOWS_HOST_ARCH" \
--output_groups=default,receipt,sdk \
--workspace_status_command=./scripts/workspace-status.cmd \
--build_metadata=COMMIT_SHA="$GITHUB_SHA" \
-- \
"//third_party/voice:native_runtime_windows_$ARCH" \
@rules_rust//cargo/private/cargo_build_script_runner:test \
//codex-rs/voice-host:codex-voice-host
- name: Stage verified voice build output
shell: bash
env:
TARGET: ${{ matrix.target }}
ARCH: ${{ matrix.arch }}
run: |
set -euo pipefail
runtime="bazel-bin/third_party/voice/native_runtime_windows_${ARCH}"
PYTHONPATH=third_party/voice python - "$runtime" "$TARGET" <<'PY'
from pathlib import Path
import sys
from package_runtime import runtime_files
runtime_files(Path(sys.argv[1]).resolve(strict=True), sys.argv[2])
PY
output="voice-unsigned/${TARGET}"
mkdir -p "$output"
cp -R "$runtime" "$output/runtime"
cp bazel-bin/codex-rs/voice-host/codex-voice-host.exe "$output/codex-voice-host.exe"
chmod -R u+w "$output"
tar -C "$output" -czf "voice-unsigned-${TARGET}.tar.gz" runtime codex-voice-host.exe
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: voice-${{ matrix.target }}-unsigned
path: voice-unsigned-${{ matrix.target }}.tar.gz
if-no-files-found: error
build-windows-symbols:
needs:
- build-windows-binaries
name: Build Windows symbols - ${{ matrix.target }} - ${{ matrix.build-system }}
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
defaults:
run:
working-directory: codex-rs
env:
ARTIFACT_SUFFIX: ${{ matrix.build-system == 'bazel' && '-bazel' || '' }}
strategy:
fail-fast: false
matrix:
build-system: [cargo] # Bazel releases are disabled while the BuildBuddy key is revoked.
target:
- aarch64-pc-windows-msvc
- x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: ./.github/actions/setup-ci
- name: Download prebuilt Windows binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: windows-binaries-${{ matrix.target }}-{primary,helpers,app-server}${{ env.ARTIFACT_SUFFIX }}
merge-multiple: true
path: ${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release
- name: Build symbols archive
shell: bash
run: |
bash "${GITHUB_WORKSPACE}/.github/scripts/archive-release-symbols-and-strip-binaries.sh" \
--target "${{ matrix.target }}" \
--artifact-name "${{ matrix.target }}" \
--release-dir "${CARGO_TARGET_DIR}/${{ matrix.target }}/release" \
--archive-dir "symbols-dist/${{ matrix.target }}" \
--binaries "${WINDOWS_BINARIES}"
- name: Suffix Bazel artifact filenames
if: ${{ matrix.build-system == 'bazel' }}
shell: bash
run: |
set -euo pipefail
for artifact in "symbols-dist/${{ matrix.target }}"/*; do
name="${artifact##*/}"
stem="${name%%.*}"
mv "$artifact" "${artifact%/*}/${stem}-bazel${name#"$stem"}"
done
- name: Upload symbols archive
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ matrix.target }}-symbols${{ env.ARTIFACT_SUFFIX }}
path: codex-rs/symbols-dist/${{ matrix.target }}/*
if-no-files-found: error
build-windows:
needs:
- build-windows-binaries
- build-windows-voice
name: Build - ${{ matrix.runner }} - ${{ matrix.target }} - ${{ matrix.build-system }}
runs-on: ${{ matrix.runs_on }}
environment:
name: azure-artifact-signing
deployment: false
timeout-minutes: 120
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: codex-rs
env:
ARTIFACT_SUFFIX: ${{ matrix.build-system == 'bazel' && '-bazel' || '' }}
strategy:
fail-fast: false
matrix:
build-system: [cargo] # Bazel releases are disabled while the BuildBuddy key is revoked.
target:
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
include:
- runner: windows-x64
target: x86_64-pc-windows-msvc
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
- runner: windows-x64
target: aarch64-pc-windows-msvc
runs_on:
group: ${{ github.event.repository.name }}-runners
labels: ${{ github.event.repository.name }}-windows-x64
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: ./.github/actions/setup-ci
- name: Download prebuilt Windows primary binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: windows-binaries-${{ matrix.target }}-primary${{ env.ARTIFACT_SUFFIX }}
path: ${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release
- name: Download prebuilt Windows helper binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: windows-binaries-${{ matrix.target }}-helpers${{ env.ARTIFACT_SUFFIX }}
path: ${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release
- name: Download prebuilt Windows app-server binary
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: windows-binaries-${{ matrix.target }}-app-server${{ env.ARTIFACT_SUFFIX }}
path: ${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/release
- name: Verify binaries
shell: bash
run: |
set -euo pipefail
for binary in ${WINDOWS_BINARIES}; do
ls -lh "$CARGO_TARGET_DIR/${{ matrix.target }}/release/${binary}.exe"
done
- name: Sign Windows release files with Azure Trusted Signing
uses: ./.github/actions/windows-code-sign
with:
target: ${{ matrix.target }}
binaries: ${{ env.WINDOWS_BINARIES }}
# The installer is architecture-independent; sign it only in the x64 job.
additional-files: ${{ matrix.target == 'x86_64-pc-windows-msvc' && format('{0}/scripts/install/install.ps1', github.workspace) || '' }}
client-id: ${{ secrets.AZURE_ARTIFACT_SIGNING_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_ARTIFACT_SIGNING_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_ARTIFACT_SIGNING_SUBSCRIPTION_ID }}
endpoint: ${{ secrets.AZURE_ARTIFACT_SIGNING_ENDPOINT }}
account-name: ${{ secrets.AZURE_ARTIFACT_SIGNING_ACCOUNT_NAME }}
certificate-profile-name: ${{ secrets.AZURE_ARTIFACT_SIGNING_CERTIFICATE_PROFILE_NAME }}
- name: Download matching native voice build
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: voice-${{ matrix.target }}-unsigned
path: ${{ runner.temp }}/unsigned-voice
- name: Stage voice files for signing
id: voice_files
shell: bash
run: |
set -euo pipefail
target="${{ matrix.target }}"
unsigned="${RUNNER_TEMP}/unsigned-voice/extracted"
signed="${GITHUB_WORKSPACE}/signed-voice/${target}"
mkdir -p "$unsigned" "$signed"
tar -xzf "$(cygpath -u "${RUNNER_TEMP}/unsigned-voice/voice-unsigned-${target}.tar.gz")" -C "$(cygpath -u "$unsigned")"
python "${GITHUB_WORKSPACE}/third_party/voice/release_runtime.py" stage \
--source "$unsigned/runtime" --target "$target" --output "$signed/runtime"
cp "$unsigned/codex-voice-host.exe" "$signed/codex-voice-host.exe"
chmod -R u+w "$signed"
{
echo 'files<<EOF'
echo "$signed/codex-voice-host.exe"
find "$signed/runtime/bin" -name '*.dll' -type f -print
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Sign Windows voice helper and native DLLs
uses: azure/trusted-signing-action@1d365fec12862c4aa68fcac418143d73f0cea293 # v0.5.11
with:
endpoint: ${{ secrets.AZURE_ARTIFACT_SIGNING_ENDPOINT }}
trusted-signing-account-name: ${{ secrets.AZURE_ARTIFACT_SIGNING_ACCOUNT_NAME }}
certificate-profile-name: ${{ secrets.AZURE_ARTIFACT_SIGNING_CERTIFICATE_PROFILE_NAME }}
exclude-environment-credential: true
exclude-workload-identity-credential: true
exclude-managed-identity-credential: true
exclude-shared-token-cache-credential: true
exclude-visual-studio-credential: true
exclude-visual-studio-code-credential: true
exclude-azure-cli-credential: false
exclude-azure-powershell-credential: true
exclude-azure-developer-cli-credential: true
exclude-interactive-browser-credential: true
cache-dependencies: false
files: ${{ steps.voice_files.outputs.files }}
- uses: ./.github/actions/setup-msvc-env
with:
target: ${{ matrix.target }}
- name: Seal and verify signed voice output
shell: pwsh
run: |
$target = "${{ matrix.target }}"
$signed = Join-Path $env:GITHUB_WORKSPACE "signed-voice/$target"
python (Join-Path $env:GITHUB_WORKSPACE 'third_party/voice/windows_crt.py') --root (Join-Path $signed 'runtime') --target $target --helper (Join-Path $signed 'codex-voice-host.exe')
if ($LASTEXITCODE -ne 0) { throw 'Cannot stage verified Microsoft CRT' }
$files = @(Join-Path $signed "codex-voice-host.exe") + @(
Get-ChildItem (Join-Path $signed "runtime/bin") -Filter *.dll -File |
ForEach-Object FullName
)
if ($files.Count -lt 8) { throw "Voice DLL closure is incomplete" }
foreach ($file in $files) {
$signature = Get-AuthenticodeSignature $file
if ($signature.Status -ne 'Valid') { throw "Unsigned voice file: $file ($($signature.Status))" }
}
python (Join-Path $env:GITHUB_WORKSPACE 'third_party/voice/release_runtime.py') seal --target $target --output (Join-Path $signed 'runtime')
if ($LASTEXITCODE -ne 0) { throw 'Cannot seal signed voice runtime' }
"VOICE_RELEASE_DIR=$signed" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
- name: Stage artifacts
shell: bash
run: |
dest="dist/${{ matrix.target }}"
mkdir -p "$dest"
for binary in ${WINDOWS_BINARIES}; do
cp "$CARGO_TARGET_DIR/${{ matrix.target }}/release/${binary}.exe" \
"$dest/${binary}-${{ matrix.target }}.exe"
done
- name: Build Codex package archives
shell: bash
run: |
set -euo pipefail
target="${{ matrix.target }}"
archive_script="${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh"
voice_args=(--voice-release-dir "$VOICE_RELEASE_DIR")
voice_args+=(--release-version "${GITHUB_REF_NAME#rust-v}")
bash "$archive_script" \
--target "$target" --bundle primary \
--entrypoint-dir "$CARGO_TARGET_DIR/$target/release" \
--archive-dir "dist/$target" "${voice_args[@]}"
bash "$archive_script" \
--target "$target" --bundle app-server \
--entrypoint-dir "$CARGO_TARGET_DIR/$target/release" \
--archive-dir "dist/$target"
- name: Verify packaged executor signatures and bytes
shell: pwsh
run: |
$target = "${{ matrix.target }}"
$source = Join-Path $env:CARGO_TARGET_DIR "$target/release/codex-exec-server.exe"
foreach ($stem in @("codex-package", "codex-app-server-package")) {
$package = Join-Path $env:RUNNER_TEMP "verify-executor-$stem-$target"
New-Item -ItemType Directory -Path $package | Out-Null
tar -xzf "dist/$target/$stem-$target.tar.gz" -C $package
if ($LASTEXITCODE -ne 0) { throw "Cannot extract executor package" }
$binary = Join-Path $package "bin/codex-exec-server.exe"
if ((Get-FileHash $binary).Hash -ne (Get-FileHash $source).Hash) {
throw "Packaged executor differs from the signed input"
}
$signature = Get-AuthenticodeSignature $binary
if ($signature.Status -ne "Valid" -or $null -eq $signature.TimeStamperCertificate) {
throw "Invalid or untimestamped executor signature"
}
}
- name: Verify packaged Windows voice closure
shell: pwsh
run: |
$target = "${{ matrix.target }}"
$package = Join-Path $env:RUNNER_TEMP "verify-voice-archive-$target"
New-Item -ItemType Directory -Path $package | Out-Null
tar -xzf "dist/$target/codex-package-$target.tar.gz" -C $package
if ($LASTEXITCODE -ne 0) { throw "Cannot extract the final Windows package" }
$voice = Join-Path $package 'codex-resources/voice'
$helper = Join-Path $voice 'bin/codex-voice-host.exe'
if (-not (Test-Path $helper) -or -not (Test-Path (Join-Path $voice 'bin/gstreamer-1.0-0.dll'))) {
throw 'Signed Windows voice files are missing from the canonical package'
}
$signature = Get-AuthenticodeSignature $helper
if ($signature.Status -ne 'Valid') { throw "Packaged helper signature: $($signature.Status)" }
python -c 'import sys; from pathlib import Path; sys.path.insert(0, sys.argv[3]); from package_runtime import runtime_files; runtime_files(Path(sys.argv[1]), sys.argv[2], public_release=True)' $voice $target (Join-Path $env:GITHUB_WORKSPACE 'third_party/voice')
if ($LASTEXITCODE -ne 0) { throw 'Packaged runtime receipt verification failed' }
- name: Set up Python release tools
if: ${{ matrix.build-system == 'cargo' }}
uses: ./.github/actions/setup-python-release-tools
with:
group: runtime
- name: Build Python runtime wheel
if: ${{ matrix.build-system == 'cargo' }}
shell: bash
run: |
set -euo pipefail
case "${{ matrix.target }}" in
aarch64-pc-windows-msvc)
platform_tag="win_arm64"
;;
x86_64-pc-windows-msvc)
platform_tag="win_amd64"
;;
*)
echo "No Python runtime wheel platform tag for ${{ matrix.target }}"
exit 1
;;
esac
# The wheel's Windows support floor predates the native voice
# runtime's verified device/VC++ prerequisites. Keep it voice-free.
wheel_package="${RUNNER_TEMP}/codex-package-${{ matrix.target }}"
python - "$wheel_package" <<'PY'
import sys
from pathlib import Path
assert not (Path(sys.argv[1]) / "codex-resources" / "voice").exists()
PY
stage_dir="${RUNNER_TEMP}/openai-codex-cli-bin-${{ matrix.target }}"
wheel_dir="${GITHUB_WORKSPACE}/python-runtime-dist/${{ matrix.target }}"
python "${GITHUB_WORKSPACE}/sdk/python/scripts/update_sdk_artifacts.py" \
stage-runtime \
"$stage_dir" \
"$wheel_package" \
--codex-version "${GITHUB_REF_NAME}" \
--platform-tag "$platform_tag"
uv build --offline --no-build-isolation --no-create-gitignore \
--python "${RUNNER_TEMP}/python-runtime-build-venv" --wheel --out-dir "$wheel_dir" "$stage_dir"
- name: Upload Python runtime wheel
if: ${{ matrix.build-system == 'cargo' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: python-runtime-wheel-${{ matrix.target }}
path: python-runtime-dist/${{ matrix.target }}/*.whl
if-no-files-found: error
- name: Compress artifacts
shell: bash
run: |
# Path that contains the uncompressed binaries for the current
# ${{ matrix.target }}
dest="dist/${{ matrix.target }}"
repo_root=$PWD
target="${{ matrix.target }}"
export dest repo_root target
# For compatibility with environments that lack the `zstd` tool we
# additionally create a `.tar.gz` and `.zip` for every Windows binary.
# The end result is:
# codex-<target>.zst
# codex-<target>.tar.gz
# codex-<target>.zip
# Variables in the single-quoted script expand in the child shell.
# shellcheck disable=SC2016
# Start larger binaries first so both workers stay busy.
find "$dest" -maxdepth 1 -type f -printf '%s %p\0' |
sort -z -nr |
cut -z -d ' ' -f 2- |
xargs -0 -n1 -P2 bash -c '
set -euo pipefail
f=$1
base="$(basename "$f")"
# Skip files that are already archives (should not happen, but be
# safe).
if [[ "$base" == *.tar.gz || "$base" == *.tar.zst || "$base" == *.zip || "$base" == *.dmg ]]; then
exit 0
fi
# Do not try to compress signature bundles.
if [[ "$base" == *.sigstore ]]; then
exit 0
fi
# Create per-binary tar.gz
tar -C "$dest" -czf "$dest/${base}.tar.gz" "$base"
# Create zip archive for Windows binaries.
# Must run from inside the dest dir so 7z does not embed the
# directory path inside the zip.
if [[ "$base" == "codex-${target}.exe" ]]; then
# Preserve WinGet executable paths while including the signed
# runtime, resources, and package metadata from the canonical tar.
bundle_dir="$(mktemp -d)"
tar -xzf "$dest/codex-package-${target}.tar.gz" -C "$bundle_dir"
python "${GITHUB_WORKSPACE}/scripts/build_winget_package.py" "$(cygpath -w "$bundle_dir")"
(cd "$bundle_dir" && 7z a "$repo_root/$dest/${base}.zip" .)
rm -rf "$bundle_dir"
else
(cd "$dest" && 7z a "${base}.zip" "$base")
fi
# Keep raw executables and produce .zst alongside them.
"${GITHUB_WORKSPACE}/.github/workflows/zstd" -T0 -19 "$dest/$base"
' _
- name: Verify and stage signed PowerShell installer
if: matrix.build-system == 'cargo' && matrix.target == 'x86_64-pc-windows-msvc'
shell: powershell
run: |
$installer = Join-Path $env:GITHUB_WORKSPACE 'scripts/install/install.ps1'
$signature = Get-AuthenticodeSignature $installer
if ($signature.Status -ne 'Valid' -or $null -eq $signature.TimeStamperCertificate) {
throw "Installer signature is invalid or missing a timestamp: $($signature.Status)"
}
# Stage after compression so the installer remains a plain script.
Copy-Item $installer 'dist/${{ matrix.target }}/install.ps1'
- name: Suffix Bazel artifact filenames
if: ${{ matrix.build-system == 'bazel' }}
shell: bash
run: |
set -euo pipefail
for artifact in "dist/${{ matrix.target }}"/*; do
name="${artifact##*/}"
stem="${name%%.*}"
mv "$artifact" "${artifact%/*}/${stem}-bazel${name#"$stem"}"
done
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ matrix.target }}${{ env.ARTIFACT_SUFFIX }}
path: |
codex-rs/dist/${{ matrix.target }}/*
+68
View File
@@ -0,0 +1,68 @@
name: Xcoder Linux
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: xcoder-linux-${{ github.ref }}
cancel-in-progress: true
jobs:
linux:
name: Build and test Linux x86_64
runs-on: ubuntu-24.04
timeout-minutes: 120
env:
CARGO_BUILD_JOBS: '1'
# Published builds keep the optimized profile; local builds use `local`.
XCODER_CARGO_PROFILE: release
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up the locked Ziran toolchain
id: ziran
uses: ziranlang/ziran/.github/actions/setup@d2db9d35feaf2a3278dc7bed571022b0e0323247
with:
fetch: 'true'
packages: build-essential pkg-config libssl-dev libcap-dev libbz2-dev libzstd-dev zlib1g-dev bubblewrap
- uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Enable private Linux test namespaces
run: |
sudo sysctl -w kernel.unprivileged_userns_clone=1
if sysctl kernel.apparmor_restrict_unprivileged_userns >/dev/null 2>&1; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
- name: Cache Cargo downloads and compiled dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
build/cargo-home/registry
build/cargo-home/git
codex-rs/target
key: xcoder-linux-${{ runner.arch }}-${{ hashFiles('codex-rs/Cargo.lock', 'codex-rs/rust-toolchain.toml', 'ziran.lock') }}
restore-keys: xcoder-linux-${{ runner.arch }}-
- name: Build and run the complete offline local suite
run: make test
- name: Package the tested Linux build and its native compiler
env:
ZIRAN_TOOLCHAIN: ${{ steps.ziran.outputs.root }}
run: python3 scripts/package-linux.py --toolchain "$ZIRAN_TOOLCHAIN"
- name: Test the relocated download
run: python3 tests/linux_package_test.py
- name: Upload Linux download
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: xcoder-linux-x86_64
path: |
build/xcoder-linux-x86_64.tar.gz
build/xcoder-linux-x86_64.tar.gz.sha256
if-no-files-found: error
retention-days: 30
+2
View File
@@ -1,4 +1,6 @@
# deps
ziran.local.toml
backup/
# Node.js dependencies
node_modules
.pnpm-store
+58
View File
@@ -2,4 +2,62 @@ The changelog can be found on the [releases page](https://github.com/openai/code
## Unreleased
- Local builds are faster. `make` builds a `local` profile (no cross-crate LTO, 16 codegen units, incremental, no debug info) whose final link spreads over many cores and needs a fraction of the memory; published releases keep the optimized `release` profile (`XCODER_CARGO_PROFILE=release`, set in CI).
- `codex-protocol`, which nearly every crate depends on, no longer waits for the network proxy to compile: the policy values it shares with the proxy live in a small `codex-network-policy` crate. The proxy was the slowest crate in the build (about 140 s), so its compile time now overlaps the rest.
- Line diffs, unified diff text and unified-diff parsing come from the Ziran `diff` package (`native/diff.zi`, `codex-utils-text-diff`) instead of `similar` and `diffy`; the turn diff, `apply_patch` results, the git baseline and the TUI diff view use it. Output matches `similar` byte for byte and parsing matches `diffy` on generated and damaged patches. The 100 ms diff deadline is now a deterministic work budget.
- The private git baseline repository is written and read with the Ziran `git` package instead of `gix`, and `SanitizedGitUrl` removes remote credentials with the package's port of gix-url's rules. `gix` and `gix-url` (about 40 crates) are no longer in the build, only in tests: the `git` CLI checks the objects (`git fsck --strict`), and gix-url is the oracle for 200,000 generated remotes.
- Builds no longer recompile most of the workspace every time: the Ziran build scripts watched the optional `ziran.local.toml`, and Cargo reruns a script on every build while a watched file is missing. The override is now watched only while it exists; touch `ziran.toml` after adding one.
- Make builds no longer cap themselves at 2 GiB of RAM in their own `xcoder-compilation.scope`: a release build that needs more spent hours in swap. They still run at nice 19 and the lowest I/O priority; memory limits come from the surrounding build queue. `XCODER_BUILD_SCOPE` is gone.
- The TUI header, `/status`, the session banner of `xcoder exec`, analytics and turn metadata show the Codex version Xcoder tracks (at least 0.169.0, following the newest upstream release) instead of `v0.0.0`; `xcoder --version` still shows Xcoder's own number.
- Windows support is removed. Gone: the Windows sandbox crates (restricted-token, elevated and MXC backends, their setup service and `codex sandbox windows`/`uninstall`), PowerShell and `cmd` shell support (including the tree-sitter PowerShell grammar), Windows-only code paths, the `[windows]` config and managed requirements, Windows hook commands and managed hook directories, Windows computer-use app rules, the Windows sandbox app-server requests and TUI prompts, the Windows standalone updater, and the Windows CI and installer scripts. Old config keys for these features are ignored.
- `apply_patch` recognizes its heredoc form (`apply_patch <<'EOF' ... EOF`, optionally after `cd <path> &&`) with Ziran instead of a tree-sitter query; tree-sitter is now only a test dependency of apply-patch. Heredoc bodies end at the exact delimiter line, as in Bash, so a patch line such as `EOFX` no longer cuts the patch short.
- Dangerous-command detection finds the commands in a shell script with Ziran (`native/shell.zi`): every command in lists, pipelines, subshells, groups, if/while/until/for/case and function bodies, `$(...)`, backticks, process substitutions, double quotes and unquoted heredoc bodies. It never misses a dangerous command tree-sitter found in a script Bash would run (40,000 generated scripts, 1,005 real ones), still ignores scripts Bash rejects, and also catches dangerous commands in real scripts tree-sitter could not parse.
- The check that a shell script is only plain commands joined by `&&`, `||`, `;`, `|` and newlines (the proof exec policy and the safe-command lists rely on) runs in Ziran (`native/shell.zi`) instead of walking a tree-sitter parse. It is never looser than tree-sitter: on 50,000 generated scripts it accepts nothing tree-sitter rejects and returns the same words, and on 1,005 real agent commands the two agree exactly.
- Streaming an `apply_patch` call no longer clones and reformats the whole patch for every few characters the model sends: the progress snapshot is rebuilt only when a delta completes a line, and the patch parser reads deltas line by line instead of one character at a time.
- Rules files (`.rules` exec policies) are parsed in Ziran (`native/execpolicy.zi`) instead of by a Starlark interpreter. The declarative subset they use still works: `prefix_rule`, `network_rule` and `host_executable` calls, `NAME = value` assignments, strings with Starlark escapes, lists, tuples, `None`/`True`/`False`, names and `+`. Functions, loops, conditions, `load` and f-strings are reported as unsupported with their line. The Starlark interpreter and about 60 crates it pulled in are gone.
- `apply_patch` applies an update in Ziran from start to end: it splits the file into line offsets, finds every hunk, and writes the new contents once, keeping each line's ending, instead of copying every line into a string several times. A 20-hunk update of a 50,000-line file takes 3.2 ms instead of 7.7 ms; results and error messages match the Rust code on 3,000 generated patches.
- `apply_patch` finds where each hunk goes with a Ziran matcher (`native/apply_patch.zi`) that borrows the file's lines instead of copying them. Answers are identical to the Rust matcher it replaces (checked against it on thousands of generated cases); on a 50,000-line file the whitespace- and punctuation-tolerant searches and searches that find nothing are 4-5x faster, exact matches cost about 0.4 ms more. `make benchmark-apply-patch` measures it.
- Parallel tool cells no longer fail at random with "Text file busy": starting a freshly compiled cell retries while another thread's fork still holds the file.
- The upstream Codex version check runs on its own thread, so a slow network never delays Xcoder exiting; the offline local tests turn it off.
- GPT-6.2-Sol (`gpt-6.2-sol`) is in the bundled model table, first, so it is the default when no model is configured even if the live catalog cannot be fetched. The entry is the provider's own (500,000-token context, efforts low to ultra, freeform `apply_patch`, code-mode-only tools, the `ultrafast` service tier, audio input). Before, a session whose catalog request timed out (the request has 5 s, including DNS) started on GPT-6.1-Sol, or ran GPT-6.2-Sol with fallback metadata and the warning "Model metadata for `gpt-6.2-sol` not found".
- The `new-model` skill (`skills/new-model/SKILL.md`) lists the steps for adopting a new model, with the checks that save time: logins with quota and DNS speed first, builds only through `make`, real turns started as soon as the binary exists. `scripts/model-turns.py` runs the 12 real turns (a plain answer, a shell call and a patch edit at each effort). `scripts/install-xcoder-remote.sh omega|delta` installs the locally installed build on Omega or Delta, renaming each file into place.
## 0.1.0 — 2026-11-14
First Xcoder release: Codex with native Ziran tool execution, for Linux x86_64.
- Installing replaces the previous binaries in place; the installer no longer keeps copies of them.
- Shell commands that run before the session's shell snapshot is written also put Xcoder's `apply_patch` ahead of a login profile's `PATH`; only snapshot restores replayed it before.
- Tool cells no longer fail with "unexpected end of file" when they exit: the callback channels a cell leaves unused now close quietly.
- The version Xcoder reports to the Codex service follows the newest upstream Codex release, not Xcoder's own version: at least 0.169.0, and newer once GitHub's latest `openai/codex` release says so (checked in the background at most every 20 hours, cached in `CODEX_HOME/xcoder-upstream-version.json`; `XCODER_UPSTREAM_VERSION_CHECK=0` turns the check off). The model catalog, the User-Agent and the `version` header all use it, so newer models such as GPT-6.1-Sol are listed and accepted; while requests said `0.0.0`, the service hid GPT-6.1-Sol and refused it.
- `xcoder --version` shows Xcoder's own release number.
- Remove parts Xcoder never uses under Harmony: the `cloud`, `tcp-tunnel`, `responses-api-proxy`, `exec-server` and `debug app-server` subcommands with their seven crates, the Ollama and LM Studio providers, and the AWS SDK behind Amazon Bedrock sign-in. `--oss` now stops at startup with an explanation instead of probing for local servers, and Bedrock selection reports that it is unavailable. About 22,000 lines and the AWS SDK dependency tree are gone.
- An idle Xcoder session gives its memory back. After two minutes without work (`XCODER_IDLE_RELEASE_SECONDS`; `0` turns it off) a watcher written in Ziran returns the allocator's free pages, moves private memory to swap and unmaps unmodified program pages. The session stays intact and pages back what its next event touches. `make benchmark-memory` measures a long offline session before and after.
- The TUI's replay copy of a finished command keeps only the start and end of output above 16 KiB; the live cell still holds the full output. Every command's output was held twice for the life of the session.
- Identify the running Xcoder CLI process as `xcode` on Linux, including when
compatibility launch paths retain their existing filenames.
- Shell commands run Xcoder's own `apply_patch`, even when a login profile resets `PATH` or puts another `apply_patch` first. A profile copy had dropped each added file's first line and written the rest twice.
- New standalone installations expose the `xcoder` command without adding a `codex` alias.
- Download tested Linux x86_64 Xcoder builds, including the native compiler, from the repository's Xcoder Linux workflow.
- Render Mermaid diagrams through the standalone Ziran `mermaid` package; the Rust crate is only its adapter, and the original renderer's snapshots and public-API tests run against it.
- Use the exact streamed custom tool input when a final snapshot disagrees with its deltas; reject mismatched completions and incomplete streams.
- Replace the TUI fuzzy matcher with a Ziran native implementation that streams the haystack and caches only the lowered needle.
- Bound GNU allocator arena retention while preserving owner settings; keep custom-cell compilation to one worker and support long private runtime paths.
- Execute ordinary tool plans through the precompiled Ziran executor and cache custom Zi2c cells; add matched offline JavaScript/native benchmarks.
- Xcoder executes tool programs natively from Ziran, with tool approvals, cancellation and saved session values.
- Certify installation only after the complete local test suite passes for the exact packaged executables; test pending parallel calls and recovery after callback errors.
- Fix missing command lifecycle events when unified exec cannot create a process, preserving approval rejection and sandbox retry behavior. Thanks @Marvinthebored ([#44557](https://github.com/openai/codex/issues/44557)).
+76
View File
@@ -0,0 +1,76 @@
LOCAL_RUST_BIN := $(CURDIR)/build/toolchain/bin
CARGO ?= $(if $(wildcard $(LOCAL_RUST_BIN)/cargo),$(LOCAL_RUST_BIN)/cargo,cargo)
RUSTC ?= $(if $(wildcard $(LOCAL_RUST_BIN)/rustc),$(LOCAL_RUST_BIN)/rustc,rustc)
ZIRAN ?= ziran
export CARGO_HOME := $(CURDIR)/build/cargo-home
export CARGO_TARGET_DIR := $(CURDIR)/codex-rs/target
export XCODER_RUNTIME_DIR := $(CURDIR)/build/native-runtime
export RUSTC ZIRAN
export CARGO_BUILD_JOBS ?= 1
# `local` (default) skips LTO for fast builds; published releases use `release`.
export XCODER_CARGO_PROFILE ?= local
# UI plugins retain their separate JavaScript sandbox; tool execution is native.
UI_FEATURES ?=
CARGO_FEATURE_FLAGS := $(if $(UI_FEATURES),--features $(UI_FEATURES),)
BACKGROUND_BUILD := python3 scripts/low-priority-build.py
.PHONY: all native-test native-test-build prebuild-tests test runtime-check install
all:
mkdir -p build/bin
$(BACKGROUND_BUILD) $(CARGO) build --manifest-path codex-rs/Cargo.toml --profile $(XCODER_CARGO_PROFILE) -p codex-cli -p codex-code-mode-host $(CARGO_FEATURE_FLAGS)
python3 scripts/package-xcoder.py
native-test-build:
mkdir -p build/native-dispatch
$(ZIRAN) build --project --target=c -o build/native-dispatch native/dispatch.zi
$(CC) -O3 -std=c99 -c build/native-dispatch/dispatch.c -I build/native-dispatch -o build/native-dispatch/dispatch.o
$(AR) rcs build/native-dispatch/libxcoder_dispatch.a build/native-dispatch/dispatch.o
$(BACKGROUND_BUILD) $(RUSTC) --edition=2024 --test tests/native_abi.rs -L build/native-dispatch -l static=xcoder_dispatch -o build/native-dispatch/native-abi-test
$(BACKGROUND_BUILD) $(RUSTC) --edition=2024 --test tests/native_allocator.rs -o build/native-dispatch/native-allocator-test
rm -rf build/native-idle && mkdir -p build/native-idle
$(ZIRAN) build --project --target=c -o build/native-idle native/idle.zi
$(CC) -O3 -std=c99 -c build/native-idle/idle.c -I build/native-idle -o build/native-idle/idle.o
$(AR) rcs build/native-idle/libxcoder_idle.a build/native-idle/idle.o
$(BACKGROUND_BUILD) $(RUSTC) --edition=2024 --test tests/native_idle.rs -L build/native-idle -l static=xcoder_idle -o build/native-dispatch/native-idle-test
native-test: native-test-build
build/native-dispatch/native-abi-test
build/native-dispatch/native-allocator-test
build/native-dispatch/native-idle-test
XCODER_ZIRAN_TOOLCHAIN="$$($(ZIRAN) pkg path ziran)" python3 tests/native_cell_test.py
prebuild-tests: native-test-build
$(BACKGROUND_BUILD) python3 scripts/prebuild-tests.py --cargo "$(CARGO)"
runtime-check:
$(BACKGROUND_BUILD) $(CARGO) check --manifest-path codex-rs/Cargo.toml -p codex-code-mode-runtime
test:
$(BACKGROUND_BUILD) python3 scripts/test-xcoder.py --cargo "$(CARGO)" --ui-features "$(UI_FEATURES)"
install:
python3 scripts/install-xcoder.py
JAVASCRIPT_HOST ?= $(HOME)/.codex/packages/standalone/current/bin/codex-code-mode-host.javascript
JAVASCRIPT_CLI ?= $(HOME)/.codex/packages/standalone/current/bin/codex-upstream
.PHONY: benchmark-source benchmark-plan benchmark-fuzzy benchmark-memory benchmark-apply-patch
benchmark-json:
python3 scripts/benchmark-runtime.py --native-host build/bin/codex-code-mode-host --javascript-host "$(JAVASCRIPT_HOST)" --diagnose-json
benchmark-source:
python3 scripts/benchmark-runtime.py --native-host build/bin/codex-code-mode-host --native-cli build/bin/xcoder --javascript-host "$(JAVASCRIPT_HOST)" --javascript-cli "$(JAVASCRIPT_CLI)" --native-mode source
benchmark-plan:
python3 scripts/benchmark-runtime.py --native-host build/bin/codex-code-mode-host --native-cli build/bin/xcoder --javascript-host "$(JAVASCRIPT_HOST)" --javascript-cli "$(JAVASCRIPT_CLI)" --native-mode plan
# A long offline session: memory per tool call, the idle footprint, and the
# footprint and wake time after the idle release.
benchmark-memory:
python3 scripts/benchmark-memory.py --cli build/bin/xcoder --calls 150 --idle-seconds 5 --release-wait 30 --environment XCODER_IDLE_RELEASE_SECONDS=15 --output build/memory/benchmark.json
benchmark-apply-patch:
$(CARGO) test --manifest-path codex-rs/Cargo.toml --release -p codex-apply-patch --lib -- --ignored --nocapture bench
benchmark-fuzzy:
$(CARGO) run --manifest-path codex-rs/Cargo.toml --release -p codex-utils-fuzzy-match --example fuzzy_bench
.PHONY: mermaid-test
MERMAID_LOCKED := $(if $(wildcard ziran.local.toml),,--locked)
mermaid-test:
$(MAKE) -C "$$($(ZIRAN) pkg path mermaid $(MERMAID_LOCKED))" test ZIRAN="$(ZIRAN)"
$(BACKGROUND_BUILD) $(CARGO) test --manifest-path codex-rs/Cargo.toml -p codex-mermaid --lib
+5
View File
@@ -1,6 +1,11 @@
OpenAI Codex
Copyright 2025 OpenAI
Xcoder fork modifications
Copyright 2026 Waozi <[email protected]>
This fork changes tool orchestration to native Ziran/Zi2c execution with
embedded Rust supervision. The original license and upstream notices remain.
This project includes code derived from [Ratatui](https://github.com/ratatui/ratatui), licensed under the MIT license.
Copyright (c) 2016-2022 Florian Dehau
Copyright (c) 2023-2025 The Ratatui Developers
+75 -10
View File
@@ -1,3 +1,78 @@
## Xcoder
For automatic Linux builds and downloads, see
[Xcoder Linux](https://github.com/waozixyz/xcoder/actions/workflows/xcoder-linux.yml).
Xcoder is Waozi's source fork of OpenAI Codex, under the original Apache 2.0
license. Tool orchestration uses Ziran compiled through Zi2c. Ordinary plans run
through an executor linked into Rust, without a compiler or child process.
Custom Ziran cells compile on a cache miss and reuse private cached executables.
The Rust session
and approval protocols remain the authority for host operations. JavaScript
tool cells have no execution path in this fork. Sessions share the Rust process;
only custom native cells start sandboxed children. Ordinary tool calls do not
start a separate code-mode host. The optional JavaScript UI plugin renderer is
excluded from the default build (`UI_FEATURES=codex-code-mode-runtime/ui` enables
it when the corresponding upstream V8 artifacts are available).
The initial native backend targets Linux with bubblewrap, a C compiler, Rust
1.95 and a built Ziran toolchain. `ziran lock` resolves the pinned toolchain;
local development uses an ignored `ziran.local.toml` override.
The Make targets run Rust work at nice 19 and the lowest best-effort I/O priority, with one
Cargo job by default (set `CARGO_BUILD_JOBS` to use more). They add no memory limit of their
own; run them under a build queue or scope that sizes memory for the machine. Completed
artifacts are reused when a build is resumed.
Run `make test` for Rust/C ABI, Ziran-backed Mermaid and fuzzy-match, native
sandbox, callback, host transport and offline full-CLI local tests. The CLI fixture runs a real shell tool through the
embedded supervisor without contacting an external model service.
`make` builds the CLI at `build/bin/xcoder` with its adjacent tool host.
`make test` writes an installation receipt only after the full local suite passes;
a failed rerun removes the earlier receipt. `make install` verifies the exact binaries and preserves
Harmony's existing launcher, accounts and histories. It replaces the launcher's
Codex executable for new invocations; running sessions are not restarted.
Local interactive launches use the embedded server so an older stock Codex
daemon cannot supply their tool runtime. Explicit remote endpoints keep their
normal behavior.
Update this fork from its source with `make test` and `make install`; the stock
Codex package updater cannot replace the installed native fork.
Prefer a JSON tool plan for ordinary calls:
```json
{"calls":[{"tool":"exec_command","input":{"cmd":"pwd"}}]}
```
Plans validate structure, tool names and freeform input types before execution;
each tool validates its own arguments. Results include the call index and tool
name. Add `"parallel":true` for up to four independent calls at
once. A plan supports up to 128 calls; dependent steps use a later cell or custom
code. This path works without the compiler installed.
Custom native cells import `xcoder/runtime`. `Call(name, json)` returns caller-owned
storage: inspect `Body(*reply)` and release it with `defer Release(*reply)`.
`Text`, `Image`, `Audio`, `Notify`, `Store`, `Load`, `Catalog` and `Yield` provide
output and session state. `CallBatch` runs arrays of `BatchCall` on up to four
explicit threads, then joins them; release each result after use. A native cell has only its executable and callback
socket; the compiler has only its binaries, headers, standard library and cell
sources. Tool errors never fall back to JavaScript.
The custom-cell cache holds at most 64 executables and 256 MiB on disk.
Files default to `~/.local/state/xcoder/runtime/cache`; an explicit
`XCODER_RUNTIME_DIR` keeps its selected location. Cache keys include source,
the runtime API, sandbox/compiler settings, toolchain inputs and the C compiler.
Executables are verified before reuse; corruption triggers recompilation.
`scripts/benchmark-runtime.py --help` describes the offline comparison with
preserved JavaScript binaries. It records raw samples, hashes, CPU time,
process-tree proportional RAM and latency under ignored `backup/runtime-benchmark/`.
Use `--native-mode source` for custom cells and `--native-mode plan` for ordinary
calls. Compilation and sandbox startup are included; model inference is excluded.
The fork retains upstream documentation below.
---
<p align="center"><strong>Codex CLI</strong> is a coding agent from OpenAI that runs locally on your computer.
<p align="center">
<img src="https://github.com/openai/codex/blob/main/.github/codex-cli-splash.png" alt="Codex CLI splash" width="80%" />
@@ -19,22 +94,12 @@ Run the following on Mac or Linux to install Codex CLI:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
```
Run the following on Windows to install Codex CLI:
```shell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
```
The standalone installers download from `https://releases.openai.com/codex` by default and fall back to GitHub Releases if a metadata or asset download is unavailable. To force GitHub Releases, set `CODEX_INSTALLER_USE_RELEASES_OPENAI_COM` to `false` (`0` and `no` are also accepted):
```shell
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false sh
```
```powershell
$env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iex
```
Codex CLI can also be installed via the following package managers:
```shell
+2 -4
View File
@@ -1,11 +1,9 @@
[advisories]
# Reviewed 2026-07-02. Keep this list in sync with ../deny.toml.
ignore = [
"RUSTSEC-2024-0388", # derivative 2.2.0 via starlark/starlark_syntax; upstream crate is unmaintained
"RUSTSEC-2024-0449", # unsafe-libyaml via serde_yaml in skills, ext/skills, core-plugins, external-agent-migration; remove when migrated off serde_yaml/unsafe-libyaml
"RUSTSEC-2025-0057", # fxhash 0.2.1 via starlark_map/bm25; upstream crate is unmaintained
"RUSTSEC-2024-0436", # paste 1.0.15 via starlark/v8; upstream crate is unmaintained
"RUSTSEC-2023-0089", # atomic-polyfill via postcard/heapless/pagable; upstream crate is unmaintained
"RUSTSEC-2025-0057", # fxhash 0.2.1 via bm25; upstream crate is unmaintained
"RUSTSEC-2024-0436", # paste 1.0.15 via v8; upstream crate is unmaintained
"RUSTSEC-2024-0320", # yaml-rust via syntect; remove when syntect drops or updates it
"RUSTSEC-2025-0141", # bincode via syntect; remove when syntect drops or updates it
"RUSTSEC-2026-0118", # hickory-proto via rama-dns/rama-tcp; remove when rama updates to hickory 0.26.1 or hickory-net
+201 -1683
View File
File diff suppressed because it is too large. Load diff
+28 -32
View File
@@ -20,7 +20,6 @@ members = [
"app-server-client",
"app-server-protocol",
"app-server-protocol-noop-macros",
"app-server-test-client",
"apply-patch",
"arg0",
"feedback",
@@ -34,9 +33,6 @@ members = [
"plugin-host",
"codex-home",
"cloud-config",
"cloud-tasks",
"cloud-tasks-client",
"cloud-tasks-mock-client",
"cli",
"collaboration-mode-templates",
"connectors",
@@ -46,6 +42,7 @@ members = [
"shell-command",
"skills",
"core",
"core-config",
"core-api",
"core-plugin-common",
"core-plugins",
@@ -60,7 +57,6 @@ members = [
"file-system",
"exec-server-protocol",
"exec-server",
"exec-server-cli",
"exec-server/tests/support",
"execpolicy",
"ext/agent",
@@ -86,7 +82,6 @@ members = [
"file-search",
"file-watcher",
"linux-sandbox",
"lmstudio",
"login",
"codex-mcp",
"memories/read",
@@ -95,10 +90,9 @@ members = [
"message-board",
"message-board-mcp",
"model-provider-info",
"mxc-sandbox",
"models-manager",
"network-policy",
"network-proxy",
"ollama",
"process-hardening",
"realtime-webrtc",
"voice-host",
@@ -108,22 +102,18 @@ members = [
"rollout",
"rollout-trace",
"rmcp-client",
"responses-api-proxy",
"runtime-agent-instance",
"response-debug-context",
"sandboxing",
"stdio-to-uds",
"otel",
"otel-trace-websocket",
"tcp-tunnel",
"tui",
"user-verification",
"tools",
"v8-poc",
"websocket-auth",
"websocket-client",
"windows-sandbox-rs/tests/support",
"windows-sandbox-service",
"worktree",
"workload-identity",
"utils/absolute-path",
@@ -144,6 +134,7 @@ members = [
"utils/redacted-string",
"utils/rustls-provider",
"utils/string",
"utils/text-diff",
"utils/cli",
"utils/elapsed",
"utils/sandbox-summary",
@@ -198,7 +189,6 @@ codex-app-server-daemon = { path = "app-server-daemon" }
codex-app-server-client = { path = "app-server-client" }
codex-app-server-protocol = { path = "app-server-protocol" }
codex-app-server-protocol-noop-macros = { path = "app-server-protocol-noop-macros" }
codex-app-server-test-client = { path = "app-server-test-client" }
codex-apply-patch = { path = "apply-patch" }
codex-arg0 = { path = "arg0" }
codex-async-utils = { path = "async-utils" }
@@ -208,8 +198,6 @@ codex-chatgpt = { path = "chatgpt" }
codex-client = { path = "codex-client" }
codex-collaboration-mode-templates = { path = "collaboration-mode-templates" }
codex-cloud-config = { path = "cloud-config" }
codex-cloud-tasks-client = { path = "cloud-tasks-client" }
codex-cloud-tasks-mock-client = { path = "cloud-tasks-mock-client" }
codex-code-mode = { path = "code-mode" }
codex-code-mode-protocol = { path = "code-mode-protocol" }
codex-code-mode-runtime = { path = "code-mode-runtime" }
@@ -228,6 +216,7 @@ codex-message-board-mcp = { path = "message-board-mcp" }
codex-connectors-extension = { path = "ext/connectors" }
codex-context-fragments = { path = "context-fragments" }
codex-core = { path = "core" }
codex-core-config = { path = "core-config" }
codex-core-api = { path = "core-api" }
codex-core-plugin-common = { path = "core-plugin-common" }
codex-core-plugins = { path = "core-plugins" }
@@ -237,7 +226,6 @@ codex-exec = { path = "exec" }
codex-file-system = { path = "file-system" }
codex-exec-server-protocol = { path = "exec-server-protocol" }
codex-exec-server = { path = "exec-server" }
codex-exec-server-cli = { path = "exec-server-cli" }
codex-exec-server-test-support = { path = "exec-server/tests/support" }
codex-execpolicy = { path = "execpolicy" }
codex-extension-api = { path = "ext/extension-api" }
@@ -263,7 +251,6 @@ codex-hooks = { path = "hooks" }
codex-history = { path = "history" }
codex-keyring-store = { path = "keyring-store" }
codex-linux-sandbox = { path = "linux-sandbox" }
codex-lmstudio = { path = "lmstudio" }
codex-login = { path = "login" }
codex-mermaid = { path = "mermaid" }
codex-message-history = { path = "message-history" }
@@ -275,9 +262,8 @@ codex-mcp = { path = "codex-mcp" }
codex-mcp-extension = { path = "ext/mcp" }
codex-model-provider-info = { path = "model-provider-info" }
codex-models-manager = { path = "models-manager" }
codex-mxc-sandbox = { path = "mxc-sandbox" }
codex-network-policy = { path = "network-policy" }
codex-network-proxy = { path = "network-proxy" }
codex-ollama = { path = "ollama" }
codex-otel = { path = "otel" }
codex-otel-trace-websocket = { path = "otel-trace-websocket" }
codex-plugin = { path = "plugin" }
@@ -287,7 +273,6 @@ codex-protocol = { path = "protocol" }
codex-protocol-test-support = { path = "protocol/tests/support" }
codex-prompts = { path = "prompts" }
codex-queue-extension = { path = "ext/queue" }
codex-responses-api-proxy = { path = "responses-api-proxy" }
codex-response-debug-context = { path = "response-debug-context" }
codex-rmcp-client = { path = "rmcp-client" }
codex-rollout = { path = "rollout" }
@@ -304,7 +289,6 @@ codex-terminal-detection = { path = "terminal-detection" }
codex-test-binary-support = { path = "test-binary-support" }
codex-thread-store = { path = "thread-store" }
codex-tools = { path = "tools" }
codex-tcp-tunnel = { path = "tcp-tunnel" }
codex-tui = { path = "tui" }
codex-uds = { path = "uds" }
codex-utils-absolute-path = { path = "utils/absolute-path" }
@@ -335,12 +319,11 @@ codex-worktree = { path = "worktree" }
codex-utils-sleep-inhibitor = { path = "utils/sleep-inhibitor" }
codex-utils-stream-parser = { path = "utils/stream-parser" }
codex-utils-string = { path = "utils/string" }
codex-utils-text-diff = { path = "utils/text-diff" }
codex-utils-template = { path = "utils/template" }
codex-user-verification = { path = "user-verification" }
codex-v8-poc = { path = "v8-poc" }
codex-workload-identity = { path = "workload-identity" }
codex-windows-sandbox = { path = "windows-sandbox-rs" }
codex-windows-sandbox-test-support = { path = "windows-sandbox-rs/tests/support" }
core_test_support = { path = "core/tests/common" }
# External
@@ -354,12 +337,8 @@ assert_matches = "1.5.0"
async-channel = "2.3.1"
async-io = "2.6.0"
async-stream = "0.3.6"
aws-config = "1"
aws-credential-types = "1"
aws-sigv4 = "1"
aws-smithy-runtime-api = { version = "1", features = ["client", "http-1x"] }
aws-smithy-types = { version = "1", features = ["http-body-1-x"] }
aws-types = "1"
axum = { version = "0.8", default-features = false }
base64 = "0.22.1"
bitflags = "2.13.1"
@@ -437,7 +416,6 @@ maplit = "1.0.2"
memchr = "2.7.6"
mime_guess = "2.0.5"
multimap = "0.10.0"
mxc-sdk = { git = "https://github.com/microsoft/mxc", rev = "b21120168d70befe12356411423266bfef168446" }
notify = "8.2.0"
nucleo = { git = "https://github.com/helix-editor/nucleo.git", rev = "4253de9faabb4e5c6d81d946a5e35a90f87347ee" }
once_cell = "1.20.2"
@@ -520,7 +498,6 @@ sqlx = { version = "=0.9.0", default-features = false, features = [
sqlx-macros = { version = "=0.9.0", default-features = false, features = ["derive", "migrate"] }
# Preserve the target driver's query-description support without building it on the host.
sqlx-sqlite = { version = "=0.9.0", default-features = false, features = ["offline"] }
starlark = { version = "0.14.2", default-features = false }
strum = "0.27.2"
strum_macros = "0.28.0"
supports-color = "3.0.2"
@@ -555,10 +532,8 @@ tonic = { version = "0.14.3", default-features = false, features = ["channel", "
tonic-prost = "0.14.3"
tree-sitter = "0.25.10"
tree-sitter-bash = "0.25"
tree-sitter-powershell = "=0.26.4"
ts-rs = "11"
tungstenite = { version = "0.27.0", features = ["deflate", "proxy"] }
uds_windows = "1.1.0"
unicode-linebreak = "0.1.5"
unicode-normalization = "0.1.25"
unicode-segmentation = "1.12.0"
@@ -574,7 +549,6 @@ webbrowser = "1.2.2"
which = "8"
whoami = "1.6.1"
wildmatch = "2.6.1"
winapi-util = "0.1.11"
windows-sys = "0.61.2"
winreg = "0.55.0"
# Keep the zip 2.x feature set. In zip 9, `bzip2-rs` selects the bzip2-sys
@@ -666,6 +640,28 @@ strip = false
# Balance parallel release code generation against binary size.
codegen-units = 4
# The TUI is a very large crate and can otherwise exhaust constrained builders
# during release code generation. Keep its runtime-independent presentation
# layer cheap to compile while the core remains optimized.
[profile.release.package.codex-tui]
opt-level = 0
codegen-units = 256
# Local builds (`make`; XCODER_CARGO_PROFILE=local): no cross-crate LTO and
# more codegen units, so the final link and the largest crates spread over
# more cores and need far less memory. Published release builds keep the
# `release` profile (XCODER_CARGO_PROFILE=release).
[profile.local]
inherits = "release"
lto = false
codegen-units = 16
debug = false
incremental = true
[profile.local.package.codex-tui]
opt-level = 0
codegen-units = 256
[profile.profiling]
inherits = "release"
debug = "full"
@@ -25,7 +25,6 @@ pub(crate) fn append_payload(path: &Path, payload: &TrackEventsRequest) -> io::R
fn open_capture_file(path: &Path) -> io::Result<File> {
let mut options = OpenOptions::new();
options.create(true).append(true);
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
options.mode(0o600);
-2
View File
@@ -327,7 +327,6 @@ fn analytics_destination_uses_explicit_capture_file() {
fs::read_to_string(&capture_path).expect("read capture file"),
""
);
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
@@ -924,7 +923,6 @@ fn track_response_only_enqueues_analytics_relevant_responses() {
assert!(matches!(receiver.try_recv(), Err(TryRecvError::Empty)));
}
#[cfg(unix)]
#[test]
fn track_response_ignores_unserializable_thread_responses() {
use std::ffi::OsString;
+1 -1
View File
@@ -1579,7 +1579,7 @@ pub(crate) fn current_runtime_metadata() -> CodexRuntimeMetadata {
static OS_INFO: LazyLock<os_info::Info> = LazyLock::new(os_info::get);
let os_info = &*OS_INFO;
CodexRuntimeMetadata {
codex_rs_version: env!("CARGO_PKG_VERSION").to_string(),
codex_rs_version: codex_protocol::client_version::reported_client_version().to_string(),
runtime_os: std::env::consts::OS.to_string(),
runtime_os_version: os_info.version().to_string(),
runtime_arch: std::env::consts::ARCH.to_string(),
@@ -83,17 +83,10 @@ fn normalize_path_for_skill_id_repo_root_not_in_skill_path_uses_absolute_path()
/// Foreign paths keep native telemetry spelling without depending on host filesystem lookup.
#[test]
fn normalize_path_for_skill_id_foreign_path_uses_native_spelling() {
let (uri, expected) = if cfg!(windows) {
(
"file:///Users/abc/.codex/skills/doc%20%23/SKILL.md",
"/Users/abc/.codex/skills/doc #/SKILL.md",
)
} else {
(
"file:///C:/Users/abc/.codex/skills/doc%20%23/SKILL.md",
"C:/Users/abc/.codex/skills/doc #/SKILL.md",
)
};
let (uri, expected) = (
"file:///C:/Users/abc/.codex/skills/doc%20%23/SKILL.md",
"C:/Users/abc/.codex/skills/doc #/SKILL.md",
);
let path = normalize_path_for_skill_id(
/*repo_url*/ None,
/*repo_root*/ None,
+143 -143
View File
@@ -314,149 +314,6 @@ async fn cua_tool_call_lifecycle_requires_a_start_and_deduplicates_replay() {
);
}
#[tokio::test]
async fn item_lifecycle_notifications_publish_command_execution_event() {
let mut reducer = AnalyticsReducer::default();
let mut events = Vec::new();
ingest_review_prerequisites(&mut reducer, &mut events).await;
reducer
.ingest(
AnalyticsFact::Notification(Box::new(sample_turn_started_notification(
"thread-1", "turn-1",
))),
&mut events,
)
.await;
for model in ["invoking-model", "later-model"] {
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemStarted(
ItemStartedNotification::new(
"thread-1".to_string(),
"turn-1".to_string(),
{
let mut item = sample_command_execution_item(
CommandExecutionStatus::InProgress,
/*exit_code*/ None,
/*duration_ms*/ None,
);
if let ThreadItemPayload::CommandExecution { model_context, .. } =
&mut item
{
*model_context =
Some(codex_protocol::items::ModelInvocationContext {
model_slug: model.to_string(),
reasoning_effort: Some("max".to_string()),
});
}
item
},
/*started_at_ms*/ 1_000,
),
))),
&mut events,
)
.await;
}
assert!(
events.is_empty(),
"tool item event should emit on completion"
);
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemCompleted(
ItemCompletedNotification::new(
"thread-1".to_string(),
"turn-1".to_string(),
sample_command_execution_item_with_actions(
CommandExecutionStatus::Completed,
Some(0),
Some(42),
vec![
CommandAction::Read {
command: "cat README.md".to_string(),
name: "README.md".to_string(),
path: test_path_buf("/tmp/README.md").abs().into(),
},
CommandAction::ListFiles {
command: "ls".to_string(),
path: None,
},
CommandAction::Search {
command: "rg TODO".to_string(),
query: Some("TODO".to_string()),
path: None,
},
CommandAction::Unknown {
command: "cargo test".to_string(),
},
],
Some("sample@openai-curated"),
Some("scripts/run.py"),
Some(SandboxType::WindowsMxc),
),
/*started_at_ms*/ None,
/*completed_at_ms*/ 1_045,
),
))),
&mut events,
)
.await;
let payload = serde_json::to_value(&events).expect("serialize events");
assert_eq!(payload.as_array().expect("events array").len(), 1);
assert_eq!(payload[0]["event_params"]["model_slug"], "invoking-model");
assert_eq!(payload[0]["event_params"]["sandbox_backend"], "windows_mxc");
assert_eq!(payload[0]["event_params"]["reasoning_effort"], "max");
assert_eq!(payload[0]["event_type"], "codex_command_execution_event");
assert_eq!(payload[0]["event_params"]["thread_id"], "thread-1");
assert_eq!(payload[0]["event_params"]["session_id"], "session-thread-1");
assert_eq!(payload[0]["event_params"]["turn_id"], "turn-1");
assert_eq!(payload[0]["event_params"]["item_id"], "item-1");
assert_eq!(payload[0]["event_params"]["tool_name"], "shell");
assert_eq!(
payload[0]["event_params"]["plugin_id"],
"sample@openai-curated"
);
assert_eq!(payload[0]["event_params"]["script_path"], "scripts/run.py");
assert_eq!(
payload[0]["event_params"]["command_execution_source"],
"agent"
);
assert_eq!(payload[0]["event_params"]["terminal_status"], "completed");
assert_eq!(
payload[0]["event_params"]["final_approval_outcome"],
"unknown"
);
assert_eq!(
payload[0]["event_params"]["failure_kind"],
serde_json::Value::Null
);
assert_eq!(payload[0]["event_params"]["exit_code"], 0);
assert_eq!(payload[0]["event_params"]["command_total_action_count"], 4);
assert_eq!(payload[0]["event_params"]["command_read_action_count"], 1);
assert_eq!(
payload[0]["event_params"]["command_list_files_action_count"],
1
);
assert_eq!(payload[0]["event_params"]["command_search_action_count"], 1);
assert_eq!(
payload[0]["event_params"]["command_unknown_action_count"],
1
);
assert_eq!(payload[0]["event_params"]["started_at_ms"], 1_000);
assert_eq!(payload[0]["event_params"]["completed_at_ms"], 1_045);
assert_eq!(payload[0]["event_params"]["duration_ms"], 45);
assert_eq!(payload[0]["event_params"]["execution_duration_ms"], 42);
assert_eq!(
payload[0]["event_params"]["app_server_client"]["client_name"],
"codex-tui"
);
assert_eq!(payload[0]["event_params"]["thread_source"], "user");
}
#[tokio::test]
async fn collaborator_tool_events_keep_response_ids_when_completion_races_sampling() {
for response_first in [false, true] {
@@ -1038,3 +895,146 @@ async fn image_generation_events_preserve_transparent_background_metadata() {
assert_eq!(payload["event_params"]["terminal_status"], json!(status));
}
}
#[tokio::test]
async fn item_lifecycle_notifications_publish_command_execution_event() {
let mut reducer = AnalyticsReducer::default();
let mut events = Vec::new();
ingest_review_prerequisites(&mut reducer, &mut events).await;
reducer
.ingest(
AnalyticsFact::Notification(Box::new(sample_turn_started_notification(
"thread-1", "turn-1",
))),
&mut events,
)
.await;
for model in ["invoking-model", "later-model"] {
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemStarted(
ItemStartedNotification::new(
"thread-1".to_string(),
"turn-1".to_string(),
{
let mut item = sample_command_execution_item(
CommandExecutionStatus::InProgress,
/*exit_code*/ None,
/*duration_ms*/ None,
);
if let ThreadItemPayload::CommandExecution { model_context, .. } =
&mut item
{
*model_context =
Some(codex_protocol::items::ModelInvocationContext {
model_slug: model.to_string(),
reasoning_effort: Some("max".to_string()),
});
}
item
},
/*started_at_ms*/ 1_000,
),
))),
&mut events,
)
.await;
}
assert!(
events.is_empty(),
"tool item event should emit on completion"
);
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemCompleted(
ItemCompletedNotification::new(
"thread-1".to_string(),
"turn-1".to_string(),
sample_command_execution_item_with_actions(
CommandExecutionStatus::Completed,
Some(0),
Some(42),
vec![
CommandAction::Read {
command: "cat README.md".to_string(),
name: "README.md".to_string(),
path: test_path_buf("/tmp/README.md").abs().into(),
},
CommandAction::ListFiles {
command: "ls".to_string(),
path: None,
},
CommandAction::Search {
command: "rg TODO".to_string(),
query: Some("TODO".to_string()),
path: None,
},
CommandAction::Unknown {
command: "cargo test".to_string(),
},
],
Some("sample@openai-curated"),
Some("scripts/run.py"),
Some(SandboxType::LinuxSeccomp),
),
/*started_at_ms*/ None,
/*completed_at_ms*/ 1_045,
),
))),
&mut events,
)
.await;
let payload = serde_json::to_value(&events).expect("serialize events");
assert_eq!(payload.as_array().expect("events array").len(), 1);
assert_eq!(payload[0]["event_params"]["model_slug"], "invoking-model");
assert_eq!(payload[0]["event_params"]["sandbox_backend"], "seccomp");
assert_eq!(payload[0]["event_params"]["reasoning_effort"], "max");
assert_eq!(payload[0]["event_type"], "codex_command_execution_event");
assert_eq!(payload[0]["event_params"]["thread_id"], "thread-1");
assert_eq!(payload[0]["event_params"]["session_id"], "session-thread-1");
assert_eq!(payload[0]["event_params"]["turn_id"], "turn-1");
assert_eq!(payload[0]["event_params"]["item_id"], "item-1");
assert_eq!(payload[0]["event_params"]["tool_name"], "shell");
assert_eq!(
payload[0]["event_params"]["plugin_id"],
"sample@openai-curated"
);
assert_eq!(payload[0]["event_params"]["script_path"], "scripts/run.py");
assert_eq!(
payload[0]["event_params"]["command_execution_source"],
"agent"
);
assert_eq!(payload[0]["event_params"]["terminal_status"], "completed");
assert_eq!(
payload[0]["event_params"]["final_approval_outcome"],
"unknown"
);
assert_eq!(
payload[0]["event_params"]["failure_kind"],
serde_json::Value::Null
);
assert_eq!(payload[0]["event_params"]["exit_code"], 0);
assert_eq!(payload[0]["event_params"]["command_total_action_count"], 4);
assert_eq!(payload[0]["event_params"]["command_read_action_count"], 1);
assert_eq!(
payload[0]["event_params"]["command_list_files_action_count"],
1
);
assert_eq!(payload[0]["event_params"]["command_search_action_count"], 1);
assert_eq!(
payload[0]["event_params"]["command_unknown_action_count"],
1
);
assert_eq!(payload[0]["event_params"]["started_at_ms"], 1_000);
assert_eq!(payload[0]["event_params"]["completed_at_ms"], 1_045);
assert_eq!(payload[0]["event_params"]["duration_ms"], 45);
assert_eq!(payload[0]["event_params"]["execution_duration_ms"], 42);
assert_eq!(
payload[0]["event_params"]["app_server_client"]["client_name"],
"codex-tui"
);
assert_eq!(payload[0]["event_params"]["thread_source"], "user");
}
+64 -1
View File
@@ -7,6 +7,7 @@ use crate::TypedRequestError;
use codex_app_server_protocol::ClientNotification;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_app_server_protocol::ModelListParams;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::Result as JsonRpcResult;
use codex_app_server_protocol::Turn;
@@ -62,6 +63,7 @@ pub struct CloudCommand {
#[derive(Clone)]
pub struct CloudRequestHandle {
commands: mpsc::Sender<CloudCommand>,
catalog: Option<Arc<codex_cloud_client::Client>>,
}
/// Tracks only losses queued for delivery. The worker remains the sole owner
@@ -126,13 +128,27 @@ impl CloudClient {
Self,
mpsc::Receiver<CloudCommand>,
mpsc::UnboundedSender<AppServerEvent>,
) {
Self::channel_with_catalog(capacity, /*catalog*/ None)
}
pub(super) fn channel_with_catalog(
capacity: usize,
catalog: Option<codex_cloud_client::Client>,
) -> (
Self,
mpsc::Receiver<CloudCommand>,
mpsc::UnboundedSender<AppServerEvent>,
) {
let (commands, receiver) = mpsc::channel(capacity.max(1));
let (events, event_receiver) = mpsc::unbounded_channel();
(
Self {
stream_losses: CloudStreamLosses::default(),
handle: CloudRequestHandle { commands },
handle: CloudRequestHandle {
commands,
catalog: catalog.map(Arc::new),
},
events: event_receiver,
},
receiver,
@@ -191,6 +207,47 @@ impl CloudClient {
}
impl CloudRequestHandle {
/// Whether a completed model read still belongs to the bound Cloud account.
pub fn model_catalog_is_current(&self) -> bool {
self.catalog
.as_ref()
.is_none_or(|catalog| catalog.model_catalog_is_current())
}
async fn model_list(
catalog: &codex_cloud_client::Client,
params: &ModelListParams,
) -> RequestResult {
if params.model_provider.is_some() {
return Err(JSONRPCErrorError {
code: -32602,
message: "Cloud model discovery uses the server's model provider.".into(),
data: None,
});
}
let result = async {
let body = catalog
.list_models(
params.cursor.as_deref(),
params.limit,
params.include_hidden,
)
.await
.map_err(|error| error.to_string())?;
if !catalog.model_catalog_is_current() {
return Err("Cloud model catalog account changed.".into());
}
serde_json::from_slice(&body)
.map_err(|_| "Invalid Cloud model catalog response.".into())
}
.await;
result.map_err(|message| JSONRPCErrorError {
code: -32000,
message,
data: None,
})
}
pub(crate) async fn start_project_thread(
&self,
request_id: RequestId,
@@ -242,6 +299,12 @@ impl CloudRequestHandle {
}
pub(crate) async fn request(&self, request: ClientRequest) -> io::Result<RequestResult> {
// Catalog reads must not occupy the serialized send and attachment lane.
if let (Some(catalog), ClientRequest::ModelList { params, .. }) = (&self.catalog, &request)
{
// Keep the catalog HTTP state out of the shared request future.
return Ok(Box::pin(Self::model_list(catalog, params)).await);
}
self.send(CloudOperation::Request(Box::new(request))).await
}
@@ -5,6 +5,147 @@
use super::*;
use futures::stream;
use pretty_assertions::assert_eq;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test]
async fn failed_archive_loaded_list_tracks_attachment_not_cached_metadata() -> Result<()> {
let server = MockServer::start().await;
let home = tempfile::tempdir()?;
let config = crate::legacy_core::config::ConfigBuilder::default()
.codex_home(home.path().to_owned())
.fallback_cwd(Some(home.path().to_owned()))
.without_project_context()
.build()
.await?;
let cached = Box::new(serde_json::from_value::<protocol::ThreadResumeResponse>(
serde_json::json!({
"thread": {
"id": "t", "sessionId": "t", "preview": "", "ephemeral": false,
"modelProvider": "openai", "createdAt": 0, "updatedAt": 0,
"status": {"type": "idle"}, "cwd": home.path(), "cliVersion": "",
"source": "cli", "turns": [],
},
"model": "test", "modelProvider": "openai", "cwd": home.path(),
"approvalPolicy": "never", "approvalsReviewer": "user",
"sandbox": {"type": "readOnly"},
}),
)?);
let mut requests = requests::Requests {
client: cloud::Client::new(
&config.http_client_factory(),
&server.uri(),
cloud::Credentials::new("synthetic-bearer", "synthetic-account")?,
)?,
account: protocol::GetAccountResponse {
user_id: None,
account: None,
requires_openai_auth: true,
workspace_routing: None,
},
loaded: Some(cached.clone()),
warned_partial_history: None,
};
let (output, mut notifications) = mpsc::unbounded_channel();
let (sender, stream) = futures::channel::mpsc::unbounded();
let mut replies = Replies::default();
replies
.replace("t", async { Ok(stream.boxed()) }, &output)
.await?;
Mock::given(method("POST"))
.and(path(
"/oaiproto.codex_app_server_backend.ThreadService/ArchiveThread",
))
.respond_with(ResponseTemplate::new(503))
.expect(2)
.mount(&server)
.await;
// A rejection before shutdown must preserve both this attachment and an
// unrelated attachment when the rejected archive targets another thread.
for id in ["t", "other"] {
assert!(
handle_request(
protocol::ClientRequest::ThreadArchive {
request_id: protocol::RequestId::Integer(1),
params: protocol::ThreadArchiveParams {
thread_id: id.into(),
},
},
cloud::SubmissionMode::StartIfIdle,
/*project*/ None,
&mut requests,
&mut replies,
&output,
)
.await
.is_err()
);
let loaded = handle_request(
protocol::ClientRequest::ThreadLoadedList {
request_id: protocol::RequestId::Integer(2),
params: Default::default(),
},
cloud::SubmissionMode::StartIfIdle,
/*project*/ None,
&mut requests,
&mut replies,
&output,
)
.await?;
assert_eq!(
loaded,
serde_json::json!({"data": ["t"], "nextCursor": null})
);
replies.admit_turn("t", &output)?;
assert!(notifications.try_recv().is_err());
}
// Model a late archive failure winning while_listening's biased select
// when Attach's EOF is also ready. No worker poll has observed the EOF yet.
drop(sender);
let failed: Result<()> = replies
.while_listening(
async { Err(eyre!("archive failed after shutdown")) },
&output,
)
.await;
assert!(failed.is_err());
assert!(replies.active.is_some());
// The first query must notice EOF itself; the second sees an already
// observed disconnect. Neither may use the cached resume response.
for _ in 0..2 {
let loaded = handle_request(
protocol::ClientRequest::ThreadLoadedList {
request_id: protocol::RequestId::Integer(3),
params: Default::default(),
},
cloud::SubmissionMode::StartIfIdle,
/*project*/ None,
&mut requests,
&mut replies,
&output,
)
.await?;
assert_eq!(loaded, serde_json::json!({"data": [], "nextCursor": null}));
assert_eq!(requests.loaded.as_ref(), Some(&cached));
}
let AppServerEvent::ThreadStreamDisconnected(error) = notifications.try_recv()? else {
panic!("expected the existing stream-loss recovery notification");
};
assert_eq!(
*error,
cloud_error(
"t",
"Cloud stream ended. Reopen the conversation to reconnect."
)
);
assert!(notifications.try_recv().is_err());
Ok(())
}
#[tokio::test]
async fn failed_replacement_keeps_old_thread_until_new_attachment_succeeds() -> Result<()> {
@@ -1,5 +1,6 @@
//! Adapts native Cloud requests and the currently open conversation’s reply stream.
//! A replacement becomes active only after its native attachment opens successfully.
//! Loaded-thread queries report reply attachments, not retained resume metadata.
mod auth;
mod events;
@@ -150,7 +151,8 @@ impl Replies {
/// Opens an app-server client backed by the authenticated native Cloud client.
fn start_worker(client: cloud::Client, account: protocol::GetAccountResponse) -> AppServerClient {
let (app_client, commands, output) = CloudClient::channel(/*capacity*/ 32);
let (app_client, commands, output) =
CloudClient::channel_with_catalog(/*capacity*/ 32, Some(client.clone()));
let mut requests = requests::Requests {
client,
account,
@@ -252,6 +254,15 @@ async fn handle_request(
replies: &mut Replies,
output: &mpsc::UnboundedSender<AppServerEvent>,
) -> Result<Value> {
if let protocol::ClientRequest::ThreadLoadedList { .. } = &request {
// The archive RPC can fail after closing Attach. Observe a ready EOF even
// when the RPC result won the worker's select before the stream did.
let _ = tokio::task::unconstrained(replies.forward_next(output)).now_or_never();
return Ok(serde_json::json!({
"data": replies.active.iter().map(|active| &active.thread_id).collect::<Vec<_>>(),
"nextCursor": null,
}));
}
if let protocol::ClientRequest::ThreadRead { params, .. } = &request {
return requests.read_thread(params, replies.thread_status(&params.thread_id));
}
@@ -277,6 +288,24 @@ async fn handle_request(
.await?
{
requests::Response::Value(value) => Ok(value),
requests::Response::Archived(thread_id) => {
replies.detach(&thread_id);
replies.stream_losses.supersede(&thread_id);
if requests
.loaded
.as_ref()
.is_some_and(|loaded| loaded.thread.id == thread_id)
{
requests.loaded = None;
}
send_notification(
output,
protocol::ServerNotification::ThreadArchived(
protocol::ThreadArchivedNotification { thread_id },
),
);
Ok(serde_json::to_value(protocol::ThreadArchiveResponse {})?)
}
requests::Response::Attach(settings) => {
let id = &settings.thread.id;
let result = serde_json::to_value(&settings)?;
@@ -7,7 +7,7 @@ use pretty_assertions::assert_eq;
fn ordinary_multi_backend_resume_queries_cloud_interactive_threads_on_every_page() {
// The mixed picker has no shared cwd/provider filter. It sends conventional
// interactive source names, even when the connection belongs to Cloud.
for (cursor, state_db_only) in [(None, true), (Some("page-2"), false)] {
for (cursor, state_db_only, archived) in [(None, true, false), (Some("page-2"), false, true)] {
let params = serde_json::from_value(json!({
"currentAccountOnly": true,
"cursor": cursor,
@@ -15,13 +15,14 @@ fn ordinary_multi_backend_resume_queries_cloud_interactive_threads_on_every_page
"sortKey": "updated_at",
"modelProviders": [],
"sourceKinds": ["cli", "vscode"],
"archived": false,
"archived": archived,
"useStateDbOnly": state_db_only,
}))
.unwrap();
let query = thread_list_query(params).unwrap();
assert_eq!(query.cursor.as_deref(), cursor);
assert_eq!(query.limit, Some(25));
assert_eq!(query.archived, archived);
assert!(matches!(query.sort_key, cloud::ThreadSortKey::UpdatedAt));
assert!(matches!(
query.sort_direction,
@@ -34,7 +35,6 @@ fn ordinary_multi_backend_resume_queries_cloud_interactive_threads_on_every_page
#[test]
fn unsupported_filters_do_not_return_unrelated_cloud_rows() {
for filter in [
json!({"archived": true}),
json!({"sourceKinds": ["exec"]}),
json!({"attachedToThreadId": "other"}),
json!({"modelProviders": ["other"]}),
@@ -28,6 +28,7 @@ pub(super) struct Requests {
pub(super) enum Response {
Value(Value),
Attach(Box<protocol::ThreadResumeResponse>),
Archived(String),
}
impl Requests {
@@ -70,6 +71,24 @@ impl Requests {
}
serde_json::to_value(page)?
}
Request::ThreadArchive { params, .. } => {
self.client.archive_thread(&params.thread_id).await?;
return Ok(Response::Archived(params.thread_id));
}
Request::ThreadUnarchive { params, .. } => {
let mut thread = self.client.unarchive_thread(&params.thread_id).await?;
use_paginated_history(&mut thread);
let value = json!({ "thread": thread });
send_notification(
output,
protocol::ServerNotification::ThreadUnarchived(
protocol::ThreadUnarchivedNotification {
thread_id: params.thread_id,
},
),
);
value
}
Request::ThreadStart { mut params, .. } => {
let model = params.model.take();
let provider = params.model_provider.take();
@@ -98,14 +117,6 @@ impl Requests {
let settings = self.client.activate(&params.thread_id).await?;
return attach_response(settings);
}
Request::ThreadLoadedList { .. } => {
let ids = self
.loaded
.iter()
.map(|loaded| &loaded.thread.id)
.collect::<Vec<_>>();
json!({"data": ids, "nextCursor": null})
}
Request::ThreadTurnsList { params, .. } => {
if params.items_view != Some(protocol::TurnItemsView::NotLoaded) {
bail!("Read cloud turn items separately with thread/items/list.");
@@ -246,7 +257,6 @@ fn thread_list_query(params: protocol::ThreadListParams) -> Result<cloud::Thread
// Its explicit CLI/VS Code defaults are conventional source names.
let sources = params.source_kinds.as_deref().unwrap_or_default();
if !matches!(sources, [] | [Cli, VsCode] | [VsCode, Cli])
|| params.archived == Some(true)
|| params.cwd.is_some()
|| params.search_term.is_some()
|| params.section_id.is_some()
@@ -268,6 +278,7 @@ fn thread_list_query(params: protocol::ThreadListParams) -> Result<cloud::Thread
Ok(cloud::ThreadListQuery {
cursor: params.cursor,
limit: params.limit,
archived: params.archived.unwrap_or_default(),
originators: params.originators.unwrap_or_default(),
sort_key: match params.sort_key {
Some(protocol::ThreadSortKey::CreatedAt) | None => cloud::ThreadSortKey::CreatedAt,
@@ -303,6 +314,11 @@ fn cloud_message(
))?;
let input = std::mem::take(&mut params.input);
let turn_trigger = params.turn_trigger.take();
let (model, effort) = if turn_trigger.as_deref() == Some("user") {
(params.model.take(), params.effort.take())
} else {
(None, None)
};
if params != protocol::TurnStartParams::default() {
return Err(PreflightRejection(
"Changing cloud settings or sending structured input is not supported yet.",
@@ -374,6 +390,8 @@ fn cloud_message(
client_user_message_id,
input: content,
turn_trigger,
model,
effort: effort.map(|effort| effort.to_string()),
mode: cloud::SubmissionMode::StartIfIdle,
shared_access: false,
})
@@ -14,6 +14,9 @@ fn submission(message_id: &str) -> protocol::TurnStartParams {
protocol::TurnStartParams {
thread_id: "t".into(),
client_user_message_id: Some(message_id.into()),
model: Some("chosen-model".into()),
effort: Some(codex_protocol::openai_models::ReasoningEffort::High),
turn_trigger: Some("user".into()),
input: vec![protocol::UserInput::Text {
text: "hello".into(),
text_elements: Vec::new(),
@@ -114,7 +117,7 @@ async fn native_submission_uses_one_admission_and_keeps_preflight_guards() -> Re
for params in [
protocol::TurnStartParams {
model: Some("other".into()),
service_tier: Some(Some("other".into())),
..submission("invalid")
},
protocol::TurnStartParams {
@@ -189,12 +192,14 @@ async fn native_submission_uses_one_admission_and_keeps_preflight_guards() -> Re
client.shutdown().await?;
worker.await?;
let calls = server.received_requests().await.unwrap();
assert!(calls.iter().all(|request| {
request
.body
.windows(url.len())
.any(|bytes| bytes == url.as_bytes())
}));
for expected in [url.as_bytes(), b"\x4a\x04high", b"\x62\x0cchosen-model"] {
assert!(calls.iter().all(|request| {
request
.body
.windows(expected.len())
.any(|bytes| bytes == expected)
}));
}
assert_eq!(
calls
.iter()
@@ -102,3 +102,80 @@ async fn cloud_shutdown_times_out_when_owner_does_not_respond() {
assert!(events.is_closed());
assert!(commands.recv().await.is_none());
}
#[tokio::test]
async fn native_model_list_bypasses_the_cloud_command_queue() -> color_eyre::Result<()> {
use codex_app_server_protocol::ModelListResponse;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
use wiremock::matchers::query_param;
let server = MockServer::start().await;
let home = tempfile::tempdir()?;
let config = crate::legacy_core::config::ConfigBuilder::default()
.codex_home(home.path().to_owned())
.fallback_cwd(Some(home.path().to_owned()))
.without_project_context()
.build()
.await?;
let native = codex_cloud_client::Client::new(
&config.http_client_factory(),
&server.uri(),
codex_cloud_client::Credentials::new("synthetic-bearer", "synthetic-account")?,
)?;
let response = serde_json::json!({
"data": [{
"id": "test-model",
"model": "test-model",
"displayName": "Test model",
"description": "Cloud catalog fixture",
"hidden": true,
"supportedReasoningEfforts": [],
"defaultReasoningEffort": "medium",
"isDefault": false
}],
"nextCursor": "next"
});
Mock::given(method("GET"))
.and(path("/v2/models"))
.and(header("authorization", "Bearer synthetic-bearer"))
.and(header("chatgpt-account-id", "synthetic-account"))
.and(query_param("cursor", "previous"))
.and(query_param("limit", "2"))
.and(query_param("includeHidden", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&response))
.expect(1)
.mount(&server)
.await;
// Leave the command receiver idle. The catalog must finish without its worker.
let (client, mut commands, _events) =
CloudClient::channel_with_catalog(/*capacity*/ 1, Some(native));
let handle = AppServerClient::Cloud(client).request_handle();
let result = tokio::time::timeout(
std::time::Duration::from_secs(/*secs*/ 5),
handle.request_typed::<ModelListResponse>(ClientRequest::ModelList {
request_id: RequestId::Integer(1),
params: ModelListParams {
cursor: Some("previous".into()),
limit: Some(2),
include_hidden: Some(true),
model_provider: None,
},
}),
)
.await??;
assert_eq!(
result,
serde_json::from_value::<ModelListResponse>(response)?
);
assert!(matches!(
commands.try_recv(),
Err(mpsc::error::TryRecvError::Empty)
));
Ok(())
}
-17
View File
@@ -178,8 +178,6 @@ pub struct RemoteAppServerRequestHandle {
enum SocketPeerPolicy {
ExplicitEndpoint,
#[cfg(windows)]
NonElevatedCurrentUser,
}
impl RemoteAppServerClient {
@@ -187,19 +185,6 @@ impl RemoteAppServerClient {
Self::connect_with_policy(args, SocketPeerPolicy::ExplicitEndpoint).await
}
/// Connects to an implicitly discovered Windows daemon, verifying its peer
/// token before the WebSocket handshake or any session requests.
#[cfg(windows)]
pub async fn connect_local_daemon(args: RemoteAppServerConnectArgs) -> IoResult<Self> {
if !matches!(args.endpoint, RemoteAppServerEndpoint::UnixSocket { .. }) {
return Err(IoError::new(
ErrorKind::InvalidInput,
"local daemon requires a Unix socket",
));
}
Self::connect_with_policy(args, SocketPeerPolicy::NonElevatedCurrentUser).await
}
async fn connect_with_policy(
args: RemoteAppServerConnectArgs,
peer_policy: SocketPeerPolicy,
@@ -810,8 +795,6 @@ async fn connect_unix_socket_endpoint(
})?;
match peer_policy {
SocketPeerPolicy::ExplicitEndpoint => {}
#[cfg(windows)]
SocketPeerPolicy::NonElevatedCurrentUser => stream.ensure_non_elevated_peer()?,
}
let websocket_config = remote_websocket_config();
let stream = timeout(
-3
View File
@@ -47,6 +47,3 @@ codex-utils-cargo-bin = { workspace = true }
pretty_assertions = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }
tracing-subscriber = { workspace = true }
[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_IO", "Win32_System_JobObjects", "Win32_Security", "Win32_Security_Authorization", "Win32_System_Threading"] }
@@ -1,7 +1,5 @@
mod pid;
pub(crate) mod stderr_log;
#[cfg(windows)]
pub(crate) mod windows;
use std::collections::BTreeMap;
use std::path::Path;
+1 -146
View File
@@ -4,7 +4,6 @@
#[path = "pid_identity.rs"]
mod identity;
#[cfg(any(unix, windows))]
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::io::SeekFrom;
@@ -16,14 +15,12 @@ use crate::managed_install::ExecutableIdentity;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
#[cfg(any(unix, windows))]
use codex_app_server_transport::REMOTE_CONTROL_DISABLED_ENV_VAR;
use serde::Deserialize;
use serde::Serialize;
use tokio::fs;
use tokio::io::AsyncReadExt;
use tokio::io::AsyncSeekExt;
#[cfg(unix)]
use tokio::process::Command;
use tokio::time::sleep;
@@ -35,7 +32,6 @@ const START_TIMEOUT: Duration = Duration::from_secs(10);
const STDERR_LOG_TAIL_BYTES: u64 = 4096;
#[derive(Debug)]
#[cfg_attr(not(any(unix, windows)), allow(dead_code))]
pub(crate) struct PidBackend {
pub(super) feature_overrides: BTreeMap<String, bool>,
codex_bin: PathBuf,
@@ -84,7 +80,6 @@ enum PidFileState {
}
#[derive(Debug, Clone)]
#[cfg_attr(not(any(unix, windows)), allow(dead_code))]
enum PidCommandKind {
AppServer { remote_control_enabled: bool },
UpdateLoop { restore_release: Option<String> },
@@ -155,16 +150,10 @@ impl PidBackend {
}
}
#[cfg(any(unix, windows))]
pub(crate) async fn start(&self) -> Result<Option<u32>> {
self.start_inner(/*replacement*/ None).await
}
#[cfg(not(any(unix, windows)))]
pub(crate) async fn start(&self) -> Result<Option<u32>> {
bail!("pid-managed app-server startup is unsupported on this platform")
}
pub(crate) async fn stop(&self) -> Result<()> {
self.stop_with_grace(DEFAULT_SHUTDOWN_GRACE_SECONDS).await
}
@@ -186,42 +175,9 @@ impl PidBackend {
let started_at = tokio::time::Instant::now();
let force_after = Duration::from_secs(grace_seconds.into());
let deadline = started_at + force_after + STOP_FORCE_TIMEOUT;
#[cfg(unix)]
self.terminate_process(pid)?;
#[cfg(windows)]
let process = {
let Some(process) = super::windows::Process::open(pid)? else {
continue;
};
if process.start_time()? != record.process_start_time {
continue;
}
match self.command_kind {
PidCommandKind::AppServer { .. } => {
let codex_home = self
.pid_file
.parent()
.and_then(Path::parent)
.context("daemon pid path has no Codex home")?;
let socket_path =
codex_app_server_transport::app_server_control_socket_path(codex_home)?;
if let Err(err) =
crate::client::request_shutdown(socket_path.as_path(), pid).await
{
tracing::warn!(%pid, %err, "managed app-server shutdown request failed; waiting for force deadline");
}
}
PidCommandKind::UpdateLoop { .. } => {
fs::write(self.pid_file.with_extension("shutdown"), pid.to_string())
.await
.context("failed to request updater shutdown")?;
}
}
process
};
let mut forced = false;
loop {
#[cfg(unix)]
if let Ok(raw_pid) = libc::pid_t::try_from(pid)
&& raw_pid > 0
{
@@ -239,10 +195,7 @@ impl PidBackend {
}
if !forced && started_at.elapsed() >= force_after {
crate::diagnostics::event("shutdown_forced", serde_json::json!({ "pid": pid }));
#[cfg(unix)]
self.force_terminate_process(pid)?;
#[cfg(windows)]
process.terminate()?;
forced = true;
}
sleep(STOP_POLL_INTERVAL).await;
@@ -362,7 +315,6 @@ impl PidBackend {
Ok(reservation_lock)
}
#[cfg(any(unix, windows))]
async fn open_stderr_log(&self) -> Result<fs::File> {
let stderr_log_file = stderr_log_file_for_pid_file(&self.pid_file);
super::stderr_log::preserve(&stderr_log_file).await;
@@ -389,7 +341,6 @@ impl PidBackend {
})
}
#[cfg(any(unix, windows))]
fn command_args(&self) -> Vec<Cow<'_, str>> {
let mut args = match &self.command_kind {
PidCommandKind::AppServer {
@@ -425,7 +376,6 @@ impl PidBackend {
args
}
#[cfg(any(unix, windows))]
fn command_env(&self) -> Option<(&'static str, &'static str)> {
match self.command_kind {
PidCommandKind::AppServer {
@@ -441,14 +391,10 @@ impl PidBackend {
fn terminate_process(&self, pid: u32) -> Result<()> {
match self.command_kind {
PidCommandKind::AppServer { .. } => terminate_process(pid),
#[cfg(unix)]
PidCommandKind::UpdateLoop { .. } => terminate_process_group(pid),
#[cfg(not(unix))]
PidCommandKind::UpdateLoop { .. } => terminate_process(pid),
}
}
#[cfg(not(windows))]
fn force_terminate_process(&self, pid: u32) -> Result<()> {
match self.command_kind {
PidCommandKind::AppServer { .. } => force_terminate_process(pid),
@@ -525,7 +471,6 @@ async fn read_log_tail(path: &Path, byte_limit: u64) -> Result<Option<String>> {
Ok(Some(contents))
}
#[cfg(unix)]
fn process_exists(pid: u32) -> bool {
let Ok(pid) = libc::pid_t::try_from(pid) else {
return false;
@@ -534,7 +479,6 @@ fn process_exists(pid: u32) -> bool {
result == 0 || std::io::Error::last_os_error().raw_os_error() == Some(libc::EPERM)
}
#[cfg(unix)]
fn terminate_process(pid: u32) -> Result<()> {
let raw_pid = libc::pid_t::try_from(pid)
.with_context(|| format!("pid-managed app server pid {pid} is out of range"))?;
@@ -549,7 +493,6 @@ fn terminate_process(pid: u32) -> Result<()> {
Err(err).with_context(|| format!("failed to terminate pid-managed app server {pid}"))
}
#[cfg(unix)]
fn force_terminate_process(pid: u32) -> Result<()> {
let raw_pid = libc::pid_t::try_from(pid)
.with_context(|| format!("pid-managed app server pid {pid} is out of range"))?;
@@ -564,7 +507,6 @@ fn force_terminate_process(pid: u32) -> Result<()> {
Err(err).with_context(|| format!("failed to force terminate pid-managed app server {pid}"))
}
#[cfg(unix)]
fn terminate_process_group(pid: u32) -> Result<()> {
let raw_pid = libc::pid_t::try_from(pid)
.with_context(|| format!("pid-managed updater pid {pid} is out of range"))?;
@@ -579,7 +521,6 @@ fn terminate_process_group(pid: u32) -> Result<()> {
Err(err).with_context(|| format!("failed to terminate pid-managed updater group {pid}"))
}
#[cfg(unix)]
fn force_terminate_process_group(pid: u32) -> Result<()> {
let raw_pid = libc::pid_t::try_from(pid)
.with_context(|| format!("pid-managed updater pid {pid} is out of range"))?;
@@ -594,29 +535,12 @@ fn force_terminate_process_group(pid: u32) -> Result<()> {
Err(err).with_context(|| format!("failed to force terminate pid-managed updater group {pid}"))
}
#[cfg(not(any(unix, windows)))]
fn terminate_process(_pid: u32) -> Result<()> {
bail!("pid-managed app-server shutdown is unsupported on this platform")
}
#[cfg(not(any(unix, windows)))]
fn force_terminate_process(_pid: u32) -> Result<()> {
bail!("pid-managed app-server shutdown is unsupported on this platform")
}
#[cfg(not(any(unix, windows)))]
fn force_terminate_process_group(_pid: u32) -> Result<()> {
bail!("pid-managed updater shutdown is unsupported on this platform")
}
#[cfg(unix)]
async fn process_matches_record(record: &PidRecord) -> Result<bool> {
if !process_exists(record.pid) {
return Ok(false);
}
let details = async {
#[cfg(any(target_os = "linux", target_os = "macos"))]
if let Some(expected) = &record.process_identity {
return expected.matches_process(record.pid).await;
}
@@ -652,20 +576,13 @@ async fn process_matches_record(record: &PidRecord) -> Result<bool> {
}
}
#[cfg(not(any(unix, windows)))]
async fn process_matches_record(_record: &PidRecord) -> Result<bool> {
Ok(false)
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(not(any(unix, windows)), allow(dead_code))]
enum EmptyPidReservation {
Active,
Stale,
Record(PidRecord),
}
#[cfg(unix)]
fn try_lock_file(file: &fs::File) -> Result<bool> {
use std::os::fd::AsRawFd;
@@ -681,12 +598,6 @@ fn try_lock_file(file: &fs::File) -> Result<bool> {
Err(err).context("failed to lock pid reservation")
}
#[cfg(not(any(unix, windows)))]
fn try_lock_file(_file: &fs::File) -> Result<bool> {
bail!("pid-managed app-server startup is unsupported on this platform")
}
#[cfg(any(unix, windows))]
async fn reservation_lock_is_active(path: &Path) -> Result<bool> {
let file = match fs::OpenOptions::new()
.write(true)
@@ -707,12 +618,10 @@ async fn reservation_lock_is_active(path: &Path) -> Result<bool> {
probe_reservation_lock(file)
}
#[cfg(any(unix, windows))]
fn probe_reservation_lock(file: fs::File) -> Result<bool> {
if !try_lock_file(&file)? {
return Ok(true);
}
#[cfg(unix)]
{
use std::os::fd::AsRawFd;
@@ -726,12 +635,6 @@ fn probe_reservation_lock(file: fs::File) -> Result<bool> {
Ok(false)
}
#[cfg(not(any(unix, windows)))]
async fn reservation_lock_is_active(_path: &Path) -> Result<bool> {
Ok(false)
}
#[cfg(any(unix, windows))]
async fn inspect_empty_pid_reservation(
pid_path: &Path,
lock_path: &Path,
@@ -753,10 +656,8 @@ async fn inspect_empty_pid_reservation(
inspect_empty_pid_reservation_with_file(pid_path, file).await
}
#[cfg(unix)]
struct EmptyPidProbeLock(fs::File);
#[cfg(unix)]
impl Drop for EmptyPidProbeLock {
fn drop(&mut self) {
use std::os::fd::AsRawFd;
@@ -770,7 +671,6 @@ impl Drop for EmptyPidProbeLock {
}
}
#[cfg(any(unix, windows))]
async fn inspect_empty_pid_reservation_with_file(
pid_path: &Path,
file: fs::File,
@@ -778,7 +678,6 @@ async fn inspect_empty_pid_reservation_with_file(
if !try_lock_file(&file)? {
return Ok(EmptyPidReservation::Active);
}
#[cfg(unix)]
let _probe_lock = EmptyPidProbeLock(file);
let contents = match fs::read_to_string(pid_path).await {
@@ -801,20 +700,10 @@ async fn inspect_empty_pid_reservation_with_file(
Ok(EmptyPidReservation::Record(record))
}
#[cfg(not(any(unix, windows)))]
async fn inspect_empty_pid_reservation(
_pid_path: &Path,
_lock_path: &Path,
) -> Result<EmptyPidReservation> {
Ok(EmptyPidReservation::Stale)
}
#[cfg(unix)]
async fn read_process_start_time(pid: u32) -> Result<String> {
Ok(read_process_details(pid).await?.1)
}
#[cfg(unix)]
async fn read_process_details(pid: u32) -> Result<(String, String)> {
let output = Command::new("ps")
.args(["-p", &pid.to_string(), "-o", "stat=", "-o", "lstart="])
@@ -838,43 +727,9 @@ async fn read_process_details(pid: u32) -> Result<(String, String)> {
Ok((state.to_string(), start_time.to_string()))
}
#[cfg(all(test, any(unix, windows)))]
#[cfg(test)]
#[path = "pid_tests.rs"]
mod tests;
#[cfg(windows)]
use super::windows::try_lock_file;
#[cfg(windows)]
async fn read_process_start_time(pid: u32) -> Result<String> {
super::windows::Process::open(pid)?
.context("daemon process exited during startup")?
.start_time()
}
#[cfg(windows)]
async fn process_matches_record(record: &PidRecord) -> Result<bool> {
let Some(process) = super::windows::Process::open(record.pid)? else {
return Ok(false);
};
Ok(process.is_running()? && process.start_time()? == record.process_start_time)
}
#[cfg(windows)]
fn force_terminate_process(pid: u32) -> Result<()> {
if let Some(process) = super::windows::Process::open(pid)? {
process.terminate()?;
}
Ok(())
}
#[cfg(windows)]
use force_terminate_process as terminate_process;
#[cfg(windows)]
#[path = "pid_windows.rs"]
mod windows;
#[cfg(any(unix, windows))]
#[path = "pid_start.rs"]
mod start;
@@ -1,9 +1,7 @@
//! Native process identities and zombie state, independent of locale and timezone.
//! Boot IDs prevent records surviving reboot from matching reused process identifiers.
#[cfg(any(target_os = "linux", target_os = "macos", test))]
use anyhow::Context;
#[cfg(any(target_os = "linux", target_os = "macos", test))]
use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;
@@ -28,7 +26,6 @@ pub(super) enum ProcessIdentity {
},
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
impl ProcessIdentity {
pub(super) async fn matches_process(&self, pid: u32) -> Result<(bool, bool)> {
// A different boot proves staleness even when the reused PID is inaccessible.
@@ -65,7 +62,6 @@ impl ProcessIdentity {
}
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
impl super::PidBackend {
pub(crate) async fn promote_legacy_identity(&self) -> Result<()> {
let _reservation = self.acquire_reservation_lock().await?;
@@ -25,7 +25,6 @@ fn reads_earlier_linux_identity_field() {
assert_eq!(serde_json::to_value(record).unwrap(), expected);
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[tokio::test]
async fn previous_boot_does_not_require_process_inspection() {
let (_, identity) = super::read_process_details(std::process::id())
@@ -4,8 +4,6 @@
//! Recover a deleted Unix cwd without changing workspace defaults for usable directories.
use super::PidBackend;
#[cfg(windows)]
use super::PidCommandKind;
use super::PidFileState;
use super::PidRecord;
use super::read_process_start_time;
@@ -20,28 +18,11 @@ use tokio::process::Command;
impl PidBackend {
pub(super) async fn start_inner(&self, replacement: Option<PidRecord>) -> Result<Option<u32>> {
#[cfg(windows)]
crate::backend::windows::ensure_not_elevated()?;
if let Some(parent) = self.pid_file.parent() {
codex_uds::prepare_private_socket_directory(parent)
.await
.with_context(|| format!("failed to create pid directory {}", parent.display()))?;
}
#[cfg(windows)]
let workdir = {
let workdir = self
.pid_file
.parent()
.context("daemon pid path has no parent")?
.join("workdir");
fs::create_dir_all(&workdir).await.with_context(|| {
format!(
"failed to create daemon working directory {}",
workdir.display()
)
})?;
workdir
};
let reservation_lock = self.acquire_reservation_lock().await?;
loop {
match fs::OpenOptions::new()
@@ -158,7 +139,6 @@ impl PidBackend {
.context("daemon pid path has no parent")?,
)?;
#[cfg(unix)]
{
unsafe {
command.pre_exec(|| {
@@ -170,50 +150,7 @@ impl PidBackend {
}
}
#[cfg(windows)]
{
use windows_sys::Win32::System::Threading::CREATE_BREAKAWAY_FROM_JOB;
use windows_sys::Win32::System::Threading::CREATE_NO_WINDOW;
use windows_sys::Win32::System::Threading::DETACHED_PROCESS;
// A Windows process pins its working directory for its lifetime.
// Keep both managed children out of the launching project's directory.
// Sandbox setup may broaden the cwd ACL, so do not use the private state directory.
command.current_dir(&workdir);
// Never retry inside the parent's Job Object: that would report a
// successful launch that dies when the terminal/SSH session closes.
command.creation_flags(CREATE_NO_WINDOW | DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB);
if matches!(self.command_kind, PidCommandKind::UpdateLoop { .. }) {
match fs::remove_file(self.pid_file.with_extension("ready")).await {
Ok(()) => {}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
Err(err) => return Err(err).context("failed to clear updater readiness"),
}
}
match self.command_kind {
PidCommandKind::AppServer { .. } => {
command.env(codex_app_server_transport::DAEMON_SHUTDOWN_SOCKET_ENV, "1");
}
PidCommandKind::UpdateLoop { .. } => {
let shutdown_file = self.pid_file.with_extension("shutdown");
match fs::remove_file(&shutdown_file).await {
Ok(()) => {}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
Err(err) => {
return Err(err).context("failed to clear updater shutdown request");
}
}
command.env(
codex_app_server_transport::DAEMON_SHUTDOWN_FILE_ENV,
shutdown_file,
);
}
}
}
let started = std::time::Instant::now();
#[cfg(windows)]
let child = super::super::windows::spawn_without_inheriting_stdio(&mut command);
#[cfg(not(windows))]
let child = command.spawn().map_err(anyhow::Error::from);
let child = crate::diagnostics::result("process_spawn", started, child);
let mut child = match child {
@@ -223,11 +160,7 @@ impl PidBackend {
let _ = fs::remove_file(&self.pid_file).await;
}
return Err(err).with_context(|| {
let job_hint = if cfg!(windows) {
" (the Windows host job must allow breakaway)"
} else {
""
};
let job_hint = "";
StartFailure::Spawn(format!(
"failed to spawn detached app-server process using {}{job_hint}",
self.codex_bin.display()
@@ -242,13 +175,10 @@ impl PidBackend {
let started = std::time::Instant::now();
let record = async {
let process_start_time = read_process_start_time(pid).await?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
let process_identity = super::identity::read_process_details(pid)
.await
.ok()
.map(|(_, identity)| identity);
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let process_identity = None;
anyhow::Ok(PidRecord {
pid,
process_start_time,
@@ -312,11 +242,6 @@ impl PidBackend {
format!("failed to publish pid file {}", self.pid_file.display())
});
}
#[cfg(windows)]
if matches!(self.command_kind, PidCommandKind::UpdateLoop { .. }) {
self.finish_updater_start(&record, replacement.as_ref())
.await?;
}
drop(reservation_lock);
Ok(Some(pid))
}
@@ -1,10 +1,8 @@
#[cfg(any(unix, windows))]
use std::process::Stdio;
use std::time::Duration;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
#[cfg(any(unix, windows))]
use tokio::time::sleep;
use codex_app_server_transport::REMOTE_CONTROL_DISABLED_ENV_VAR;
@@ -14,33 +12,11 @@ use super::PidCommandKind;
use super::PidFileState;
use super::PidLogTail;
use super::PidRecord;
#[cfg(unix)]
use super::read_process_start_time;
use super::read_stderr_log_tail;
use super::stderr_log_file_for_pid_file;
use super::try_lock_file;
#[cfg(windows)]
fn is_elevated_test_process() -> anyhow::Result<bool> {
let output = std::process::Command::new("powershell.exe")
.args([
"-NoProfile",
"-NonInteractive",
"-Command",
"[Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)",
])
.output()?;
anyhow::ensure!(
output.status.success(),
"administrator membership query failed"
);
match String::from_utf8(output.stdout)?.trim() {
"True" => Ok(true),
"False" => Ok(false),
other => anyhow::bail!("unexpected administrator membership: {other}"),
}
}
#[tokio::test]
async fn locked_empty_pid_file_is_treated_as_active_reservation() {
let temp_dir = TempDir::new().expect("temp dir");
@@ -100,7 +76,6 @@ async fn unlocked_empty_pid_file_is_treated_as_stale_reservation() {
assert!(!pid_file.exists());
}
#[cfg(unix)]
#[test]
fn reservation_probe_releases_lock_with_duplicated_handle() {
#[derive(Debug, Clone, Copy)]
@@ -259,16 +234,6 @@ async fn start_retries_stale_empty_pid_file_under_its_own_lock() {
);
let err = backend.start().await.expect_err("start");
#[cfg(windows)]
if is_elevated_test_process().expect("query administrator membership") {
assert!(err.to_string().contains("non-elevated terminal"));
assert_eq!(
tokio::fs::read(&backend.pid_file).await.unwrap(),
Vec::<u8>::new()
);
assert!(!backend.lock_file.exists());
return;
}
assert!(
err.to_string()
.starts_with("failed to spawn detached app-server process using ")
@@ -279,7 +244,6 @@ async fn start_retries_stale_empty_pid_file_under_its_own_lock() {
);
}
#[cfg(unix)]
#[tokio::test]
async fn legacy_launch_clears_recovery_best_effort() {
for snapshot_is_directory in [false, true] {
@@ -346,7 +310,6 @@ async fn stale_record_cleanup_preserves_replacement_record() {
);
}
#[cfg(unix)]
#[tokio::test]
async fn pid_record_captures_the_resolved_launch_binary() {
let temp = TempDir::new().expect("temp dir");
@@ -396,7 +359,6 @@ async fn pid_record_captures_the_resolved_launch_binary() {
backend.stop().await.expect("stop daemon");
}
#[cfg(unix)]
#[tokio::test]
async fn legacy_start_time_mismatch_preserves_record_and_process() {
let temp = TempDir::new().unwrap();
@@ -428,7 +390,6 @@ async fn legacy_start_time_mismatch_preserves_record_and_process() {
assert_eq!(std::fs::read(&backend.pid_file).unwrap(), contents);
}
#[cfg(unix)]
#[tokio::test]
async fn stop_reaps_untracked_app_server_child() {
let temp_dir = TempDir::new().expect("temp dir");
@@ -470,28 +431,18 @@ async fn stop_reaps_untracked_app_server_child() {
assert!(!pid_file.exists());
}
#[cfg(any(unix, windows))]
#[tokio::test]
async fn shutdown_grace_child() {
let Some(ready) = std::env::var_os("CODEX_TEST_SHUTDOWN_GRACE_READY") else {
return;
};
let ready = std::path::PathBuf::from(ready);
#[cfg(unix)]
let mut terminate = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("install shutdown handler");
tokio::fs::write(&ready, "").await.expect("ready marker");
// Outlive the parent's stop deadline so this watchdog cannot look like a forced stop.
let _ = tokio::time::timeout(Duration::from_secs(/*secs*/ 30), async {
#[cfg(unix)]
terminate.recv().await;
#[cfg(windows)]
loop {
if ready.with_extension("shutdown").exists() {
break;
}
sleep(Duration::from_millis(10)).await;
}
if std::env::var_os("CODEX_TEST_SHUTDOWN_GRACE_EXIT").is_some() {
sleep(Duration::from_millis(150)).await;
tokio::fs::write(ready.with_extension("exited"), "")
@@ -504,7 +455,6 @@ async fn shutdown_grace_child() {
.await;
}
#[cfg(any(unix, windows))]
#[tokio::test]
async fn shutdown_grace_handles_process_exit() {
let temp = TempDir::new().expect("temp dir");
@@ -546,18 +496,11 @@ async fn shutdown_grace_handles_process_exit() {
)
.await
.expect("write pid file");
#[cfg(unix)]
let backend = PidBackend::new(
temp.path().join("codex"),
pid_file,
/*remote_control_enabled*/ false,
);
#[cfg(windows)]
let backend = PidBackend::new_update_loop(
temp.path().join("codex"),
pid_file,
/*restore_release*/ None,
);
// Cover the backend's full stop budget, plus scheduling headroom on busy runners.
let stop_timeout =
super::STOP_FORCE_TIMEOUT + Duration::from_secs(u64::from(grace_seconds) + 5);
@@ -577,7 +520,6 @@ async fn shutdown_grace_handles_process_exit() {
}
}
#[cfg(unix)]
#[tokio::test]
async fn stopping_updater_signals_its_installer_process_group() {
use std::os::unix::process::CommandExt;
@@ -644,7 +586,6 @@ async fn stopping_updater_signals_its_installer_process_group() {
}
}
#[cfg(unix)]
#[tokio::test]
async fn exited_unreaped_updater_is_reaped() {
let temp = TempDir::new().expect("temp dir");
@@ -652,15 +593,12 @@ async fn exited_unreaped_updater_is_reaped() {
.arg("60")
.spawn()
.expect("spawn updater shim");
#[cfg(any(target_os = "linux", target_os = "macos"))]
let process_identity = Some(
super::identity::read_process_details(child.id())
.await
.unwrap()
.1,
);
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let process_identity = None;
let record = PidRecord {
pid: child.id(),
process_start_time: read_process_start_time(child.id())
@@ -783,7 +721,6 @@ async fn stale_creation_time_never_stops_reused_pid() {
temp.path().join("server.pid"),
/*remote_control_enabled*/ false,
);
#[cfg(any(target_os = "linux", target_os = "macos"))]
let identities = {
use super::identity::ProcessIdentity;
let (_, identity) = super::identity::read_process_details(std::process::id())
@@ -807,8 +744,6 @@ async fn stale_creation_time_never_stops_reused_pid() {
}
[Some(stale_time), Some(stale_epoch)]
};
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let identities = [None];
for process_identity in identities {
let record = PidRecord {
pid: std::process::id(),
@@ -824,311 +759,6 @@ async fn stale_creation_time_never_stops_reused_pid() {
}
}
#[cfg(windows)]
#[tokio::test]
async fn managed_children_launch_in_workdir_without_changing_private_state_directory() {
if is_elevated_test_process().expect("query administrator membership") {
return;
}
let temp = TempDir::new().expect("temp dir");
let state_dir = temp.path().join("state");
let codex_bin = temp.path().join("codex.cmd");
tokio::fs::write(
&codex_bin,
"@echo off\r\n\
if \"%3\"==\"--help\" exit /b 1\r\n\
echo ready > launched.cwd\r\n\
if defined CODEX_DAEMON_SHUTDOWN_FILE (for %%F in (\"%CODEX_DAEMON_SHUTDOWN_FILE%\") do type nul > \"%%~dpnF.ready\")\r\n\
for /l %%i in (1,1,10000000) do @rem\r\n",
)
.await
.expect("write daemon fixture");
let backends = [
PidBackend::new(
codex_bin.clone(),
state_dir.join("app-server.pid"),
/*remote_control_enabled*/ false,
),
PidBackend::new_update_loop(
codex_bin,
state_dir.join("updater.pid"),
/*restore_release*/ None,
),
];
for backend in backends {
backend.start().await.expect("launch managed child");
let marker = state_dir.join("workdir/launched.cwd");
let launched_in_workdir = tokio::time::timeout(Duration::from_secs(5), async {
while !marker.exists() {
sleep(Duration::from_millis(10)).await;
}
})
.await;
backend
.stop_with_grace(/*grace_seconds*/ 0)
.await
.expect("stop managed child");
launched_in_workdir.expect("child did not write its relative marker in workdir");
codex_uds::prepare_private_socket_directory(&state_dir)
.await
.expect("state directory remains private");
assert!(!backend.pid_file.exists());
tokio::fs::remove_file(marker)
.await
.expect("remove marker before next child launch");
}
}
#[cfg(windows)]
#[tokio::test]
async fn failed_updater_handoff_preserves_predecessor_record() {
let elevated = is_elevated_test_process().expect("query administrator membership");
let temp = TempDir::new().expect("temp");
let state_dir = temp.path().join("state");
codex_uds::prepare_private_socket_directory(&state_dir)
.await
.expect("private state directory");
let backend = PidBackend::new_update_loop(
temp.path().join("missing-codex.exe"),
state_dir.join("updater.pid"),
/*restore_release*/ None,
);
let record = PidRecord {
pid: std::process::id(),
process_start_time: super::read_process_start_time(std::process::id())
.await
.unwrap(),
process_identity: None,
executable_identity: None,
};
for record in [
record.clone(),
PidRecord {
process_start_time: "stale".into(),
..record
},
] {
tokio::fs::write(&backend.pid_file, serde_json::to_vec(&record).unwrap())
.await
.unwrap();
let error = backend.replace_current_updater().await.unwrap_err();
if elevated {
assert!(error.to_string().contains("non-elevated terminal"));
} else {
// Windows may reject breakaway before reporting the missing executable.
// Both must reach process I/O rather than rejecting stale ownership.
assert!(error.root_cause().is::<std::io::Error>(), "{error:#}");
}
assert_eq!(
backend.read_pid_file_state().await.unwrap(),
PidFileState::Running(record)
);
}
}
#[cfg(windows)]
#[tokio::test]
async fn updater_readiness_and_post_publication_failure_preserve_ownership() {
use futures::FutureExt;
use tokio::io::AsyncWriteExt;
use windows_sys::Win32::Security::ImpersonateAnonymousToken;
use windows_sys::Win32::Security::RevertToSelf;
use windows_sys::Win32::System::Threading::GetCurrentThread;
let temp = TempDir::new().expect("temp");
let backend = PidBackend::new_update_loop(
temp.path().join("codex.exe"),
temp.path().join("updater.pid"),
/*restore_release*/ None,
);
let _lock = backend
.acquire_reservation_lock()
.await
.expect("reservation lock");
let mut predecessor_stderr = backend.open_stderr_log().await.expect("predecessor log");
predecessor_stderr
.write_all(&vec![b'x'; 512 * 1024])
.await
.unwrap();
predecessor_stderr.flush().await.unwrap();
let successor_stderr = backend.open_stderr_log().await.expect("successor log");
let ready = backend.pid_file.with_extension("ready");
let mut child = tokio::process::Command::new("powershell.exe")
.args([
"-NoProfile",
"-NonInteractive",
"-Command",
"[Console]::Error.WriteLine('successor startup'); [IO.File]::WriteAllText($env:CODEX_TEST_UPDATER_READY, ''); Start-Sleep 60",
])
.env("CODEX_TEST_UPDATER_READY", &ready)
.stderr(Stdio::from(successor_stderr.into_std().await))
.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW)
.kill_on_drop(true)
.spawn()
.expect("successor fixture");
let pid = child.id().expect("pid");
let successor = PidRecord {
pid,
process_start_time: super::read_process_start_time(pid)
.await
.expect("creation time"),
process_identity: None,
executable_identity: None,
};
let predecessor = PidRecord {
pid: std::process::id(),
process_start_time: super::read_process_start_time(std::process::id())
.await
.expect("creation time"),
process_identity: None,
executable_identity: None,
};
tokio::fs::write(&backend.pid_file, serde_json::to_vec(&successor).unwrap())
.await
.unwrap();
backend
.finish_updater_start(&successor, Some(&predecessor))
.await
.expect("ready successor");
predecessor_stderr
.write_all(b"predecessor handoff complete\n")
.await
.unwrap();
predecessor_stderr.flush().await.unwrap();
let log_path = stderr_log_file_for_pid_file(&backend.pid_file);
let log = tokio::fs::read(&log_path).await.unwrap();
assert!(log.len() < 256 * 1024);
let log = String::from_utf8(log).expect("no stale-offset gap");
assert!(log.contains("successor startup"));
assert!(log.contains("predecessor handoff complete"));
assert!(!ready.exists());
assert_eq!(
backend.read_pid_file_state().await.unwrap(),
PidFileState::Running(successor.clone())
);
// If cleanup cannot even query the successor, leave its ownership intact.
std::thread::scope(|scope| {
scope
.spawn(|| {
assert_ne!(unsafe { ImpersonateAnonymousToken(GetCurrentThread()) }, 0);
let result = backend
.finish_updater_start(&successor, Some(&predecessor))
.now_or_never();
let reverted = unsafe { RevertToSelf() };
assert_ne!(reverted, 0);
let error = result
.expect("denied cleanup must not suspend")
.unwrap_err();
assert_eq!(
error
.downcast_ref::<std::io::Error>()
.unwrap()
.raw_os_error(),
Some(windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED as i32)
);
})
.join()
.expect("anonymous cleanup check");
});
assert_eq!(
backend.read_pid_file_state().await.unwrap(),
PidFileState::Running(successor.clone())
);
let reused_pid = PidRecord {
process_start_time: "stale".into(),
..successor.clone()
};
assert!(
backend
.finish_updater_start(&reused_pid, Some(&predecessor))
.await
.is_err()
);
assert_eq!(
backend.read_pid_file_state().await.unwrap(),
PidFileState::Running(predecessor.clone())
);
assert!(
child.try_wait().unwrap().is_none(),
"PID reuse must not terminate another process"
);
tokio::fs::write(&backend.pid_file, serde_json::to_vec(&successor).unwrap())
.await
.unwrap();
// An invalid readiness path triggers cleanup while the successor is alive.
tokio::fs::create_dir(&ready).await.unwrap();
assert!(
backend
.finish_updater_start(&successor, Some(&predecessor))
.await
.is_err()
);
assert!(
child.try_wait().unwrap().is_some(),
"successor must exit before rollback"
);
assert_eq!(
backend.read_pid_file_state().await.unwrap(),
PidFileState::Running(predecessor)
);
}
#[cfg(windows)]
#[test]
fn inaccessible_pid_preserves_identity_check_error() {
use futures::FutureExt;
use windows_sys::Win32::Security::ImpersonateAnonymousToken;
use windows_sys::Win32::Security::RevertToSelf;
use windows_sys::Win32::System::Threading::GetCurrentThread;
// Isolate impersonation from Tokio workers and other tests. Query our own
// process anonymously instead of assuming a system PID is inaccessible.
std::thread::spawn(|| {
let record = PidRecord {
pid: std::process::id(),
process_start_time: "stale".into(),
process_identity: None,
executable_identity: None,
};
assert!(
crate::backend::windows::Process::open(record.pid)
.unwrap()
.is_some()
);
assert_ne!(unsafe { ImpersonateAnonymousToken(GetCurrentThread()) }, 0);
let opened = crate::backend::windows::Process::open(record.pid);
// Windows identity checks are synchronous; never suspend while impersonating.
let matches = super::process_matches_record(&record).now_or_never();
let reverted = unsafe { RevertToSelf() };
assert_ne!(reverted, 0);
let error = match opened {
Err(error) => error,
Ok(_) => panic!("anonymous caller unexpectedly queried the test process"),
};
assert_eq!(
error
.downcast_ref::<std::io::Error>()
.unwrap()
.raw_os_error(),
Some(windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED as i32),
);
assert_eq!(
matches
.expect("identity check must not suspend")
.unwrap_err()
.downcast_ref::<std::io::Error>()
.unwrap()
.raw_os_error(),
Some(windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED as i32),
);
})
.join()
.expect("anonymous identity check");
}
#[tokio::test]
async fn stderr_preservation_failure_does_not_prevent_opening_new_log() -> anyhow::Result<()> {
let home = TempDir::new()?;
@@ -1,119 +0,0 @@
//! Windows updater publication handshake. The predecessor holds the operation
//! and reservation locks until its successor initializes and acknowledges readiness.
use super::super::windows::Process;
use super::PidBackend;
use super::PidFileState;
use super::PidRecord;
use super::START_TIMEOUT;
use super::STOP_POLL_INTERVAL;
use super::process_matches_record;
use super::read_process_start_time;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use tokio::fs;
use tokio::time::sleep;
impl PidBackend {
pub(crate) async fn wait_for_ownership(&self) -> Result<()> {
let deadline = tokio::time::Instant::now() + START_TIMEOUT;
loop {
if let PidFileState::Running(record) = self.read_pid_file_state().await?
&& record.pid == std::process::id()
&& self.record_is_active(&record).await?
{
return Ok(());
}
if tokio::time::Instant::now() >= deadline {
bail!("updater was not published by its launcher");
}
sleep(STOP_POLL_INTERVAL).await;
}
}
pub(crate) async fn mark_ready(&self) -> Result<()> {
fs::write(self.pid_file.with_extension("ready"), b"")
.await
.context("failed to acknowledge updater startup")
}
// Keep pruning excluded until successor startup and any ownership rollback finish.
#[allow(clippy::await_holding_invalid_type)]
pub(crate) async fn replace_current_updater(&self) -> Result<()> {
// Retry busy pruning instead of waiting on the logging worker. Keep it paused
// before open_stderr_log() truncates the shared log and throughout startup.
let mut pruning_enabled = super::super::stderr_log::PRUNING_ENABLED
.try_lock()
.context("stderr pruning is busy; retry updater handoff")?;
let record = PidRecord {
pid: std::process::id(),
process_start_time: read_process_start_time(std::process::id()).await?,
process_identity: None,
executable_identity: None,
};
*pruning_enabled = false;
let result = self.start_inner(Some(record.clone())).await;
// Resume only after ownership is restored. Failed cleanup may leave the
// successor alive, and successful handoff leaves it in charge of retention.
if result.is_err()
&& matches!(
self.read_pid_file_state().await,
Ok(PidFileState::Running(previous)) if previous == record
)
{
*pruning_enabled = true;
}
result?;
Ok(())
}
pub(super) async fn finish_updater_start(
&self,
record: &PidRecord,
replacement: Option<&PidRecord>,
) -> Result<()> {
let temp_pid_file = self.pid_file.with_extension("pid.tmp");
let ready = self.pid_file.with_extension("ready");
let deadline = tokio::time::Instant::now() + START_TIMEOUT;
let startup = async {
loop {
if !process_matches_record(record).await? {
bail!("updater exited before becoming ready");
}
match fs::remove_file(&ready).await {
Ok(()) => return Ok(()),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
Err(err) => return Err(err.into()),
}
if tokio::time::Instant::now() >= deadline {
bail!("updater did not become ready");
}
sleep(STOP_POLL_INTERVAL).await;
}
}
.await;
if let Err(err) = startup {
if let Some(process) = Process::open(record.pid)?
&& process.start_time()? == record.process_start_time
{
process.terminate()?;
let deadline = tokio::time::Instant::now() + START_TIMEOUT;
while process.is_running()? {
if tokio::time::Instant::now() >= deadline {
bail!("failed updater did not exit; ownership was not restored");
}
sleep(STOP_POLL_INTERVAL).await;
}
}
if let Some(previous) = replacement {
fs::write(&temp_pid_file, serde_json::to_vec(previous)?).await?;
fs::rename(&temp_pid_file, &self.pid_file).await?;
} else {
let _ = fs::remove_file(&self.pid_file).await;
}
return Err(err);
}
Ok(())
}
}
@@ -104,7 +104,6 @@ impl Write for LogFile {
}
}
#[cfg(unix)]
fn enable_append() -> io::Result<()> {
use std::os::fd::AsRawFd;
@@ -121,47 +120,6 @@ fn enable_append() -> io::Result<()> {
Ok(())
}
#[cfg(windows)]
fn enable_append() -> io::Result<()> {
use std::os::windows::io::AsRawHandle;
use std::os::windows::io::FromRawHandle;
use std::os::windows::io::IntoRawHandle;
use std::os::windows::io::OwnedHandle;
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
use windows_sys::Win32::Storage::FileSystem::FILE_GENERIC_WRITE;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_DELETE;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE;
use windows_sys::Win32::Storage::FileSystem::FILE_WRITE_DATA;
use windows_sys::Win32::Storage::FileSystem::ReOpenFile;
use windows_sys::Win32::System::Console::STD_ERROR_HANDLE;
use windows_sys::Win32::System::Console::SetStdHandle;
let stderr = std::io::stderr();
// SAFETY: stderr is borrowed and remains open; reopening does not truncate it.
let handle = unsafe {
ReOpenFile(
stderr.as_raw_handle(),
// Append-only access makes writes follow EOF after truncation.
FILE_GENERIC_WRITE & !FILE_WRITE_DATA,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
/*dwflagsandattributes*/ 0,
)
};
if handle == INVALID_HANDLE_VALUE {
return Err(io::Error::last_os_error());
}
// SAFETY: ReOpenFile returned a new, valid handle owned by this function.
let handle = unsafe { OwnedHandle::from_raw_handle(handle) };
// SAFETY: the append handle is valid and retained for the process lifetime on success.
if unsafe { SetStdHandle(STD_ERROR_HANDLE, handle.as_raw_handle()) } == 0 {
return Err(io::Error::last_os_error());
}
// The process owns its new stderr. Keep the borrowed original valid for cached users.
let _ = handle.into_raw_handle();
Ok(())
}
fn prune(path: &Path, pruning_enabled: &Mutex<bool>) -> io::Result<()> {
let Ok(enabled) = pruning_enabled.try_lock() else {
return Ok(());
@@ -4,7 +4,6 @@ use super::preserve;
use super::prune;
use pretty_assertions::assert_eq;
#[cfg(any(unix, windows))]
#[tokio::test]
async fn pruning_resets_the_write_position_of_a_legacy_nonappend_writer() -> anyhow::Result<()> {
use std::io::Write;
@@ -1,327 +0,0 @@
//! Windows process identity and file locks. Keep a process handle across shutdown
//! so PID reuse can never redirect forced termination to a different process.
//! Managed servers must not elevate ordinary clients sharing the account's socket.
//! Installer jobs contain extraction processes when an update is cancelled.
//! Detached launches stop the launcher's original stdio handles from propagating.
//! Launch probes distinguish job restrictions from other failures without running the binary.
use std::fmt;
use std::io;
use std::os::windows::io::AsRawHandle;
use std::os::windows::io::FromRawHandle;
use std::os::windows::io::OwnedHandle;
use std::os::windows::process::CommandExt;
use std::path::Path;
use std::process::Command;
use std::process::Stdio;
use anyhow::Context;
use anyhow::Result;
use windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED;
use windows_sys::Win32::Foundation::ERROR_INVALID_HANDLE;
use windows_sys::Win32::Foundation::ERROR_INVALID_PARAMETER;
use windows_sys::Win32::Foundation::ERROR_LOCK_VIOLATION;
use windows_sys::Win32::Foundation::FILETIME;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Foundation::HANDLE_FLAG_INHERIT;
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
use windows_sys::Win32::Foundation::SetHandleInformation;
use windows_sys::Win32::Foundation::WAIT_OBJECT_0;
use windows_sys::Win32::Foundation::WAIT_TIMEOUT;
use windows_sys::Win32::Security::GetTokenInformation;
use windows_sys::Win32::Security::TOKEN_ELEVATION;
use windows_sys::Win32::Security::TOKEN_QUERY;
use windows_sys::Win32::Security::TokenElevation;
use windows_sys::Win32::Storage::FileSystem::LOCKFILE_EXCLUSIVE_LOCK;
use windows_sys::Win32::Storage::FileSystem::LOCKFILE_FAIL_IMMEDIATELY;
use windows_sys::Win32::Storage::FileSystem::LockFileEx;
use windows_sys::Win32::System::JobObjects::AssignProcessToJobObject;
use windows_sys::Win32::System::JobObjects::CreateJobObjectW;
use windows_sys::Win32::System::JobObjects::JOB_OBJECT_LIMIT_BREAKAWAY_OK;
use windows_sys::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
use windows_sys::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
use windows_sys::Win32::System::JobObjects::JobObjectExtendedLimitInformation;
use windows_sys::Win32::System::JobObjects::SetInformationJobObject;
use windows_sys::Win32::System::Threading::CREATE_BREAKAWAY_FROM_JOB;
use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;
use windows_sys::Win32::System::Threading::DETACHED_PROCESS;
use windows_sys::Win32::System::Threading::GetCurrentProcess;
use windows_sys::Win32::System::Threading::GetProcessId;
use windows_sys::Win32::System::Threading::GetProcessTimes;
use windows_sys::Win32::System::Threading::OpenProcess;
use windows_sys::Win32::System::Threading::OpenProcessToken;
use windows_sys::Win32::System::Threading::PROCESS_ACCESS_RIGHTS;
use windows_sys::Win32::System::Threading::PROCESS_QUERY_LIMITED_INFORMATION;
use windows_sys::Win32::System::Threading::PROCESS_SYNCHRONIZE;
use windows_sys::Win32::System::Threading::PROCESS_TERMINATE;
use windows_sys::Win32::System::Threading::TerminateProcess;
use windows_sys::Win32::System::Threading::WaitForSingleObject;
pub(super) fn spawn_without_inheriting_stdio(
command: &mut tokio::process::Command,
) -> Result<tokio::process::Child> {
// The daemon must not inherit the launcher's output pipes: callers wait for
// them to close after the launcher exits. Leave the flags cleared so concurrent
// launches cannot inherit them either; Rust duplicates the child's chosen stdio.
for (name, handle) in [
("stdin", io::stdin().as_raw_handle()),
("stdout", io::stdout().as_raw_handle()),
("stderr", io::stderr().as_raw_handle()),
] {
if handle.is_null() || handle == INVALID_HANDLE_VALUE {
continue;
}
// SAFETY: these are borrowed standard handles; changing the inherit
// flag neither closes them nor changes their read/write access.
if unsafe {
SetHandleInformation(handle, HANDLE_FLAG_INHERIT, /*dwflags*/ 0)
} == 0
{
let error = io::Error::last_os_error();
// An already-closed handle cannot be inherited.
if error.raw_os_error() == Some(ERROR_INVALID_HANDLE as i32) {
continue;
}
return Err(error)
.with_context(|| format!("failed to clear launcher {name} inheritance"));
}
}
Ok(command.spawn()?)
}
/// Reports whether this process has administrator privileges, rather than
/// merely belonging to an administrator account.
pub fn is_elevated() -> Result<bool> {
let mut token = std::ptr::null_mut();
if unsafe { OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token) } == 0 {
return Err(io::Error::last_os_error()).context("failed to query daemon launcher token");
}
let token = unsafe { OwnedHandle::from_raw_handle(token) };
let mut elevation: TOKEN_ELEVATION = unsafe { std::mem::zeroed() };
let mut returned = 0;
if unsafe {
GetTokenInformation(
token.as_raw_handle(),
TokenElevation,
(&mut elevation as *mut TOKEN_ELEVATION).cast(),
std::mem::size_of::<TOKEN_ELEVATION>() as u32,
&mut returned,
)
} == 0
{
return Err(io::Error::last_os_error())
.context("failed to query daemon launcher elevation");
}
Ok(elevation.TokenIsElevated != 0)
}
pub(crate) fn ensure_not_elevated() -> Result<()> {
anyhow::ensure!(
!is_elevated()?,
"start the Windows daemon from a non-elevated terminal; shared clients must not inherit administrator privileges"
);
Ok(())
}
/// A launch that only fails when asked to leave the launcher's Windows job.
/// Automatic CLI startup may use its embedded server; lifecycle operations
/// must still return this error before stopping an existing daemon.
#[derive(Debug)]
pub struct DetachedLaunchRestricted;
impl fmt::Display for DetachedLaunchRestricted {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(
"this Windows launcher prevents background processes from outliving it (for example, cargo run); build and run codex.exe directly to use the background server",
)
}
}
// Check that breakaway launch is permitted before stopping an existing daemon.
// An outer system job may remain attached; membership alone does not establish
// whether it will terminate the daemon. Suspend the probe before cleanup.
pub(crate) fn ensure_detached_launch(executable: &Path) -> Result<()> {
let mut command = Command::new(executable);
command
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.creation_flags(CREATE_SUSPENDED | DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB);
let (mut child, launch_result) = match command.spawn() {
Ok(child) => (child, Ok(())),
Err(err) if err.raw_os_error() == Some(ERROR_ACCESS_DENIED as i32) => {
// Access denied can also mean the file cannot be executed. Only
// classify a job restriction if removing breakaway makes it work.
// This diagnostic child stays suspended and is always reaped.
command.creation_flags(CREATE_SUSPENDED | DETACHED_PROCESS);
let child = match command.spawn() {
Ok(child) => child,
Err(_) => {
return Err(err).context(crate::telemetry::StartFailure::Spawn(
"cannot launch detached daemon".into(),
));
}
};
(child, Err(err).context(DetachedLaunchRestricted))
}
Err(err) => {
return Err(err).context(crate::telemetry::StartFailure::Spawn(
"cannot launch detached daemon".into(),
));
}
};
child
.kill()
.context("failed to terminate suspended launch probe")?;
child
.wait()
.context("failed to reap suspended launch probe")?;
launch_result
}
pub(super) struct Process(OwnedHandle);
impl Process {
pub(super) fn open(pid: u32) -> Result<Option<Self>> {
Self::open_with_access(pid, PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_SYNCHRONIZE)
}
fn open_with_access(pid: u32, access: PROCESS_ACCESS_RIGHTS) -> Result<Option<Self>> {
let handle = unsafe {
OpenProcess(access, /*binherithandle*/ 0, pid)
};
if handle.is_null() {
let err = io::Error::last_os_error();
return if err.raw_os_error() == Some(ERROR_INVALID_PARAMETER as i32) {
Ok(None)
} else {
Err(err).context("failed to open daemon process")
};
}
Ok(Some(Self(unsafe { OwnedHandle::from_raw_handle(handle) })))
}
pub(super) fn start_time(&self) -> Result<String> {
let mut created: FILETIME = unsafe { std::mem::zeroed() };
let mut exited = created;
let mut kernel = created;
let mut user = created;
if unsafe {
GetProcessTimes(
self.0.as_raw_handle(),
&mut created,
&mut exited,
&mut kernel,
&mut user,
)
} == 0
{
return Err(io::Error::last_os_error()).context("failed to query daemon creation time");
}
Ok(
((u64::from(created.dwHighDateTime) << 32) | u64::from(created.dwLowDateTime))
.to_string(),
)
}
pub(super) fn is_running(&self) -> Result<bool> {
match unsafe {
WaitForSingleObject(self.0.as_raw_handle(), /*dwmilliseconds*/ 0)
} {
WAIT_TIMEOUT => Ok(true),
WAIT_OBJECT_0 => Ok(false),
_ => Err(io::Error::last_os_error()).context("failed to wait for daemon process"),
}
}
pub(super) fn terminate(&self) -> Result<()> {
if !self.is_running()? {
return Ok(());
}
let pid = unsafe { GetProcessId(self.0.as_raw_handle()) };
let Some(target) = Self::open_with_access(
pid,
PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_SYNCHRONIZE | PROCESS_TERMINATE,
)?
else {
return Ok(());
};
// Keep the original identity handle alive and validate the handle that
// will actually be terminated, rather than trusting a second PID lookup.
if target.start_time()? != self.start_time()? || !target.is_running()? {
return Ok(());
}
if unsafe {
TerminateProcess(target.0.as_raw_handle(), /*uexitcode*/ 1)
} == 0
{
return Err(io::Error::last_os_error()).context("failed to terminate daemon process");
}
Ok(())
}
}
pub(crate) fn try_lock_file(file: &tokio::fs::File) -> Result<bool> {
let mut overlapped = unsafe { std::mem::zeroed() };
if unsafe {
LockFileEx(
file.as_raw_handle(),
LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY,
/*dwreserved*/ 0,
/*nnumberofbytestolocklow*/ 1,
/*nnumberofbytestolockhigh*/ 0,
&mut overlapped,
)
} != 0
{
return Ok(true);
}
let err = io::Error::last_os_error();
if err.raw_os_error() == Some(ERROR_LOCK_VIOLATION as i32) {
return Ok(false);
}
Err(err).context("failed to lock daemon state")
}
// Keep installer descendants bounded by the updater's lifetime, while allowing
// app-server launches and successor updaters to break away from this job.
pub(crate) fn updater_job() -> Result<OwnedHandle> {
process_job(unsafe { GetCurrentProcess() })
}
/// Called before writing the installer script, while PowerShell is waiting on stdin.
pub(crate) fn installer_job(child: &tokio::process::Child) -> Result<OwnedHandle> {
let process = child
.raw_handle()
.context("installer process handle is unavailable")?;
process_job(process)
}
fn process_job(process: HANDLE) -> Result<OwnedHandle> {
let job = unsafe { CreateJobObjectW(std::ptr::null(), std::ptr::null()) };
if job.is_null() {
return Err(io::Error::last_os_error()).context("failed to create updater job");
}
let owned = unsafe { OwnedHandle::from_raw_handle(job) };
let mut limits: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = unsafe { std::mem::zeroed() };
limits.BasicLimitInformation.LimitFlags =
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_BREAKAWAY_OK;
if unsafe {
SetInformationJobObject(
job,
JobObjectExtendedLimitInformation,
(&limits as *const JOBOBJECT_EXTENDED_LIMIT_INFORMATION).cast(),
std::mem::size_of_val(&limits) as u32,
)
} == 0
|| unsafe { AssignProcessToJobObject(job, process) } == 0
{
return Err(io::Error::last_os_error())
.context("failed to contain updater installer processes");
}
Ok(owned)
}
#[cfg(test)]
#[path = "windows_tests.rs"]
mod tests;
@@ -1,365 +0,0 @@
use super::Process;
use pretty_assertions::assert_eq;
use std::os::windows::io::AsRawHandle;
use std::os::windows::io::FromRawHandle;
use std::os::windows::io::OwnedHandle;
use std::os::windows::process::CommandExt;
use std::process::Stdio;
use std::time::Duration;
use tokio::io::AsyncReadExt;
use windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED;
use windows_sys::Win32::Foundation::HANDLE_FLAG_INHERIT;
use windows_sys::Win32::Foundation::SetHandleInformation;
use windows_sys::Win32::System::JobObjects::IsProcessInJob;
use windows_sys::Win32::System::Threading::CREATE_NO_WINDOW;
use windows_sys::Win32::System::Threading::DETACHED_PROCESS;
use windows_sys::Win32::System::Threading::TerminateProcess;
#[tokio::test]
async fn captured_stdio_closes_while_child_is_alive() {
const TEST: &str = "backend::windows::tests::captured_stdio_closes_while_child_is_alive";
const ROLE: &str = "CODEX_TEST_STDIO_ROLE";
const HOME: &str = "CODEX_TEST_STDIO_HOME";
let executable = std::env::current_exe().expect("test executable");
if let Ok(role) = std::env::var(ROLE) {
let home = std::path::PathBuf::from(std::env::var_os(HOME).expect("test home"));
if role == "child" {
eprintln!("child stderr");
std::fs::write(home.join("ready"), []).unwrap();
tokio::time::sleep(Duration::from_secs(30)).await;
return;
}
let handles = [
std::io::stdout().as_raw_handle(),
std::io::stderr().as_raw_handle(),
];
for handle in handles {
assert_ne!(
unsafe { SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) },
0
);
}
let mut command = tokio::process::Command::new(executable);
command
.args(["--exact", TEST, "--nocapture"])
.env(ROLE, "child")
// The CI job may forbid breakaway; it does not affect stdio inheritance.
.creation_flags(DETACHED_PROCESS)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(std::fs::File::create(home.join("child.log")).unwrap());
let child = super::spawn_without_inheriting_stdio(&mut command).unwrap();
let pid = child.id().unwrap();
let started = Process::open(pid).unwrap().unwrap().start_time().unwrap();
std::fs::write(
home.join("pid"),
serde_json::to_vec(&(pid, started)).unwrap(),
)
.unwrap();
println!("launcher stdout");
eprintln!("launcher stderr");
return;
}
let home = tempfile::tempdir().unwrap();
let mut launcher = tokio::process::Command::new(executable)
.args(["--exact", TEST, "--nocapture"])
.env(ROLE, "launcher")
.env(HOME, home.path())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.kill_on_drop(true)
.spawn()
.unwrap();
let status = tokio::time::timeout(Duration::from_secs(10), launcher.wait())
.await
.expect("launcher exit")
.unwrap();
let (pid, started): (u32, String) =
serde_json::from_slice(&std::fs::read(home.path().join("pid")).unwrap()).unwrap();
let child = Process::open(pid).unwrap().expect("live child");
assert_eq!(
child.start_time().unwrap(),
started,
"fixture PID was reused"
);
let mut stdout = String::new();
let mut stderr = String::new();
let captured = tokio::time::timeout(Duration::from_secs(5), async {
let ready = home.path().join("ready");
while !ready.exists() {
tokio::time::sleep(Duration::from_millis(25)).await;
}
tokio::try_join!(
launcher
.stdout
.as_mut()
.unwrap()
.read_to_string(&mut stdout),
launcher
.stderr
.as_mut()
.unwrap()
.read_to_string(&mut stderr),
)
})
.await;
let still_running = child.is_running();
child.terminate().expect("cleanup child");
tokio::time::timeout(Duration::from_secs(5), async {
while child.is_running().unwrap() {
tokio::time::sleep(Duration::from_millis(25)).await;
}
})
.await
.expect("child exit after cleanup");
captured.expect("launcher output must close").unwrap();
assert!(status.success(), "{stderr}");
assert!(
still_running.unwrap(),
"child exited before its launcher output closed"
);
assert!(stdout.contains("launcher stdout"));
assert!(stderr.contains("launcher stderr"));
assert!(
std::fs::read_to_string(home.path().join("child.log"))
.unwrap()
.contains("child stderr")
);
}
#[test]
fn detached_launch_preflight_rejects_restrictive_job() {
const CHILD: &str = "CODEX_TEST_RESTRICTIVE_LAUNCH_JOB";
let executable = std::env::current_exe().expect("test executable");
if std::env::var_os(CHILD).is_some() {
let job = unsafe { super::CreateJobObjectW(std::ptr::null(), std::ptr::null()) };
assert!(!job.is_null());
let job = unsafe {
<std::os::windows::io::OwnedHandle as std::os::windows::io::FromRawHandle>::from_raw_handle(job)
};
assert_ne!(
unsafe {
super::AssignProcessToJobObject(job.as_raw_handle(), super::GetCurrentProcess())
},
0
);
// A new job does not permit breakaway. Reject before any lifecycle mutation.
let err = super::ensure_detached_launch(&executable).expect_err("breakaway forbidden");
assert!(
err.is::<super::DetachedLaunchRestricted>(),
"expected a classified job restriction: {err:#}"
);
// File access failures must still fail normally, even in a restricted
// job: a CLI must not hide corrupt or inaccessible installations.
let temp = tempfile::tempdir().expect("test directory");
let err =
super::ensure_detached_launch(temp.path()).expect_err("directory is not an executable");
assert!(!err.is::<super::DetachedLaunchRestricted>(), "{err:#}");
return;
}
let output = std::process::Command::new(executable)
.args([
"--exact",
"backend::windows::tests::detached_launch_preflight_rejects_restrictive_job",
"--nocapture",
])
.env(CHILD, "1")
.output()
.expect("isolated job test");
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"));
}
#[test]
fn detached_launch_preflight_allows_residual_job() {
const CHILD: &str = "CODEX_TEST_RESIDUAL_LAUNCH_JOB";
let executable = std::env::current_exe().expect("test executable");
if std::env::var_os(CHILD).is_some() {
let mut jobs = Vec::new();
for inner in [false, true] {
let job = unsafe { super::CreateJobObjectW(std::ptr::null(), std::ptr::null()) };
assert!(!job.is_null());
let job = unsafe { OwnedHandle::from_raw_handle(job) };
if inner {
let mut limits: super::JOBOBJECT_EXTENDED_LIMIT_INFORMATION =
unsafe { std::mem::zeroed() };
limits.BasicLimitInformation.LimitFlags = super::JOB_OBJECT_LIMIT_BREAKAWAY_OK;
assert_ne!(
unsafe {
super::SetInformationJobObject(
job.as_raw_handle(),
super::JobObjectExtendedLimitInformation,
(&limits as *const super::JOBOBJECT_EXTENDED_LIMIT_INFORMATION).cast(),
std::mem::size_of_val(&limits) as u32,
)
},
0
);
}
assert_ne!(
unsafe {
super::AssignProcessToJobObject(job.as_raw_handle(), super::GetCurrentProcess())
},
0
);
jobs.push(job);
}
let mut probe = std::process::Command::new(&executable)
.creation_flags(
super::CREATE_SUSPENDED
| super::DETACHED_PROCESS
| super::CREATE_BREAKAWAY_FROM_JOB,
)
.spawn()
.expect("breakaway probe");
let mut in_outer = 0;
let mut in_inner = 0;
let outer_checked = unsafe {
IsProcessInJob(
probe.as_raw_handle(),
jobs[0].as_raw_handle(),
&mut in_outer,
)
};
let inner_checked = unsafe {
IsProcessInJob(
probe.as_raw_handle(),
jobs[1].as_raw_handle(),
&mut in_inner,
)
};
probe.kill().expect("terminate probe");
probe.wait().expect("reap probe");
assert_ne!(outer_checked, 0);
assert_ne!(inner_checked, 0);
assert_ne!(in_outer, 0, "probe must retain its outer job");
assert_eq!(in_inner, 0, "probe must leave its inner job");
super::ensure_detached_launch(&executable).expect("residual job must be accepted");
if let Err(err) = super::ensure_not_elevated() {
assert!(err.to_string().contains("non-elevated terminal"));
return;
}
let temp = tempfile::tempdir().expect("temp dir");
let script = temp.path().join("codex.cmd");
std::fs::write(
&script,
"@echo off\r\nif \"%3\"==\"--help\" exit /b 1\r\necho ready > \"%~dp0ready\"\r\nfor /l %%i in (1,1,10000000) do @rem\r\n",
)
.expect("write daemon fixture");
let backend = crate::backend::pid::PidBackend::new(
script,
temp.path().join("state").join("daemon.pid"),
/*remote_control_enabled*/ false,
);
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("runtime");
let pid = runtime
.block_on(backend.start())
.expect("daemon launch")
.expect("new daemon pid");
let process = Process::open(pid)
.expect("open daemon")
.expect("live daemon");
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
while !temp.path().join("ready").exists() && std::time::Instant::now() < deadline {
std::thread::sleep(std::time::Duration::from_millis(50));
}
let ready = temp.path().join("ready").exists();
let outer_checked = unsafe {
IsProcessInJob(
process.0.as_raw_handle(),
jobs[0].as_raw_handle(),
&mut in_outer,
)
};
let inner_checked = unsafe {
IsProcessInJob(
process.0.as_raw_handle(),
jobs[1].as_raw_handle(),
&mut in_inner,
)
};
process.terminate().expect("terminate daemon fixture");
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
while process.is_running().expect("daemon liveness") && std::time::Instant::now() < deadline
{
std::thread::sleep(std::time::Duration::from_millis(50));
}
assert!(!process.is_running().expect("daemon liveness"));
assert!(ready, "daemon fixture did not start");
assert_ne!(outer_checked, 0);
assert_ne!(inner_checked, 0);
assert_ne!(in_outer, 0, "daemon must retain its outer job");
assert_eq!(in_inner, 0, "daemon must leave its inner job");
return;
}
let output = std::process::Command::new(executable)
.args([
"--exact",
"backend::windows::tests::detached_launch_preflight_allows_residual_job",
"--nocapture",
])
.env(CHILD, "1")
.output()
.expect("isolated job test");
assert!(
output.status.success(),
"{}\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"));
}
#[tokio::test]
async fn identity_queries_do_not_require_termination_access() {
let mut child = tokio::process::Command::new("powershell.exe")
.args([
"-NoProfile",
"-NonInteractive",
"-Command",
"Start-Sleep 60",
])
.creation_flags(CREATE_NO_WINDOW)
.kill_on_drop(true)
.spawn()
.expect("child");
let process = Process::open(child.id().expect("pid"))
.expect("query handle")
.expect("live process");
assert!(!process.start_time().expect("creation time").is_empty());
assert!(process.is_running().expect("liveness"));
// Check the rights on the actual query handle, independent of privileges
// that could let the caller reopen the process with termination access.
assert_eq!(
unsafe {
TerminateProcess(process.0.as_raw_handle(), /*uexitcode*/ 1)
},
0
);
assert_eq!(
std::io::Error::last_os_error().raw_os_error(),
Some(ERROR_ACCESS_DENIED as i32)
);
assert!(
process
.is_running()
.expect("query must not terminate child")
);
child
.kill()
.await
.expect("cleanup through original spawn handle");
}
@@ -7,7 +7,6 @@ use std::process::Command;
use anyhow::Result;
pub(crate) fn set_working_directory(command: &mut Command, state_dir: &Path) -> Result<()> {
#[cfg(unix)]
let cwd_missing = match std::env::current_dir() {
Ok(_) => false,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => true,
@@ -32,8 +31,6 @@ pub(crate) fn set_working_directory(command: &mut Command, state_dir: &Path) ->
}
// Preserve process-scoped paths before changing cwd; CA names match CUSTOM_CA_ENV_KEYS.
for name in [
#[cfg(windows)]
"CODEX_SQLITE_HOME",
"CODEX_CA_CERTIFICATE",
"SSL_CERT_FILE",
"REQUESTS_CA_BUNDLE",
@@ -82,11 +79,8 @@ pub(crate) fn set_working_directory(command: &mut Command, state_dir: &Path) ->
.collect::<std::io::Result<Vec<_>>>()?;
command.env("SSL_CERT_DIR", std::env::join_paths(paths)?);
}
#[cfg(unix)]
if cwd_missing {
command.current_dir(state_dir);
}
#[cfg(windows)]
command.current_dir(state_dir);
Ok(())
}
+1 -23
View File
@@ -74,28 +74,6 @@ async fn connect_at(socket_path: &Path, url: &str) -> Result<WebSocketStream<Uni
Ok(websocket)
}
#[cfg(windows)]
pub(crate) async fn request_shutdown(socket_path: &Path, pid: u32) -> Result<()> {
timeout(CONTROL_SOCKET_RESPONSE_TIMEOUT, async {
let mut websocket = connect_at(socket_path, "ws://localhost/daemon/shutdown").await?;
websocket
.send(Message::Text(pid.to_string().into()))
.await?;
let reply = websocket
.next()
.await
.context("shutdown socket closed without acknowledgment")??;
anyhow::ensure!(
matches!(reply, Message::Text(ack) if ack == pid.to_string()),
"shutdown acknowledgment did not match the managed process {pid}"
);
websocket.close(None).await?;
Ok(())
})
.await
.context("timed out waiting for managed app-server shutdown acknowledgment")?
}
pub(crate) async fn initialize<S>(
websocket: &mut WebSocketStream<S>,
experimental_api: bool,
@@ -183,7 +161,7 @@ fn parse_version_from_user_agent(user_agent: &str) -> Result<String> {
Ok(version.to_string())
}
#[cfg(all(test, unix))]
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
+1 -12
View File
@@ -25,7 +25,6 @@ impl Drop for InstallLock {
pub(crate) async fn acquire_install_lock(root: &Path) -> Result<InstallLock> {
let lock = root.join("install.lock");
let deadline = tokio::time::Instant::now() + Duration::from_secs(30);
#[cfg(unix)]
let use_lockf = {
// Match the installer so both processes coordinate on the same lock.
let choice = tokio::process::Command::new("/bin/sh")
@@ -95,14 +94,8 @@ pub(crate) async fn acquire_install_lock(root: &Path) -> Result<InstallLock> {
};
let mut options = OpenOptions::new();
options.create(true).truncate(false).write(true);
#[cfg(windows)]
{
use std::os::windows::fs::OpenOptionsExt;
options.share_mode(0);
}
loop {
let acquired = options.open(&lock);
#[cfg(unix)]
let acquired = acquired.and_then(|file| {
{
use std::os::fd::AsRawFd;
@@ -125,11 +118,7 @@ pub(crate) async fn acquire_install_lock(root: &Path) -> Result<InstallLock> {
_directory_owner: None,
});
}
Err(error)
if error.kind() == std::io::ErrorKind::WouldBlock
|| cfg!(windows)
&& (error.raw_os_error() == Some(32)
|| error.kind() == std::io::ErrorKind::PermissionDenied) => {}
Err(error) if error.kind() == std::io::ErrorKind::WouldBlock => {}
Err(error) => return Err(error).context("failed to acquire daemon installer lock"),
}
if tokio::time::Instant::now() >= deadline {
-4
View File
@@ -24,8 +24,6 @@ pub async fn start_with_features_classified(
features: &BTreeMap<String, bool>,
) -> Result<LifecycleOutput, StartError> {
ensure_supported_platform()?;
#[cfg(windows)]
crate::backend::windows::ensure_not_elevated()?;
let mut daemon = Daemon::from_environment()?;
daemon.log_diagnostics = true;
let _operation_lock = daemon.acquire_operation_lock().await?;
@@ -40,8 +38,6 @@ pub async fn start_with_features_classified(
/// then verify effective server compatibility after this operation completes.
pub async fn restart_with_features(features: &BTreeMap<String, bool>) -> Result<LifecycleOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
crate::backend::windows::ensure_not_elevated()?;
let daemon = Daemon::from_environment()?;
let _operation_lock = daemon.acquire_operation_lock().await?;
let selected = daemon.current_installation()?;
+1 -65
View File
@@ -2,12 +2,6 @@
mod backend;
mod background_command;
#[cfg(windows)]
pub use backend::windows::DetachedLaunchRestricted;
#[cfg(windows)]
pub use backend::windows::is_elevated;
#[cfg(windows)]
use backend::windows::try_lock_file;
mod client;
mod diagnostics;
mod install_lock;
@@ -42,7 +36,6 @@ use codex_app_server_protocol::RemoteControlPairingStartResponse;
use codex_app_server_transport::app_server_control_socket_path;
use codex_utils_home_dir::find_codex_home;
use managed_install::managed_codex_bin;
#[cfg(any(unix, windows))]
use managed_install::managed_codex_version;
use serde::Serialize;
use settings::DaemonSettings;
@@ -52,13 +45,7 @@ use telemetry::StartFailure;
use tokio::time::sleep;
const START_POLL_INTERVAL: Duration = Duration::from_millis(50);
// An older updater can pass background policy to a replacement daemon, so retain
// the longer readiness allowance during upgrades on macOS. On Linux, a cold
// start from a rotational disk can take more than ten seconds.
#[cfg(any(target_os = "macos", target_os = "linux"))]
const START_TIMEOUT: Duration = Duration::from_secs(30);
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
const START_TIMEOUT: Duration = Duration::from_secs(10);
// Leave room for the longest graceful stop, forced-exit check, and restart.
const OPERATION_LOCK_TIMEOUT: Duration =
Duration::from_secs(MAX_SHUTDOWN_GRACE_SECONDS as u64 + 75);
@@ -214,7 +201,6 @@ pub struct RemoteControlOutput {
pub app_server_version: Option<String>,
}
#[cfg(any(unix, windows))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RestartIfRunningOutcome {
Busy,
@@ -224,7 +210,6 @@ pub(crate) enum RestartIfRunningOutcome {
Restarted,
}
#[cfg(any(unix, windows))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RestartMode {
IfVersionChanged,
@@ -232,7 +217,6 @@ pub(crate) enum RestartMode {
Always,
}
#[cfg(any(unix, windows))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum RestartDecision {
NotReady,
@@ -242,28 +226,17 @@ enum RestartDecision {
pub async fn run(command: LifecycleCommand) -> Result<LifecycleOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
if matches!(
command,
LifecycleCommand::Start { .. } | LifecycleCommand::Restart { .. }
) {
backend::windows::ensure_not_elevated()?;
}
// Keep daemon package preparation off callers' async stack frames.
Box::pin(Daemon::from_environment()?.run(command)).await
}
pub async fn bootstrap(options: BootstrapOptions) -> Result<BootstrapOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
backend::windows::ensure_not_elevated()?;
Box::pin(Daemon::from_environment()?.bootstrap(options)).await
}
pub async fn ensure_remote_control_ready() -> Result<RemoteControlReadyOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
backend::windows::ensure_not_elevated()?;
Box::pin(Daemon::from_environment()?.ensure_remote_control_ready()).await
}
@@ -290,8 +263,6 @@ pub async fn start_remote_control_pairing() -> Result<RemoteControlPairingStartR
pub async fn set_remote_control(mode: RemoteControlMode) -> Result<RemoteControlOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
backend::windows::ensure_not_elevated()?;
Box::pin(Daemon::from_environment()?.set_remote_control(mode)).await
}
@@ -300,8 +271,6 @@ pub async fn run_pid_update_loop(
restore_release: Option<String>,
) -> Result<()> {
ensure_supported_platform()?;
#[cfg(windows)]
backend::windows::ensure_not_elevated()?;
update_loop::run(http_client_factory, restore_release).await
}
@@ -323,23 +292,13 @@ pub async fn update(
http_client_factory: codex_http_client::HttpClientFactory,
) -> Result<UpdateOutput> {
ensure_supported_platform()?;
#[cfg(windows)]
backend::windows::ensure_not_elevated()?;
update_loop::request_manual_update(&Daemon::from_environment()?, http_client_factory).await
}
#[cfg(any(unix, windows))]
fn ensure_supported_platform() -> Result<()> {
Ok(())
}
#[cfg(not(any(unix, windows)))]
fn ensure_supported_platform() -> Result<()> {
Err(anyhow!(
"codex app-server daemon lifecycle is only supported on Unix and Windows platforms"
))
}
#[derive(Clone)]
struct Daemon {
// Feature-aware TUI startup owns a live terminal. Direct lifecycle commands
@@ -555,7 +514,6 @@ impl Daemon {
.await)
}
#[cfg(any(unix, windows))]
pub(crate) async fn try_restart_if_running(
&self,
mode: RestartMode,
@@ -605,8 +563,6 @@ impl Daemon {
}
RestartDecision::AlreadyCurrent => RestartIfRunningOutcome::AlreadyCurrent,
RestartDecision::Restart => {
#[cfg(windows)]
backend::windows::ensure_detached_launch(managed_codex_bin)?;
if let Err(err) = thread_recovery::discard_pending(self) {
let _ = stderr_writer().write_all(format!(
"warning: failed to clear stale daemon recovery before update: {err}\n"
@@ -901,7 +857,6 @@ impl Daemon {
backend::pid_update_loop_backend(self.backend_paths(&settings))
.stop()
.await?;
#[cfg(unix)]
{
use std::os::unix::fs::FileTypeExt;
@@ -927,7 +882,6 @@ impl Daemon {
backend.start().await?;
let info = self.wait_until_ready().await?;
let auto_update_enabled = managed.ensure_managed_updater(&settings).await?;
#[cfg(unix)]
// Older automatic updaters have no manual request socket to wait for.
if auto_update_enabled
&& managed_install::supports_daemon_command(
@@ -1099,8 +1053,6 @@ impl Daemon {
fn ensure_managed_codex_bin(&self) -> Result<()> {
if self.managed_codex_bin.is_file() {
#[cfg(windows)]
backend::windows::ensure_detached_launch(&self.managed_codex_bin)?;
return Ok(());
}
@@ -1110,16 +1062,10 @@ impl Daemon {
))
}
#[cfg(any(unix, windows))]
async fn managed_codex_version_best_effort(&self) -> Option<String> {
managed_codex_version(&self.managed_codex_bin).await.ok()
}
#[cfg(not(any(unix, windows)))]
async fn managed_codex_version_best_effort(&self) -> Option<String> {
None
}
fn backend_paths(&self, settings: &DaemonSettings) -> BackendPaths {
self.backend_paths_with_bin(settings, &self.managed_codex_bin)
}
@@ -1163,7 +1109,6 @@ impl Daemon {
async fn open_operation_lock_file(&self) -> Result<tokio::fs::File> {
if let Some(parent) = self.operation_lock_file.parent() {
#[cfg(unix)]
if let Some(home) = parent.parent() {
tokio::fs::create_dir_all(home).await?;
}
@@ -1242,7 +1187,6 @@ fn already_remote_control_status(mode: RemoteControlMode) -> RemoteControlStatus
}
}
#[cfg(any(unix, windows))]
fn restart_decision(
mode: RestartMode,
info: Option<&client::ProbeInfo>,
@@ -1262,7 +1206,6 @@ fn restart_decision(
}
}
#[cfg(unix)]
fn try_lock_file(file: &tokio::fs::File) -> Result<bool> {
use std::os::fd::AsRawFd;
@@ -1278,12 +1221,7 @@ fn try_lock_file(file: &tokio::fs::File) -> Result<bool> {
Err(err).context("failed to lock daemon operation")
}
#[cfg(not(any(unix, windows)))]
fn try_lock_file(_file: &tokio::fs::File) -> Result<bool> {
Ok(true)
}
#[cfg(all(test, any(unix, windows)))]
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use tempfile::TempDir;
@@ -1300,7 +1238,6 @@ mod tests {
use super::RestartMode;
use super::restart_decision;
use crate::client::ProbeInfo;
#[cfg(unix)]
use crate::settings::DaemonSettings;
#[test]
@@ -1513,7 +1450,6 @@ mod tests {
assert!(!daemon.recovery_file().expect("recovery path").exists());
}
#[cfg(unix)]
#[tokio::test]
async fn managed_local_backend_counts_as_bootstrapped_without_updater() {
let home = TempDir::new().expect("home");
@@ -61,9 +61,7 @@ pub(crate) fn managed_codex_bin(codex_home: &Path) -> PathBuf {
let current = root.join("current");
let packaged = current.join("bin").join(managed_codex_file_name());
let legacy = current.join(managed_codex_file_name());
if packaged.is_file()
|| !legacy.is_file() && (cfg!(windows) || root.ends_with("app-server-daemon"))
{
if packaged.is_file() || !legacy.is_file() && (root.ends_with("app-server-daemon")) {
packaged
} else {
legacy
@@ -123,8 +121,6 @@ pub(crate) async fn supports_daemon_update_loop(codex_bin: &Path) -> bool {
/// Probe an internal daemon command without running a long-lived process.
pub(crate) async fn supports_daemon_command(codex_bin: &Path, args: &[&str]) -> bool {
let mut command = Command::new(codex_bin);
#[cfg(windows)]
command.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW);
timeout(
Duration::from_secs(5),
command
@@ -151,8 +147,6 @@ pub(crate) async fn resolved_managed_codex_bin(codex_bin: &Path) -> Result<PathB
pub(crate) async fn managed_codex_version(codex_bin: &Path) -> Result<String> {
let mut command = Command::new(codex_bin);
#[cfg(windows)]
command.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW);
let output = command
.arg("--version")
.kill_on_drop(true)
@@ -224,23 +218,15 @@ pub(crate) fn executable_identity_from_reader(
pub(crate) fn path_digest(path: &Path) -> [u8; 32] {
let mut hasher = blake3::Hasher::new();
#[cfg(unix)]
{
use std::os::unix::ffi::OsStrExt;
hasher.update(path.as_os_str().as_bytes());
}
#[cfg(windows)]
{
use std::os::windows::ffi::OsStrExt;
for unit in path.as_os_str().encode_wide() {
hasher.update(&unit.to_le_bytes());
}
}
*hasher.finalize().as_bytes()
}
fn managed_codex_file_name() -> &'static str {
if cfg!(windows) { "codex.exe" } else { "codex" }
"codex"
}
fn parse_codex_version(output: &str) -> Result<String> {
@@ -54,7 +54,6 @@ fn discovers_package_and_legacy_installs() {
home.path().join("packages/app-server-daemon")
);
#[cfg(unix)]
{
let dedicated = home.path().join("packages/app-server-daemon");
std::fs::write(&dedicated, b"not a directory").expect("unreadable selection");
@@ -62,7 +61,6 @@ fn discovers_package_and_legacy_installs() {
}
}
#[cfg(unix)]
#[test]
fn updater_only_runs_for_stable_installer_owned_releases() {
let home = tempfile::TempDir::new().expect("home");
@@ -111,7 +109,6 @@ fn updater_only_runs_for_stable_installer_owned_releases() {
));
}
#[cfg(unix)]
#[tokio::test]
async fn older_managed_binary_does_not_claim_updater_support() {
let temp = tempfile::TempDir::new().expect("home");
@@ -101,8 +101,6 @@ pub(crate) async fn request(daemon: &Daemon) -> Result<UpdateOutput> {
};
let mut response = Vec::new();
let transport = async {
#[cfg(windows)]
connection.ensure_non_elevated_peer()?;
connection.write_all(b"update\n").await?;
connection
.take(MAX_RESPONSE_BYTES)
@@ -185,10 +183,6 @@ pub(super) async fn handle_request(
terminate: &mut Signal,
trigger: UpdateTrigger<'_>,
) -> Result<RequestDisposition> {
#[cfg(windows)]
if connection.ensure_non_elevated_peer().is_err() {
return Ok(RequestDisposition::Unchanged);
}
let mut request = [0; 7];
if !matches!(
timeout(Duration::from_secs(5), connection.read_exact(&mut request)).await,
+1 -17
View File
@@ -38,16 +38,12 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
if running.is_none() && client::probe(&legacy.socket_path).await.is_ok() {
return super::manual_update::unsupported(legacy).await;
}
#[cfg(unix)]
let mut terminate = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())?;
let cancellation = async {
#[cfg(unix)]
tokio::select! {
_ = terminate.recv() => {},
_ = tokio::signal::ctrl_c() => {},
}
#[cfg(windows)]
let _ = tokio::signal::ctrl_c().await;
Some(())
};
let mut cancellation = std::pin::pin!(cancellation);
@@ -60,7 +56,6 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
"the published installer does not support daemon migration yet; the legacy installation was left unchanged"
);
eprintln!("Preparing the daemon update in {}...", root.display());
#[cfg(unix)]
{
if matches!(
run_installer_script(
@@ -75,11 +70,6 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
return Err(std::io::Error::from(std::io::ErrorKind::Interrupted).into());
}
}
#[cfg(windows)]
tokio::select! {
result = run_installer_script(&script, InstallerMode::Migration, &root) => { result?; },
_ = &mut cancellation => return Err(std::io::Error::from(std::io::ErrorKind::Interrupted).into()),
}
let _install_lock = acquire_install_lock(&root).await?;
let pending = root.join(".migration-current");
@@ -94,11 +84,7 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
&& std::fs::read_to_string(root.join("auto-update-version"))? == name.to_string_lossy(),
"installer did not prepare a latest-channel daemon package"
);
let entrypoint = if cfg!(windows) {
"bin/codex.exe"
} else {
"bin/codex"
};
let entrypoint = "bin/codex";
let binary = release.join(entrypoint);
let version = managed_install::managed_codex_version(&binary).await?;
anyhow::ensure!(
@@ -114,8 +100,6 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
.await,
"the latest production release does not support daemon migration yet; the legacy daemon was left running"
);
#[cfg(windows)]
backend::windows::ensure_detached_launch(&binary)?;
anyhow::ensure!(
selected_release(legacy)? == previous,
"daemon selection changed; retry the update"
@@ -48,8 +48,6 @@ pub async fn update_from_cli(
confirm: impl FnOnce(&InstallRequest) -> Result<bool>,
) -> Result<Option<crate::UpdateOutput>> {
crate::ensure_supported_platform()?;
#[cfg(windows)]
crate::backend::windows::ensure_not_elevated()?;
let daemon = Daemon::from_environment()?;
let settings = daemon.load_settings().await?;
let source = InstallContext::current().package_layout.as_ref();
@@ -157,15 +155,9 @@ async fn prepare_from_package(
let version = manifest.version.to_string();
let target = platform_target()?;
let mut metadata: serde_json::Value = serde_json::from_slice(&manifest_bytes)?;
let entrypoint = if cfg!(windows) {
"bin/codex.exe"
} else {
"bin/codex"
};
let entrypoint = "bin/codex";
let source_entrypoint = metadata["entrypoint"].as_str().unwrap_or_default();
let winget = cfg!(windows)
&& metadata["layoutVersion"] == 1
&& source_entrypoint == format!("codex-{target}.exe");
let winget = false;
anyhow::ensure!(
metadata["target"] == target && (source_entrypoint == entrypoint || winget),
"the CLI package does not match this platform or executable"
@@ -250,19 +242,6 @@ async fn prepare_from_package(
// source. Hash the final tree for reuse, since it now differs from the source.
let digest = if winget {
std::fs::create_dir_all(stage.path().join("bin"))?;
#[cfg(windows)]
for (from, to) in [
(staged_exe, Path::new(entrypoint)),
(
Path::new("codex-code-mode-host.exe"),
Path::new("bin/codex-code-mode-host.exe"),
),
] {
windows::publish_release(&stage.path().join(from), &stage.path().join(to)).await?;
if let Some(digest) = staged_digests.remove(from) {
staged_digests.insert(to.to_path_buf(), digest);
}
}
let voice_path = stage.path().join("codex-resources/voice/manifest.json");
if voice_path.try_exists()? {
let mut voice: serde_json::Value =
@@ -309,13 +288,9 @@ async fn prepare_from_package(
"an existing daemon release has different contents; refusing to overwrite it"
);
} else {
#[cfg(unix)]
if !stage.path().join("codex").exists() {
std::os::unix::fs::symlink("bin/codex", stage.path().join("codex"))?;
}
#[cfg(windows)]
windows::publish_release(stage.path(), &release).await?;
#[cfg(not(windows))]
std::fs::rename(stage.path(), &release)?;
}
let release = release.canonicalize()?;
@@ -334,12 +309,6 @@ async fn prepare_from_package(
&& (backend.is_some() || crate::client::probe(&daemon.socket_path).await.is_err()),
"daemon package location or socket ownership changed while preparing its package; retry the command"
);
#[cfg(windows)]
if backend.is_some() {
crate::backend::windows::ensure_detached_launch(&release.join(entrypoint))?;
}
#[cfg(windows)]
windows::validate_selection(&root)?;
if mode == InstallMode::Replace {
let stopped = async {
crate::backend::pid_update_loop_backend(daemon.backend_paths(settings))
@@ -388,15 +357,12 @@ async fn prepare_from_package(
std::fs::remove_file(marker)?;
}
if previous_release.as_deref() != Some(release.as_path()) {
#[cfg(unix)]
{
let temporary = tempfile::TempDir::new_in(&root)?;
let link = temporary.path().join("current");
std::os::unix::fs::symlink(&release, &link)?;
std::fs::rename(link, root.join("current"))?;
}
#[cfg(windows)]
windows::select_release(&root, &release)?;
if let Err(error) =
crate::release_pruning::record_selection(&root, previous_release.as_deref())
{
@@ -438,8 +404,7 @@ fn package_tree(
while let Some(path) = paths.pop() {
let relative = path.strip_prefix(root)?;
// The Unix installer adds this alias outside the package layout.
if cfg!(unix)
&& relative == Path::new("codex")
if relative == Path::new("codex")
&& std::fs::read_link(&path).ok().as_deref() == Some(Path::new("bin/codex"))
{
continue;
@@ -486,7 +451,6 @@ fn package_tree(
};
hasher.update(b"file");
hasher.update(digest.as_bytes());
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
hasher.update(&(metadata.permissions().mode() & 0o777).to_le_bytes());
@@ -505,28 +469,15 @@ fn stable_version(value: &str) -> Option<semver::Version> {
}
fn validate_package(root: &Path, entrypoint: &str) -> Result<()> {
let code_mode_host = Path::new(entrypoint).with_file_name(if cfg!(windows) {
"codex-code-mode-host.exe"
} else {
"codex-code-mode-host"
});
let code_mode_host = Path::new(entrypoint).with_file_name("codex-code-mode-host");
let code_mode_host = code_mode_host.to_string_lossy();
let mut names = vec![
"codex-package.json",
entrypoint,
code_mode_host.as_ref(),
if cfg!(windows) {
"codex-path/rg.exe"
} else {
"codex-path/rg"
},
"codex-path/rg",
];
if cfg!(windows) {
names.extend([
"codex-resources/codex-command-runner.exe",
"codex-resources/codex-windows-sandbox-setup.exe",
]);
} else if cfg!(target_os = "linux") {
if cfg!(target_os = "linux") {
names.push("codex-resources/bwrap");
}
for name in names {
@@ -535,7 +486,6 @@ fn validate_package(root: &Path, entrypoint: &str) -> Result<()> {
"local Codex package is missing {name}; reinstall the CLI or use the standalone installer"
));
}
#[cfg(unix)]
if name != "codex-package.json" {
use std::os::unix::fs::PermissionsExt;
if std::fs::metadata(root.join(name))?.permissions().mode() & 0o111 == 0 {
@@ -562,10 +512,6 @@ fn platform_target() -> Result<&'static str> {
}
}
#[cfg(windows)]
#[path = "prepare_install_windows.rs"]
mod windows;
#[cfg(test)]
#[path = "prepare_install_tests.rs"]
mod tests;
@@ -1,5 +1,4 @@
//! Covers complete-package staging, conservative selection, and legacy preservation.
#![cfg(unix)]
use std::collections::BTreeMap;
use super::InstallMode;
@@ -1,212 +0,0 @@
//! Publishes and selects Windows managed releases despite transient filesystem contention.
use std::os::windows::ffi::OsStrExt;
use std::os::windows::fs::OpenOptionsExt;
use std::os::windows::io::AsRawHandle;
use std::os::windows::process::CommandExt;
use std::path::Path;
use std::process::Command;
use std::time::Duration;
use anyhow::Context;
use anyhow::Result;
use windows_sys::Win32::Foundation::ERROR_SHARING_VIOLATION;
use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS;
use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OPEN_REPARSE_POINT;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_DELETE;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE;
use windows_sys::Win32::System::IO::DeviceIoControl;
use windows_sys::Win32::System::Threading::CREATE_NO_WINDOW;
const PUBLISH_RELEASE_RETRY_INTERVAL: Duration = Duration::from_millis(50);
const PUBLISH_RELEASE_RETRY_LIMIT: usize = 100;
pub(super) async fn publish_release(stage: &Path, release: &Path) -> Result<()> {
let mut retries = 0;
loop {
match std::fs::rename(stage, release) {
Ok(()) => return Ok(()),
// Executable scanners can briefly hold newly staged files without delete sharing.
Err(error)
if retries < PUBLISH_RELEASE_RETRY_LIMIT
&& (error.kind() == std::io::ErrorKind::PermissionDenied
|| error.raw_os_error() == Some(ERROR_SHARING_VIOLATION as i32)) =>
{
retries += 1;
tokio::time::sleep(PUBLISH_RELEASE_RETRY_INTERVAL).await;
}
Err(error) => {
return Err(error).with_context(|| {
format!(
"failed to publish managed daemon release from {} to {}",
stage.display(),
release.display()
)
});
}
}
}
}
pub(super) fn select_release(root: &Path, release: &Path) -> Result<()> {
select_release_with(root, release, retarget_junction)
}
fn select_release_with(
root: &Path,
release: &Path,
retarget: impl FnOnce(&Path, &Path) -> Result<()>,
) -> Result<()> {
let release = release.canonicalize()?;
let current = root.join("current");
if current.symlink_metadata().is_err() {
let temporary = tempfile::TempDir::new_in(root)?;
let junction = temporary.path().join("current");
std::fs::create_dir(&junction)?;
return match retarget(&junction, &release) {
Ok(()) => Ok(std::fs::rename(junction, current)?),
Err(error) if is_permission_denied(&error) => install_junction(root, &release)
.with_context(|| format!("failed to create managed daemon junction after native creation was denied: {error:#}")),
Err(error) => Err(error),
};
}
validate_selection(root)?;
match retarget(&current, &release) {
Ok(()) => Ok(()),
Err(error) if is_permission_denied(&error) => {
install_junction(root, &release).with_context(|| format!("failed to replace managed daemon junction after retargeting was denied: {error:#}"))
}
Err(error) => Err(error),
}
}
fn is_permission_denied(error: &anyhow::Error) -> bool {
error
.downcast_ref::<std::io::Error>()
.is_some_and(|error| error.kind() == std::io::ErrorKind::PermissionDenied)
}
fn install_junction(root: &Path, release: &Path) -> Result<()> {
let temporary = tempfile::TempDir::new_in(root)?;
let junction = temporary.path().join("current");
let current = root.join("current");
let replacing = current.symlink_metadata().is_ok();
if replacing {
validate_selection(root)?;
}
// Some Windows policies deny in-process reparse-point mutation while allowing the system
// junction creator. Pass paths through the environment so cmd metacharacters stay quoted.
let system_root = std::env::var_os("SystemRoot").context("SystemRoot is not set")?;
let command_shell = Path::new(&system_root).join("System32").join("cmd.exe");
anyhow::ensure!(
command_shell.is_absolute(),
"SystemRoot must be an absolute path"
);
let output = Command::new(command_shell)
.env("CODEX_DAEMON_JUNCTION_LINK", &junction)
.env("CODEX_DAEMON_JUNCTION_TARGET", release)
.args(["/d", "/s", "/e:on", "/v:off", "/c"])
.raw_arg(r#""mklink /J "%CODEX_DAEMON_JUNCTION_LINK%" "%CODEX_DAEMON_JUNCTION_TARGET%"""#)
.creation_flags(CREATE_NO_WINDOW)
.output()
.context("failed to run cmd.exe to create managed daemon junction")?;
anyhow::ensure!(
output.status.success(),
"cmd.exe could not create managed daemon junction (status {}): stdout: {}; stderr: {}",
output.status,
String::from_utf8_lossy(&output.stdout).trim(),
String::from_utf8_lossy(&output.stderr).trim()
);
if !replacing {
std::fs::rename(junction, current)?;
return Ok(());
}
let previous = temporary.path().join("previous");
std::fs::rename(&current, &previous)?;
if let Err(error) = std::fs::rename(&junction, &current) {
if let Err(restore_error) = std::fs::rename(&previous, &current) {
let preserved = temporary.keep();
anyhow::bail!(
"failed to replace managed daemon junction: {error}; also failed to restore the previous junction from {}: {restore_error}",
preserved.display()
);
}
return Err(error).context("failed to replace managed daemon junction");
}
if let Err(error) = std::fs::remove_dir(previous) {
tracing::warn!(
%error,
"failed to remove previous managed daemon junction"
);
}
Ok(())
}
fn retarget_junction(current: &Path, release: &Path) -> Result<()> {
// Use the same mount-point reparse operation as the standalone installer.
// Retargeting in place keeps current available to concurrent readers.
const FSCTL_SET_REPARSE_POINT: u32 = 0x0009_00a4;
const IO_REPARSE_TAG_MOUNT_POINT: u32 = 0xa000_0003;
const GENERIC_WRITE: u32 = 0x4000_0000;
let release: Vec<u16> = release.as_os_str().encode_wide().collect();
let prefix: Vec<u16> = r"\\?\".encode_utf16().collect();
let release = release.strip_prefix(prefix.as_slice()).unwrap_or(&release);
let substitute: Vec<u8> = r"\??\"
.encode_utf16()
.chain(release.iter().copied())
.flat_map(u16::to_le_bytes)
.collect();
u16::try_from(substitute.len() + 20).context("managed release path is too long")?;
let length = substitute.len() as u16;
// REPARSE_DATA_BUFFER: an 8-byte header, then four u16 byte offsets/lengths
// for substitute and print names. The UTF-16 path buffer starts at byte 16;
// both names have a trailing NUL, and the print name is empty.
let mut data = vec![0; substitute.len() + 20];
data[0..4].copy_from_slice(&IO_REPARSE_TAG_MOUNT_POINT.to_le_bytes());
data[4..6].copy_from_slice(&(length + 12).to_le_bytes());
data[10..12].copy_from_slice(&length.to_le_bytes());
data[12..14].copy_from_slice(&(length + 2).to_le_bytes());
data[16..16 + substitute.len()].copy_from_slice(&substitute);
let handle = std::fs::OpenOptions::new()
.access_mode(GENERIC_WRITE)
.share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT)
.open(current)?;
let mut returned = 0;
if unsafe {
DeviceIoControl(
handle.as_raw_handle(),
FSCTL_SET_REPARSE_POINT,
data.as_ptr().cast(),
data.len() as u32,
std::ptr::null_mut(),
0,
&mut returned,
std::ptr::null_mut(),
)
} == 0
{
return Err(std::io::Error::last_os_error())
.context("failed to retarget managed daemon junction");
}
Ok(())
}
pub(super) fn validate_selection(root: &Path) -> Result<()> {
let current = root.join("current");
if matches!(current.symlink_metadata(), Err(error) if error.kind() == std::io::ErrorKind::NotFound)
{
return Ok(());
}
anyhow::ensure!(
current.canonicalize()?.parent() == Some(root.join("releases").canonicalize()?.as_path()),
"refusing to replace a daemon selection outside its releases directory"
);
Ok(())
}
#[cfg(test)]
#[path = "prepare_install_windows_tests.rs"]
mod tests;
@@ -1,60 +0,0 @@
//! Verifies Windows package publication and selection without requiring an elevated daemon.
use anyhow::Context;
use pretty_assertions::assert_eq;
use std::os::windows::fs::OpenOptionsExt;
use std::time::Duration;
use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ;
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE;
#[tokio::test]
async fn publishing_release_retries_transient_access_denied() {
let home = tempfile::TempDir::new().unwrap();
let stage = home.path().join(".staging");
let release = home.path().join("release");
std::fs::create_dir(&stage).unwrap();
std::fs::write(stage.join("payload"), b"complete").unwrap();
let directory = std::fs::OpenOptions::new()
.read(true)
.share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE)
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
.open(&stage)
.unwrap();
let holder = tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(150)).await;
drop(directory);
});
super::publish_release(&stage, &release).await.unwrap();
holder.await.unwrap();
assert_eq!(std::fs::read(release.join("payload")).unwrap(), b"complete");
}
#[cfg(windows)]
#[test]
fn daemon_junction_can_be_created_retargeted_and_replaced_without_cli_links() {
let home = tempfile::TempDir::new().unwrap();
let root = home
.path()
.join("home & 100% ready!/packages/app-server-daemon");
for (version, native_denied) in [("first", true), ("second", false), ("third", true)] {
let release = root.join("releases").join(version);
std::fs::create_dir_all(&release).unwrap();
if native_denied {
super::select_release_with(&root, &release, |_, _| {
Err(std::io::Error::from(std::io::ErrorKind::PermissionDenied))
.context("failed to retarget managed daemon junction")
})
.unwrap();
} else {
super::select_release(&root, &release).unwrap();
}
assert_eq!(
root.join("current").canonicalize().unwrap(),
release.canonicalize().unwrap()
);
}
assert!(!root.with_file_name("standalone").exists());
}
@@ -6,8 +6,6 @@ use std::path::Path;
use anyhow::Context;
use anyhow::Result;
#[cfg(windows)]
use windows_sys::Win32::Storage::FileSystem as winfs;
use crate::Daemon;
use crate::backend;
@@ -21,7 +19,6 @@ struct Manifest {
entrypoint: String,
}
#[cfg(unix)]
fn selection_identity(current: &Path) -> Result<String> {
use std::os::unix::fs::MetadataExt;
let meta = current.symlink_metadata()?;
@@ -34,45 +31,6 @@ fn selection_identity(current: &Path) -> Result<String> {
))
}
#[cfg(windows)]
fn selection_identity(current: &Path) -> Result<String> {
use std::os::windows::fs::OpenOptionsExt;
use std::os::windows::io::AsRawHandle;
use windows_sys::Win32::System::IO::DeviceIoControl;
let file = std::fs::OpenOptions::new()
.access_mode(winfs::FILE_READ_ATTRIBUTES)
.share_mode(winfs::FILE_SHARE_READ | winfs::FILE_SHARE_WRITE | winfs::FILE_SHARE_DELETE)
.custom_flags(winfs::FILE_FLAG_BACKUP_SEMANTICS | winfs::FILE_FLAG_OPEN_REPARSE_POINT)
.open(current)?;
// FSCTL_READ_FILE_USN_DATA, with default V2 record version. The input is always
// "current", so 1024 bytes accommodates its journal record including the file name.
let mut record = [0u8; 1024];
let mut returned = 0;
if unsafe {
DeviceIoControl(
file.as_raw_handle(),
0x0009_00eb,
std::ptr::null(),
0,
record.as_mut_ptr().cast(),
record.len() as u32,
&raw mut returned,
std::ptr::null_mut(),
)
} == 0
{
return Err(std::io::Error::last_os_error().into());
}
let usn = i64::from_le_bytes(record[24..32].try_into()?);
anyhow::ensure!(
returned >= 32 && u16::from_le_bytes(record[4..6].try_into()?) == 2 && usn > 0,
"no reliable daemon selection journal record"
);
let file_id = u64::from_le_bytes(record[8..16].try_into()?);
Ok(format!("{file_id:x} {usn:x}"))
}
/// Call after changing the selection, while holding the installer lock.
pub(crate) fn record_selection(root: &Path, previous: Option<&Path>) -> Result<()> {
let current = root.join("current");
@@ -98,16 +56,6 @@ fn owned_mount(path: &Path) -> Result<u64> {
meta.is_dir() || meta.is_file(),
"not an ordinary package entry"
);
#[cfg(windows)]
{
use std::os::windows::fs::MetadataExt;
anyhow::ensure!(
meta.file_attributes() & winfs::FILE_ATTRIBUTE_REPARSE_POINT == 0,
"package entry is a reparse point"
);
// Volume mount points on Windows are reparse points.
Ok(0)
}
#[cfg(target_os = "linux")]
{
use std::os::fd::AsRawFd;
@@ -124,7 +72,7 @@ fn owned_mount(path: &Path) -> Result<u64> {
.parse()
.context("invalid package mount")
}
#[cfg(all(unix, not(target_os = "linux")))]
#[cfg(not(target_os = "linux"))]
{
use std::os::unix::fs::MetadataExt;
Ok(meta.dev())
@@ -224,8 +172,6 @@ pub(crate) async fn prune(daemon: &Daemon, root: &Path, settings: &DaemonSetting
}
let mut pending = vec![path.clone()];
while let Some(child) = pending.pop() {
// The Unix installer adds this alias; it never traverses outside the release.
#[cfg(unix)]
if child == path.join("codex")
&& std::fs::read_link(&child).ok().as_deref() == Some(Path::new("bin/codex"))
{
@@ -373,7 +373,7 @@ impl From<RemoteControlStatusChangedNotification> for RemoteControlReadyStatus {
}
}
#[cfg(all(test, unix))]
#[cfg(test)]
mod tests {
use anyhow::Result;
use codex_app_server_protocol::JSONRPCError;
@@ -12,10 +12,6 @@ pub struct StartError {
impl StartError {
pub fn failure_reason(&self) -> &'static str {
#[cfg(windows)]
if self.error.is::<crate::DetachedLaunchRestricted>() {
return "spawn";
}
match self.error.downcast_ref::<StartFailure>() {
Some(StartFailure::Spawn(_)) => "spawn",
Some(StartFailure::EarlyChildExit(_)) => "early_child_exit",
+1 -92
View File
@@ -3,7 +3,6 @@
use std::collections::VecDeque;
use std::io::Write;
use std::path::Path;
#[cfg(unix)]
use std::process::Command as StdCommand;
use std::process::Stdio;
use std::sync::Arc;
@@ -16,16 +15,12 @@ use codex_http_client::ClientRouteClass;
use codex_http_client::HttpClientFactory;
use codex_http_client::RouteAwareClientPool;
use futures::FutureExt;
#[cfg(unix)]
use std::os::unix::process::CommandExt;
use tokio::io::AsyncReadExt;
use tokio::io::AsyncWriteExt;
use tokio::process::Command;
#[cfg(unix)]
use tokio::signal::unix::Signal;
#[cfg(unix)]
use tokio::signal::unix::SignalKind;
#[cfg(unix)]
use tokio::signal::unix::signal;
use tokio::time::Instant;
use tokio::time::sleep;
@@ -37,7 +32,6 @@ use crate::RestartMode;
use crate::managed_install::ExecutableIdentity;
use crate::managed_install::executable_identity;
use crate::managed_install::resolved_managed_codex_bin;
#[cfg(any(target_os = "linux", target_os = "macos", windows))]
use crate::settings::DaemonSettings;
use crate::settings::UpdaterSettings;
@@ -71,10 +65,7 @@ const RESTART_RETRY_INTERVAL: Duration = Duration::from_millis(50);
// envelope, and the worst-case six-byte JSON escape for every captured byte.
const INSTALLER_STDERR_TAIL_BYTES: usize = 2 * 1024;
const INSTALLER_STDERR_DRAIN_TIMEOUT: Duration = Duration::from_secs(1);
#[cfg(unix)]
const INSTALL_URL: &str = "https://chatgpt.com/codex/install.sh";
#[cfg(windows)]
const INSTALL_URL: &str = "https://chatgpt.com/codex/install.ps1";
pub(crate) async fn run(
http_client_factory: HttpClientFactory,
@@ -101,10 +92,8 @@ async fn run_with_http(
running_updater_identity: &ExecutableIdentity,
mut restore_release: Option<String>,
) -> Result<()> {
#[cfg(unix)]
let mut terminate =
signal(SignalKind::terminate()).context("failed to install updater shutdown handler")?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let paths = daemon.backend_paths(&DaemonSettings::default());
for backend in [
@@ -115,17 +104,6 @@ async fn run_with_http(
let _ = backend.promote_legacy_identity().await;
}
}
#[cfg(windows)]
let updater = {
// Updater ownership needs only paths, not settings that may be mid-edit.
crate::backend::pid_update_loop_backend(daemon.backend_paths(&DaemonSettings::default()))
};
#[cfg(windows)]
updater.wait_for_ownership().await?;
#[cfg(windows)]
let mut terminate = Signal;
#[cfg(windows)]
let _installer_job = crate::backend::windows::updater_job()?;
let socket_path = daemon.manual_update_socket_path();
codex_uds::prepare_private_socket_directory(
socket_path
@@ -133,19 +111,9 @@ async fn run_with_http(
.context("updater socket has no parent")?,
)
.await?;
#[cfg(unix)]
let (listener, _socket_guard) =
codex_app_server_transport::bind_private_daemon_socket(&socket_path).await?;
#[cfg(windows)]
let listener = {
if socket_path.exists() {
tokio::fs::remove_file(&socket_path).await?;
}
codex_uds::UnixListener::bind(&socket_path).await?
};
let mut listener = Some(listener);
#[cfg(windows)]
updater.mark_ready().await?;
let needs_managed_handoff =
match resolved_managed_codex_bin(&daemon.current_managed_codex_bin()?).await {
Ok(managed_bin) => executable_identity(&managed_bin)
@@ -279,7 +247,6 @@ async fn adopt_managed_updater(
if !crate::managed_install::supports_daemon_update_loop(&managed_bin).await {
return Ok(UpdateLoopControl::Stop);
}
#[cfg(unix)]
{
let _ = listener;
reexec_managed_updater(
@@ -291,25 +258,6 @@ async fn adopt_managed_updater(
)
.map(|_| UpdateLoopControl::Stop)
}
#[cfg(windows)]
{
let replacement = crate::backend::pid_update_loop_backend(
daemon.backend_paths_with_bin(&daemon.load_settings().await?, &managed_bin),
);
listener.take();
if let Err(err) = replacement.replace_current_updater().await {
// A failed replacement may still own the PID if its cleanup could
// not terminate the successor. Never reopen our request socket then.
replacement.wait_for_ownership().await?;
let socket_path = daemon.manual_update_socket_path();
if socket_path.exists() {
tokio::fs::remove_file(&socket_path).await?;
}
*listener = Some(codex_uds::UnixListener::bind(&socket_path).await?);
return Err(err);
}
Ok(UpdateLoopControl::Stop)
}
}
async fn sleep_or_terminate(duration: Duration, terminate: &mut Signal) -> bool {
@@ -405,7 +353,6 @@ async fn update_once(
"daemon package root changed during the update; retry the command"
);
let started = std::time::Instant::now();
#[cfg(unix)]
if matches!(
crate::diagnostics::result(
"installer_run",
@@ -416,11 +363,6 @@ async fn update_once(
) {
return Ok((UpdateLoopControl::Stop, None));
}
#[cfg(windows)]
tokio::select! {
result = run_installer_script(&script, installer_mode, &package_root) => { crate::diagnostics::result("installer_run", started, result)?; },
_ = terminate.recv() => return Ok((UpdateLoopControl::Stop, None)),
}
anyhow::ensure!(
trigger == UpdateTrigger::Scheduled || daemon.is_stable_standalone_release()?,
"installer did not select a stable latest release; retry the update"
@@ -553,7 +495,6 @@ async fn current_updater_identity() -> Result<ExecutableIdentity> {
executable_identity(&current_exe).await
}
#[cfg(unix)]
pub(crate) fn reexec_managed_updater(managed_codex_bin: &Path, state_dir: &Path) -> Result<()> {
let mut command = StdCommand::new(managed_codex_bin);
command.args(["app-server", "daemon", "pid-update-loop"]);
@@ -577,23 +518,14 @@ async fn run_installer_script(
script: &[u8],
mode: InstallerMode<'_>,
package_root: &Path,
#[cfg(unix)] terminate: impl std::future::Future<Output = Option<()>>,
terminate: impl std::future::Future<Output = Option<()>>,
) -> Result<UpdateLoopControl> {
#[cfg(unix)]
let mut command = {
let mut command = Command::new("/bin/sh");
command.arg("-s");
command.process_group(0);
command
};
#[cfg(windows)]
let mut command = {
let mut command = Command::new("powershell.exe");
command.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW);
command.args(["-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); try { Invoke-Expression ([Console]::In.ReadToEnd()) } catch { Write-Error $_; exit 1 }"])
.kill_on_drop(true);
command
};
let (latest_guard, current_guard, previous_release, defer_selection) = match mode {
InstallerMode::Update(release) => ("1", "0", release, "0"),
InstallerMode::RestoreProduction(release) => ("0", "1", release, "0"),
@@ -662,23 +594,16 @@ async fn run_installer_script(
}
}
});
#[cfg(windows)]
let _installer_job = crate::backend::windows::installer_job(&child)?;
let mut stdin = child
.stdin
.take()
.context("standalone Codex updater stdin was unavailable")?;
#[cfg(unix)]
let mut terminate = std::pin::pin!(terminate);
#[cfg(unix)]
let write_result = tokio::select! {
result = stdin.write_all(script) => Some(result),
_ = &mut terminate => None,
};
#[cfg(windows)]
let write_result = Some(stdin.write_all(script).await);
drop(stdin);
#[cfg(unix)]
if write_result.is_none() {
cancel_installer(&mut child, package_root).await;
stderr_task.abort();
@@ -688,7 +613,6 @@ async fn run_installer_script(
stderr_task.abort();
return Err(err).context("failed to pass standalone Codex updater to shell");
}
#[cfg(unix)]
let status = tokio::select! {
result = child.wait() => result,
_ = &mut terminate => {
@@ -696,8 +620,6 @@ async fn run_installer_script(
return Ok(UpdateLoopControl::Stop);
}
};
#[cfg(windows)]
let status = child.wait().await;
let status = match status {
Ok(status) => status,
Err(err) => {
@@ -725,7 +647,6 @@ async fn run_installer_script(
}
}
#[cfg(unix)]
async fn cancel_installer(child: &mut tokio::process::Child, package_root: &Path) {
let Some(pid) = child.id().and_then(|pid| libc::pid_t::try_from(pid).ok()) else {
return;
@@ -795,15 +716,3 @@ impl InstallerHttp for RouteAwareClientPool {
#[cfg(test)]
#[path = "update_loop_tests.rs"]
mod tests;
#[cfg(windows)]
struct Signal;
#[cfg(windows)]
impl Signal {
async fn recv(&mut self) -> Option<()> {
// An unreadable control path must stop the updater rather than disable shutdown.
let _ = codex_app_server_transport::daemon_shutdown_signal().await;
Some(())
}
}
@@ -1,28 +1,19 @@
use std::sync::Mutex;
#[cfg(unix)]
use std::time::Duration;
use pretty_assertions::assert_eq;
#[cfg(unix)]
use tempfile::TempDir;
use super::INSTALL_URL;
use super::InstallerHttp;
use super::InstallerResponse;
use super::fetch_installer_script;
#[cfg(unix)]
use super::manual_update::run as manual_update_once;
#[cfg(unix)]
use crate::Daemon;
#[cfg(unix)]
use crate::RestartIfRunningOutcome;
#[cfg(unix)]
use crate::UpdateOutput;
#[cfg(unix)]
use crate::UpdateStatus;
#[cfg(unix)]
use crate::managed_install::executable_identity;
#[cfg(unix)]
use crate::managed_install::executable_identity_from_reader;
#[tokio::test]
@@ -51,7 +42,6 @@ async fn installer_fetch_rejects_non_success_status() {
assert_eq!(http.requested_urls(), vec![INSTALL_URL.to_string()]);
}
#[cfg(unix)]
#[test]
fn updater_reexec_preserves_paths_and_recovers_deleted_working_directory() {
use std::os::unix::ffi::OsStrExt;
@@ -155,7 +145,6 @@ fn updater_reexec_preserves_paths_and_recovers_deleted_working_directory() {
}
}
#[cfg(unix)]
#[test]
fn updater_reexec_child() {
use std::os::unix::process::CommandExt;
@@ -194,7 +183,6 @@ struct FakeInstallerHttp {
requested_urls: Mutex<Vec<String>>,
}
#[cfg(unix)]
#[tokio::test]
async fn explicit_update_migrates_running_and_stopped_installations() {
for (running, local) in [(false, false), (true, false), (false, true), (true, true)] {
@@ -372,7 +360,6 @@ impl InstallerHttp for FakeInstallerHttp {
}
}
#[cfg(unix)]
#[tokio::test]
async fn cancelling_installer_stops_children_and_releases_fallback_lock() {
let home = tempfile::TempDir::new().expect("home");
@@ -417,7 +404,6 @@ async fn cancelling_installer_stops_children_and_releases_fallback_lock() {
assert!(!delayed.exists());
}
#[cfg(unix)]
fn manual_update_daemon(home: &TempDir) -> (Daemon, String) {
let target = if cfg!(target_os = "macos") {
format!("{}-apple-darwin", std::env::consts::ARCH)
@@ -453,13 +439,11 @@ fn manual_update_daemon(home: &TempDir) -> (Daemon, String) {
)
}
#[cfg(unix)]
fn test_terminate() -> tokio::signal::unix::Signal {
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("install test signal handler")
}
#[cfg(unix)]
#[tokio::test]
async fn manual_request_retries_after_updater_replacement() {
use tokio::io::AsyncReadExt;
@@ -513,7 +497,6 @@ async fn manual_request_retries_after_updater_replacement() {
server.await.expect("replacement task");
}
#[cfg(unix)]
#[tokio::test]
async fn manual_request_accepts_maximum_installer_stderr_detail() {
use tokio::io::AsyncReadExt;
@@ -553,7 +536,6 @@ async fn manual_request_accepts_maximum_installer_stderr_detail() {
server.await.expect("server task");
}
#[cfg(unix)]
#[tokio::test]
async fn manual_request_recovers_when_one_shot_updater_exits() {
use tokio::io::AsyncReadExt;
@@ -591,7 +573,6 @@ async fn manual_request_recovers_when_one_shot_updater_exits() {
server.await.expect("updater task");
}
#[cfg(unix)]
#[tokio::test]
async fn unsupported_request_preserves_updater_schedule() {
use tokio::io::AsyncReadExt;
@@ -667,7 +648,6 @@ async fn unsupported_request_preserves_updater_schedule() {
worker.abort();
}
#[cfg(unix)]
async fn test_control_server(
daemon: &Daemon,
home: &std::path::Path,
@@ -716,7 +696,6 @@ async fn test_control_server(
})
}
#[cfg(unix)]
#[tokio::test]
async fn scheduled_no_op_preserves_daemon_and_hands_off_stale_updater() {
let home = TempDir::new().expect("home");
@@ -776,7 +755,6 @@ async fn scheduled_no_op_preserves_daemon_and_hands_off_stale_updater() {
server.abort();
}
#[cfg(unix)]
#[tokio::test]
async fn scheduled_resource_only_update_restarts_daemon() {
let home = TempDir::new().expect("home");
@@ -823,13 +801,11 @@ async fn scheduled_resource_only_update_restarts_daemon() {
server.abort();
}
#[cfg(unix)]
#[tokio::test]
async fn manual_update_restarts_managed_daemon_with_automatic_updates_disabled() {
check_manual_update_restart("standalone").await;
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[tokio::test]
async fn readiness_waits_for_a_slow_managed_daemon() {
let home = TempDir::new().unwrap();
@@ -858,7 +834,6 @@ async fn readiness_waits_for_a_slow_managed_daemon() {
assert_eq!(ready.unwrap().app_server_version, "1.0.0");
}
#[cfg(unix)]
#[tokio::test]
async fn daemon_start_and_restart_preserve_launch_features() {
for features in [
@@ -934,7 +909,6 @@ async fn daemon_start_and_restart_preserve_launch_features() {
}
}
#[cfg(unix)]
#[tokio::test]
async fn confirmed_feature_restart_preserves_ownership_and_skips_matching_settings() {
use crate::LifecycleStatus;
@@ -1002,13 +976,11 @@ async fn confirmed_feature_restart_preserves_ownership_and_skips_matching_settin
}
}
#[cfg(unix)]
#[tokio::test]
async fn manual_update_restarts_local_daemon_with_automatic_updates_disabled() {
check_manual_update_restart("app-server-daemon").await;
}
#[cfg(unix)]
async fn check_manual_update_restart(package_directory: &str) {
use tokio::io::AsyncReadExt;
use tokio::io::AsyncWriteExt;
@@ -1176,48 +1148,6 @@ async fn check_manual_update_restart(package_directory: &str) {
server.abort();
}
#[cfg(windows)]
#[tokio::test]
async fn powershell_installer_is_noninteractive_and_reports_script_failure() {
let valid = FakeInstallerHttp::new(InstallerResponse::Success(
br#"
function Test-Installer {
if ($env:CODEX_NON_INTERACTIVE -ne '1') { throw 'interactive installer' }
if ($env:CODEX_INSTALL_DAEMON_ONLY -ne '1') { throw 'wrong package destination' }
if ($env:CODEX_INSTALL_IF_CURRENT -ne '1' -or $env:CODEX_INSTALL_IF_LATEST -ne '0') { throw 'wrong update guard' }
}
Test-Installer
"#
.to_vec(),
));
let script = super::fetch_installer_script(&valid)
.await
.expect("fetch installer");
super::run_installer_script(
&script,
super::InstallerMode::RestoreProduction("0.150.0-x86_64-pc-windows-msvc"),
std::path::Path::new("packages/app-server-daemon"),
)
.await
.expect("installer succeeds");
let failing = FakeInstallerHttp::new(InstallerResponse::Success(
b"throw ([string][char]0x00E9 + 'chec installation')".to_vec(),
));
let script = super::fetch_installer_script(&failing)
.await
.expect("fetch failing installer");
let error = super::run_installer_script(
&script,
super::InstallerMode::RestoreProduction("0.150.0-x86_64-pc-windows-msvc"),
std::path::Path::new("packages/app-server-daemon"),
)
.await
.err()
.expect("installer should fail");
assert!(error.to_string().contains("échec installation"));
}
#[cfg(unix)]
#[tokio::test]
async fn installer_failure_includes_stderr() {
let script = format!(
@@ -1238,7 +1168,6 @@ async fn installer_failure_includes_stderr() {
assert!(!error.contains("discard me"));
}
#[cfg(unix)]
#[tokio::test]
async fn installer_failure_preserves_stderr_before_drain_timeout() {
let error = tokio::time::timeout(
@@ -1257,7 +1186,6 @@ async fn installer_failure_preserves_stderr_before_drain_timeout() {
assert!(error.to_string().contains("installer failed"));
}
#[cfg(unix)]
#[tokio::test]
async fn update_rejects_a_package_root_change_during_download() {
struct ChangingRoot<'a>(&'a std::path::Path);
@@ -1289,7 +1217,6 @@ async fn update_rejects_a_package_root_change_during_download() {
assert!(error.to_string().contains("package root changed"));
}
#[cfg(unix)]
#[tokio::test]
async fn daemon_owned_updates_require_and_request_an_isolated_installer() {
let home = TempDir::new().unwrap();
@@ -99,6 +99,9 @@
],
"type": "object"
},
"LegacyAppPathString": {
"type": "string"
},
"ModeKind": {
"description": "Initial collaboration mode to use when the TUI starts.",
"enum": [
@@ -300,6 +303,29 @@
],
"type": "object"
},
"ThreadEnvironment": {
"description": "An environment selected by a loaded thread, independent of connection status.",
"properties": {
"cwd": {
"$ref": "#/definitions/LegacyAppPathString"
},
"environmentId": {
"type": "string"
},
"runtimeWorkspaceRoots": {
"items": {
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
}
},
"required": [
"cwd",
"environmentId",
"runtimeWorkspaceRoots"
],
"type": "object"
},
"ThreadSettings": {
"properties": {
"activePermissionProfile": {
@@ -1113,6 +1113,7 @@ client_request_definitions! {
#[experimental("turn/settings/update")]
TurnSettingsUpdate => "turn/settings/update" {
params: v2::TurnSettingsUpdateParams,
inspect_params: true,
serialization: thread_id(params.thread_id),
response: v2::TurnSettingsUpdateResponse,
},
@@ -1347,17 +1348,6 @@ client_request_definitions! {
response: v2::McpServerToolCallResponse,
},
WindowsSandboxSetupStart => "windowsSandbox/setupStart" {
params: v2::WindowsSandboxSetupStartParams,
serialization: global("windows-sandbox-setup"),
response: v2::WindowsSandboxSetupStartResponse,
},
WindowsSandboxReadiness => "windowsSandbox/readiness" {
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
serialization: global("config"),
response: v2::WindowsSandboxReadinessResponse,
},
LoginAccount => "account/login/start" {
params: v2::LoginAccountParams,
inspect_params: true,
@@ -2160,9 +2150,6 @@ server_notification_definitions! {
#[experimental("thread/realtime/closed")]
ThreadRealtimeClosed => "thread/realtime/closed" (v2::ThreadRealtimeClosedNotification),
/// Notifies the user of world-writable directories on Windows, which cannot be protected by the sandbox.
WindowsWorldWritableWarning => "windows/worldWritableWarning" (v2::WindowsWorldWritableWarningNotification),
WindowsSandboxSetupCompleted => "windowsSandbox/setupCompleted" (v2::WindowsSandboxSetupCompletedNotification),
#[serde(rename = "account/login/completed")]
#[ts(rename = "account/login/completed")]
@@ -4623,6 +4610,7 @@ mod tests {
thread_id: "thr_123".to_string(),
thread_settings: v2::ThreadSettings {
disabled_plugin_ids: Vec::new(),
environments: Some(Vec::new()),
cwd: absolute_path("/tmp/repo"),
approval_policy: v2::AskForApproval::Never,
approvals_reviewer: v2::ApprovalsReviewer::User,
@@ -104,7 +104,6 @@ fn client_response_jsonrpc_parts_preserve_legacy_interrupt() -> Result<()> {
Ok(())
}
#[cfg(unix)]
#[test]
fn client_response_jsonrpc_parts_preserve_serialization_errors() {
use std::ffi::OsString;
@@ -11,7 +11,6 @@ use std::collections::BTreeMap;
pub struct ComputerUseConfig {
pub default_app_access: Option<AllowDenyRequirement>,
pub macos: Option<ComputerUseMacosConfig>,
pub windows: Option<ComputerUseWindowsConfig>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
@@ -20,21 +19,3 @@ pub struct ComputerUseConfig {
pub struct ComputerUseMacosConfig {
pub bundle_ids: Option<BTreeMap<String, AllowDenyRequirement>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export_to = "v2/")]
pub struct ComputerUseWindowsConfig {
pub aumids: Option<BTreeMap<String, AllowDenyRequirement>>,
pub exes: Option<Vec<ComputerUseWindowsExeConfig>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export_to = "v2/")]
pub struct ComputerUseWindowsExeConfig {
pub publisher_name: String,
pub product_name: String,
pub binary_name: Option<String>,
pub access: AllowDenyRequirement,
}
@@ -4,7 +4,6 @@ use super::AskForApproval;
use super::BrowserUseConfig;
use super::ComputerUseConfig;
use super::SandboxMode;
use super::WindowsSandboxImplementation;
use super::shared::default_enabled;
use crate::JsonSchema;
use crate::TS;
@@ -429,7 +428,6 @@ pub struct ConfigRequirements {
#[experimental("configRequirements/read.allowedApprovalsReviewers")]
pub allowed_approvals_reviewers: Option<Vec<ApprovalsReviewer>>,
pub allowed_sandbox_modes: Option<Vec<SandboxMode>>,
pub allowed_windows_sandbox_implementations: Option<Vec<WindowsSandboxImplementation>>,
pub allowed_permission_profiles: Option<BTreeMap<String, bool>>,
pub default_permissions: Option<String>,
pub allowed_web_search_modes: Option<Vec<WebSearchMode>>,
@@ -577,7 +575,6 @@ pub struct ComputerUseRequirements {
pub allow_persistent_approval: Option<bool>,
pub default_app_access: Option<AllowDenyRequirement>,
pub macos: Option<ComputerUseMacosRequirements>,
pub windows: Option<ComputerUseWindowsRequirements>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
@@ -653,24 +650,6 @@ pub struct ComputerUseMacosRequirements {
pub bundle_ids: Option<BTreeMap<String, AllowDenyRequirement>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ComputerUseWindowsRequirements {
pub aumids: Option<BTreeMap<String, AllowDenyRequirement>>,
pub exes: Option<Vec<ComputerUseWindowsExeRequirement>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ComputerUseWindowsExeRequirement {
pub publisher_name: String,
pub product_name: String,
pub binary_name: Option<String>,
pub access: AllowDenyRequirement,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -689,7 +668,6 @@ pub struct ManagedHooksRequirements {
#[ts(rename = "PostModelRequest")]
pub post_model_request: Vec<ConfiguredHookMatcherGroup>,
pub managed_dir: Option<PathBuf>,
pub windows_managed_dir: Option<PathBuf>,
#[serde(rename = "PreToolUse")]
#[ts(rename = "PreToolUse")]
pub pre_tool_use: Vec<ConfiguredHookMatcherGroup>,
@@ -744,9 +722,6 @@ pub enum ConfiguredHookHandler {
#[ts(rename = "command")]
Command {
command: String,
#[serde(rename = "commandWindows")]
#[ts(rename = "commandWindows")]
command_windows: Option<String>,
#[serde(rename = "timeoutSec")]
#[ts(rename = "timeoutSec")]
timeout_sec: Option<u64>,
@@ -42,7 +42,6 @@ mod thread_sample;
mod thread_usage;
mod turn;
mod user_verification;
mod windows_sandbox;
pub use account::*;
pub use application::*;
@@ -87,7 +86,6 @@ pub use thread_sample::*;
pub use thread_usage::*;
pub use turn::*;
pub use user_verification::*;
pub use windows_sandbox::*;
#[cfg(test)]
mod tests;
@@ -797,16 +797,8 @@ fn command_execution_request_approval_localization_rejects_relative_additional_p
#[test]
fn permissions_request_approval_uses_request_permission_profile() {
let read_only_path = if cfg!(windows) {
r"C:\tmp\read-only"
} else {
"/tmp/read-only"
};
let read_write_path = if cfg!(windows) {
r"C:\tmp\read-write"
} else {
"/tmp/read-write"
};
let read_only_path = "/tmp/read-only";
let read_write_path = "/tmp/read-write";
let params = serde_json::from_value::<PermissionsRequestApprovalParams>(json!({
"threadId": "thr_123",
"turnId": "turn_123",
@@ -973,25 +965,6 @@ fn additional_file_system_permissions_preserves_canonical_entries() {
core_permissions
);
}
#[cfg(windows)]
for path in ["//server/share/read-only", r"/\server/share/read-only"] {
let path = LegacyAppPathString::from_string(path);
let core_permissions =
CoreFileSystemPermissions::try_from(AdditionalFileSystemPermissions {
read: Some(vec![path.clone()]),
write: None,
glob_scan_max_depth: None,
entries: None,
})
.expect("native slash UNC permission path");
let permissions = AdditionalFileSystemPermissions::from(core_permissions);
assert_eq!(
permissions.read,
Some(vec![LegacyAppPathString::from_string(
r"\\server\share\read-only"
)])
);
}
assert!(
CoreFileSystemPermissions::try_from(AdditionalFileSystemPermissions {
read: Some(vec![LegacyAppPathString::from_string(r"\\localhost\share")]),
@@ -1078,16 +1051,8 @@ fn legacy_current_working_directory_special_path_deserializes_as_project_roots()
#[test]
fn permissions_request_approval_response_uses_granted_permission_profile_without_macos() {
let read_only_path = if cfg!(windows) {
r"C:\tmp\read-only"
} else {
"/tmp/read-only"
};
let read_write_path = if cfg!(windows) {
r"C:\tmp\read-write"
} else {
"/tmp/read-write"
};
let read_only_path = "/tmp/read-only";
let read_write_path = "/tmp/read-write";
let response = serde_json::from_value::<PermissionsRequestApprovalResponse>(json!({
"permissions": {
"network": {
@@ -2210,7 +2175,6 @@ fn config_requirements_granular_allowed_approval_policy_is_marked_experimental()
}]),
allowed_approvals_reviewers: None,
allowed_sandbox_modes: None,
allowed_windows_sandbox_implementations: None,
allowed_permission_profiles: None,
default_permissions: None,
allowed_web_search_modes: None,
@@ -4054,11 +4018,7 @@ fn skills_extra_roots_set_params_rejects_relative_roots() {
#[test]
fn plugin_source_serializes_local_git_npm_and_remote_variants() {
let local_path = if cfg!(windows) {
r"C:\plugins\linear"
} else {
"/plugins/linear"
};
let local_path = "/plugins/linear";
let local_path = AbsolutePathBuf::try_from(PathBuf::from(local_path)).unwrap();
let local_path_json = local_path.as_path().display().to_string();
@@ -4192,18 +4152,10 @@ fn plugin_marketplace_entry_serializes_remote_only_path_as_null() {
#[test]
fn plugin_interface_serializes_local_paths_and_remote_urls_separately() {
let composer_icon = if cfg!(windows) {
r"C:\plugins\linear\icon.png"
} else {
"/plugins/linear/icon.png"
};
let composer_icon = "/plugins/linear/icon.png";
let composer_icon = AbsolutePathBuf::try_from(PathBuf::from(composer_icon)).unwrap();
let composer_icon_json = composer_icon.as_path().display().to_string();
let logo_dark = if cfg!(windows) {
r"C:\plugins\linear\logo-dark.png"
} else {
"/plugins/linear/logo-dark.png"
};
let logo_dark = "/plugins/linear/logo-dark.png";
let logo_dark = AbsolutePathBuf::try_from(PathBuf::from(logo_dark)).unwrap();
let logo_dark_json = logo_dark.as_path().display().to_string();
@@ -4337,11 +4289,7 @@ fn plugin_installed_params_serializes_install_suggestion_names() {
#[test]
fn plugin_read_params_serialization_uses_install_source_fields() {
let marketplace_path = if cfg!(windows) {
r"C:\plugins\marketplace.json"
} else {
"/plugins/marketplace.json"
};
let marketplace_path = "/plugins/marketplace.json";
let marketplace_path = AbsolutePathBuf::try_from(PathBuf::from(marketplace_path)).unwrap();
let marketplace_path_json = marketplace_path.as_path().display().to_string();
assert_eq!(
@@ -4388,11 +4336,7 @@ fn plugin_read_params_serialization_uses_install_source_fields() {
#[test]
fn plugin_install_params_serialization_omits_force_remote_sync() {
let marketplace_path = if cfg!(windows) {
r"C:\plugins\marketplace.json"
} else {
"/plugins/marketplace.json"
};
let marketplace_path = "/plugins/marketplace.json";
let marketplace_path = AbsolutePathBuf::try_from(PathBuf::from(marketplace_path)).unwrap();
let marketplace_path_json = marketplace_path.as_path().display().to_string();
assert_eq!(
@@ -4461,11 +4405,7 @@ fn plugin_skill_read_params_serialization_uses_remote_plugin_id() {
#[test]
fn plugin_share_params_and_response_serialization_use_camel_case_fields() {
let plugin_path = if cfg!(windows) {
r"C:\plugins\gmail"
} else {
"/plugins/gmail"
};
let plugin_path = "/plugins/gmail";
let plugin_path = AbsolutePathBuf::try_from(PathBuf::from(plugin_path)).unwrap();
let plugin_path_json = plugin_path.as_path().display().to_string();
@@ -4596,18 +4536,10 @@ fn plugin_share_params_and_response_serialization_use_camel_case_fields() {
}),
);
let plugin_path = if cfg!(windows) {
r"C:\Users\me\plugins\gmail"
} else {
"/Users/me/plugins/gmail"
};
let plugin_path = "/Users/me/plugins/gmail";
let plugin_path = AbsolutePathBuf::try_from(PathBuf::from(plugin_path)).unwrap();
let plugin_path_json = plugin_path.as_path().display().to_string();
let marketplace_path = if cfg!(windows) {
r"C:\Users\me\.agents\plugins\marketplace.json"
} else {
"/Users/me/.agents/plugins/marketplace.json"
};
let marketplace_path = "/Users/me/.agents/plugins/marketplace.json";
let marketplace_path = AbsolutePathBuf::try_from(PathBuf::from(marketplace_path)).unwrap();
let marketplace_path_json = marketplace_path.as_path().display().to_string();
assert_eq!(
@@ -4821,11 +4753,7 @@ fn plugin_uninstall_params_serialization_omits_force_remote_sync() {
#[test]
fn marketplace_remove_response_serializes_nullable_installed_root() {
let installed_root = if cfg!(windows) {
r"C:\marketplaces\debug"
} else {
"/tmp/marketplaces/debug"
};
let installed_root = "/tmp/marketplaces/debug";
let installed_root = AbsolutePathBuf::try_from(PathBuf::from(installed_root)).unwrap();
let installed_root_json = installed_root.as_path().display().to_string();
assert_eq!(
@@ -4855,11 +4783,7 @@ fn marketplace_remove_response_serializes_nullable_installed_root() {
#[test]
fn marketplace_upgrade_response_serializes_camel_case_fields() {
let upgraded_root = if cfg!(windows) {
r"C:\marketplaces\debug"
} else {
"/tmp/marketplaces/debug"
};
let upgraded_root = "/tmp/marketplaces/debug";
let upgraded_root = AbsolutePathBuf::try_from(PathBuf::from(upgraded_root)).unwrap();
let upgraded_root_json = upgraded_root.as_path().display().to_string();
@@ -5389,11 +5313,6 @@ fn thread_settings_update_params_preserve_field_level_experimental_gates() {
#[test]
fn turn_start_params_round_trip_environments() {
// Use a path foreign to the test host so this exercises syntax preservation instead of the
// host-native conversion performed by test_absolute_path().
#[cfg(windows)]
let raw_cwd = "/workspace";
#[cfg(not(windows))]
let raw_cwd = r"C:\workspace";
let cwd: LegacyAppPathString =
serde_json::from_value(json!(raw_cwd)).expect("API path should deserialize");
@@ -4,6 +4,7 @@ use super::AskForApproval;
use super::SandboxMode;
use super::SandboxPolicy;
use super::Thread;
use super::ThreadEnvironment;
use super::ThreadHistoryMode;
use super::ThreadItem;
use super::ThreadRealtimeItem;
@@ -242,6 +243,12 @@ pub struct ThreadSettingsUpdateParams {
/// Override the working directory for subsequent turns.
#[ts(optional = nullable)]
pub cwd: Option<PathBuf>,
/// Replace the environments for future turns without changing the running turn.
/// Omitted/null preserves the selection unless `cwd` is also provided, which selects
/// the default environments for that directory. [] clears the selection.
#[experimental("thread/settings/update.environments")]
#[ts(optional = nullable)]
pub environments: Option<Vec<TurnEnvironmentParams>>,
/// Override the approval policy for subsequent turns.
#[experimental(nested)]
#[ts(optional = nullable)]
@@ -306,6 +313,11 @@ pub struct ThreadSettings {
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
pub cwd: AbsolutePathBuf,
/// Environments configured for future turns, in priority order, primary first.
/// `null` means the server does not expose the selection; [] means none are selected.
#[experimental("thread/settings.environments")]
#[serde(default)]
pub environments: Option<Vec<ThreadEnvironment>>,
pub approval_policy: AskForApproval,
pub approvals_reviewer: ApprovalsReviewer,
pub sandbox_policy: SandboxPolicy,
@@ -43,7 +43,9 @@ pub enum TurnStatus {
/// Unsupported fields are rejected rather than silently ignored.
/// Any live task kind may accept publication. Child sessions and consumers of
/// frozen initial settings are unchanged.
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS)]
#[derive(
Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS, ExperimentalApi,
)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[ts(export_to = "v2/")]
pub struct TurnSettingsUpdateParams {
@@ -53,6 +55,11 @@ pub struct TurnSettingsUpdateParams {
/// Already captured steps and pending approvals retain their original reviewer.
#[ts(optional = nullable)]
pub approvals_reviewer: Option<ApprovalsReviewer>,
/// Replace the environments for subsequent steps of this turn, not future turns.
/// Omitted/null preserves the selection; [] clears it. An already-started step is unchanged.
#[experimental("turn/settings/update.environments")]
#[ts(optional = nullable)]
pub environments: Option<Vec<TurnEnvironmentParams>>,
/// Omission or `null` leaves the model unchanged.
#[ts(optional = nullable)]
pub model: Option<String>,
@@ -1,72 +0,0 @@
use crate::JsonSchema;
use crate::TS;
use codex_utils_absolute_path::AbsolutePathBuf;
use serde::Deserialize;
use serde::Serialize;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct WindowsWorldWritableWarningNotification {
pub sample_paths: Vec<String>,
pub extra_count: usize,
pub failed_scan: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum WindowsSandboxSetupMode {
Elevated,
Unelevated,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase", export_to = "v2/")]
pub enum WindowsSandboxImplementation {
Elevated,
Unelevated,
Mxc,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum WindowsSandboxReadiness {
Ready,
NotConfigured,
UpdateRequired,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct WindowsSandboxSetupStartParams {
pub mode: WindowsSandboxSetupMode,
#[ts(optional = nullable)]
pub cwd: Option<AbsolutePathBuf>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct WindowsSandboxSetupStartResponse {
pub started: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct WindowsSandboxReadinessResponse {
pub status: WindowsSandboxReadiness,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct WindowsSandboxSetupCompletedNotification {
pub mode: WindowsSandboxSetupMode,
pub success: bool,
pub error: Option<String>,
}
@@ -1,7 +0,0 @@
load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "app-server-test-client",
crate_name = "codex_app_server_test_client",
lib_data_extra = ["scripts/live_elicitation_hold.sh"],
)
@@ -1,32 +0,0 @@
[package]
name = "codex-app-server-test-client"
version.workspace = true
edition.workspace = true
license.workspace = true
[lints]
workspace = true
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive", "env"] }
codex-app-server-protocol = { workspace = true }
codex-core = { workspace = true }
codex-otel = { workspace = true }
codex-protocol = { workspace = true }
codex-utils-cargo-bin = { workspace = true }
codex-utils-cli = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tungstenite = { workspace = true }
url = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
[lib]
doctest = false
[dev-dependencies]
pretty_assertions = { workspace = true }
-185
View File
@@ -1,185 +0,0 @@
# App Server Test Client
Quickstart for running and hitting `codex app-server`.
## Quickstart
Run from `<reporoot>/codex-rs`.
```bash
# 1) Build debug codex binary
cargo build -p codex-cli --bin codex
# 2) Start websocket app-server in background
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
serve --listen ws://127.0.0.1:4222 --kill
# 3) Call app-server (defaults to ws://127.0.0.1:4222)
cargo run -p codex-app-server-test-client -- model-list
```
`send-message` and `send-message-v2` handle `request_user_input` server requests interactively.
When Codex asks a question, choose a numbered option (or `o` for a free-form answer when offered)
and the client will send the response and continue streaming the same turn.
## Testing Codex-managed Amazon Bedrock login
`test-login --amazon-bedrock` initializes the experimental app-server API, sends an
`account/login/start` request with an Amazon Bedrock API key, and waits for the
`account/login/completed` and `account/updated` notifications. Login replaces the current primary
credential and sets `model_provider = "amazon-bedrock"`, so use an isolated `CODEX_HOME` when
testing.
```bash
export CODEX_HOME="$(mktemp -d)"
printf 'cli_auth_credentials_store = "file"\n' > "$CODEX_HOME/config.toml"
cargo build -p codex-cli --bin codex
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
test-login \
--amazon-bedrock \
--api-key "<BEDROCK_API_KEY>" \
--region us-west-2
```
The test client redacts `apiKey` from its outbound request log. After login, start a fresh Codex
process with the same `CODEX_HOME` to verify that it uses the persisted managed credential.
## Testing logout
`test-logout` initializes the app-server, sends an `account/logout` request, and waits for the
resulting `account/updated` notification. It uses the active `CODEX_HOME`, so point it at an
isolated directory when testing credential cleanup.
```bash
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
test-logout
```
## Testing Plugin Analytics
The `plugin-analytics-smoke` command exercises `plugin/installed`, plugin
enable/disable config writes, and a structured plugin mention through one
app-server connection. Analytics are captured to a local JSONL file and are
not sent to the analytics backend. The model turn uses a loopback Responses
API server.
The selected plugin must already be installed and enabled remotely, and the
active Codex profile must be authenticated. On a fresh local cache, the command
retries ephemeral turns while the installed remote bundle finishes syncing.
```bash
# Build a debug Codex binary; analytics capture is unavailable in release builds.
cargo build -p codex-cli --bin codex
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
plugin-analytics-smoke \
--plugin-id linear@openai-curated-remote
```
Use `--capture-file /tmp/plugin-analytics.jsonl` to select the output path.
The command validates one `codex_plugin_disabled`, `codex_plugin_enabled`, and
`codex_plugin_used` event with the expected local and remote plugin identities
and capability metadata. Each event includes the local ID in `plugin_id` and the
backend ID in `remote_plugin_id`. The enabled and disabled events come from
successful writes to the temporary config; the command does not mutate the
remote enabled state. It prints the events and leaves the JSONL file in place
for inspection. It does not install or uninstall plugins and does not modify
the profile's persistent config.
### Testing remote install and uninstall analytics
`plugin-analytics-mutation-smoke` is a manually invoked live smoke test. It
contacts the configured remote plugin API and temporarily changes the active
account's installed-plugin state. It is not run by `cargo test`, `just test`,
or CI.
Choose a remote plugin that is available to the active account and is not
currently installed. The command refuses to run when the plugin is already
installed, installs it, validates `codex_plugin_installed`, uninstalls it, and
validates `codex_plugin_uninstalled`, and verifies that the original
uninstalled state was restored.
The mutation events include the local Codex ID in `plugin_id` and the backend ID
in `remote_plugin_id`.
`--remote-plugin-id` takes the backend ID, such as `plugins~Plugin_...`, not the
local `<plugin>@<marketplace>` ID.
```bash
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
plugin-analytics-mutation-smoke \
--remote-plugin-id <REMOTE_PLUGIN_ID> \
--confirm-account-mutation \
--capture-file /tmp/plugin-mutation-analytics.jsonl
```
Analytics use the normal queue, reduction, batching, and serialization path,
but the debug capture destination suppresses analytics network delivery. The
command prints one of these final states:
- `PASS`: the install and uninstall events validated and the plugin is uninstalled.
- `FAIL-CLEAN`: validation failed, but the original uninstalled state was
restored.
- `FAIL-LOCAL-CACHE`: the backend is uninstalled, but local cleanup reported
an error.
- `FAIL-DIRTY`: cleanup failed and the plugin still appears installed.
- `FAIL-UNKNOWN`: the command could not verify the final installed state.
For a dirty or uncertain result, retry cleanup with:
```bash
cargo run -p codex-app-server-test-client -- \
--codex-bin ./target/debug/codex \
plugin-remote-uninstall \
--remote-plugin-id <REMOTE_PLUGIN_ID> \
--confirm-account-mutation
```
Cleanup does not require analytics capture or a debug Codex binary. When the
smoke uses global `--config` overrides, its printed recovery command preserves
them so cleanup targets the same backend and account.
## Watching Raw Inbound Traffic
Initialize a connection, then print every inbound JSON-RPC message until you stop it with
`Ctrl+C`:
```bash
cargo run -p codex-app-server-test-client -- watch
```
## Testing Thread Rejoin Behavior
Build and start an app server using commands above. The app-server log is written to `/tmp/codex-app-server-test-client/app-server.log`
### 1) Get a thread id
Create at least one thread, then list threads:
```bash
cargo run -p codex-app-server-test-client -- send-message-v2 "seed thread for rejoin test"
cargo run -p codex-app-server-test-client -- thread-list --limit 5
```
Copy a thread id from the `thread-list` output.
### 2) Rejoin while a turn is in progress (two terminals)
Terminal A:
```bash
cargo run --bin codex-app-server-test-client -- \
resume-message-v2 <THREAD_ID> "respond with thorough docs on the rust core"
```
Terminal B (while Terminal A is still streaming):
```bash
cargo run --bin codex-app-server-test-client -- thread-resume <THREAD_ID>
```
@@ -1,46 +0,0 @@
#!/bin/sh
set -eu
require_env() {
eval "value=\${$1-}"
if [ -z "$value" ]; then
echo "missing required env var: $1" >&2
exit 1
fi
}
require_env APP_SERVER_URL
require_env APP_SERVER_TEST_CLIENT_BIN
thread_id="${CODEX_THREAD_ID:-${THREAD_ID-}}"
if [ -z "$thread_id" ]; then
echo "missing required env var: CODEX_THREAD_ID" >&2
exit 1
fi
hold_seconds="${ELICITATION_HOLD_SECONDS:-15}"
incremented=0
cleanup() {
if [ "$incremented" -eq 1 ]; then
"$APP_SERVER_TEST_CLIENT_BIN" --url "$APP_SERVER_URL" \
thread-decrement-elicitation "$thread_id" >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT INT TERM HUP
echo "[elicitation-hold] increment thread=$thread_id"
"$APP_SERVER_TEST_CLIENT_BIN" --url "$APP_SERVER_URL" \
thread-increment-elicitation "$thread_id"
incremented=1
echo "[elicitation-hold] sleeping ${hold_seconds}s"
sleep "$hold_seconds"
echo "[elicitation-hold] decrement thread=$thread_id"
"$APP_SERVER_TEST_CLIENT_BIN" --url "$APP_SERVER_URL" \
thread-decrement-elicitation "$thread_id"
incremented=0
echo "[elicitation-hold] done"
File diff suppressed because it is too large. Load diff
@@ -1,145 +0,0 @@
use anyhow::Context;
use anyhow::Result;
use std::io;
use std::io::Read;
use std::io::Write;
use std::net::TcpListener;
use std::net::TcpStream;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::thread;
use std::thread::JoinHandle;
use std::time::Duration;
pub(super) struct LoopbackResponsesServer {
base_url: String,
shutdown: Arc<AtomicBool>,
thread: Option<JoinHandle<()>>,
}
impl LoopbackResponsesServer {
pub(super) fn start() -> Result<Self> {
let listener =
TcpListener::bind("127.0.0.1:0").context("bind loopback Responses API server")?;
listener
.set_nonblocking(true)
.context("set loopback Responses API server nonblocking")?;
let address = listener.local_addr()?;
let shutdown = Arc::new(AtomicBool::new(false));
let thread_shutdown = Arc::clone(&shutdown);
let thread = thread::spawn(move || {
while !thread_shutdown.load(Ordering::Relaxed) {
match listener.accept() {
Ok((stream, _)) => {
if let Err(err) = handle_model_connection(stream) {
eprintln!("loopback Responses API server error: {err}");
}
}
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {
thread::sleep(Duration::from_millis(10));
}
Err(err) => {
eprintln!("loopback Responses API accept error: {err}");
break;
}
}
}
});
Ok(Self {
base_url: format!("http://{address}"),
shutdown,
thread: Some(thread),
})
}
pub(super) fn base_url(&self) -> &str {
&self.base_url
}
}
impl Drop for LoopbackResponsesServer {
fn drop(&mut self) {
self.shutdown.store(true, Ordering::Relaxed);
if let Some(thread) = self.thread.take() {
let _ = thread.join();
}
}
}
fn handle_model_connection(mut stream: TcpStream) -> io::Result<()> {
stream.set_nonblocking(false)?;
stream.set_read_timeout(Some(Duration::from_secs(2)))?;
let request = read_http_request(&mut stream)?;
let request_line = request
.split(|byte| *byte == b'\n')
.next()
.and_then(|line| std::str::from_utf8(line).ok())
.unwrap_or_default();
if request_line.starts_with("POST ") && request_line.contains("/responses ") {
let body = concat!(
"event: response.created\n",
"data: {\"type\":\"response.created\",\"response\":{\"id\":\"resp-plugin-analytics\"}}\n\n",
"event: response.completed\n",
"data: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-plugin-analytics\",\"usage\":{\"input_tokens\":0,\"input_tokens_details\":null,\"output_tokens\":0,\"output_tokens_details\":null,\"total_tokens\":0}}}\n\n"
);
write_http_response(&mut stream, "200 OK", "text/event-stream", body)
} else {
write_http_response(
&mut stream,
"404 Not Found",
"application/json",
r#"{"error":"not found"}"#,
)
}
}
fn read_http_request(stream: &mut TcpStream) -> io::Result<Vec<u8>> {
let mut request = Vec::new();
let mut buffer = [0_u8; 4096];
let header_end = loop {
let read = stream.read(&mut buffer)?;
if read == 0 {
return Ok(request);
}
request.extend_from_slice(&buffer[..read]);
if let Some(position) = request.windows(4).position(|window| window == b"\r\n\r\n") {
break position + 4;
}
};
let content_length = parse_content_length(&request[..header_end]);
while request.len() < header_end + content_length {
let read = stream.read(&mut buffer)?;
if read == 0 {
break;
}
request.extend_from_slice(&buffer[..read]);
}
Ok(request)
}
fn parse_content_length(headers: &[u8]) -> usize {
String::from_utf8_lossy(headers)
.lines()
.find_map(|line| {
let (name, value) = line.split_once(':')?;
name.eq_ignore_ascii_case("content-length")
.then(|| value.trim().parse().ok())
.flatten()
})
.unwrap_or(0)
}
fn write_http_response(
stream: &mut TcpStream,
status: &str,
content_type: &str,
body: &str,
) -> io::Result<()> {
write!(
stream,
"HTTP/1.1 {status}\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
body.len()
)?;
stream.flush()
}
@@ -1,7 +0,0 @@
use anyhow::Result;
use tokio::runtime::Builder;
fn main() -> Result<()> {
let runtime = Builder::new_current_thread().enable_all().build()?;
runtime.block_on(codex_app_server_test_client::run())
}
@@ -1,107 +0,0 @@
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use serde_json::Value;
use std::fs;
use std::io;
use std::path::Path;
pub(super) fn read_events_for_remote_plugin(
path: &Path,
remote_plugin_id: &str,
) -> Result<Vec<Value>> {
let contents = match fs::read_to_string(path) {
Ok(contents) => contents,
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(Vec::new()),
Err(err) => {
return Err(err).with_context(|| format!("read capture file {}", path.display()));
}
};
let mut matching = Vec::new();
for (index, line) in contents.lines().enumerate() {
if line.trim().is_empty() {
continue;
}
let payload: Value = serde_json::from_str(line).with_context(|| {
format!(
"parse analytics capture line {} from {}",
index + 1,
path.display()
)
})?;
let events = payload["events"]
.as_array()
.context("analytics capture payload is missing events")?;
matching.extend(
events
.iter()
.filter(|event| event["event_params"]["remote_plugin_id"] == remote_plugin_id)
.cloned(),
);
}
Ok(matching)
}
pub(super) struct PluginEventIdentity<'a> {
pub(super) plugin_id: &'a str,
pub(super) remote_plugin_id: &'a str,
pub(super) plugin_name: &'a str,
pub(super) marketplace_name: &'a str,
}
pub(super) fn validate_mutation_events(
events: Vec<Value>,
expected: PluginEventIdentity<'_>,
) -> Result<Vec<Value>> {
let mut validated = Vec::new();
for event_type in ["codex_plugin_installed", "codex_plugin_uninstalled"] {
let matching = events
.iter()
.filter(|event| event["event_type"] == event_type)
.collect::<Vec<_>>();
let [event] = matching.as_slice() else {
bail!(
"expected exactly one `{event_type}` event for `{}`, found {}",
expected.remote_plugin_id,
matching.len()
);
};
validate_event(event, &expected)?;
validated.push((*event).clone());
}
Ok(validated)
}
fn validate_event(event: &Value, expected: &PluginEventIdentity<'_>) -> Result<()> {
let params = &event["event_params"];
require_string(params, "plugin_id", expected.plugin_id)?;
require_string(params, "remote_plugin_id", expected.remote_plugin_id)?;
require_string(params, "plugin_name", expected.plugin_name)?;
require_string(params, "marketplace_name", expected.marketplace_name)?;
for field in [
"has_skills",
"mcp_server_count",
"connector_ids",
"product_client_id",
] {
if params.get(field).is_none_or(Value::is_null) {
bail!(
"{} event has null or missing `{field}`",
event["event_type"]
);
}
}
Ok(())
}
fn require_string(params: &Value, field: &str, expected: &str) -> Result<()> {
let actual = params.get(field).and_then(Value::as_str);
if actual != Some(expected) {
bail!("expected `{field}` to be `{expected}`, got {actual:?}");
}
Ok(())
}
#[cfg(test)]
#[path = "plugin_analytics_capture_tests.rs"]
mod tests;
@@ -1,97 +0,0 @@
use super::PluginEventIdentity;
use super::read_events_for_remote_plugin;
use super::validate_mutation_events;
use serde_json::Value;
use serde_json::json;
use std::fs;
use std::path::PathBuf;
use std::process;
use std::time::SystemTime;
const REMOTE_PLUGIN_ID: &str = "plugins~Plugin_test";
#[test]
fn reads_and_validates_remote_plugin_mutation_events() {
let path = unique_capture_path("valid");
let installed = mutation_event("codex_plugin_installed");
let uninstalled = mutation_event("codex_plugin_uninstalled");
let unrelated = json!({
"event_type": "codex_plugin_installed",
"event_params": {
"plugin_id": "other@openai-curated-remote",
"remote_plugin_id": "plugins~Plugin_other"
}
});
let contents = [
json!({"events": [unrelated]}),
json!({"events": [installed, uninstalled]}),
]
.into_iter()
.map(|payload| serde_json::to_string(&payload).expect("serialize capture payload"))
.collect::<Vec<_>>()
.join("\n");
fs::write(&path, contents).expect("write capture file");
let events = read_events_for_remote_plugin(&path, REMOTE_PLUGIN_ID)
.expect("read matching plugin events");
let validated =
validate_mutation_events(events, expected_identity()).expect("validate mutation events");
assert_eq!(validated, vec![installed, uninstalled]);
fs::remove_file(path).expect("remove capture file");
}
#[test]
fn rejects_duplicate_mutation_events() {
let installed = mutation_event("codex_plugin_installed");
let error = validate_mutation_events(vec![installed.clone(), installed], expected_identity())
.expect_err("duplicate install events should fail validation");
assert!(error.to_string().contains("found 2"));
}
#[test]
fn rejects_missing_capability_metadata() {
let mut installed = mutation_event("codex_plugin_installed");
installed["event_params"]["has_skills"] = Value::Null;
let error = validate_mutation_events(vec![installed], expected_identity())
.expect_err("missing capability metadata should fail validation");
assert!(error.to_string().contains("has_skills"));
}
fn mutation_event(event_type: &str) -> Value {
json!({
"event_type": event_type,
"event_params": {
"plugin_id": "sample@openai-curated-remote",
"remote_plugin_id": REMOTE_PLUGIN_ID,
"plugin_name": "sample",
"marketplace_name": "openai-curated-remote",
"has_skills": true,
"mcp_server_count": 0,
"connector_ids": [],
"product_client_id": "test-client"
}
})
}
fn expected_identity() -> PluginEventIdentity<'static> {
PluginEventIdentity {
plugin_id: "sample@openai-curated-remote",
remote_plugin_id: REMOTE_PLUGIN_ID,
plugin_name: "sample",
marketplace_name: "openai-curated-remote",
}
}
fn unique_capture_path(name: &str) -> PathBuf {
let nonce = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("system clock should be after Unix epoch")
.as_nanos();
std::env::temp_dir().join(format!(
"codex-plugin-analytics-capture-{name}-{}-{nonce}.jsonl",
process::id()
))
}
@@ -1,488 +0,0 @@
use super::CodexClient;
use super::plugin_analytics_capture::PluginEventIdentity;
use super::plugin_analytics_capture::read_events_for_remote_plugin;
use super::plugin_analytics_capture::validate_mutation_events;
use super::plugin_analytics_smoke::ANALYTICS_CAPTURE_ENV_VAR;
use super::plugin_analytics_smoke::prepare_capture_file;
use super::plugin_analytics_smoke::wait_until_capture_is_ready;
use super::shell_quote;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use anyhow::bail;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::PluginAvailability;
use codex_app_server_protocol::PluginInstallParams;
use codex_app_server_protocol::PluginInstallPolicy;
use codex_app_server_protocol::PluginInstallResponse;
use codex_app_server_protocol::PluginReadParams;
use codex_app_server_protocol::PluginReadResponse;
use codex_app_server_protocol::PluginUninstallParams;
use codex_app_server_protocol::PluginUninstallResponse;
use serde_json::Value;
use std::ffi::OsString;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::thread;
use std::time::Duration;
use std::time::Instant;
const REMOTE_MARKETPLACE_HINT: &str = "openai-curated-remote";
const STATE_TIMEOUT: Duration = Duration::from_secs(15);
const CAPTURE_TIMEOUT: Duration = Duration::from_secs(10);
const POLL_INTERVAL: Duration = Duration::from_millis(100);
pub(super) fn run(
codex_bin: &Path,
config_overrides: &[String],
remote_plugin_id: &str,
confirmation: AccountMutationConfirmation,
capture_file: Option<PathBuf>,
) -> Result<()> {
require_confirmation(confirmation)?;
let capture_path = capture_file.unwrap_or_else(|| {
std::env::temp_dir().join(format!(
"codex-plugin-analytics-mutation-{}.jsonl",
process::id()
))
});
prepare_capture_file(&capture_path)?;
let mut client = spawn_client(codex_bin, config_overrides, &capture_path)?;
wait_until_capture_is_ready(&capture_path)?;
client.initialize()?;
let initial = read_remote_plugin(&mut client, remote_plugin_id)?;
validate_initial_plugin(&initial, remote_plugin_id)?;
println!(
"remote plugin mutation smoke: local_id={} remote_id={} marketplace={}",
initial.plugin_id, initial.remote_plugin_id, initial.marketplace_name
);
let MutationSequenceResult {
result: sequence_result,
uninstall_rpc_failed,
} = run_mutation_sequence(&mut client, &capture_path, &initial);
let restoration = restore_uninstalled_state(&mut client, remote_plugin_id);
println!("capture file: {}", capture_path.display());
match (sequence_result, restoration) {
(Ok(events), RestorationStatus::Clean) => {
println!(
"\n[plugin analytics mutation smoke validated]\n{}",
serde_json::to_string_pretty(&events)?
);
println!("PASS: analytics validated; original uninstalled state restored");
Ok(())
}
(Err(err), RestorationStatus::Clean) if uninstall_rpc_failed => {
eprintln!(
"FAIL-LOCAL-CACHE: backend state is uninstalled, but the uninstall RPC failed after the backend mutation: {err:#}"
);
Err(err)
}
(Err(err), RestorationStatus::Clean) => {
eprintln!("FAIL-CLEAN: {err:#}");
eprintln!("The original uninstalled account state was restored.");
Err(err)
}
(sequence_result, RestorationStatus::LocalCleanupFailure(cleanup_err)) => {
let sequence_err = sequence_result.err();
eprintln!(
"FAIL-LOCAL-CACHE: backend state is uninstalled, but local cleanup reported an error: {cleanup_err:#}"
);
Err(sequence_err.unwrap_or(cleanup_err))
}
(sequence_result, RestorationStatus::Dirty(cleanup_err)) => {
if let Err(err) = sequence_result {
eprintln!("mutation smoke failed before cleanup: {err:#}");
}
print_dirty_recovery(codex_bin, config_overrides, remote_plugin_id, &cleanup_err);
Err(cleanup_err)
}
(sequence_result, RestorationStatus::Unknown(cleanup_err)) => {
if let Err(err) = sequence_result {
eprintln!("mutation smoke failed before final state verification: {err:#}");
}
eprintln!(
"FAIL-UNKNOWN: could not verify whether `{remote_plugin_id}` is installed: {cleanup_err:#}"
);
print_recovery_command(codex_bin, config_overrides, remote_plugin_id);
Err(cleanup_err)
}
}
}
pub(super) fn run_cleanup(
codex_bin: &Path,
config_overrides: &[String],
remote_plugin_id: &str,
confirmation: AccountMutationConfirmation,
) -> Result<()> {
require_confirmation(confirmation)?;
let mut overrides = config_overrides.to_vec();
overrides.extend([
"analytics.enabled=false".to_string(),
"features.plugins=true".to_string(),
]);
let mut client = CodexClient::spawn_stdio(codex_bin, &overrides)?;
client.initialize()?;
match restore_uninstalled_state(&mut client, remote_plugin_id) {
RestorationStatus::Clean => {
println!("PASS: `{remote_plugin_id}` is uninstalled");
Ok(())
}
RestorationStatus::LocalCleanupFailure(err) => {
eprintln!(
"FAIL-LOCAL-CACHE: backend state is uninstalled, but local cleanup reported an error: {err:#}"
);
Err(err)
}
RestorationStatus::Dirty(err) => {
print_dirty_recovery(codex_bin, config_overrides, remote_plugin_id, &err);
Err(err)
}
RestorationStatus::Unknown(err) => {
eprintln!(
"FAIL-UNKNOWN: could not verify whether `{remote_plugin_id}` is installed: {err:#}"
);
Err(err)
}
}
}
#[derive(Clone, Copy)]
pub(super) enum AccountMutationConfirmation {
Confirmed,
Missing,
}
impl AccountMutationConfirmation {
pub(super) fn from_flag(confirm_account_mutation: bool) -> Self {
if confirm_account_mutation {
Self::Confirmed
} else {
Self::Missing
}
}
}
fn require_confirmation(confirmation: AccountMutationConfirmation) -> Result<()> {
if matches!(confirmation, AccountMutationConfirmation::Missing) {
bail!(
"this command installs and uninstalls a plugin on the active account; rerun with --confirm-account-mutation"
);
}
Ok(())
}
#[derive(Clone, Copy, Debug)]
enum ExpectedInstalledState {
Installed,
Uninstalled,
}
impl ExpectedInstalledState {
fn is_installed(self) -> bool {
matches!(self, Self::Installed)
}
}
fn spawn_client(
codex_bin: &Path,
config_overrides: &[String],
capture_path: &Path,
) -> Result<CodexClient> {
let mut overrides = config_overrides.to_vec();
overrides.extend([
"analytics.enabled=true".to_string(),
"features.plugins=true".to_string(),
]);
let environment = vec![(
OsString::from(ANALYTICS_CAPTURE_ENV_VAR),
capture_path.as_os_str().to_os_string(),
)];
CodexClient::spawn_stdio_with_env(codex_bin, &overrides, &environment)
}
#[derive(Clone, Debug)]
struct RemotePluginExpectation {
plugin_id: String,
remote_plugin_id: String,
plugin_name: String,
marketplace_name: String,
installed: bool,
install_policy: PluginInstallPolicy,
availability: PluginAvailability,
}
fn read_remote_plugin(
client: &mut CodexClient,
remote_plugin_id: &str,
) -> Result<RemotePluginExpectation> {
let request_id = client.request_id();
let response: PluginReadResponse = client.send_request(
ClientRequest::PluginRead {
request_id: request_id.clone(),
params: PluginReadParams {
marketplace_path: None,
remote_marketplace_name: Some(REMOTE_MARKETPLACE_HINT.to_string()),
plugin_name: remote_plugin_id.to_string(),
},
},
request_id,
"plugin/read",
)?;
let summary = response.plugin.summary;
let actual_remote_plugin_id = summary
.remote_plugin_id
.with_context(|| format!("plugin/read returned no remote id for `{remote_plugin_id}`"))?;
if actual_remote_plugin_id != remote_plugin_id {
bail!(
"plugin/read returned remote id `{actual_remote_plugin_id}` for requested id `{remote_plugin_id}`"
);
}
Ok(RemotePluginExpectation {
plugin_id: summary.id,
remote_plugin_id: actual_remote_plugin_id,
plugin_name: summary.name,
marketplace_name: response.plugin.marketplace_name,
installed: summary.installed,
install_policy: summary.install_policy,
availability: summary.availability,
})
}
fn validate_initial_plugin(plugin: &RemotePluginExpectation, remote_plugin_id: &str) -> Result<()> {
if plugin.installed {
bail!(
"refusing to run: remote plugin `{remote_plugin_id}` is already installed; choose an initially uninstalled plugin"
);
}
if plugin.availability != PluginAvailability::Available {
bail!(
"remote plugin `{remote_plugin_id}` is not available: {:?}",
plugin.availability
);
}
if plugin.install_policy == PluginInstallPolicy::NotAvailable {
bail!("remote plugin `{remote_plugin_id}` is not available for install");
}
Ok(())
}
struct MutationSequenceResult {
result: Result<Vec<Value>>,
uninstall_rpc_failed: bool,
}
fn run_mutation_sequence(
client: &mut CodexClient,
capture_path: &Path,
expected: &RemotePluginExpectation,
) -> MutationSequenceResult {
let mut uninstall_rpc_failed = false;
let result = (|| {
install_remote_plugin(client, expected)?;
wait_for_installed_state(
client,
&expected.remote_plugin_id,
ExpectedInstalledState::Installed,
)?;
wait_for_remote_plugin_event(
capture_path,
&expected.remote_plugin_id,
"codex_plugin_installed",
)?;
let uninstall_error = uninstall_remote_plugin(client, &expected.remote_plugin_id).err();
uninstall_rpc_failed = uninstall_error.is_some();
wait_for_installed_state(
client,
&expected.remote_plugin_id,
ExpectedInstalledState::Uninstalled,
)
.map_err(|state_err| {
if let Some(err) = uninstall_error.as_ref() {
anyhow!("plugin/uninstall failed: {err:#}; final state check failed: {state_err:#}")
} else {
state_err
}
})?;
wait_for_remote_plugin_event(
capture_path,
&expected.remote_plugin_id,
"codex_plugin_uninstalled",
)?;
let captured_events =
read_events_for_remote_plugin(capture_path, &expected.remote_plugin_id)?;
let events = validate_mutation_events(
captured_events,
PluginEventIdentity {
plugin_id: &expected.plugin_id,
remote_plugin_id: &expected.remote_plugin_id,
plugin_name: &expected.plugin_name,
marketplace_name: &expected.marketplace_name,
},
)?;
if let Some(err) = uninstall_error {
return Err(err.context(
"plugin/uninstall reported an error after the backend became uninstalled",
));
}
Ok(events)
})();
MutationSequenceResult {
result,
uninstall_rpc_failed,
}
}
fn install_remote_plugin(client: &mut CodexClient, plugin: &RemotePluginExpectation) -> Result<()> {
let request_id = client.request_id();
let _: PluginInstallResponse = client.send_request(
ClientRequest::PluginInstall {
request_id: request_id.clone(),
params: PluginInstallParams {
marketplace_path: None,
remote_marketplace_name: Some(plugin.marketplace_name.clone()),
install_attempt_id: None,
plugin_name: plugin.remote_plugin_id.clone(),
},
},
request_id,
"plugin/install",
)?;
Ok(())
}
fn uninstall_remote_plugin(client: &mut CodexClient, remote_plugin_id: &str) -> Result<()> {
let request_id = client.request_id();
let _: PluginUninstallResponse = client.send_request(
ClientRequest::PluginUninstall {
request_id: request_id.clone(),
params: PluginUninstallParams {
plugin_id: remote_plugin_id.to_string(),
},
},
request_id,
"plugin/uninstall",
)?;
Ok(())
}
fn wait_for_installed_state(
client: &mut CodexClient,
remote_plugin_id: &str,
expected_state: ExpectedInstalledState,
) -> Result<RemotePluginExpectation> {
let deadline = Instant::now() + STATE_TIMEOUT;
loop {
match read_remote_plugin(client, remote_plugin_id) {
Ok(plugin) if plugin.installed == expected_state.is_installed() => return Ok(plugin),
Ok(_) => {}
Err(err) if Instant::now() >= deadline => return Err(err),
Err(_) => {}
}
if Instant::now() >= deadline {
bail!(
"timed out waiting for remote plugin `{remote_plugin_id}` to become {expected_state:?}"
);
}
thread::sleep(POLL_INTERVAL);
}
}
enum RestorationStatus {
Clean,
LocalCleanupFailure(anyhow::Error),
Dirty(anyhow::Error),
Unknown(anyhow::Error),
}
fn restore_uninstalled_state(
client: &mut CodexClient,
remote_plugin_id: &str,
) -> RestorationStatus {
let current = match read_remote_plugin(client, remote_plugin_id) {
Ok(current) => current,
Err(err) => return RestorationStatus::Unknown(err),
};
if !current.installed {
return RestorationStatus::Clean;
}
let uninstall_result = uninstall_remote_plugin(client, remote_plugin_id);
match wait_for_installed_state(
client,
remote_plugin_id,
ExpectedInstalledState::Uninstalled,
) {
Ok(_) => match uninstall_result {
Ok(()) => RestorationStatus::Clean,
Err(err) => RestorationStatus::LocalCleanupFailure(err),
},
Err(state_err) => {
let error = match uninstall_result {
Ok(()) => state_err,
Err(uninstall_err) => anyhow!(
"cleanup uninstall failed: {uninstall_err:#}; state verification failed: {state_err:#}"
),
};
RestorationStatus::Dirty(error)
}
}
}
fn wait_for_remote_plugin_event(
path: &Path,
remote_plugin_id: &str,
event_type: &str,
) -> Result<()> {
let deadline = Instant::now() + CAPTURE_TIMEOUT;
loop {
let events = read_events_for_remote_plugin(path, remote_plugin_id)?;
if events.iter().any(|event| event["event_type"] == event_type) {
return Ok(());
}
if Instant::now() >= deadline {
bail!("timed out waiting for `{event_type}` for remote plugin `{remote_plugin_id}`");
}
thread::sleep(POLL_INTERVAL);
}
}
fn print_dirty_recovery(
codex_bin: &Path,
config_overrides: &[String],
remote_plugin_id: &str,
err: &anyhow::Error,
) {
eprintln!(
"FAIL-DIRTY: remote plugin `{remote_plugin_id}` still appears installed after cleanup: {err:#}"
);
print_recovery_command(codex_bin, config_overrides, remote_plugin_id);
}
fn print_recovery_command(codex_bin: &Path, config_overrides: &[String], remote_plugin_id: &str) {
let test_client = std::env::current_exe()
.map(|path| path.display().to_string())
.unwrap_or_else(|_| "codex-app-server-test-client".to_string());
let mut command = format!(
"{} --codex-bin {}",
shell_quote(&test_client),
shell_quote(&codex_bin.display().to_string())
);
for override_kv in config_overrides {
command.push_str(&format!(" --config {}", shell_quote(override_kv)));
}
command.push_str(&format!(
" plugin-remote-uninstall --remote-plugin-id {} --confirm-account-mutation",
shell_quote(remote_plugin_id)
));
eprintln!("Recovery command:");
eprintln!(" {command}");
}
@@ -1,504 +0,0 @@
use super::CodexClient;
use super::loopback_responses_server::LoopbackResponsesServer;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::ConfigValueWriteParams;
use codex_app_server_protocol::ConfigWriteResponse;
use codex_app_server_protocol::MergeStrategy;
use codex_app_server_protocol::PluginAvailability;
use codex_app_server_protocol::PluginInstalledParams;
use codex_app_server_protocol::PluginInstalledResponse;
use codex_app_server_protocol::ThreadStartParams;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UserInput;
use codex_app_server_protocol::WriteStatus;
use serde_json::Value;
use serde_json::json;
use std::ffi::OsString;
use std::fs;
use std::io;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::thread;
use std::time::Duration;
use std::time::Instant;
pub(super) const ANALYTICS_CAPTURE_ENV_VAR: &str = "CODEX_ANALYTICS_EVENTS_CAPTURE_FILE";
const TEST_USER_CONFIG_ENV_VAR: &str = "CODEX_APP_SERVER_TEST_USER_CONFIG_FILE";
const CAPTURE_READY_TIMEOUT: Duration = Duration::from_secs(5);
const CAPTURE_TIMEOUT: Duration = Duration::from_secs(10);
const CAPTURE_POLL_INTERVAL: Duration = Duration::from_millis(50);
const PLUGIN_READY_TIMEOUT: Duration = Duration::from_secs(30);
const PLUGIN_READY_RETRY_INTERVAL: Duration = Duration::from_millis(250);
const MOCK_MODEL_SLUG: &str = "plugin-analytics-smoke";
const MOCK_PROVIDER_ID: &str = "plugin_analytics_smoke";
pub(super) fn run(
codex_bin: &Path,
config_overrides: &[String],
plugin_id: &str,
capture_file: Option<PathBuf>,
) -> Result<()> {
let capture_path = capture_file.unwrap_or_else(|| {
std::env::temp_dir().join(format!("codex-plugin-analytics-{}.jsonl", process::id()))
});
prepare_capture_file(&capture_path)?;
let temporary_config = TemporaryConfigFile::create()?;
let responses_server = LoopbackResponsesServer::start()?;
let mut overrides = config_overrides.to_vec();
overrides.extend(smoke_config_overrides(responses_server.base_url())?);
let child_environment = vec![
(
OsString::from(ANALYTICS_CAPTURE_ENV_VAR),
capture_path.as_os_str().to_os_string(),
),
(
OsString::from(TEST_USER_CONFIG_ENV_VAR),
temporary_config.path().as_os_str().to_os_string(),
),
];
let mut client = CodexClient::spawn_stdio_with_env(codex_bin, &overrides, &child_environment)?;
wait_until_capture_is_ready(&capture_path)?;
client.initialize()?;
let installed = plugin_installed(&mut client)?;
let expected = expected_plugin(&installed, plugin_id)?;
write_plugin_enabled(
&mut client,
temporary_config.path(),
plugin_id,
/*enabled*/ false,
)?;
write_plugin_enabled(
&mut client,
temporary_config.path(),
plugin_id,
/*enabled*/ true,
)?;
wait_for_plugin_usage(&mut client, &capture_path, &expected)?;
let events = wait_for_plugin_events(&capture_path, plugin_id)?;
let validated = validate_plugin_events(events, &expected)?;
println!(
"\n[plugin analytics smoke validated]\n{}",
serde_json::to_string_pretty(&validated)?
);
println!("capture file: {}", capture_path.display());
Ok(())
}
fn run_plugin_turn(client: &mut CodexClient, expected: &ExpectedPlugin) -> Result<String> {
let thread = client.thread_start(ThreadStartParams {
model: Some(MOCK_MODEL_SLUG.to_string()),
model_provider: Some(MOCK_PROVIDER_ID.to_string()),
base_instructions: Some(String::new()),
developer_instructions: Some(String::new()),
ephemeral: Some(true),
..Default::default()
})?;
let turn = client.turn_start(TurnStartParams {
thread_id: thread.thread.id.clone(),
client_user_message_id: None,
input: vec![UserInput::Mention {
name: expected.plugin_name.clone(),
path: format!("plugin://{}", expected.plugin_id),
}],
..Default::default()
})?;
client.stream_turn(&thread.thread.id, &turn.turn.id)?;
if client.last_turn_status != Some(TurnStatus::Completed) {
bail!(
"plugin analytics smoke turn did not complete: status={:?}, error={:?}",
client.last_turn_status,
client.last_turn_error_message
);
}
Ok(turn.turn.id)
}
fn wait_for_plugin_usage(
client: &mut CodexClient,
capture_path: &Path,
expected: &ExpectedPlugin,
) -> Result<()> {
let deadline = Instant::now() + PLUGIN_READY_TIMEOUT;
let mut attempts = 0;
loop {
attempts += 1;
let turn_id = run_plugin_turn(client, expected)?;
// Turn completion is queued after plugin usage, so its captured event is the
// barrier that tells us whether this attempt resolved the plugin.
let events = wait_for_turn_analytics(capture_path, &turn_id)?;
if events.iter().any(|event| {
event["event_type"] == "codex_plugin_used"
&& event["event_params"]["turn_id"].as_str() == Some(turn_id.as_str())
&& event["event_params"]["plugin_id"].as_str() == Some(expected.plugin_id.as_str())
}) {
if attempts > 1 {
println!("remote plugin bundle became ready after {attempts} turn attempts");
}
return Ok(());
}
if Instant::now() >= deadline {
bail!(
"timed out waiting for remote plugin bundle `{}` to become usable after {attempts} turn attempts",
expected.plugin_id
);
}
thread::sleep(PLUGIN_READY_RETRY_INTERVAL);
}
}
#[derive(Debug)]
struct ExpectedPlugin {
plugin_id: String,
remote_plugin_id: String,
plugin_name: String,
marketplace_name: String,
}
fn plugin_installed(client: &mut CodexClient) -> Result<PluginInstalledResponse> {
let request_id = client.request_id();
client.send_request(
ClientRequest::PluginInstalled {
request_id: request_id.clone(),
params: PluginInstalledParams {
cwds: None,
install_suggestion_plugin_names: None,
},
},
request_id,
"plugin/installed",
)
}
fn expected_plugin(response: &PluginInstalledResponse, plugin_id: &str) -> Result<ExpectedPlugin> {
let matches = response
.marketplaces
.iter()
.flat_map(|marketplace| {
marketplace
.plugins
.iter()
.filter(move |plugin| plugin.id == plugin_id)
.map(move |plugin| (marketplace, plugin))
})
.collect::<Vec<_>>();
let [(marketplace, plugin)] = matches.as_slice() else {
bail!(
"expected exactly one installed plugin with local id `{plugin_id}`, found {}",
matches.len()
);
};
if !plugin.installed {
bail!("plugin `{plugin_id}` is not installed");
}
if !plugin.enabled {
bail!("plugin `{plugin_id}` is installed remotely but disabled");
}
if plugin.availability != PluginAvailability::Available {
bail!(
"plugin `{plugin_id}` is not available: {:?}",
plugin.availability
);
}
let remote_plugin_id = plugin
.remote_plugin_id
.as_ref()
.with_context(|| format!("plugin `{plugin_id}` does not have a remote plugin id"))?
.clone();
Ok(ExpectedPlugin {
plugin_id: plugin.id.clone(),
remote_plugin_id,
plugin_name: plugin.name.clone(),
marketplace_name: marketplace.name.clone(),
})
}
fn write_plugin_enabled(
client: &mut CodexClient,
config_path: &Path,
plugin_id: &str,
enabled: bool,
) -> Result<()> {
let request_id = client.request_id();
let response: ConfigWriteResponse = client.send_request(
ClientRequest::ConfigValueWrite {
request_id: request_id.clone(),
params: ConfigValueWriteParams {
key_path: format!("plugins.{plugin_id}.enabled"),
value: json!(enabled),
merge_strategy: MergeStrategy::Replace,
file_path: Some(config_path.display().to_string()),
expected_version: None,
},
},
request_id,
"config/value/write",
)?;
println!(
"< config/value/write plugin={plugin_id} enabled={enabled} status={:?}",
response.status
);
if response.status != WriteStatus::Ok {
bail!(
"config/value/write for plugin `{plugin_id}` enabled={enabled} was overridden: {:?}",
response.overridden_metadata
);
}
Ok(())
}
fn smoke_config_overrides(responses_base_url: &str) -> Result<Vec<String>> {
let provider_base_url = serde_json::to_string(&format!("{responses_base_url}/v1"))
.context("serialize mock provider base URL")?;
Ok(vec![
"analytics.enabled=true".to_string(),
"features.plugins=true".to_string(),
format!("model={}", quoted(MOCK_MODEL_SLUG)?),
format!("model_provider={}", quoted(MOCK_PROVIDER_ID)?),
format!(
"model_providers.{MOCK_PROVIDER_ID}.name={}",
quoted("Plugin analytics smoke mock provider")?
),
format!("model_providers.{MOCK_PROVIDER_ID}.base_url={provider_base_url}"),
format!(
"model_providers.{MOCK_PROVIDER_ID}.wire_api={}",
quoted("responses")?
),
format!("model_providers.{MOCK_PROVIDER_ID}.requires_openai_auth=false"),
format!("model_providers.{MOCK_PROVIDER_ID}.request_max_retries=0"),
format!("model_providers.{MOCK_PROVIDER_ID}.stream_max_retries=0"),
])
}
fn quoted(value: &str) -> Result<String> {
serde_json::to_string(value).context("serialize config string")
}
pub(super) fn prepare_capture_file(path: &Path) -> Result<()> {
let parent = path
.parent()
.context("capture file must have a parent directory")?;
if !parent.is_dir() {
bail!(
"capture file parent directory does not exist: {}",
parent.display()
);
}
match fs::remove_file(path) {
Ok(()) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => {
return Err(err)
.with_context(|| format!("remove previous capture file {}", path.display()));
}
}
Ok(())
}
pub(super) fn wait_until_capture_is_ready(path: &Path) -> Result<()> {
let deadline = Instant::now() + CAPTURE_READY_TIMEOUT;
loop {
match fs::metadata(path) {
Ok(_) => return Ok(()),
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => {
return Err(err)
.with_context(|| format!("inspect capture file {}", path.display()));
}
}
if Instant::now() >= deadline {
bail!(
"analytics capture did not become ready at {}; use a debug Codex binary",
path.display()
);
}
thread::sleep(CAPTURE_POLL_INTERVAL);
}
}
fn wait_for_plugin_events(path: &Path, plugin_id: &str) -> Result<Vec<Value>> {
let deadline = Instant::now() + CAPTURE_TIMEOUT;
loop {
let events = read_plugin_events(path, plugin_id)?;
if required_event_types()
.iter()
.all(|event_type| event_count(&events, event_type) >= 1)
{
return Ok(events);
}
if Instant::now() >= deadline {
bail!(
"timed out waiting for plugin analytics events in {}: found {:?}",
path.display(),
events
.iter()
.filter_map(|event| event["event_type"].as_str())
.collect::<Vec<_>>()
);
}
thread::sleep(CAPTURE_POLL_INTERVAL);
}
}
fn wait_for_turn_analytics(path: &Path, turn_id: &str) -> Result<Vec<Value>> {
let deadline = Instant::now() + CAPTURE_TIMEOUT;
loop {
let events = read_capture_events(path)?;
if events.iter().any(|event| {
event["event_type"] == "codex_turn_event"
&& event["event_params"]["turn_id"].as_str() == Some(turn_id)
}) {
return Ok(events);
}
if Instant::now() >= deadline {
bail!(
"timed out waiting for turn analytics for `{turn_id}` in {}",
path.display()
);
}
thread::sleep(CAPTURE_POLL_INTERVAL);
}
}
fn read_plugin_events(path: &Path, plugin_id: &str) -> Result<Vec<Value>> {
Ok(read_capture_events(path)?
.into_iter()
.filter(|event| event["event_params"]["plugin_id"] == plugin_id)
.collect())
}
fn read_capture_events(path: &Path) -> Result<Vec<Value>> {
let contents = match fs::read_to_string(path) {
Ok(contents) => contents,
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(Vec::new()),
Err(err) => {
return Err(err).with_context(|| format!("read capture file {}", path.display()));
}
};
let mut captured = Vec::new();
for (index, line) in contents.lines().enumerate() {
if line.trim().is_empty() {
continue;
}
let payload: Value = serde_json::from_str(line).with_context(|| {
format!(
"parse analytics capture line {} from {}",
index + 1,
path.display()
)
})?;
let events = payload["events"]
.as_array()
.context("analytics capture payload is missing events")?;
captured.extend(events.iter().cloned());
}
Ok(captured)
}
fn validate_plugin_events(events: Vec<Value>, expected: &ExpectedPlugin) -> Result<Vec<Value>> {
let mut validated = Vec::new();
for event_type in required_event_types() {
let matching = events
.iter()
.filter(|event| event["event_type"] == event_type)
.collect::<Vec<_>>();
let [event] = matching.as_slice() else {
bail!(
"expected exactly one `{event_type}` event for `{}`, found {}",
expected.plugin_id,
matching.len()
);
};
validate_identity(event, expected)?;
if event_type == "codex_plugin_used" {
validate_used_metadata(event)?;
}
validated.push((*event).clone());
}
Ok(validated)
}
fn required_event_types() -> [&'static str; 3] {
[
"codex_plugin_disabled",
"codex_plugin_enabled",
"codex_plugin_used",
]
}
fn event_count(events: &[Value], event_type: &str) -> usize {
events
.iter()
.filter(|event| event["event_type"] == event_type)
.count()
}
fn validate_identity(event: &Value, expected: &ExpectedPlugin) -> Result<()> {
let params = &event["event_params"];
require_string(params, "plugin_id", &expected.plugin_id)?;
require_string(params, "remote_plugin_id", &expected.remote_plugin_id)?;
require_string(params, "plugin_name", &expected.plugin_name)?;
require_string(params, "marketplace_name", &expected.marketplace_name)
}
fn validate_used_metadata(event: &Value) -> Result<()> {
let params = &event["event_params"];
for field in [
"has_skills",
"mcp_server_count",
"connector_ids",
"mcp_server_names",
"thread_id",
"turn_id",
"model_slug",
] {
if params.get(field).is_none_or(Value::is_null) {
bail!("codex_plugin_used event has null or missing `{field}`");
}
}
require_string(params, "model_slug", MOCK_MODEL_SLUG)
}
fn require_string(params: &Value, field: &str, expected: &str) -> Result<()> {
let actual = params.get(field).and_then(Value::as_str);
if actual != Some(expected) {
bail!("expected `{field}` to be `{expected}`, got {actual:?}");
}
Ok(())
}
struct TemporaryConfigFile {
path: PathBuf,
}
impl TemporaryConfigFile {
fn create() -> Result<Self> {
let path = std::env::temp_dir().join(format!(
"codex-plugin-analytics-config-{}.toml",
process::id()
));
fs::write(&path, "")
.with_context(|| format!("create temporary config file {}", path.display()))?;
Ok(Self { path })
}
fn path(&self) -> &Path {
&self.path
}
}
impl Drop for TemporaryConfigFile {
fn drop(&mut self) {
let _ = fs::remove_file(&self.path);
}
}
@@ -1,145 +0,0 @@
use std::collections::HashMap;
use std::io;
use std::io::BufRead;
use std::io::IsTerminal;
use std::io::Write;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use codex_app_server_protocol::ToolRequestUserInputAnswer;
use codex_app_server_protocol::ToolRequestUserInputParams;
use codex_app_server_protocol::ToolRequestUserInputResponse;
pub(super) fn prompt_for_answers(
params: &ToolRequestUserInputParams,
) -> Result<ToolRequestUserInputResponse> {
let stdin = io::stdin();
if !stdin.is_terminal() {
bail!("request_user_input requires an interactive stdin terminal");
}
let stdout = io::stdout();
prompt_for_answers_with(&mut stdin.lock(), &mut stdout.lock(), params)
}
fn prompt_for_answers_with(
input: &mut impl BufRead,
output: &mut impl Write,
params: &ToolRequestUserInputParams,
) -> Result<ToolRequestUserInputResponse> {
writeln!(
output,
"\n[request_user_input for thread {}, turn {}]",
params.thread_id, params.turn_id
)?;
if !params.is_blocking {
writeln!(output, "This request is non-blocking.")?;
}
let mut answers = HashMap::new();
for question in &params.questions {
writeln!(output, "\n{}: {}", question.header, question.question)?;
let options = question
.options
.as_deref()
.filter(|options| !options.is_empty());
let answer_values = if let Some(options) = options {
for (index, option) in options.iter().enumerate() {
writeln!(
output,
" {}. {} - {}",
index + 1,
option.label,
option.description
)?;
}
if question.is_other {
writeln!(output, " o. Other (free-form)")?;
}
loop {
if question.is_other {
write!(output, "Choose 1-{} or o: ", options.len())?;
} else {
write!(output, "Choose 1-{}: ", options.len())?;
}
output.flush()?;
let mut line = String::new();
if input
.read_line(&mut line)
.context("failed to read request_user_input selection")?
== 0
{
bail!("stdin closed while waiting for request_user_input selection");
}
let selection = line.trim();
if let Ok(index) = selection.parse::<usize>()
&& let Some(option) = index.checked_sub(1).and_then(|index| options.get(index))
{
break vec![option.label.clone()];
}
if let Some(option) = options
.iter()
.find(|option| option.label.eq_ignore_ascii_case(selection))
{
break vec![option.label.clone()];
}
if question.is_other && selection.eq_ignore_ascii_case("o") {
write!(output, "Other: ")?;
output.flush()?;
line.clear();
if input
.read_line(&mut line)
.context("failed to read request_user_input free-form answer")?
== 0
{
bail!("stdin closed while waiting for request_user_input free-form answer");
}
let answer = line.trim();
if !answer.is_empty() {
break vec![format!("user_note: {answer}")];
}
}
writeln!(output, "Invalid selection; try again.")?;
}
} else {
loop {
write!(output, "Answer: ")?;
output.flush()?;
let mut line = String::new();
if input
.read_line(&mut line)
.context("failed to read request_user_input answer")?
== 0
{
bail!("stdin closed while waiting for request_user_input answer");
}
let answer = line.trim();
if !answer.is_empty() {
break vec![format!("user_note: {answer}")];
}
writeln!(output, "Answer cannot be empty; try again.")?;
}
};
answers.insert(
question.id.clone(),
ToolRequestUserInputAnswer {
answers: answer_values,
},
);
}
Ok(ToolRequestUserInputResponse { answers })
}
#[cfg(test)]
#[path = "request_user_input_tests.rs"]
mod tests;
@@ -1,127 +0,0 @@
use std::collections::HashMap;
use std::io::Cursor;
use codex_app_server_protocol::ToolRequestUserInputAnswer;
use codex_app_server_protocol::ToolRequestUserInputOption;
use codex_app_server_protocol::ToolRequestUserInputParams;
use codex_app_server_protocol::ToolRequestUserInputQuestion;
use codex_app_server_protocol::ToolRequestUserInputResponse;
use pretty_assertions::assert_eq;
use super::prompt_for_answers_with;
#[test]
fn collects_option_and_free_form_answers() {
let params = ToolRequestUserInputParams {
thread_id: "thread-1".to_string(),
turn_id: "turn-1".to_string(),
item_id: "item-1".to_string(),
questions: vec![
ToolRequestUserInputQuestion {
id: "target".to_string(),
header: "Target".to_string(),
question: "Which target?".to_string(),
is_other: true,
is_secret: false,
options: Some(vec![
ToolRequestUserInputOption {
label: "Core".to_string(),
description: "Inspect core".to_string(),
},
ToolRequestUserInputOption {
label: "TUI".to_string(),
description: "Inspect TUI".to_string(),
},
]),
},
ToolRequestUserInputQuestion {
id: "details".to_string(),
header: "Details".to_string(),
question: "Anything else?".to_string(),
is_other: true,
is_secret: false,
options: None,
},
],
is_blocking: false,
auto_resolution_ms: Some(60_000),
};
let mut input = Cursor::new(b"2\ninclude snapshots\n");
let mut output = Vec::new();
let response = prompt_for_answers_with(&mut input, &mut output, &params).unwrap();
assert_eq!(
response,
ToolRequestUserInputResponse {
answers: HashMap::from([
(
"target".to_string(),
ToolRequestUserInputAnswer {
answers: vec!["TUI".to_string()],
},
),
(
"details".to_string(),
ToolRequestUserInputAnswer {
answers: vec!["user_note: include snapshots".to_string()],
},
),
]),
}
);
assert_eq!(
String::from_utf8(output).unwrap(),
concat!(
"\n[request_user_input for thread thread-1, turn turn-1]\n",
"This request is non-blocking.\n",
"\nTarget: Which target?\n",
" 1. Core - Inspect core\n",
" 2. TUI - Inspect TUI\n",
" o. Other (free-form)\n",
"Choose 1-2 or o: ",
"\nDetails: Anything else?\n",
"Answer: ",
)
);
}
#[test]
fn retries_invalid_selection_and_collects_other_answer() {
let params = ToolRequestUserInputParams {
thread_id: "thread-1".to_string(),
turn_id: "turn-1".to_string(),
item_id: "item-1".to_string(),
questions: vec![ToolRequestUserInputQuestion {
id: "target".to_string(),
header: "Target".to_string(),
question: "Which target?".to_string(),
is_other: true,
is_secret: false,
options: Some(vec![ToolRequestUserInputOption {
label: "Core".to_string(),
description: "Inspect core".to_string(),
}]),
}],
is_blocking: true,
auto_resolution_ms: None,
};
let mut input = Cursor::new(b"9\no\nSDK wrapper\n");
let mut output = Vec::new();
let response = prompt_for_answers_with(&mut input, &mut output, &params).unwrap();
assert_eq!(
response,
ToolRequestUserInputResponse {
answers: HashMap::from([(
"target".to_string(),
ToolRequestUserInputAnswer {
answers: vec!["user_note: SDK wrapper".to_string()],
},
)]),
}
);
let output = String::from_utf8(output).unwrap();
assert!(output.contains("Invalid selection; try again."));
}
@@ -5,27 +5,6 @@
use std::io;
use std::io::Read;
use std::path::Path;
#[cfg(windows)]
use std::path::PathBuf;
#[cfg(windows)]
use std::time::Duration;
#[cfg(windows)]
pub const DAEMON_SHUTDOWN_FILE_ENV: &str = "CODEX_DAEMON_SHUTDOWN_FILE";
/// Waits for and consumes one updater shutdown request.
#[cfg(windows)]
pub async fn daemon_shutdown_signal() -> io::Result<()> {
let Some(path) = std::env::var_os(DAEMON_SHUTDOWN_FILE_ENV).map(PathBuf::from) else {
return std::future::pending().await;
};
loop {
if take_shutdown_request(&path, std::process::id())? {
return Ok(());
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
}
fn take_shutdown_request(path: &Path, pid: u32) -> io::Result<bool> {
let file = match std::fs::File::open(path) {
+1 -5
View File
@@ -1,10 +1,6 @@
pub mod daemon_recovery;
#[cfg(any(windows, test))]
#[cfg(test)]
mod daemon_shutdown;
#[cfg(windows)]
pub use daemon_shutdown::DAEMON_SHUTDOWN_FILE_ENV;
#[cfg(windows)]
pub use daemon_shutdown::daemon_shutdown_signal;
/// Only managed app-server launches accept the local socket shutdown request.
pub const DAEMON_SHUTDOWN_SOCKET_ENV: &str = "CODEX_DAEMON_SHUTDOWN_SOCKET";
mod connection_auth;
@@ -366,7 +366,6 @@ mod tests {
);
}
#[cfg(unix)]
#[test]
fn serialize_invalid_typed_response_returns_jsonrpc_error() {
use std::ffi::OsString;
@@ -9,24 +9,18 @@ use super::segment::ClientSegmentReassembler;
use super::segment::REMOTE_CONTROL_SEGMENT_MAX_BYTES;
use super::segment::split_server_envelope_for_transport;
use crate::outgoing_message::OutgoingMessage;
#[cfg(unix)]
use crate::outgoing_message::OutgoingResponse;
use base64::Engine;
#[cfg(unix)]
use codex_app_server_protocol::ClientResponsePayload;
use codex_app_server_protocol::ConfigWarningNotification;
#[cfg(unix)]
use codex_app_server_protocol::InitializeResponse;
use codex_app_server_protocol::JSONRPCMessage;
use codex_app_server_protocol::JSONRPCNotification;
#[cfg(unix)]
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ServerNotificationEnvelope;
#[cfg(unix)]
use codex_utils_absolute_path::AbsolutePathBuf;
use pretty_assertions::assert_eq;
#[cfg(unix)]
use serde_json::json;
#[test]
@@ -120,7 +114,6 @@ fn splits_large_server_messages_into_wire_chunks() {
}));
}
#[cfg(unix)]
#[test]
fn invalid_response_becomes_remote_control_jsonrpc_error() {
use std::ffi::OsString;
@@ -31,7 +31,6 @@ pub async fn start_stdio_connection(
install_shutdown_signal_handler: bool,
) -> IoResult<JoinHandle<()>> {
let shutdown_signal = CancellationToken::new();
#[cfg(unix)]
if install_shutdown_signal_handler {
use signal_hook::consts::SIGTERM;
use signal_hook::iterator::Signals;
@@ -124,7 +123,7 @@ pub async fn start_stdio_connection(
// EOF can finish the transport before RPC or runtime cleanup. Start
// the same process deadline even if no SIGTERM arrives.
if cfg!(unix) && install_shutdown_signal_handler {
if install_shutdown_signal_handler {
start_shutdown_watchdog();
}
let _ = transport_event_tx_for_reader
Loaded 100 of 1730 files, more files were not shown because too many files have changed in this diff. Show more