Honor thread analytics opt-outs when using shared clients (#44646)

## Why

An enabled shared analytics client could override a thread's explicit opt-out.
Delegated threads also emitted initialization events through the parent's client,
bypassing the child's analytics setting.

## What changed

- Use a disabled analytics client when `config.analytics_enabled` is `Some(false)`,
  without disabling analytics for sibling threads or overriding a disabled host client.
- Emit delegated thread initialization events through the child's analytics client.
- Expose the effective analytics state through `CodexThread::analytics_enabled()`.

## Testing

Add regression tests for explicit and unset thread settings with enabled, disabled,
and absent shared clients, plus delegated child opt-outs with an enabled parent.
Update compaction and rollout-budget rollback tests to wait for thread idle after
turn completion and fail immediately on rollback errors.

GitOrigin-RevId: 547852909af1a6822b95c0bcd2336b0d6bc7aad1
This commit is contained in:
priyanshusingh-de authored and copyberry committed 2026-09-10 21:30:56 +00:00
1 parent e25bedc166
commit 60825b4988
8 files changed
+295 -19

No files matched your search

+34
View File
@@ -329,6 +329,40 @@ pub async fn submit_thread_settings(
}
}
/// For sequential tests, register this contributor and wait once after every completed turn.
/// Notifications are thread-scoped so a child or sibling cannot satisfy the wait.
pub struct ThreadIdle;
#[derive(Default)]
struct ThreadIdleNotification(tokio::sync::Notify);
impl codex_extension_api::ThreadLifecycleContributor<Config> for ThreadIdle {
fn on_thread_idle<'a>(
&'a self,
input: codex_extension_api::ThreadIdleInput<'a>,
) -> codex_extension_api::ExtensionFuture<'a, ()> {
Box::pin(async move {
input
.thread_store
.get_or_init(ThreadIdleNotification::default)
.0
.notify_one();
})
}
}
impl ThreadIdle {
pub async fn wait(thread: &CodexThread) {
// TurnComplete is sent before active-turn cleanup. Rollback requires the later idle signal.
let idle = thread
.thread_extension_data()
.get_or_init(ThreadIdleNotification::default);
tokio::time::timeout(std::time::Duration::from_secs(10), idle.0.notified())
.await
.expect("thread should become idle after turn completion");
}
}
pub async fn wait_for_event_match<T, F>(codex: &CodexThread, matcher: F) -> T
where
F: Fn(&codex_protocol::protocol::EventMsg) -> Option<T>,