Skip to content

Commit 8c87f57

Browse files
committed
chore(desktop): reclaim ratchet lines for the resume-on-restart toggle
The stateless file-size ratchet added in #3352 lets no already-over-limit file grow, and a mandatory ManagedAgentRecord field adds one line to every struct literal. Reclaimed the delta by condensing verbose comment blocks in the same files, keeping every fact each block carried. One reclaim is a correction rather than a reflow: the BUZZ_ACP_SETUP_PAYLOAD note claimed the reserved-key strip depends on running after the user-env write, but guard 1 (RESERVED_ENV_KEYS) is order-independent, so the ordering caveat was misleading. Co-authored-by: Will Pfleger <[email protected]> Signed-off-by: Will Pfleger <[email protected]>
1 parent 328c736 commit 8c87f57

13 files changed

Lines changed: 130 additions & 169 deletions

File tree

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ pub struct RuntimeFileConfigSubset {
4848
/// The pipeline: resolve the linked persona's prompt/model/provider, inject
4949
/// each into the record only where the record lacks its own value, let
5050
/// `read_config_surface` tag those injected fields `BuzzExplicit`, then re-tag
51-
/// exactly the injected fields to `PersonaDefault`.
52-
///
53-
/// Global defaults fill in when neither the record nor the linked persona
54-
/// provides a value. They are re-tagged to `GlobalDefault` so the UI can
55-
/// display "inherited from global defaults".
51+
/// exactly the injected fields to `PersonaDefault`. Global defaults fill in
52+
/// when neither the record nor the linked persona provides a value, and are
53+
/// re-tagged `GlobalDefault` so the UI can show "inherited from global
54+
/// defaults".
5655
///
5756
/// The re-tag is triple-gated — a field is re-tagged only when (a) the record
5857
/// did not already have it (`!had_*`), (b) the surface produced the field, and
59-
/// (c) the reader tagged it `BuzzExplicit`. A value the user set explicitly in
60-
/// Buzz keeps `had_* == true` and is never re-tagged.
58+
/// (c) the reader tagged it `BuzzExplicit`. A value the user set explicitly
59+
/// keeps `had_* == true` and is never re-tagged.
6160
fn resolve_config_surface(
6261
mut record: ManagedAgentRecord,
6362
personas: &[AgentDefinition],

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ pub(super) fn build_agent_archive_request(
170170
/// window on 9035s.
171171
///
172172
/// Same contract as `tombstone_managed_agent_pending`: called inside the
173-
/// `managed_agents_store_lock`-held delete body, never across an `.await`,
174-
/// best-effort — a failure is logged and swallowed so it never blocks the
175-
/// disk-authoritative delete.
173+
/// `managed_agents_store_lock`-held delete body, never across an `.await`, and
174+
/// best-effort — a failure never blocks the disk-authoritative delete.
176175
pub(super) fn archive_managed_agent_pending(app: &AppHandle, state: &AppState, agent_pubkey: &str) {
177176
use crate::managed_agents::retention::{open_retention_db, retain_event, RetainedEvent};
178177
use buzz_core_pkg::kind::KIND_IA_ARCHIVE_REQUEST;

‎desktop/src-tauri/src/commands/personas/snapshot/fidelity_tests.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn make_definition(slug: &str) -> ManagedAgentRecord {
3636
env_vars: BTreeMap::new(),
3737
start_on_app_launch: false,
3838
auto_restart_on_config_change: false,
39+
resume_on_restart: true,
3940
runtime_pid: None,
4041
backend: BackendKind::Local,
4142
backend_agent_id: None,

‎desktop/src-tauri/src/commands/personas/snapshot/tests.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ fn import_none_level_with_entries_is_rejected() {
510510
);
511511
}
512512

513-
/// A well-formed snapshot with memory level != none and non-empty entries
514-
/// is accepted.
513+
/// A well-formed snapshot with memory level != none and non-empty entries is accepted.
515514
#[test]
516515
fn import_memory_bearing_snapshot_is_accepted() {
517516
let entries = vec![
@@ -574,9 +573,9 @@ fn import_preview_includes_exported_definition_metadata() {
574573

575574
// ── Import: resolve_snapshot_import_behavior — the production selection path
576575
//
577-
// All tests below call `resolve_snapshot_import_behavior` directly. This is
578-
// the same function invoked by `confirm_agent_snapshot_import`, so the tests
579-
// exercise the exact production code path, not a reconstruction of it.
576+
// All tests below call `resolve_snapshot_import_behavior` directly — the same
577+
// function `confirm_agent_snapshot_import` invokes, so they exercise the
578+
// production path rather than a reconstruction.
580579

581580
/// Uppercase hex pubkeys are lowercased and duplicates are removed before the
582581
/// resolved allowlist is persisted.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ fn resolve_avatar(
266266
return (Some(data_url), None);
267267
}
268268
}
269-
// Fall back to URL reference (caller provided a URL avatar or bytes were
270-
// too large).
269+
// Fall back to URL reference (caller provided a URL avatar or bytes were too large).
271270
let url_ref = record
272271
.avatar_url
273272
.as_deref()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ fn effective_agent_command_empty_override_is_inherit() {
481481

482482
#[test]
483483
fn effective_agent_command_falls_back_to_default() {
484-
// No override, no persona runtime, and a deleted persona all fall back
485-
// to the bundled default.
484+
// No override, no persona runtime, and a deleted persona all fall back to the bundled default.
486485
let personas = vec![persona_with_runtime("p1", None)];
487486
assert_eq!(
488487
effective_agent_command(Some("p1"), &personas, None),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ pub(crate) struct EffectiveHarnessDescriptor {
113113
/// persona) references a runtime id that no longer exists in the registry —
114114
/// the same typed error produced by `try_record_agent_command`. Callers that
115115
/// cannot meaningfully continue with a dangling id (e.g. `spawn_agent_child`)
116-
/// propagate the error; callers that degrade gracefully may use
117-
/// `.unwrap_or_else(|_| …)`.
116+
/// propagate the error; callers that degrade gracefully may use `.unwrap_or_else(|_| …)`.
118117
///
119118
/// Does NOT require an `AppHandle` so it is fully unit-testable.
120119
///

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

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ pub fn build_managed_agent_summary(
150150
// Two-axis status model for remote agents:
151151
//
152152
// Control-plane (this field): "deployed" = provider has been invoked and
153-
// returned a backend_agent_id. "not_deployed" = no deploy call yet (or it
154-
// failed). This axis tracks whether infrastructure *exists*, not whether
155-
// the process is currently running.
153+
// returned a backend_agent_id. "not_deployed" = no deploy call yet (or
154+
// it failed). Tracks whether infrastructure *exists*, not whether the
155+
// process is currently running.
156156
//
157-
// Live axis (relay presence, polled by frontend): online/away/offline.
158-
// Shown as a PresenceDot next to the agent name. This is the real-time
159-
// signal for whether the harness is connected.
157+
// Live axis (relay presence, polled by frontend): online/away/offline,
158+
// shown as a PresenceDot next to the agent name — the real-time signal
159+
// for whether the harness is connected.
160160
//
161161
// After !shutdown the agent goes offline (presence) but stays "deployed"
162162
// (infrastructure still exists). This is intentional — the provider may
@@ -243,7 +243,6 @@ pub fn build_managed_agent_summary(
243243
// Global config drives both the restart-drift hash and descriptor env
244244
// layering below — the caller loads it once and passes it in, so
245245
// list-style callers pay one disk read per call rather than one per record.
246-
247246
let needs_restart = pair_key
248247
.as_ref()
249248
.and_then(|key| runtimes.get(key).map(|runtime| (key, runtime)))
@@ -604,12 +603,8 @@ pub fn spawn_agent_child(
604603
// readiness predicate, and if anything is missing, serialize the payload
605604
// into BUZZ_ACP_SETUP_PAYLOAD. buzz-acp detects this env var on startup
606605
// and enters the minimal setup-listener mode instead of the agent pool.
607-
//
608-
// SECURITY: BUZZ_ACP_SETUP_PAYLOAD is in RESERVED_ENV_KEYS so user env
609-
// cannot set it, but we also explicitly remove it after writing user env
610-
// to guard against the parent-process environment. We then set it only
611-
// when desktop has computed NotReady — the desktop is the sole readiness
612-
// source and buzz-acp only transports the payload.
606+
// SECURITY: the key is in RESERVED_ENV_KEYS, and desktop is the sole
607+
// readiness source — buzz-acp only transports the payload.
613608
//
614609
// The JSON format mirrors `setup_mode::SetupPayload` in buzz-acp:
615610
// { "agent_name": "...", "agent_pubkey": "...", "requirements": [{ "surface": "...", ... }] }
@@ -700,9 +695,8 @@ pub fn spawn_agent_child(
700695
// 2. This env_remove() clears any ambient parent-process value
701696
// inherited by std::process::Command before we conditionally
702697
// set the desktop-computed trusted value below.
703-
// Note: merged_user_env() is written further below in this function;
704-
// ordering relative to that call is NOT what makes this safe — the
705-
// reserved-key strip (guard 1) handles user env regardless of order.
698+
// Guard 1 handles user env regardless of where merged_user_env() is
699+
// written relative to this call, so ordering is NOT what makes it safe.
706700
command.env_remove("BUZZ_ACP_SETUP_PAYLOAD");
707701

708702
// Set the payload only when desktop computed NotReady.
@@ -728,9 +722,8 @@ pub fn spawn_agent_child(
728722
command.env("BUZZ_ACP_MAX_TURN_DURATION", max_dur.to_string());
729723
}
730724
// Emitted only when the toggle is OFF, so the harness default stays the
731-
// source of truth when ON — same rationale as BUZZ_ACP_IDLE_TIMEOUT above.
732-
// The key is not reserved, so a user setting it in the env-vars editor wins
733-
// (descriptor.env is written last; see the user-env block below).
725+
// source of truth when ON (as with BUZZ_ACP_IDLE_TIMEOUT above). The key is
726+
// not reserved, so a user setting it in the env-vars editor wins.
734727
if !record.resume_on_restart {
735728
command.env("BUZZ_ACP_RESUME_ON_RESTART", "false");
736729
}
@@ -757,10 +750,10 @@ pub fn spawn_agent_child(
757750
// instances never consult the record's own model/provider/prompt bytes;
758751
// definition-less instances fall back to their own fields, then global.
759752
//
760-
// Derive the mesh decision BEFORE moving fields out — `relay_mesh_model_id`
761-
// is the single authoritative gate; the mesh-llm block below MUST use it
762-
// rather than re-deriving from `effective_provider` to keep preflight and
763-
// spawn semantics in lock-step (see `EffectiveAgentConfig::relay_mesh_model_id`).
753+
// Derive the mesh decision BEFORE moving fields out — `relay_mesh_model_id` is
754+
// the single authoritative gate; the mesh-llm block below MUST use it rather
755+
// than re-deriving from `effective_provider`, keeping preflight and spawn
756+
// semantics in lock-step (see `EffectiveAgentConfig::relay_mesh_model_id`).
764757
#[cfg(feature = "mesh-llm")]
765758
let mesh_model_id = effective_cfg.relay_mesh_model_id();
766759
let effective_prompt = effective_cfg.system_prompt.value;
@@ -824,13 +817,13 @@ pub fn spawn_agent_child(
824817

825818
// ── Git credential helper for Buzz relay ──────────────────────────
826819
//
827-
// Agents need to clone/push repos hosted on the Buzz relay's git
828-
// server, which authenticates via NIP-98. The `git-credential-nostr`
829-
// binary signs auth events using the agent's nostr key.
820+
// Agents need to clone/push repos hosted on the Buzz relay's git server,
821+
// which authenticates via NIP-98. The `git-credential-nostr` binary signs
822+
// auth events using the agent's nostr key.
830823
//
831-
// We configure git via GIT_CONFIG_COUNT env vars (ephemeral, no
832-
// filesystem writes) scoped to the relay's git URL so we don't
833-
// interfere with other remotes (e.g. GitHub).
824+
// We configure git via GIT_CONFIG_COUNT env vars (ephemeral, no filesystem
825+
// writes) scoped to the relay's git URL so we don't interfere with other
826+
// remotes (e.g. GitHub).
834827
//
835828
// NOSTR_PRIVATE_KEY mirrors BUZZ_PRIVATE_KEY — keep in sync.
836829
if let Some(cred_helper) = resolve_command("git-credential-nostr") {
@@ -863,8 +856,8 @@ pub fn spawn_agent_child(
863856
// baked floor → runtime metadata → definition env (harness author defaults) →
864857
// global → live persona → per-agent, with reserved-key and malformed-key filtering
865858
// applied. Writing it last lets user-provided values win over every Buzz-set env
866-
// written above — reserved keys were already stripped from descriptor.env so they
867-
// cannot clobber BUZZ_PRIVATE_KEY, NOSTR_PRIVATE_KEY, etc.
859+
// written above — reserved keys were already stripped, so they cannot clobber
860+
// BUZZ_PRIVATE_KEY, NOSTR_PRIVATE_KEY, etc.
868861
for (key, value) in &descriptor.env {
869862
command.env(key, value);
870863
}
@@ -930,11 +923,10 @@ pub fn spawn_agent_child(
930923
// Stamp the adapter availability for runtimes with a version gate (codex
931924
// only). The summary builder compares this against the current cached value
932925
// to detect out-of-band adapter changes after spawn (Phase-2 badge fallback).
933-
// Non-codex runtimes get `None` — nothing changes for them.
934-
// When the cache is cold (e.g. Doctor just installed and cleared the cache),
935-
// `adapter_availability_cached()` returns `None`, so the stamp is `None` and
936-
// the drift check is skipped until discovery warms the cache — preventing a
937-
// false restart badge immediately after auto-restart.
926+
// Non-codex runtimes get `None` — nothing changes for them. A cold cache
927+
// (e.g. Doctor just installed and cleared it) also stamps `None`, skipping
928+
// the drift check until discovery warms it — this prevents a false restart
929+
// badge immediately after auto-restart.
938930
let spawned_adapter_availability = if runtime_meta.is_some_and(|r| r.id == "codex") {
939931
super::adapter_availability_cached()
940932
} else {

‎desktop/src-tauri/src/managed_agents/runtime/tests.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ fn build_env_legacy_record_without_auth_tag_emits_agent_owner() {
252252

253253
#[test]
254254
fn build_env_legacy_record_without_owner_hex_removes_agent_owner() {
255-
// No owner available to forward → make sure we don't inherit a leaked
256-
// env var from the parent.
255+
// No owner available to forward → make sure we don't inherit a leaked env var from the parent.
257256
let rec = fixture(RespondTo::OwnerOnly, vec![], None);
258257
let (_set, remove) = build_respond_to_env(&rec, None).unwrap();
259258
assert!(remove.contains(&"BUZZ_ACP_AGENT_OWNER"));

0 commit comments

Comments
 (0)