mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
feat: experimental flags (#10231)
## Problem being solved
- We need a single, reliable way to mark app-server API surface as
experimental so that:
1. the runtime can reject experimental usage unless the client opts in
2. generated TS/JSON schemas can exclude experimental methods/fields for
stable clients.
Right now that’s easy to drift or miss when done ad-hoc.
## How to declare experimental methods and fields
- **Experimental method**: add `#[experimental("method/name")]` to the
`ClientRequest` variant in `client_request_definitions!`.
- **Experimental field**: on the params struct, derive `ExperimentalApi`
and annotate the field with `#[experimental("method/name.field")]` + set
`inspect_params: true` for the method variant so
`ClientRequest::experimental_reason()` inspects params for experimental
fields.
## How the macro solves it
- The new derive macro lives in
`codex-rs/codex-experimental-api-macros/src/lib.rs` and is used via
`#[derive(ExperimentalApi)]` plus `#[experimental("reason")]`
attributes.
- **Structs**:
- Generates `ExperimentalApi::experimental_reason(&self)` that checks
only annotated fields.
- The “presence” check is type-aware:
- `Option<T>`: `is_some_and(...)` recursively checks inner.
- `Vec`/`HashMap`/`BTreeMap`: must be non-empty.
- `bool`: must be `true`.
- Other types: considered present (returns `true`).
- Registers each experimental field in an `inventory` with `(type_name,
serialized field name, reason)` and exposes `EXPERIMENTAL_FIELDS` for
that type. Field names are converted from `snake_case` to `camelCase`
for schema/TS filtering.
- **Enums**:
- Generates an exhaustive `match` returning `Some(reason)` for annotated
variants and `None` otherwise (no wildcard arm).
- **Wiring**:
- Runtime gating uses `ExperimentalApi::experimental_reason()` in
`codex-rs/app-server/src/message_processor.rs` to reject requests unless
`InitializeParams.capabilities.experimental_api == true`.
- Schema/TS export filters use the inventory list and
`EXPERIMENTAL_CLIENT_METHODS` from `client_request_definitions!` to
strip experimental methods/fields when `experimental_api` is false.
This commit is contained in:
7
defs.bzl
7
defs.bzl
@@ -1,7 +1,7 @@
|
||||
load("@crates//:data.bzl", "DEP_DATA")
|
||||
load("@crates//:defs.bzl", "all_crate_deps")
|
||||
load("@rules_platform//platform_data:defs.bzl", "platform_data")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_proc_macro", "rust_test")
|
||||
load("@rules_rust//cargo/private:cargo_build_script_wrapper.bzl", "cargo_build_script")
|
||||
|
||||
PLATFORMS = [
|
||||
@@ -34,6 +34,7 @@ def codex_rust_crate(
|
||||
crate_features = [],
|
||||
crate_srcs = None,
|
||||
crate_edition = None,
|
||||
proc_macro = False,
|
||||
build_script_data = [],
|
||||
compile_data = [],
|
||||
lib_data_extra = [],
|
||||
@@ -63,6 +64,7 @@ def codex_rust_crate(
|
||||
crate_srcs: Optional explicit srcs; defaults to `src/**/*.rs`.
|
||||
crate_edition: Rust edition override, if not default.
|
||||
You probably don't want this, it's only here for a single caller.
|
||||
proc_macro: Whether this crate builds a proc-macro library.
|
||||
build_script_data: Data files exposed to the build script at runtime.
|
||||
compile_data: Non-Rust compile-time data for the library target.
|
||||
lib_data_extra: Extra runtime data for the library target.
|
||||
@@ -109,7 +111,8 @@ def codex_rust_crate(
|
||||
deps = deps + [name + "-build-script"]
|
||||
|
||||
if lib_srcs:
|
||||
rust_library(
|
||||
lib_rule = rust_proc_macro if proc_macro else rust_library
|
||||
lib_rule(
|
||||
name = name,
|
||||
crate_name = crate_name,
|
||||
crate_features = crate_features,
|
||||
|
||||
Reference in New Issue
Block a user