fix(console): keep live context metadata race-free

This commit is contained in:
2026-10-02 16:25:43 +09:00
parent 3d37f056ad
commit 07cbff9a5f
5 changed files with 307 additions and 6 deletions
+48
View File
@@ -4092,6 +4092,54 @@ mod completion_flow_tests {
assert_eq!(child_app.session_context_tokens, 12_000);
}
#[test]
fn live_internal_worker_snapshot_installs_child_metadata_before_context_updates() {
let mut app = App::new("parent".into());
let worker = test_internal_worker_snapshot("child", "research", 1).worker;
let mut greeting = test_greeting();
greeting.worker_name = "research".into();
greeting.model = "child-model".into();
greeting.context_window = 64_000;
greeting.context_usage = Some(protocol::ContextUsage {
tokens: 12_000,
source: protocol::ContextTokenSource::Measured,
});
app.handle_worker_event(Event::InternalWorker {
worker: worker.clone(),
revision: 1,
event: Box::new(Event::Snapshot {
session: protocol::SessionSnapshot {
pending_submissions: protocol::PendingSubmissionsSnapshot::default(),
entries: Vec::new(),
},
greeting,
state: WorkerStatus::Running.into(),
in_flight: Default::default(),
internal_workers: Vec::new(),
}),
});
app.handle_worker_event(Event::InternalWorker {
worker,
revision: 2,
event: Box::new(Event::ContextUsage {
usage: Some(protocol::ContextUsage {
tokens: 14_000,
source: protocol::ContextTokenSource::Estimated,
}),
}),
});
let child = &app.internal_workers[0].app;
assert_eq!(child.greeting.as_ref().unwrap().model, "child-model");
assert_eq!(child.context_window, 64_000);
assert_eq!(child.session_context_tokens, 14_000);
assert_eq!(
child.session_context_source,
Some(protocol::ContextTokenSource::Estimated)
);
}
#[test]
fn worker_view_cycle_uses_stable_session_identity_and_wraps_to_main() {
let mut app = App::new("parent".into());