migration.rs is at the desktop 1000-line file-size ratchet's frozen base (1408, pinned on origin/main), so the custom-harness boot-migration wiring cannot add its module registration without tripping the ratchet. Lift the self-contained databricks V1->V2 reconcile pair (reconcile_databricks_v1_to_v2 + its _in_file helper) into a migration/databricks_reconcile.rs submodule and move its tests to the sibling databricks_reconcile_tests.rs, reclaiming headroom.
Pure movement: function bodies are byte-identical; only patch_json_records/canonical_dev_data_dir gain a super:: qualifier, the entry point narrows pub -> pub(super) (its sole caller is the boot call), and the test file's test_support import re-roots to crate::migration::test_support. All 11 databricks reconcile tests stay green.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Complete the module extraction and field wiring left in working-tree state:
- Wire dev_service_migration and secret_projection_tests as modules
- Extract dev keyring secrets migration into dev_service_migration.rs and
secret_projection tests into secret_projection_tests.rs so both parent
files stay under the 1000-line desktop ratchet
- Reclaim ratchet lines in the six over-cap files touched by the
secrets_unavailable field additions (types.rs, migration.rs, agents.rs,
import.rs, discovery/tests.rs, readiness.rs)
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Commit the three items that were in working-tree state but not pushed:
- types.rs: add secrets_unavailable: bool field (transient, #[serde(skip)]) to
ManagedAgentRecord with doc comment explaining load-time semantics
- secret_seam.rs: set record.secrets_unavailable = true when hydration errors
are present, making the setter actually wire unavailability into the record
- storage.rs: extend spawn_key_refusal to check secrets_unavailable (in addition
to empty nsec), refuse spawn with a named error message; update comments at
both load_managed_agents callers to reflect that unavailability is now set
directly on the record and consulted by spawn_key_refusal
- storage.rs: add migrate_agent_secrets_to_dev_service (v2 marker, separately
versioned from _dev_migration_v1) covering canonical dev → prod and scoped
dev → canonical dev, with conflict detection, global:env ref check, and
collect_global_env_refs helper
- migration.rs: wire migrate_agent_secrets_to_dev_service into the boot path
(cfg(debug_assertions), after migrate_inline_secrets_to_keyring)
- secret_projection.rs: add test_cancel_before_mark_ordering_protects_in_flight_gen
covering the cancel-before-mark scenario Paul flagged (step 4 safe: a marked-
then-referenced gen survives the next boot's delete phase)
- All struct literal sites updated with secrets_unavailable: false
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
All three secret tiers (global env vars, per-agent env/auth_tag/
provider_config, definition env vars) now move from plaintext JSON
into the existing SecretStore keyring blob using an immutable
generation-reference protocol:
- Each write creates a new immutable generation entry under a UUID-
keyed coordinate (e.g. agent:<pubkey>:env:<gen>). The stripped JSON
carries a non-secret *_ref field; the atomic JSON write is THE commit
point.
- Crash before JSON commit: old ref stays authoritative, orphaned gen
is swept by GC. Crash after: new ref is authoritative, old gen swept.
- Empty vs unavailable distinguished by ref presence: no ref = field
intentionally empty (agent runs); ref present but entry missing =
unavailable, fail closed (nsec-style refusal).
- Inline precedence: on keyring write failure (Windows TooLong /
backend error) value stays inline in 0o600 JSON with a named warning
and the ref is cleared. Inline is authoritative over any keyring state
for that boot; extraction retries next boot.
- Two-cycle GC: sweep 1 marks unreferenced generations as candidates in
the blob; sweep 2 (next verified boot) deletes still-unreferenced
candidates. Saves cancel their generation's candidacy before the JSON
commit. GC is a no-op when either JSON store is absent, unreadable,
or changes between reference collection and blob mutation.
- Boot migration runs at the end of run_boot_migrations_inner (after
materialize_agent_runtimes) so raw-JSON migrations see inline values.
- OSS keyringless builds are unchanged (inline 0o600 JSON).
Coordinates:
global:env:<gen>
agent:<pubkey>:env:<gen>
agent:<pubkey>:auth_tag:<gen>
agent:<pubkey>:provider_config:<gen> (entire BackendKind::Provider.config)
definition:<id>:env:<gen>
Files changed:
secret_store.rs — add remove_keys() for batch blob deletion
managed_agents/mod.rs — expose secret_projection module
managed_agents/secret_projection.rs — new: full gen-ref protocol impl + tests
managed_agents/types.rs — add auth_tag_ref, env_vars_ref, provider_config_ref
managed_agents/global_config — add env_vars_ref, hydrate-on-load/strip-on-save
managed_agents/storage.rs — hydrate/strip seam, migration helpers
migration.rs — boot migration + two-cycle GC
commands/agents.rs — new ref fields initialised to None
commands/personas/snapshot/import.rs — same
commands/team_snapshot.rs — same
Deferred (noted in PR body, not a separate issue): existing nsec blob
(~2.8 KB) already exceeds the Windows 2,560-byte cap — pre-existing,
same accepted-risk class as the overflow path added here.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Agents in a team receive two `Team Instructions` blocks per turn, and
the observer feed renders two Team Instructions cards for them.
There are two producers. `with_team()` in `crates/buzz-acp/src/pool.rs`
appends the LIVE `[Team Instructions]` block from the runtime
`TeamRecord` — that one is correct. The second is baked into the stored
`system_prompt` itself: records written before the runtime framing
landed were composed by the now-removed `compose_prompt()` in
`buzz-persona`, which appended `"\n\n---\n# Team Instructions\n"` plus a
frozen copy of the team instructions. So an affected agent is fed a
stale roster ahead of the current one, and the transcript parser —
correctly — reports both.
Fixing this in `parseSystemPromptSections` would hide the symptom while
the agent kept receiving the stale bytes, so the suffix is removed at
rest by a boot migration.
`strip_baked_team_instructions` splits each stored `system_prompt` at
the LAST occurrence of the exact delimiter and keeps the text before it.
Last-occurrence matches the parser's own `lastIndexOf` guard: a persona
body may quote a delimiter-shaped passage, and only the final one is the
producer boundary. The match is byte-exact — a bare `---`, a `# Team
Instructions` heading at a different position, or a single preceding
newline are author content and are left alone. It applies to every
record regardless of `team_id` / `persona_id` / `pubkey`: the key-less
definition records carry the suffix exactly as the instances minted from
them do. A prompt that was nothing but the suffix becomes `None`, not
`Some("")`, matching the absent-prompt convention in
`AgentDefinition::into_agent_record`.
Stripping a definition's prompt changes its `persona_content_hash`,
which is the drift basis behind the Agents-menu "out of date" badge.
Left alone, every linked instance would light up stale for a change the
user never made. The migration therefore advances the pin of instances
whose `persona_source_version` still equals the definition's PRE-strip
hash — the same conditional `refresh_builtin_agent_avatars` already
uses. An instance that had genuinely drifted keeps its stale pin, and
its badge.
The migration runs after `fold_personas_into_agent_store` so definitions
lifted out of the legacy `personas.json` are cleaned in the same boot,
and before `backfill_standalone_agents` so a manufactured definition
never snapshots a suffix about to be removed. It writes only when at
least one record changed, so a second boot is a true no-op, and takes a
create-if-absent backup at
`managed-agents.json.pre-team-suffix-strip.bak` following the
`pre-backfill.bak` contract — a re-run after a partial failure cannot
replace the pristine backup with a half-migrated snapshot. An
unparseable store errors without writing and without taking a backup,
leaving the file for manual recovery.
Pass 5's legacy branch in `agentSessionTranscriptHelpers.ts` is
deliberately untouched: un-migrated installs and snapshot imports still
need it.
---------
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>