Skip to content

Commit 6d0d094

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 3a13e22 + 426f28c commit 6d0d094

512 files changed

Lines changed: 22577 additions & 15599 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelrc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,51 @@ common:remote --jobs=800
6060
# Enable pipelined compilation since we are not bound by local CPU count.
6161
#common:remote --@rules_rust//rust/settings:pipelined_compilation
6262

63+
# GitHub Actions CI configs.
64+
common:ci --remote_download_minimal
65+
common:ci --keep_going
66+
common:ci --verbose_failures
67+
common:ci --build_metadata=REPO_URL=https://github.com/openai/codex.git
68+
common:ci --build_metadata=ROLE=CI
69+
common:ci --build_metadata=VISIBILITY=PUBLIC
70+
71+
# Disable disk cache in CI since we have a remote one and aren't using persistent workers.
72+
common:ci --disk_cache=
73+
74+
# Shared config for the main Bazel CI workflow.
75+
common:ci-bazel --config=ci
76+
common:ci-bazel --build_metadata=TAG_workflow=bazel
77+
78+
# Rearrange caches on Windows so they're on the same volume as the checkout.
79+
common:ci-windows --config=ci-bazel
80+
common:ci-windows --build_metadata=TAG_os=windows
81+
common:ci-windows --repo_contents_cache=D:/a/.cache/bazel-repo-contents-cache
82+
common:ci-windows --repository_cache=D:/a/.cache/bazel-repo-cache
83+
84+
# We prefer to run the build actions entirely remotely so we can dial up the concurrency.
85+
# We have platform-specific tests, so we want to execute the tests on all platforms using the strongest sandboxing available on each platform.
86+
87+
# On linux, we can do a full remote build/test, by targeting the right (x86/arm) runners, so we have coverage of both.
88+
# Linux crossbuilds don't work until we untangle the libc constraint mess.
89+
common:ci-linux --config=ci-bazel
90+
common:ci-linux --build_metadata=TAG_os=linux
91+
common:ci-linux --config=remote
92+
common:ci-linux --strategy=remote
93+
common:ci-linux --platforms=//:rbe
94+
95+
# On mac, we can run all the build actions remotely but test actions locally.
96+
common:ci-macos --config=ci-bazel
97+
common:ci-macos --build_metadata=TAG_os=macos
98+
common:ci-macos --config=remote
99+
common:ci-macos --strategy=remote
100+
common:ci-macos --strategy=TestRunner=darwin-sandbox,local
101+
102+
# Linux-only V8 CI config.
103+
common:ci-v8 --config=ci
104+
common:ci-v8 --build_metadata=TAG_workflow=v8
105+
common:ci-v8 --build_metadata=TAG_os=linux
106+
common:ci-v8 --config=remote
107+
common:ci-v8 --strategy=remote
108+
109+
# Optional per-user local overrides.
110+
try-import %workspace%/user.bazelrc

.github/workflows/bazel.yml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,17 @@ jobs:
7878
shell: bash
7979
run: ./scripts/check-module-bazel-lock.sh
8080

81-
# TODO(mbolin): Bring this back once we have caching working. Currently,
82-
# we never seem to get a cache hit but we still end up paying the cost of
83-
# uploading at the end of the build, which takes over a minute!
84-
#
85-
# Cache build and external artifacts so that the next ci build is incremental.
86-
# Because github action caches cannot be updated after a build, we need to
87-
# store the contents of each build in a unique cache key, then fall back to loading
88-
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
89-
# the prefix to load the most recent cache for the branch on a cache miss. You
90-
# should customize the contents of hashFiles to capture any bazel input sources,
91-
# although this doesn't need to be perfect. If none of the input sources change
92-
# then a cache hit will load an existing cache and bazel won't have to do any work.
93-
# In the case of a cache miss, you want the fallback cache to contain most of the
94-
# previously built artifacts to minimize build time. The more precise you are with
95-
# hashFiles sources the less work bazel will have to do.
96-
# - name: Mount bazel caches
97-
# uses: actions/cache@v5
98-
# with:
99-
# path: |
100-
# ~/.cache/bazel-repo-cache
101-
# ~/.cache/bazel-repo-contents-cache
102-
# key: bazel-cache-${{ matrix.os }}-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'MODULE.bazel') }}
103-
# restore-keys: |
104-
# bazel-cache-${{ matrix.os }}
81+
# Restore bazel repository cache so we don't have to redownload all the external dependencies
82+
# on every CI run.
83+
- name: Restore bazel repository cache
84+
id: cache_bazel_repository_restore
85+
uses: actions/cache/restore@v5
86+
with:
87+
path: |
88+
~/.cache/bazel-repo-cache
89+
key: bazel-cache-${{ matrix.target }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }}
90+
restore-keys: |
91+
bazel-cache-${{ matrix.target }}
10592
10693
- name: Configure Bazel startup args (Windows)
10794
if: runner.os == 'Windows'
@@ -157,10 +144,7 @@ jobs:
157144
bazel_args=(
158145
test
159146
--test_verbose_timeout_warnings
160-
--build_metadata=REPO_URL=https://github.com/openai/codex.git
161147
--build_metadata=COMMIT_SHA=$(git rev-parse HEAD)
162-
--build_metadata=ROLE=CI
163-
--build_metadata=VISIBILITY=PUBLIC
164148
)
165149
166150
bazel_targets=(
@@ -177,6 +161,13 @@ jobs:
177161
bazel_args+=("--test_env=CODEX_JS_REPL_NODE_PATH=${node_bin}")
178162
fi
179163
164+
ci_config=ci-linux
165+
if [[ "${RUNNER_OS:-}" == "macOS" ]]; then
166+
ci_config=ci-macos
167+
elif [[ "${RUNNER_OS:-}" == "Windows" ]]; then
168+
ci_config=ci-windows
169+
fi
170+
180171
if [[ -n "${BUILDBUDDY_API_KEY:-}" ]]; then
181172
echo "BuildBuddy API key is available; using remote Bazel configuration."
182173
# Work around Bazel 9 remote repo contents cache / overlay materialization failures
@@ -186,8 +177,8 @@ jobs:
186177
set +e
187178
bazel $BAZEL_STARTUP_ARGS \
188179
--noexperimental_remote_repo_contents_cache \
189-
--bazelrc=.github/workflows/ci.bazelrc \
190180
"${bazel_args[@]}" \
181+
"--config=${ci_config}" \
191182
"--remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" \
192183
-- \
193184
"${bazel_targets[@]}" \
@@ -229,3 +220,14 @@ jobs:
229220
print_failed_bazel_test_logs "$bazel_console_log"
230221
exit "$bazel_status"
231222
fi
223+
224+
# Save bazel repository cache explicitly; make non-fatal so cache uploading
225+
# never fails the overall job. Only save when key wasn't hit.
226+
- name: Save bazel repository cache
227+
if: always() && !cancelled() && steps.cache_bazel_repository_restore.outputs.cache-hit != 'true'
228+
continue-on-error: true
229+
uses: actions/cache/save@v5
230+
with:
231+
path: |
232+
~/.cache/bazel-repo-cache
233+
key: bazel-cache-${{ matrix.target }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }}

.github/workflows/ci.bazelrc

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/rust-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,10 @@ jobs:
547547
tests:
548548
name: Tests — ${{ matrix.runner }} - ${{ matrix.target }}${{ matrix.remote_env == 'true' && ' (remote)' || '' }}
549549
runs-on: ${{ matrix.runs_on || matrix.runner }}
550-
timeout-minutes: ${{ matrix.runner == 'windows-arm64' && 35 || 30 }}
550+
# Perhaps we can bring this back down to 30m once we finish the cutover
551+
# from tui_app_server/ to tui/. Incidentally, windows-arm64 was the main
552+
# offender for exceeding the timeout.
553+
timeout-minutes: 45
551554
needs: changed
552555
if: ${{ needs.changed.outputs.codex == 'true' || needs.changed.outputs.workflows == 'true' || github.event_name == 'push' }}
553556
defaults:

.github/workflows/rusty-v8-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ jobs:
116116
117117
bazel \
118118
--noexperimental_remote_repo_contents_cache \
119-
--bazelrc=.github/workflows/v8-ci.bazelrc \
120119
"${bazel_args[@]}" \
120+
--config=ci-v8 \
121121
"--remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}"
122122
123123
- name: Stage release pair

.github/workflows/v8-canary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ jobs:
108108
109109
bazel \
110110
--noexperimental_remote_repo_contents_cache \
111-
--bazelrc=.github/workflows/v8-ci.bazelrc \
112111
"${bazel_args[@]}" \
112+
--config=ci-v8 \
113113
"--remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}"
114114
115115
- name: Stage release pair

.github/workflows/v8-ci.bazelrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules
1010
# build
1111
dist/
1212
bazel-*
13+
user.bazelrc
1314
build/
1415
out/
1516
storybook-static/

AGENTS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ In the codex-rs folder where the rust code lives:
1111
- Always collapse if statements per https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
1212
- Always inline format! args when possible per https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
1313
- Use method references over closures when possible per https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
14+
- Avoid bool or ambiguous `Option` parameters that force callers to write hard-to-read code such as `foo(false)` or `bar(None)`. Prefer enums, named methods, newtypes, or other idiomatic Rust API shapes when they keep the callsite self-documenting.
15+
- When you cannot make that API change and still need a small positional-literal callsite in Rust, follow the `argument_comment_lint` convention:
16+
- Use an exact `/*param_name*/` comment before opaque literal arguments such as `None`, booleans, and numeric literals when passing them by position.
17+
- Do not add these comments for string or char literals unless the comment adds real clarity; those literals are intentionally exempt from the lint.
18+
- If you add one of these comments, the parameter name must exactly match the callee signature.
1419
- When possible, make `match` statements exhaustive and avoid wildcard arms.
1520
- When writing tests, prefer comparing the equality of entire objects over fields one by one.
1621
- When making a change that adds or changes an API, ensure that the documentation in the `docs/` folder is up to date if applicable.
@@ -19,7 +24,23 @@ In the codex-rs folder where the rust code lives:
1924
repo root to refresh `MODULE.bazel.lock`, and include that lockfile update in the same change.
2025
- After dependency changes, run `just bazel-lock-check` from the repo root so lockfile drift is caught
2126
locally before CI.
27+
- Bazel does not automatically make source-tree files available to compile-time Rust file access. If
28+
you add `include_str!`, `include_bytes!`, `sqlx::migrate!`, or similar build-time file or
29+
directory reads, update the crate's `BUILD.bazel` (`compile_data`, `build_script_data`, or test
30+
data) or Bazel may fail even when Cargo passes.
2231
- Do not create small helper methods that are referenced only once.
32+
- Avoid large modules:
33+
- Prefer adding new modules instead of growing existing ones.
34+
- Target Rust modules under 500 LoC, excluding tests.
35+
- If a file exceeds roughly 800 LoC, add new functionality in a new module instead of extending
36+
the existing file unless there is a strong documented reason not to.
37+
- This rule applies especially to high-touch files that already attract unrelated changes, such
38+
as `codex-rs/tui/src/app.rs`, `codex-rs/tui/src/bottom_pane/chat_composer.rs`,
39+
`codex-rs/tui/src/bottom_pane/footer.rs`, `codex-rs/tui/src/chatwidget.rs`,
40+
`codex-rs/tui/src/bottom_pane/mod.rs`, and similarly central orchestration modules.
41+
- When extracting code from a large module, move the related tests and module/type docs toward
42+
the new implementation so the invariants stay close to the code that owns them.
43+
- When running Rust commands (e.g. `just fix` or `cargo test`) be patient with the command and never try to kill them using the PID. Rust lock can make the execution slow, this is expected.
2344

2445
Run `just fmt` (in `codex-rs` directory) automatically after you have finished making Rust code changes; do not ask for approval to run it. Additionally, run the tests:
2546

@@ -30,6 +51,19 @@ Before finalizing a large change to `codex-rs`, run `just fix -p <project>` (in
3051

3152
Also run `just argument-comment-lint` to ensure the codebase is clean of comment lint errors.
3253

54+
## The `codex-core` crate
55+
56+
Over time, the `codex-core` crate (defined in `codex-rs/core/`) has become bloated because it is the largest crate, so it is often easier to add something new to `codex-core` rather than refactor out the library code you need so your new code neither takes a dependency on, nor contributes to the size of, `codex-core`.
57+
58+
To that end: **resist adding code to codex-core**!
59+
60+
Particularly when introducing a new concept/feature/API, before adding to `codex-core`, consider whether:
61+
62+
- There is an existing crate other than `codex-core` that is an appropriate place for your new code to live.
63+
- It is time to introduce a new crate to the Cargo workspace for your new functionality. Refactor existing code as necessary to make this happen.
64+
65+
Likewise, when reviewing code, do not hesitate to push back on PRs that would unnecessarily add code to `codex-core`.
66+
3367
## TUI style conventions
3468

3569
See `codex-rs/tui/styles.md`.

0 commit comments

Comments
 (0)