Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions codex-rs/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[target.'cfg(target_os = "linux")']
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
# Temporarily disabled mold linker for CI environments without mold installed
# [target.'cfg(target_os = "linux")']
# linker = "clang"
# rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "link-arg=/STACK:8388608"]
Expand Down
12 changes: 12 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ toml_edit = "0.23.5"
tonic = "0.13.1"
tracing = "0.1.43"
tracing-appender = "0.2.3"
tracing-flame = "0.2"
tracing-subscriber = "0.3.20"
tracing-test = "0.2.5"
tree-sitter = "0.25.10"
Expand Down
9 changes: 9 additions & 0 deletions codex-rs/tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ upstream-updates = []
# OSS providers (Ollama, LM Studio) - forwarded to codex-common
oss-providers = ["codex-common/oss-providers"]

# Startup performance profiling with tracing-flame
# Enables detailed span instrumentation and flamegraph output for profiling
# TUI launch performance. Output goes to $NORI_HOME/log/startup-profile.folded
#
# Note: For tokio-console support, build with RUSTFLAGS="--cfg tokio_unstable"
# and add console-subscriber manually. This feature only enables tracing-flame.
startup-profiling = ["dep:tracing-flame"]

[lints]
workspace = true

Expand Down Expand Up @@ -120,6 +128,7 @@ tokio-stream = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true, features = ["log"] }
tracing-appender = { workspace = true }
tracing-flame = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tree-sitter-bash = { workspace = true }
tree-sitter-highlight = { workspace = true }
Expand Down
33 changes: 33 additions & 0 deletions codex-rs/tui/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,39 @@ Combined with `acp_event_flow` from the ACP backend, these enable full end-to-en

- ACP rolling file tracing is initialized by the CLI (`cli/src/main.rs`) at startup, writing to `$NORI_HOME/log/nori-acp.YYYY-MM-DD`. Every mock agent logs `ACP agent spawned (pid: ...)` there, which makes the agent-switching tests in `tui-pty-e2e` deterministic and ensures developers can inspect agent subprocess lifecycles during debugging.

**Startup Performance Profiling:**

The TUI supports detailed startup performance profiling via the `startup-profiling` Cargo feature. When enabled, it instruments the startup path with tracing spans and outputs a folded stack file for flame graph visualization.

Build with profiling:
```bash
cargo build -p codex-tui --features startup-profiling
```

When running, the TUI will:
1. Track timing milestones: `config_loaded`, `tracing_initialized`, `terminal_initialized`, `chat_interactive`, `session_header_visible`
2. Output folded stacks to `$NORI_HOME/log/startup-profile.folded`
3. Log time-to-interactive (TTI) via tracing

Generate a flame chart for visualization:
```bash
cargo install inferno
cat ~/.nori/cli/log/startup-profile.folded | inferno-flamegraph --flamechart > startup.svg
```

The profiling output shows the hierarchical timing of startup phases:
- `tui_startup` (root span)
- `acp_prewarm` - Background ACP installation cache pre-warming
- `config_load` - Configuration loading
- `terminal_init` - Terminal initialization
- `app_run` - Main application event loop

For tokio-console integration (async task debugging), build with:
```bash
RUSTFLAGS="--cfg tokio_unstable" cargo build -p codex-tui --features startup-profiling
```
Then add `console-subscriber` to dependencies and connect with `tokio-console`.

**Agent Switch Event Filtering:**

When switching between ACP agents (e.g., via `/agent` command), `ChatWidget` uses an event filtering mechanism to prevent race conditions:
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/tui/src/chatwidget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ impl ChatWidget {
event,
self.show_welcome_banner,
));

// Emit session_header_visible event for startup profiling
// This marks the moment the session header is added to the history
tracing::info!(
target: "startup_profiling",
milestone = "session_header_visible",
model = %model_for_header,
"Session header displayed"
);

if let Some(messages) = initial_messages {
self.replay_initial_messages(messages);
}
Expand Down
Loading
Loading