Add typed metadata snapshot events around init, checkpoint, and finalize archive writes so run logs expose durable metadata timing and failures. Include snapshot accounting, CLI rendering with compatibility-notice suppression, and event documentation.
15 KiB
Metadata Snapshot Events Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [x]) syntax for tracking.
Goal: Add first-class Fabro run events for durable metadata snapshot writes so run timing gaps are visible without emitting low-level git span events.
Architecture: Metadata snapshot events are product-domain workflow events emitted around each real metadata archive attempt. Callers own event emission around the whole metadata operation, including run-store state loading; SandboxMetadataWriter remains responsible for creating and pushing snapshots and returns snapshot accounting data.
Tech Stack: Rust, serde, strum, Fabro typed Event/RunEvent pipeline, existing CLI log/progress renderers, cargo nextest.
Summary
Add these event names:
metadata.snapshot.startedmetadata.snapshot.completedmetadata.snapshot.failed
The events cover Fabro metadata snapshots only, not every underlying git or filesystem operation. Emit them for init, checkpoint, and finalize metadata attempts so timing gaps become visible without rebuilding tracing as events.
Event Contract
MetadataSnapshotStartedProps { phase: MetadataSnapshotPhase, branch: String }MetadataSnapshotCompletedProps { phase: MetadataSnapshotPhase, branch: String, duration_ms: u64, entry_count: usize, bytes: u64, commit_sha: String }MetadataSnapshotFailedProps { phase: MetadataSnapshotPhase, branch: String, duration_ms: u64, failure_kind: MetadataSnapshotFailureKind, error: String, causes: Vec<String>, commit_sha: Option<String>, entry_count: Option<usize>, bytes: Option<u64> }
Enums:
MetadataSnapshotPhase = init | checkpoint | finalizeMetadataSnapshotFailureKind = load_state | write | push- Both enums must pair
#[serde(rename_all = "snake_case")]with#[strum(serialize_all = "snake_case")]so serde and strum stay aligned with the project enum convention.
Rules:
metadata.snapshot.completedmeans the metadata snapshot was committed and pushed successfully. There is nopushedfield because it would always be true.commit_shais intentionally asymmetric: completed snapshots always includecommit_sha: String; failed snapshots includecommit_sha: Option<String>because push failures can have a local commit while load-state and write failures cannot.- Failed accounting fields are optional:
entry_count: Option<usize>andbytes: Option<u64>areSomefor push failures andNonefor load-state/write failures. - Optional fields use
#[serde(default, skip_serializing_if = "Option::is_none")], matching the convention ininfra.rs. - Failed props follow the existing failure-event convention in
infra.rs:error: Stringcontains the primary error summary andcauses: Vec<String>contains the cause chain with#[serde(default, skip_serializing_if = "Vec::is_empty")]. - A writer
push_errormaps tometadata.snapshot.failed { failure_kind: "push", commit_sha: Some(...), entry_count: Some(...), bytes: Some(...) }. - A run-store
state()failure maps tometadata.snapshot.failed { failure_kind: "load_state", commit_sha: None, entry_count: None, bytes: None }. - If metadata is already degraded and a later snapshot would currently return early, emit no metadata snapshot event for that skipped attempt. Do not emit
started; skipped attempts are not real attempts and should not count as failures. - Writer errors before a local commit map to
metadata.snapshot.failed { failure_kind: "write", commit_sha: None, entry_count: None, bytes: None }. - Emit
metadata.snapshot.failedbefore the compatibilityrun.noticefor the same failure so human-facing consumers can deterministically suppress duplicate warning text. - Typed
metadata.snapshot.*events are not deduplicated for real attempts. Existing metadatarun.noticededuping remains compatibility-only. - Checkpoint metadata events use the existing stage scope so they include
node_id,node_label, andstage_id. Init/finalize metadata events are unscoped and must not setnode_id,node_label, orstage_id. - Keep
branchbecause the exact metadata ref is useful in raw logs and for push failure diagnostics. Do not includemessage;phasefully identifies the logical metadata operation.
Implementation Tasks
Task 1: Add Typed Event Bodies
Files:
-
Modify:
lib/crates/fabro-types/src/run_event/mod.rs -
Modify:
lib/crates/fabro-types/src/run_event/infra.rs -
Add
MetadataSnapshotPhaseandMetadataSnapshotFailureKindenums ininfra.rs. -
Derive
Serialize,Deserialize,strum::Display,strum::EnumString, andstrum::IntoStaticStr. -
Add both
#[serde(rename_all = "snake_case")]and#[strum(serialize_all = "snake_case")]to each enum. -
Add the three metadata snapshot props structs in
infra.rswith the exact fields from the Event Contract section. -
Add serde attributes for optional failed fields and empty
causesexactly as specified in the Event Contract. -
Add three
EventBodyvariants inmod.rswith exact serde names:metadata.snapshot.startedmetadata.snapshot.completedmetadata.snapshot.failed
-
Extend
EventBody::event_name()and known-event handling for all three names.
Task 2: Add Workflow Event Variants And Mapping
Files:
-
Modify:
lib/crates/fabro-workflow/src/event.rs -
Add internal
Eventvariants matching the three new event bodies. -
Extend
Event::trace()with concise tracing fields:phase,branch,duration_ms, andfailure_kind. -
Extend
event_name()with the three exact event names. -
Extend
event_body_from_event()to construct the matchingEventBodyvariants. -
Ensure unscoped metadata snapshot events do not set envelope
node_id,node_label, orstage_id; checkpoint callers will useemit_scoped().
Task 3: Return Snapshot Accounting From The Writer
Files:
-
Modify:
lib/crates/fabro-workflow/src/sandbox_metadata.rs -
Extend
MetadataSnapshotto includeentry_count: usizeandbytes: u64. -
Compute
entry_countandbytesinsideSandboxMetadataWriter::write_snapshot()from the singledump.git_entries()allocation that the writer already needs. -
Return those accounting values on successful local metadata commit, including the case where
push_erroris present. -
Do not add per-command events or expose writer-internal steps on the wire.
Task 4a: Emit Init Metadata Events
Files:
-
Modify:
lib/crates/fabro-workflow/src/lifecycle/git.rs -
If metadata is already degraded, return from the init metadata path without emitting
metadata.snapshot.*. -
Move the degraded check above the init
metadata.snapshot.startedemission point; the existing check insidewrite_metadata_snapshot()is not enough because skipped attempts must not leave a danglingstarted. -
Keep the existing inner
metadata_degraded()guard inGitLifecycle::write_metadata_snapshot()as defense-in-depth for future callers, but do not rely on it for init/checkpoint skip semantics. -
Wrap the full init metadata operation in
GitLifecycle::on_run_start, includingrun_store.state(). -
Emit
metadata.snapshot.started { phase: "init" }before loading run state for the init operation. -
Emit
metadata.snapshot.completedonly when the init metadata commit and push both succeed. -
Emit
metadata.snapshot.failedfor init load-state, write, and push failures using the Event Contract mapping. -
Emit
metadata.snapshot.failedbefore callingemit_metadata_warning()for the same init failure.
Task 4b: Emit Checkpoint Metadata Events
Files:
-
Modify:
lib/crates/fabro-workflow/src/lifecycle/git.rs -
If metadata is already degraded, return from the checkpoint metadata path without emitting
metadata.snapshot.*. -
Move the degraded check above the checkpoint
metadata.snapshot.startedemission point; the existing check insidewrite_metadata_snapshot()is not enough because skipped attempts must not leave a danglingstarted. -
Keep the existing inner
metadata_degraded()guard inGitLifecycle::write_metadata_snapshot()as defense-in-depth for future callers, but do not rely on it for init/checkpoint skip semantics. -
Wrap the full checkpoint metadata operation in
GitLifecycle::on_checkpoint, includingrun_store.state(). -
Emit scoped
metadata.snapshot.started { phase: "checkpoint" }before loading run state for the checkpoint operation. -
Emit scoped
metadata.snapshot.completedormetadata.snapshot.failedbeforecheckpoint.completed. -
Emit scoped
metadata.snapshot.failedbefore callingemit_metadata_warning()for the same checkpoint failure. -
Preserve existing metadata-degraded
run.noticeemission for compatibility, but treat the new typed event as the primary human-facing signal.
Task 5: Emit Finalize Metadata Events
Files:
-
Modify:
lib/crates/fabro-workflow/src/pipeline/finalize.rs -
If metadata is already degraded, return from the final metadata path without emitting
metadata.snapshot.*. -
Keep the degraded check above the final
metadata.snapshot.startedemission point; skipped attempts must not leave a danglingstarted. -
Wrap the full final metadata operation in
write_finalize_commit, includingrun_store.state(). -
Emit
metadata.snapshot.started { phase: "finalize" }before loading run state for the final metadata operation. -
Emit
metadata.snapshot.completedonly when the final metadata commit and push both succeed. -
Emit
metadata.snapshot.failedfor finalize load-state, write, and push failures using the Event Contract mapping. -
Emit
metadata.snapshot.failedbefore callingemit_metadata_warning()for the same final metadata failure. -
Ensure final metadata events are emitted before
run.completed. -
Preserve existing
checkpoint_metadata_write_failed,checkpoint_metadata_push_failed, andcheckpoint_metadata_degradednotices for compatibility.
Task 6: CLI, Consumers, And Documentation
Files:
-
Modify:
lib/crates/fabro-cli/src/commands/run/logs.rs -
Modify:
lib/crates/fabro-cli/src/commands/run/run_progress/event.rs -
Modify:
lib/crates/fabro-cli/src/commands/run/run_progress/mod.rs -
Modify:
docs/internal/events.md -
Audit existing consumers with
rg -n "event_name|EventBody|metadata.snapshot" lib/crates apps lib/packages docs/public/api-reference/fabro-api.yaml docs/internal --glob '!docs/superpowers/**'and update any event-name filters that should recognize metadata snapshot events. Ignore matches in implementation-plan docs. -
Render completed metadata snapshots compactly in pretty/progress output, for example
Metadata checkpoint 2.8s. -
Render
metadata.snapshot.failedas the primary user-visible metadata warning/error. -
Suppress duplicate CLI display of the compatibility
checkpoint_metadata_*notice when the same stream already contains a matching earliermetadata.snapshot.failedevent. -
Limit suppression to per-failure compatibility notices:
checkpoint_metadata_write_failedandcheckpoint_metadata_push_failed. Do not suppress thecheckpoint_metadata_degradedend-of-run summary notice; it is a distinct summary signal. -
Keep
fabro logs --jsonunchanged except for the new serialized event records. -
Document the three event definitions in
docs/internal/events.md. -
State in the docs that these are product events for durable metadata snapshots, not tracing spans.
API And Client Compatibility
Checked current API/client shape:
docs/public/api-reference/fabro-api.yamlmodelsRunEventas a generic object withevent: stringandproperties: object.lib/packages/fabro-api-client/src/models/run-event.tsincludes[key: string]: anyandproperties?: { [key: string]: any }.
No OpenAPI or TypeScript client schema changes are required for this event-only addition unless implementation discovers a stricter consumer outside this model.
Test Plan
- Add
fabro-typesserialization/deserialization tests proving the three event names are known and props serialize to the agreed JSON shape. - Add
fabro-workflowevent conversion tests for all three variants, including scoped checkpoint metadata events. - Add lifecycle tests covering successful metadata snapshot emission: started then completed.
- Add lifecycle tests covering
push_errormapping tometadata.snapshot.failed { failure_kind: "push", commit_sha: Some(...), entry_count: Some(...), bytes: Some(...) }. - Add lifecycle tests covering degraded short-circuit behavior: no
metadata.snapshot.*event is emitted and nometadata.snapshot.startedevent is left unterminated. - Add a cross-phase degraded test: after an init
metadata.snapshot.failedmarks metadata degraded, subsequent checkpoint and finalize attempts emit nometadata.snapshot.*events. - Add lifecycle tests covering pre-writer
run_store.state()failure emission for init: started then failed withfailure_kind: "load_state". - Add lifecycle tests covering pre-writer
run_store.state()failure emission for checkpoint: started then failed withfailure_kind: "load_state". - Add lifecycle tests covering pre-writer
run_store.state()failure emission for finalize: started then failed withfailure_kind: "load_state". - Add tests proving
completed.entry_countandcompleted.bytesequal the writer'sMetadataSnapshotvalues. - Add tests proving push-failure
failed.entry_countandfailed.bytesequal the writer'sMetadataSnapshotvalues. - Add ordering tests proving checkpoint metadata events occur before
checkpoint.completed. - Add ordering tests proving finalize metadata events occur before
run.completed. - Add tests proving
metadata.snapshot.failedis emitted before the matching compatibilityrun.notice. - Add tests proving compatibility
run.noticestill fires for metadata degradation while CLI display avoids duplicate warnings. - Add CLI rendering tests for pretty/progress output so metadata events display compactly and do not break generic log output.
- Run:
cargo nextest run -p fabro-types
cargo nextest run -p fabro-workflow metadata
cargo nextest run -p fabro-cli logs
cargo +nightly-2026-04-14 fmt --check --all
Assumptions
- The public wire shape uses the exact event names in this plan.
entry_countis the number of metadata files in the snapshot.bytesis the sum of serialized metadata entry byte lengths.- Existing metadata-degraded notices stay for compatibility, but typed metadata snapshot events become the preferred signal for humans and new consumers.
- Already-degraded skipped attempts are intentionally silent; the first real failure event and compatibility notice explain why later metadata work is skipped.
- Runs with no configured metadata branch stay silent for metadata snapshot events because metadata snapshots are out of scope for those runs.
- A panic between
metadata.snapshot.startedandmetadata.snapshot.completed/metadata.snapshot.failedmay leave a dangling started event; this feature treats that as a run-level crash case rather than adding panic recovery around metadata event emission. - The implementation should not introduce metadata writer sub-step events or expose low-level git command boundaries on the event stream.