Skip to content

Commit fdb093f

Browse files
chore(engine): rename ENGINE_V2_TRACE to IRONCLAW_RECORD_TRACE (#2114)
* chore(engine): rename ENGINE_V2_TRACE to IRONCLAW_RECORD_TRACE Aligns the trace-recording env var with the project-wide IRONCLAW_* naming convention so it's discoverable alongside other ironclaw flags. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * unify engine v2 trace recording with v1 RecordingLlm Address PR review feedback. Instead of having two separate trace systems both named IRONCLAW_RECORD_TRACE (the v1 RecordingLlm in src/llm/recording.rs and the engine v2 executor/trace.rs JSON dumper), collapse them to one. Engine v2's LlmBackend is wired to the host's full LLM provider chain, which already includes RecordingLlm when IRONCLAW_RECORD_TRACE=1. That means engine v2 LLM interactions are already captured by the unified trace_*.json fixture file -- no engine-side env var, no second JSON output, no risk of one flag enabling two divergent recorders. Removed: - is_trace_enabled() and write_trace() from executor/trace.rs - the engine_trace_*.json write site in runtime/manager.rs Kept (still useful, runs unconditionally for the self-improvement mission): - build_trace() / analyze_trace() / log_trace_summary() Docs updated to point to RecordingLlm as the single trace mechanism. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a56fec7 commit fdb093f

5 files changed

Lines changed: 21 additions & 46 deletions

File tree

crates/ironclaw_engine/src/executor/trace.rs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
//! Execution trace recording and analysis.
1+
//! Execution trace analysis.
22
//!
3-
//! Records full execution traces to JSON files for debugging. Optionally
4-
//! runs a post-execution analysis to detect common issues.
3+
//! Builds an in-memory `ExecutionTrace` from a completed `Thread` and runs a
4+
//! retrospective analyzer that flags common failure patterns. Used by the
5+
//! self-improvement mission and surfaced in debug logs.
56
//!
6-
//! Enable with `ENGINE_V2_TRACE=1` env var. Traces are written to
7-
//! `engine_trace_{timestamp}.json` in the current directory.
8-
9-
use std::path::PathBuf;
7+
//! **There is no separate engine trace file.** Live trace recording for the
8+
//! whole system is handled by `RecordingLlm` in the host crate
9+
//! (`src/llm/recording.rs`), gated by `IRONCLAW_RECORD_TRACE`. Because the
10+
//! engine's `LlmBackend` is wired to the same provider chain, engine LLM
11+
//! interactions are captured by that single recorder — no engine-side env var
12+
//! and no second JSON file.
1013
1114
use chrono::Utc;
1215
use serde::Serialize;
@@ -15,13 +18,6 @@ use tracing::debug;
1518
use crate::types::event::ThreadEvent;
1619
use crate::types::thread::{Thread, ThreadId, ThreadState};
1720

18-
/// Check if trace recording is enabled.
19-
pub fn is_trace_enabled() -> bool {
20-
std::env::var("ENGINE_V2_TRACE")
21-
.map(|v| v == "1" || v == "true")
22-
.unwrap_or(false)
23-
}
24-
2521
/// A complete execution trace for a single thread.
2622
#[derive(Debug, Serialize)]
2723
pub struct ExecutionTrace {
@@ -108,29 +104,6 @@ pub fn build_trace(thread: &Thread) -> ExecutionTrace {
108104
}
109105
}
110106

111-
/// Write a trace to a JSON file.
112-
pub fn write_trace(trace: &ExecutionTrace) -> Option<PathBuf> {
113-
let filename = format!("engine_trace_{}.json", Utc::now().format("%Y%m%dT%H%M%S"));
114-
let path = PathBuf::from(&filename);
115-
116-
match serde_json::to_string_pretty(trace) {
117-
Ok(json) => match std::fs::write(&path, json) {
118-
Ok(()) => {
119-
debug!(path = %path.display(), "Execution trace written");
120-
Some(path)
121-
}
122-
Err(e) => {
123-
debug!("Failed to write trace: {e}");
124-
None
125-
}
126-
},
127-
Err(e) => {
128-
debug!("Failed to serialize trace: {e}");
129-
None
130-
}
131-
}
132-
}
133-
134107
/// Print a summary of the trace to the log.
135108
pub fn log_trace_summary(trace: &ExecutionTrace) {
136109
debug!(

crates/ironclaw_engine/src/runtime/manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,9 @@ impl ThreadManager {
290290
tracing::debug!(thread_id = %thread_id, "failed to transition to Done: {e}");
291291
}
292292

293-
// Write trace file if enabled
294-
if crate::executor::trace::is_trace_enabled() {
295-
crate::executor::trace::log_trace_summary(&trace);
296-
crate::executor::trace::write_trace(&trace);
297-
}
293+
// Trace recording is handled centrally by `RecordingLlm` in the
294+
// host crate (gated by `IRONCLAW_RECORD_TRACE`). The engine no
295+
// longer writes its own JSON trace file.
298296

299297
if let Err(e) = store_for_task.append_events(&exec.thread.events).await {
300298
tracing::debug!(

docs/engine-v2-architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The bridge connects the engine to existing IronClaw infrastructure:
118118

119119
Set `ENGINE_V2=true` environment variable. The router in `src/bridge/router.rs` intercepts messages and routes them through the engine instead of the v1 agent loop.
120120

121-
For trace debugging: `ENGINE_V2_TRACE=1` writes full JSON traces to `engine_trace_*.json`.
121+
For trace debugging set `IRONCLAW_RECORD_TRACE=1`. Engine v2 reuses the host crate's `RecordingLlm` (see `src/llm/recording.rs`) — the engine's `LlmBackend` is wired to the same provider chain, so LLM interactions are captured in the standard `trace_*.json` fixture file (configurable via `IRONCLAW_TRACE_OUTPUT`). There is no separate engine trace file.
122122

123123
## Memory System
124124

docs/plans/2026-03-20-engine-v2-architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Engine broadcasts `ThreadEvent`s via `tokio::broadcast`. Router subscribes and f
346346
`EngineState` persists across messages (OnceLock singleton). ConversationManager builds the visible conversation transcript for continuity. The orchestrator persists its mutable working transcript and intermediate execution state in `persisted_state` / internal thread transcript rather than mixing tool traces into the user-visible transcript.
347347

348348
### 6.5 Trace recording + retrospective — DONE
349-
`ENGINE_V2_TRACE=1` writes full JSON traces. Automatic trace analysis detects 8 issue categories. Reflection pipeline produces Summary/Lesson/Issue/Spec/Playbook docs. All run inside ThreadManager after thread completion.
349+
Live trace recording is handled by the host crate's `RecordingLlm` (`IRONCLAW_RECORD_TRACE=1`) — engine v2 piggybacks on it via the shared LLM provider chain, so there is no separate engine trace file. Inside ThreadManager, retrospective trace analysis runs unconditionally after each thread completes: the analyzer detects 8 issue categories and the reflection pipeline produces Summary/Lesson/Issue/Spec/Playbook docs.
350350

351351
### 6.6 Bugs found and fixed via traces
352352
- Tool name hyphens vs underscores (web-search vs web_search)

docs/self-improvement.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ The mission is capped at 5 threads per day (`max_threads_per_day: 5`).
204204

205205
## Debugging Self-Improvement
206206

207-
Enable trace logging to see the self-improvement loop in action:
207+
Enable trace logging to see the self-improvement loop in action.
208+
`IRONCLAW_RECORD_TRACE=1` is the unified flag — it enables `RecordingLlm`,
209+
which captures every LLM interaction into a shared `trace_*.json` fixture
210+
file. Engine v2 reuses the same provider chain, so its LLM calls are recorded
211+
through the same mechanism (no separate engine trace file):
208212

209213
```bash
210-
ENGINE_V2=true ENGINE_V2_TRACE=1 RUST_LOG=ironclaw_engine=debug cargo run
214+
ENGINE_V2=true IRONCLAW_RECORD_TRACE=1 RUST_LOG=ironclaw_engine=debug cargo run
211215
```
212216

213217
Look for:

0 commit comments

Comments
 (0)