fix(engine): eagerly initialize engine v2 at startup

The gateway API endpoints (/api/engine/missions, etc.) call bridge
query functions that return empty results when the engine state hasn't
been initialized yet. Previously, initialization only happened lazily
on the first chat message via handle_with_engine().

Now when ENGINE_V2=true, the engine is initialized in Agent::run()
before channels start, so the self-improvement mission and other
engine state is available to gateway API endpoints immediately.

Also rename get_or_init_engine → init_engine and make it public so
it can be called from agent_loop.rs at startup.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
2026-03-26 19:07:35 -07:00
co-authored by Claude Opus 4.6
parent 7c153d584b
commit 6d56d9cb11
3 changed files with 19 additions and 6 deletions
+8
View File
@@ -450,6 +450,14 @@ impl Agent {
None
};
// Eagerly initialize engine v2 so gateway API endpoints can serve
// data (projects, missions, threads) before the first chat message.
if crate::bridge::is_engine_v2_enabled()
&& let Err(e) = crate::bridge::init_engine(&self).await
{
tracing::debug!("engine v2: eager init failed: {e}");
}
// Start channels
let mut message_stream = self.channels.start_all().await?;