Skip to content

Commit 241d57f

Browse files
committed
Merge remote-tracking branch 'origin/main' into kennylopez-huddle-stop-speaking
Signed-off-by: kenny lopez <[email protected]>
2 parents 0aa4cbb + cb4a73e commit 241d57f

41 files changed

Lines changed: 4012 additions & 772 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/buzz-conformance/src/lib.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,27 @@ pub trait Tracer: Send + Sync {
315315
/// Record one trace step. Implementations MAY be no-ops in production
316316
/// builds and write to JSONL in tests.
317317
fn record(&self, step: TraceStep);
318+
319+
/// Whether recorded steps are actually observed.
320+
///
321+
/// Emitters on hot paths MUST consult this before doing work whose
322+
/// *only* consumer is the trace — most importantly extra database
323+
/// reads that project row labels independently of the fetch query
324+
/// (the read-seam's `communities_of_channels` lookup). With a
325+
/// discarding tracer that work is pure overhead.
326+
///
327+
/// This is the `log.isDebugEnabled()` of the trace seam. It exists to
328+
/// let callers skip *building emit inputs*, never to let them skip an
329+
/// emit they would otherwise have made: when this returns `true`
330+
/// every seam must behave exactly as it did before the gate existed,
331+
/// so the coverage-breach guard stays non-vacuous.
332+
///
333+
/// Defaults to `true` — a new tracer is assumed to observe steps until
334+
/// it says otherwise. Wrappers that delegate to an inner tracer MUST
335+
/// forward this method rather than inherit the default.
336+
fn enabled(&self) -> bool {
337+
true
338+
}
318339
}
319340

320341
/// A no-op tracer for production. Zero cost: the build can omit emission
@@ -324,4 +345,9 @@ pub struct NoopTracer;
324345

325346
impl Tracer for NoopTracer {
326347
fn record(&self, _step: TraceStep) {}
348+
349+
/// Nothing is observed, so emitters should skip building inputs.
350+
fn enabled(&self) -> bool {
351+
false
352+
}
327353
}

‎crates/buzz-db/src/migration.rs‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod tests {
100100
use super::*;
101101
use std::collections::BTreeSet;
102102

103-
const TEST_DB_URL: &str = "postgres://buzz:buzz_dev@localhost:5432/buzz";
103+
const TEST_DB_URL: &str = "postgres://buzz:buzz_dev@localhost:5432/buzz"; // sadscan:disable np.postgres.1
104104

105105
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
106106
enum ConstraintKind {
@@ -561,7 +561,7 @@ mod tests {
561561
let mut migrations: Vec<_> = MIGRATOR.iter().collect();
562562
migrations.sort_by_key(|migration| migration.version);
563563

564-
assert_eq!(migrations.len(), 26);
564+
assert_eq!(migrations.len(), 27);
565565
assert_eq!(migrations[0].version, 1);
566566
assert_eq!(&*migrations[0].description, "initial schema");
567567
assert!(migrations[0]
@@ -919,6 +919,27 @@ mod tests {
919919
assert!(heartbeat.contains("epoch"));
920920
assert!(heartbeat.contains("INSERT INTO replica_heartbeat (id) VALUES (1)"));
921921
assert!(heartbeat.contains("_operator_global_tables"));
922+
923+
// Channel-id lookup index (0027): serves the tenant-independent
924+
// `channels` lookups that carry no community_id predicate, which no
925+
// community_id-leading index can satisfy. Covering + partial so the
926+
// planner can go index-only; asserted NOT UNIQUE because `id` alone is
927+
// not unique in this table (the same channel id may exist under more
928+
// than one community), so a unique index would encode a false
929+
// constraint and fail to build on such a database.
930+
assert_eq!(migrations[26].version, 27);
931+
let channel_id_index = migrations[26].sql.as_str();
932+
assert!(channel_id_index.contains("idx_channels_id_live"));
933+
assert!(channel_id_index.contains("INCLUDE (community_id)"));
934+
assert!(channel_id_index.contains("WHERE deleted_at IS NULL"));
935+
assert!(
936+
!channel_id_index.contains("CREATE UNIQUE INDEX"),
937+
"channels.id is not unique across communities — index must not be UNIQUE",
938+
);
939+
assert!(
940+
desired_schema.contains("idx_channels_id_live"),
941+
"desired-state schema must carry the channel-id lookup index",
942+
);
922943
}
923944

924945
#[test]
@@ -1161,7 +1182,7 @@ mod tests {
11611182
run_migrations(&pool)
11621183
.await
11631184
.expect("retry succeeds after operator repair");
1164-
assert_eq!(applied_versions(&pool).await.last().copied(), Some(26));
1185+
assert_eq!(applied_versions(&pool).await.last().copied(), Some(27));
11651186
}
11661187

11671188
#[tokio::test]

‎crates/buzz-relay/src/conformance/mod.rs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@ impl Tracer for CountingTracer {
370370
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
371371
self.inner.record(step);
372372
}
373+
374+
/// Delegate, never inherit the `true` default. This wrapper is
375+
/// transparent: whether emits are observed is a property of the
376+
/// tracer underneath it. Returning `true` over a `NoopTracer` would
377+
/// reintroduce the overhead the gate exists to remove; returning
378+
/// `false` over a real tracer would suppress the emits whose absence
379+
/// the `EmitGuard` reports as a coverage breach.
380+
fn enabled(&self) -> bool {
381+
self.inner.enabled()
382+
}
373383
}
374384

375385
impl EmitGuard {
@@ -455,6 +465,52 @@ mod tests {
455465
}
456466
}
457467

468+
/// Discarding tracer that reports `enabled() == false`, standing in
469+
/// for the production `NoopTracer`.
470+
#[derive(Debug, Default)]
471+
struct DisabledTracer;
472+
473+
impl Tracer for DisabledTracer {
474+
fn record(&self, _step: TraceStep) {}
475+
fn enabled(&self) -> bool {
476+
false
477+
}
478+
}
479+
480+
/// `CountingTracer` must forward `enabled()` to the tracer it wraps
481+
/// rather than inherit the trait's `true` default. Both directions
482+
/// matter, and getting either wrong is silent:
483+
///
484+
/// - over a disabled tracer, answering `true` would keep the hot-path
485+
/// read-seam `channels` lookup running in production — the overhead
486+
/// the gate exists to remove;
487+
/// - over a live tracer, answering `false` would make gated emitters
488+
/// skip emits during conformance runs, so the `EmitGuard` would
489+
/// report `ImplBug` for seams that are in fact correct (or, worse,
490+
/// mask a real breach behind an expected one).
491+
#[test]
492+
fn counting_tracer_delegates_enabled_to_inner() {
493+
let (_guard, counting) = EmitGuard::arm(
494+
Arc::new(DisabledTracer),
495+
dummy_state(),
496+
"delegates_disabled",
497+
);
498+
assert!(
499+
!counting.enabled(),
500+
"CountingTracer must report disabled when wrapping a discarding tracer"
501+
);
502+
503+
let (_guard, counting) = EmitGuard::arm(
504+
Arc::new(VecTracer::default()),
505+
dummy_state(),
506+
"delegates_live",
507+
);
508+
assert!(
509+
counting.enabled(),
510+
"CountingTracer must report enabled when wrapping an observing tracer"
511+
);
512+
}
513+
458514
fn dummy_state() -> AbstractState {
459515
AbstractState {
460516
resolved_community: CommunityLabel::from_uuid(Uuid::from_u128(0xA)),

‎crates/buzz-relay/src/conformance/tracers.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ pub struct NoopTracer;
1717

1818
impl Tracer for NoopTracer {
1919
fn record(&self, _step: TraceStep) {}
20+
21+
/// Nothing is observed, so emitters should skip building inputs —
22+
/// including the read-seam's per-request `channels` lookup.
23+
fn enabled(&self) -> bool {
24+
false
25+
}
2026
}
2127

2228
/// JSONL-to-file tracer for tests + the CI replay job. Each `record` call

‎crates/buzz-relay/src/handlers/req.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ pub async fn handle_req(
334334
// (B) projection strategy and the missing-lookup ImplBug
335335
// guard-rail. Skipped silently if `trace_state` is `None` (only
336336
// happens on malformed pubkey, a separate failure path).
337-
if let Some(state_snap) = trace_state.as_ref() {
337+
// `tracer.enabled()` short-circuits the whole block on the production
338+
// `NoopTracer`: the `communities_of_channels` lookup below is a
339+
// `channels` read whose only consumer is `record_read_message_rows`,
340+
// and this emit runs once PER FILTER. Gating on `trace_state` alone was
341+
// not enough — that is `Some` for every well-formed request.
342+
if let Some(state_snap) = trace_state.as_ref().filter(|_| state.tracer.enabled()) {
338343
let row_channels: Vec<Option<uuid::Uuid>> =
339344
events.iter().map(|e| e.channel_id).collect();
340345
let distinct: Vec<uuid::Uuid> = {
@@ -659,7 +664,9 @@ async fn handle_search_req(
659664
// level isn't bound to a single channel filter, the
660665
// per-row `channel_id` carries the channel identity
661666
// honestly.
662-
if let Some(state_snap) = trace_state {
667+
// Same `enabled()` gate as the non-search lane: skip the
668+
// trace-only `channels` lookup when nothing observes the emit.
669+
if let Some(state_snap) = trace_state.filter(|_| state.tracer.enabled()) {
663670
let row_channels: Vec<Option<uuid::Uuid>> =
664671
events.iter().map(|e| e.channel_id).collect();
665672
let distinct: Vec<uuid::Uuid> = {

‎desktop/src-tauri/src/managed_agents/custom_harnesses.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub(crate) fn registry_test_lock() -> std::sync::MutexGuard<'static, ()> {
268268

269269
/// Thread-safe registry of non-builtin (preset + custom) harness definitions,
270270
/// populated on every `discover_acp_runtimes_from` call and queried at spawn time.
271-
fn loaded_harness_registry() -> &'static RwLock<Vec<Arc<HarnessDefinition>>> {
271+
pub(super) fn loaded_harness_registry() -> &'static RwLock<Vec<Arc<HarnessDefinition>>> {
272272
use std::sync::OnceLock;
273273
static REGISTRY: OnceLock<RwLock<Vec<Arc<HarnessDefinition>>>> = OnceLock::new();
274274
REGISTRY.get_or_init(|| RwLock::new(Vec::new()))

‎desktop/src-tauri/src/managed_agents/discovery.rs‎

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ mod presets;
1313
mod runtime_metadata;
1414
#[macro_use]
1515
mod windows_install;
16+
pub(crate) use presets::{
17+
canonical_harness_command, command_for_runtime_id, preset_harness_definitions,
18+
preset_harness_ids,
19+
};
1620
use presets::{preset_catalog_entry, PRESET_HARNESSES};
17-
pub(crate) use presets::{preset_harness_definitions, preset_harness_ids};
1821
pub(crate) use runtime_metadata::KnownAcpRuntime;
1922

2023
const GOOSE_AVATAR_URL: &str = "https://goose-docs.ai/img/logo_dark.png";
@@ -233,7 +236,7 @@ fn executable_basename(command: &str) -> String {
233236
}
234237
}
235238

236-
fn normalize_command_identity(command: &str) -> String {
239+
pub(crate) fn normalize_command_identity(command: &str) -> String {
237240
let normalized = command.trim().replace('\\', "/");
238241
let basename = normalized.rsplit('/').next().unwrap_or(normalized.as_str());
239242
let lower = basename
@@ -295,9 +298,10 @@ pub fn default_agent_command() -> String {
295298
///
296299
/// Resolution order:
297300
/// 1. explicit override (non-empty) — a deliberate per-instance pin;
298-
/// 2. the record's own `runtime` id mapped to its primary command —
299-
/// records materialize their runtime at create/migration time;
300-
/// checks both static builtins AND the loaded preset/custom registry;
301+
/// 2. the record's own `runtime` id mapped to its primary command via the
302+
/// authoritative three-tier lookup (static builtins → static preset list
303+
/// → loaded registry) — preset harnesses (e.g. openclaw) resolve
304+
/// correctly even with a cold registry;
301305
/// 3. legacy fallback: the linked persona's `runtime` (records created
302306
/// before the unified model carry `persona_id` but no `runtime`);
303307
/// 4. `default_agent_command()`.
@@ -315,15 +319,11 @@ pub fn record_agent_command(
315319
}
316320

317321
if let Some(id) = record.runtime.as_deref() {
318-
// Check static builtins first.
319-
if let Some(command) = known_acp_runtime_exact(id).and_then(|r| r.commands.first().copied())
320-
{
321-
return command.to_string();
322-
}
323-
// Fall back to loaded registry for preset/custom harnesses.
324-
if let Some(def) = crate::managed_agents::custom_harnesses::lookup_loaded_harness_by_id(id)
325-
{
326-
return def.command.clone();
322+
// Three-tier lookup: static builtins → static presets → loaded registry.
323+
// Using the shared resolver ensures preset harnesses (e.g. openclaw)
324+
// resolve correctly even without a warm registry.
325+
if let Some(cmd) = presets::command_for_runtime_id(id) {
326+
return cmd;
327327
}
328328
}
329329

@@ -336,8 +336,9 @@ pub fn record_agent_command(
336336
///
337337
/// Resolution order:
338338
/// 1. explicit override (non-empty) — a deliberate per-instance pin;
339-
/// 2. the linked persona's `runtime` id mapped to its primary command
340-
/// (checks builtins then loaded preset/custom registry);
339+
/// 2. the linked persona's `runtime` id mapped to its primary command via
340+
/// the authoritative three-tier lookup (static builtins → static preset
341+
/// list → loaded registry);
341342
/// 3. `default_agent_command()` — no persona/runtime, or persona deleted.
342343
pub fn effective_agent_command(
343344
persona_id: Option<&str>,
@@ -356,15 +357,9 @@ pub fn effective_agent_command(
356357
.and_then(|persona| persona.runtime.as_deref());
357358

358359
if let Some(id) = runtime_id {
359-
// Check static builtins first.
360-
if let Some(command) = known_acp_runtime_exact(id).and_then(|r| r.commands.first().copied())
361-
{
362-
return command.to_string();
363-
}
364-
// Check loaded preset/custom registry.
365-
if let Some(def) = crate::managed_agents::custom_harnesses::lookup_loaded_harness_by_id(id)
366-
{
367-
return def.command.clone();
360+
// Three-tier lookup: static builtins → static presets → loaded registry.
361+
if let Some(cmd) = presets::command_for_runtime_id(id) {
362+
return cmd;
368363
}
369364
}
370365

@@ -423,12 +418,8 @@ pub fn try_record_agent_command(
423418

424419
// Record-level runtime id: if set but unresolvable → typed error.
425420
if let Some(id) = record.runtime.as_deref() {
426-
if let Some(cmd) = known_acp_runtime_exact(id).and_then(|r| r.commands.first().copied()) {
427-
return Ok(cmd.to_string());
428-
}
429-
if let Some(def) = crate::managed_agents::custom_harnesses::lookup_loaded_harness_by_id(id)
430-
{
431-
return Ok(def.command.clone());
421+
if let Some(cmd) = presets::command_for_runtime_id(id) {
422+
return Ok(cmd);
432423
}
433424
return Err(format!("DANGLING_HARNESS_ID:{id}"));
434425
}
@@ -437,15 +428,8 @@ pub fn try_record_agent_command(
437428
if let Some(persona_id) = record.persona_id.as_deref() {
438429
if let Some(persona) = personas.iter().find(|p| p.id == persona_id) {
439430
if let Some(id) = persona.runtime.as_deref() {
440-
if let Some(cmd) =
441-
known_acp_runtime_exact(id).and_then(|r| r.commands.first().copied())
442-
{
443-
return Ok(cmd.to_string());
444-
}
445-
if let Some(def) =
446-
crate::managed_agents::custom_harnesses::lookup_loaded_harness_by_id(id)
447-
{
448-
return Ok(def.command.clone());
431+
if let Some(cmd) = presets::command_for_runtime_id(id) {
432+
return Ok(cmd);
449433
}
450434
return Err(format!("DANGLING_HARNESS_ID:{id}"));
451435
}

0 commit comments

Comments
 (0)