From f245016b2cc44ad8ff88c16557add3e928e777f6 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Tue, 25 Aug 2026 00:48:10 +0000 Subject: [PATCH] fix(benchmark): install the authorities the observation path needs Test Linux fails on three claude_observation_benchmark tests. They drive the real observation pipeline, which host admission now refuses without the process background-CPU authority (background_cpu_unavailable) and, on the Codex provider path, without configured resident-memory preparation resources. Production installs both during daemon bootstrap, which a benchmark never runs. tracedecay-global-db's harness installs them in profile_with_session_capture_resources, but that helper is #[cfg(test)] pub(crate) and unreachable from here, so this reproduces its race-tolerant pattern locally. Co-Authored-By: Claude Opus 5 (1M context) --- .../claude_observation_benchmark/runner.rs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/sessions/claude_observation_benchmark/runner.rs b/src/sessions/claude_observation_benchmark/runner.rs index bd4d87522b..795f44195b 100644 --- a/src/sessions/claude_observation_benchmark/runner.rs +++ b/src/sessions/claude_observation_benchmark/runner.rs @@ -25,6 +25,50 @@ use tracedecay_sessions::runtime::{codex, cursor, hermes, kiro}; use tracedecay_usecases::host_admission::HostAdmissionScope; use tracedecay_usecases::observation::ObservationCancellation; +/// Installs the process-wide background CPU authority these benchmarks need. +/// +/// They drive the real observation pipeline, and host admission refuses every +/// capture with `background_cpu_unavailable` when no authority is installed. +/// Production installs it during daemon bootstrap, which a benchmark never +/// runs, and `tracedecay-global-db`'s equivalent harness helper is +/// `#[cfg(test)] pub(crate)`, so it cannot be reused from here. +fn ensure_background_cpu_authority() { + use std::num::NonZeroUsize; + use tracedecay_runtime_core::background_cpu::{ + install_process_background_cpu, process_background_cpu, + }; + + use std::sync::{Arc, OnceLock}; + use tracedecay_runtime_core::resident_memory::{ + DEFAULT_PROCESS_RESIDENT_MEMORY_LIMIT_V1, ProcessResidentMemoryV1, + }; + + static BENCHMARK_RESIDENT_MEMORY: OnceLock> = OnceLock::new(); + + if process_background_cpu().is_none() { + // A sibling benchmark can win the process-wide installation race at a + // different canonical width; reuse that authority rather than making + // success depend on execution order. + if install_process_background_cpu(NonZeroUsize::MIN).is_err() { + assert!( + process_background_cpu().is_some(), + "background CPU authority is neither installable nor already installed" + ); + } + } + + // The Codex provider path additionally refuses with + // `BackgroundResourceUnavailable { resource: "process resident-memory + // authority" }` until preparation resources are configured. + let memory = Arc::clone(BENCHMARK_RESIDENT_MEMORY.get_or_init(|| { + Arc::new(ProcessResidentMemoryV1::new( + DEFAULT_PROCESS_RESIDENT_MEMORY_LIMIT_V1, + )) + })); + let _ = tracedecay_sessions::runtime::codex::CodexDiscoveryHub::default() + .configure_preparation_resources(memory); +} + use super::artifact::{ attest_build, command_output, git_snapshot, validate_git_snapshots, workload_identity, }; @@ -81,6 +125,7 @@ impl Fixture { .expect("create Claude benchmark fixture tree"); fs::create_dir_all(&profile).expect("create benchmark profile root"); write_records(&transcript, &session_id); + ensure_background_cpu_authority(); let runtime = HostAdmissionTestRuntimeV1::profile(&profile) .await .expect("open registered benchmark runtime"); @@ -397,6 +442,7 @@ impl ProviderFixture { let project_id = enroll_provider_benchmark_project(&project); let source_path = write_provider_fixture(kind, temp.path(), &home, &project, repetition).await; + ensure_background_cpu_authority(); let runtime = if matches!(kind, ProviderKind::Claude) { HostAdmissionTestRuntimeV1::profile(&profile) .await