Skip to content

Commit f86dfc5

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
feat(desktop): surface config diff in restart-required badge (block#3637)
The "Restart required" badge reports that an agent's running config has drifted from its spawn-time config, but never says what changed. This ships the full feature: a typed Rust diff engine and a TS/UI layer that renders it at every badge site. ## Rust core (spawn-snapshot diff engine) Replaces the lossy `u64` `spawn_config_hash` with a typed `SpawnConfigSnapshot`. The snapshot is stamped from the already-resolved command/env/config values immediately before `spawn()`, closing the race window where a mid-spawn config edit would suppress the badge. `SpawnConfigSnapshot::canonical()` is the single JSON projection shared by the badge and the diff. Drift is `to_value(stamped) != to_value(current)`; the diff is a generic leaf walk over those same two values, so badge-on and diff-non-empty are structurally guaranteed. Adding a snapshot field reaches the UI with no code change to the diff engine — `mutation_table_covers_every_serialized_field` fails CI if a new field arrives without a mutation row. `eligible_restart_diff(persona_orphaned, Option<TrackedSpawnState>)` returns the final vector — snapshot walk entries plus a synthetic `adapter_availability` entry. It returns empty for an orphaned instance (spawning one would fail) and for agents with no tracked spawn state (never stamped, can never have drifted). `needs_restart = !restart_diff.is_empty()` derives from that vector and nothing else. Redaction policy (`policy_for(path)`) is shared by the wire diff and the snapshot's manual `Debug` via `is_safe_to_reveal()` from `managed_agents::env_vars` as the single authority for env-key masking: | Policy | Paths | Rendering | |---|---|---| | `Text` | `system_prompt`, `team_instructions` | character counts only | | `MaskedBare` | `args`, `relay_url` | `••••`, no suffix | | `MaskedSuffix` | non-allowlisted `env.*` | `••••` + last 4 chars when longer than 8 | | `Plain` | allowlisted `env.*` (`BUZZ_AGENT_THINKING_EFFORT`, `BUZZ_AGENT_PROVIDER`, `BUZZ_AGENT_MODEL`, `DATABRICKS_HOST/MODEL`) and everything else | verbatim | Default-deny: every env key not in the explicit allowlist stays masked. `is_safe_to_reveal()` is the single allowlist authority for both the baked-env display and the diff. `restart_diff` is omitted from the wire when empty (`skip_serializing_if`). ## TypeScript / UI layer New `restartDiff.ts` module defines `RestartDiffEntry`, `RestartChange`, `JsonValue`; `tauri.ts` and `types.ts` re-export and add `restart_diff` / `restartDiff` fields (Rust omission → `restartDiff: []`). **`RestartDiffBadge`** — hover tooltip capped at 6 entries + "and N more", `asChild` span trigger (never inside a `<button>`), auto-restart blurb below the diff list (on/off variant from `autoRestartEnabled` prop; same `AUTO_RESTART_ON_BLURB` / `AUTO_RESTART_OFF_BLURB` constants shared with the Runtime-tab banner). **`RestartDiffList`** renders the full uncapped list for the Runtime-tab banner with `tooltip`/`inline` presentation variants for correct foreground in both surfaces. **`ManagedAgentRow` B4 fix** — badge moved to a sibling `div` of the row expansion button; tooltip trigger has no `button` ancestor. **`UnifiedAgentsSection`** — both badge sites render `<RestartDiffBadge>` instead of a raw `<Badge>`, with `autoRestartEnabled` threaded from `agent.autoRestartOnConfigChange`. **Side-panel fix** — `RestartDiffBadge` rendered tab-independently in the `ProfileSummaryView` hero area (was Runtime-tab only — root cause of the ~50% inconsistency Will reported). Hero badge is `self-center` in the flex column. `ProfileRuntimeTabContent` early-return checks `needsRestart` so the banner is never dropped when all other content is empty. Auto-restart blurb in the Runtime-tab banner uses the shared constants. ## Wire shape ```jsonc "restart_diff": [ { "field": "model", "change": { "kind": "value", "before": "gpt-5", "after": "claude-4" } }, { "field": "system_prompt", "change": { "kind": "text", "before_chars": 1234, "after_chars": 1410 } }, { "field": "env.OPENAI_API_KEY", "change": { "kind": "masked", "before": "••••bc12", "after": "••••xyz9" } }, { "field": "env.BUZZ_AGENT_THINKING_EFFORT", "change": { "kind": "value", "before": "medium", "after": "high" } } ] ``` `added`/`removed` occur only for dynamic-map keys; nullable struct fields always serialize as `null`; arrays are atomic leaves (`args`, never `args.0`). ## Tests **Rust** — 1902 passing: snapshot mutation coverage, diff entry serialization, allowlist-aware env masking (`allowlisted_env_key_shows_plain_value`, `allowlisted_env_key_is_case_insensitive`, `non_allowlisted_env_key_stays_masked`), `unstamped_agent_yields_no_badge_and_no_entries` (both orphan values), `summary_without_drift_omits_restart_diff_from_the_wire`, `unstamped_availability_is_not_drift`. Clippy clean, fmt clean. **TypeScript** — `needs-restart-screenshots.spec.ts`: 11 E2E cases registered in the smoke project — all three badge sites, tooltip + keyboard focus, DOM no-button-ancestor assertion, 6+1 truncation, uncapped Runtime list, unknown field humanisation, side-panel badge on default Info tab, inactive/friendly-error Runtime opening path. Consolidates [block#3652](block#3652) Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent 540b589 commit f86dfc5

33 files changed

Lines changed: 2182 additions & 531 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export default defineConfig({
138138
"**/where-to-run-config.spec.ts",
139139
"**/huddle-transcription.spec.ts",
140140
"**/agent-numeric-tuning.spec.ts",
141+
"**/needs-restart-screenshots.spec.ts",
141142
],
142143
use: {
143144
...devices["Desktop Chrome"],

‎desktop/src-tauri/src/commands/agent_config.rs‎

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::{
1212
RuntimeConfigSurface, SessionConfigCache,
1313
},
1414
},
15-
current_instance_id, is_reserved_env_key, is_well_formed_env_key, known_acp_runtime,
16-
load_managed_agents, load_personas, save_managed_agents, sync_managed_agent_processes,
17-
AgentDefinition, GlobalAgentConfig, KnownAcpRuntime, ManagedAgentRecord,
18-
ManagedAgentRuntimeKey, MAX_ENV_VALUE_BYTES,
15+
current_instance_id, is_reserved_env_key, is_safe_to_reveal, is_well_formed_env_key,
16+
known_acp_runtime, load_managed_agents, load_personas, save_managed_agents,
17+
sync_managed_agent_processes, AgentDefinition, GlobalAgentConfig, KnownAcpRuntime,
18+
ManagedAgentRecord, ManagedAgentRuntimeKey, MAX_ENV_VALUE_BYTES,
1919
},
2020
};
2121

@@ -209,27 +209,6 @@ pub struct BakedEnvEntry {
209209
pub masked: bool,
210210
}
211211

212-
/// Returns `true` when a baked-env key is safe to display unmasked in the UI.
213-
///
214-
/// This uses an explicit allowlist of keys that are known safe (non-secret).
215-
/// Any key NOT in this set is masked — default-deny for a security surface.
216-
///
217-
/// Allowlist (case-insensitive):
218-
/// - `BUZZ_AGENT_PROVIDER`, `BUZZ_AGENT_MODEL` — agent runtime selection
219-
/// - `BUZZ_AGENT_THINKING_EFFORT` — non-secret enum (none/minimal/low/medium/high/xhigh/max)
220-
/// - `DATABRICKS_HOST`, `DATABRICKS_MODEL` — Block non-secret defaults
221-
fn is_safe_to_reveal(key: &str) -> bool {
222-
const SAFE_KEYS: &[&str] = &[
223-
"BUZZ_AGENT_PROVIDER",
224-
"BUZZ_AGENT_MODEL",
225-
"BUZZ_AGENT_THINKING_EFFORT",
226-
"DATABRICKS_HOST",
227-
"DATABRICKS_MODEL",
228-
];
229-
let upper = key.to_ascii_uppercase();
230-
SAFE_KEYS.iter().any(|safe| upper == *safe)
231-
}
232-
233212
/// Expose the baked build env to the frontend with values shown, but any
234213
/// key not in the safe-to-reveal allowlist has its value replaced by `••••••`.
235214
///

‎desktop/src-tauri/src/commands/agents_deploy.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(super) fn build_launch_block(
7676
policy_env.insert(SESSION_TITLE_ENV_VAR.into(), value);
7777
}
7878
if let Some(value) =
79-
crate::managed_agents::spawn_hash::effective_team_instructions(record, teams)
79+
crate::managed_agents::spawn_snapshot::effective_team_instructions(record, teams)
8080
{
8181
policy_env.insert("BUZZ_ACP_TEAM_INSTRUCTIONS".into(), value);
8282
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,28 @@ pub fn validate_user_env_keys(env_vars: &BTreeMap<String, String>) -> Result<(),
224224
Ok(())
225225
}
226226

227+
/// Returns `true` when `key` is safe to show verbatim — not a credential.
228+
///
229+
/// Default-deny: every key NOT in this explicit allowlist is masked. Callers
230+
/// that display env values (baked-env UI, spawn-diff tooltip) share this
231+
/// single authority — no second list.
232+
///
233+
/// Allowlist (case-insensitive):
234+
/// - `BUZZ_AGENT_PROVIDER`, `BUZZ_AGENT_MODEL` — agent runtime selection
235+
/// - `BUZZ_AGENT_THINKING_EFFORT` — non-secret enum (none/minimal/low/medium/high/xhigh/max)
236+
/// - `DATABRICKS_HOST`, `DATABRICKS_MODEL` — Block non-secret defaults
237+
pub(crate) fn is_safe_to_reveal(key: &str) -> bool {
238+
const SAFE_KEYS: &[&str] = &[
239+
"BUZZ_AGENT_PROVIDER",
240+
"BUZZ_AGENT_MODEL",
241+
"BUZZ_AGENT_THINKING_EFFORT",
242+
"DATABRICKS_HOST",
243+
"DATABRICKS_MODEL",
244+
];
245+
let upper = key.to_ascii_uppercase();
246+
SAFE_KEYS.iter().any(|safe| upper == *safe)
247+
}
248+
227249
/// Per-value byte cap for env values. 32 KiB is generous for credentials,
228250
/// JWT-ish tokens, certs etc., but small enough that a malformed IPC
229251
/// caller can't blow up the persona/agent JSON file. Tune up if real

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod runtime;
3131
mod runtime_commands;
3232
mod runtime_types;
3333
pub(crate) mod snapshot_avatar;
34-
pub(crate) mod spawn_hash;
34+
pub(crate) mod spawn_snapshot;
3535
pub(crate) mod storage;
3636
pub(crate) mod team_events;
3737
mod team_repair;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,12 @@ pub fn persona_snapshot(persona: &AgentDefinition) -> PersonaSnapshot {
450450
/// This is the single apply used by every snapshot-apply site: the spawn
451451
/// re-pin (`start_local_agent_with_preflight`), the launch backfill and
452452
/// restore re-snapshot (`restore.rs`), and the prospective re-snapshot inside
453-
/// `spawn_config_hash` — so a future `PersonaSnapshot` field addition
454-
/// propagates to all of them at once.
453+
/// `prospective_spawn_config_snapshot` — so a future `PersonaSnapshot` field
454+
/// addition propagates to all of them at once.
455455
///
456456
/// Deliberately does NOT touch `updated_at`: persistence stamps are the
457-
/// caller's concern, and `spawn_config_hash` (which applies this to a clone)
458-
/// must stay pure.
457+
/// caller's concern, and the prospective snapshot (which applies this to a
458+
/// clone) must stay pure.
459459
pub fn apply_persona_snapshot(record: &mut ManagedAgentRecord, persona: &AgentDefinition) {
460460
let snapshot = persona_snapshot(persona);
461461
if let Some(prompt) = snapshot.system_prompt {
@@ -498,16 +498,17 @@ pub fn apply_persona_snapshot(record: &mut ManagedAgentRecord, persona: &AgentDe
498498
/// paths re-pin it to its linked persona, without mutating `record` itself.
499499
///
500500
/// Every decision made ahead of the real re-pin — the relay-mesh preflight in
501-
/// `start_local_agent_with_preflight`, the restart-badge hash in
502-
/// `spawn_config_hash` — needs to reason about spawn-time state, not
501+
/// `start_local_agent_with_preflight`, the restart-badge snapshot in
502+
/// `prospective_spawn_config_snapshot` — needs to reason about spawn-time
503+
/// state, not
503504
/// pre-snapshot bytes, so a persona edit that flips a field (e.g. `provider`
504505
/// to/from relay-mesh) between saves is reflected in the decision instead of
505506
/// the stale value the real [`apply_persona_snapshot`] is about to overwrite
506507
/// anyway. Idempotent: applying it to an already-current record is a no-op,
507508
/// so the spawn-time stamp and later recomputes agree when nothing changed.
508509
///
509510
/// Orphaned records (persona deleted) pass through unchanged: the caller's
510-
/// own orphan handling — refusing to spawn, hashing as `(None, None, None)`
511+
/// own orphan handling — refusing to spawn, snapshotting as `(None, None, None)`
511512
/// — runs on the real record downstream, not on this preview.
512513
pub fn preview_prospective_persona_snapshot(
513514
record: &ManagedAgentRecord,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn taskkill_tree(pid: u32) -> Result<(), String> {
133133
pub fn finish_spawn(
134134
child: std::process::Child,
135135
log_path: std::path::PathBuf,
136-
spawn_config_hash: u64,
136+
spawn_config: super::spawn_snapshot::SpawnConfigSnapshot,
137137
setup_mode: bool,
138138
adapter_availability: Option<super::AcpAvailabilityStatus>,
139139
start_nonce: String,
@@ -149,7 +149,7 @@ pub fn finish_spawn(
149149
super::ManagedAgentProcess {
150150
child,
151151
log_path,
152-
spawn_config_hash,
152+
spawn_config,
153153
setup_mode,
154154
adapter_availability,
155155
start_nonce,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub(crate) struct EffectiveAgentEnv {
8282
//
8383
// A single owned type that fully describes what a spawn would run. Produced
8484
// by `resolve_effective_harness_descriptor` and consumed by spawn_agent_child,
85-
// spawn_config_hash, build_managed_agent_summary, get_agent_models, and
85+
// spawn_snapshot, build_managed_agent_summary, get_agent_models, and
8686
// agent_readiness — so the harness-definition lookup and arg/env resolution
8787
// happen exactly once, in one place.
8888

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use tauri::Manager;
1818
/// restore would kill reconcile's lazy child by its receipt and replace it with
1919
/// an eager one, flipping the pair's laziness on a startup race.
2020
enum SpawnOutcome {
21-
Spawned(super::ManagedAgentRuntimeKey, ManagedAgentProcess),
21+
/// Boxed: the spawned process carries its full spawn-config snapshot, so an
22+
/// inline variant would make every `Skipped`/`Failed` outcome pay for it.
23+
Spawned(super::ManagedAgentRuntimeKey, Box<ManagedAgentProcess>),
2224
Skipped,
2325
Failed(String),
2426
}
@@ -338,7 +340,9 @@ pub async fn restore_managed_agents_on_launch(
338340
owner_hex_ref,
339341
)
340342
}) {
341-
Ok(process) => SpawnOutcome::Spawned(key, process),
343+
Ok(process) => {
344+
SpawnOutcome::Spawned(key, Box::new(process))
345+
}
342346
Err(error) => SpawnOutcome::Failed(error),
343347
}
344348
}
@@ -400,7 +404,7 @@ pub async fn restore_managed_agents_on_launch(
400404
record.last_stopped_at = None;
401405
record.last_exit_code = None;
402406
record.last_error = None;
403-
runtimes.insert(key, super::ManagedAgentPairRuntime::starting(process));
407+
runtimes.insert(key, super::ManagedAgentPairRuntime::starting(*process));
404408
successfully_spawned.push(pubkey);
405409
}
406410
SpawnOutcome::Failed(error) => {

0 commit comments

Comments
 (0)