State, snapshots, and bundles
Sofka keeps small user choices across runs and creates two kinds of support artifact. Persistent state restores the user's working view. Snapshots preserve a table view for later review. Diagnostic bundles collect bounded evidence for handoff while removing sensitive values. This page extends Persistence and support artifacts and relates to Diagnostics, logging, and data protection.
Persistent state
Persistent state records choices that shape the next session. It is separate from user configuration, so a live choice can overlay a configured default without changing the hand-edited config files.
State records
The state store keeps three user-facing records: the last namespace for each context, the sort choice for each resource kind, and the contexts included in the fleet view. Missing or unreadable records act like empty state, so damaged state does not stop the application from starting.
| Record | User effect | State file |
|---|---|---|
| Namespace memory | Returns to the last selected namespace or all namespaces for a context | <state-dir>/namespaces.toml |
| Sort memory | Restores a selected column and direction for a resource kind | <state-dir>/sort.toml |
| Fleet marks | Adds or hides contexts in the fleet dashboard | <state-dir>/fleet.toml |
The application loads these records at startup. Explicit launch choices and current-session choices take priority over remembered values where the view rules require it. A later context or resource change then uses the remembered value for that scope.
References: src/nsmem.rs• L1-9 src/nsmem.rs• L19-47 src/sortmem.rs• L1-9 src/sortmem.rs• L16-46 src/fleet.rs• L14-50 src/main.rs• L408-429
Atomic state writes
State updates use whole-file replacement so readers see either the old complete record or the new complete record. The write first prepares and flushes a sibling temporary file, then replaces the target in one rename; this avoids a half-written TOML file after a crash or concurrent write.
The live application sends state changes to one ordered writer instead of making the UI wait for disk work. A burst of changes to the same destination keeps only the newest state. Independent destinations remain separate, and shutdown gives accepted writes a short drain period before it allows the process to exit.
References: src/atomicfile.rs• L25-31 src/atomicfile.rs• L44-55 src/atomicfile.rs• L95-110 src/state_writer.rs• L1-12 src/state_writer.rs• L141-168 src/state_writer.rs• L252-288
State failure reporting
A state write failure is a persistence warning, not a cluster or watch failure. While the UI is active, the application shows the error in its status path. If shutdown begins before the UI handles the message, the writer keeps the failure and prints a summary after the terminal is restored.
References: src/store.rs• L393-399 src/…/lifecycle.rs• L1026-1032 src/state_writer.rs• L69-109 src/state_writer.rs• L218-228 src/state_writer.rs• L282-288
Snapshot artifacts
A snapshot is a point-in-time copy of the current table view. It preserves the view context, cluster, namespace scope, resource, filter, visible columns, and visible rows so an engineer can inspect what the user saw without relying on the live cluster.
Snapshot capture
The :snapshot command captures the current resource table and writes it below the snapshots directory in the application state area. The command needs a selected resource and accepts text as the default format, with JSON and YAML available for structured exchange.
| Format | Main use | Extension |
|---|---|---|
| Text | Human review of a table with a metadata header | .txt |
| JSON | Structured exchange with scripts or tools | .json |
| YAML | Structured exchange that is easy to read and edit | .yaml |
The capture uses the current table values at the time of the command. Its name includes the resource scope and capture time, which makes several captures easy to distinguish. The file write runs outside the immediate UI action, and the application reports its result back to the active view.
References: src/snapshot.rs• L1-12 src/snapshot.rs• L14-42 src/snapshot.rs• L44-59 src/snapshot.rs• L61-111 src/…/snapshot.rs• L5-43 src/…/snapshot.rs• L46-83 src/diagnostics.rs• L35-52 src/diagnostics.rs• L371-382
Snapshot review and removal
The :snapshots command opens a browser of saved snapshot files. The browser sorts them by file change time and shows age and name. Opening a snapshot displays its stored text as stale point-in-time data; it does not query the cluster or apply the snapshot back to the live view. The browser can delete a selected snapshot.
References: src/…/snapshot.rs• L85-129 src/…/snapshot.rs• L131-184 src/…/snapshot.rs• L188-209
Diagnostic bundles
A diagnostic bundle is a Markdown handoff document for one selected Kubernetes object. It joins the object with related evidence so application and platform teams can review one incident without collecting each source by hand.
Bundle evidence
The bundle gathers evidence around the selected object in a fixed review shape. The selected object is the anchor; related pods, the owner, events, the explanation, the session timeline, bounded logs, and a metrics snapshot add context when available.
| Evidence | Role in the handoff |
|---|---|
| Resource YAML | Describes the selected object |
| Owner YAML | Shows the first known owning object |
| Related pods and events | Shows nearby workload and event state |
| Explanation | States the application's findings about the object |
| Session timeline | Records changes observed in the current Sofka session |
| Logs | Adds recent lines from a bounded set of pods |
| Metrics | Adds the current CPU and memory sample when available |
The bundle records what it included and what it withheld. Missing cluster data appears as an absent or empty section rather than blocking the whole handoff. Helm release views do not support this workflow.
References: src/…/bundle.rs• L8-26 src/…/bundle.rs• L27-81 src/…/bundle.rs• L86-155 src/…/bundle.rs• L196-215 src/…/bundle.rs• L229-260
Bundle protection
Bundle generation removes values that can expose credentials before it renders the document. It redacts Secret data, credential-like annotations, and the last-applied configuration. It also removes managed-field noise and counts environment variables that refer to Secrets without copying their values.
The bundle can anonymize the context and cluster names. Log line and pod limits bound the amount of live data collected, which keeps the artifact suitable for review and sharing. The manifest states the redactions and the anonymization choice so a reader can judge the evidence limits.
References: src/bundle.rs• L1-9 src/bundle.rs• L16-24 src/bundle.rs• L27-63 src/bundle.rs• L66-94 src/…/bundle.rs• L53-55 src/…/bundle.rs• L157-227 src/config.rs• L480-507
Artifact workflows
Snapshots and bundles follow different trust and review paths. A snapshot saves the current table for later inspection. A bundle is first assembled and previewed, then explicitly saved as a file after the user reviews it.
The main stages are:
- The user starts a capture or selects an object for a bundle.
- Sofka gathers the current in-memory or cluster evidence without making the UI wait on the work.
- Sofka returns a save result to the active application generation.
- The user reviews the artifact where the workflow provides a preview.
- Sofka writes the artifact and reports the resulting path or the failure.
This diagram shows the relationship between persistent state, snapshot export and review, and bundle export.
flowchart LR
A[User view and choices] --> B[Persistent state]
B --> C[Next launch or scoped view]
A --> D[:snapshot]
D --> E[Snapshot file]
E --> F[:snapshots review]
F --> G[Delete or keep]
A --> H[:bundle]
H --> I[Gather and redact evidence]
I --> J[Bundle preview]
J --> K[:bundle-save]
K --> L[Markdown handoff file]
Export and import boundaries
The supported application workflows export snapshots and bundles. Snapshot files can be reopened in the snapshot browser for review, but they are not restored into the live resource store. Bundles can be previewed and written to a temporary-directory file, but this area provides no bundle import or replay path.
Persistent state is the only artifact class that restores application choices automatically. Its load path restores namespace, sort, and fleet selections; snapshots and bundles remain records of past observations.
References: src/…/input.rs• L801-812 src/…/snapshot.rs• L5-43 src/…/snapshot.rs• L143-184 src/…/bundle.rs• L281-305 src/main.rs• L401-429 src/…/lifecycle.rs• L1516-1562
Change checklist
When these files or sections are changed, remember to consider these:
- A new persistent choice must have one clear scope, a load fallback, and a state path that does not overwrite user config.
- Changes to state serialization must remain compatible with hand-edited TOML and with the empty-state behavior for missing or invalid files.
- Changes to async state writes must preserve newest-per-destination ordering, shutdown draining, and visible failure reporting.
- Changes to snapshot fields or formats must update both capture output and the browser's stale-data review behavior.
- Changes to snapshot capture validation or save handling must keep the selected-resource rule, format names, output extension, and asynchronous result reporting aligned.
- Changes to bundle evidence must update the manifest and the redaction notes together so the handoff states its limits.
- Changes to bundle limits or identity handling must keep configuration, collection, and rendered metadata aligned.
- Changes to artifact save messages must keep generation checks and status claims paired so a late result cannot overwrite the active view's status.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Crash or competing writer during a state update | A partial state record could erase remembered choices | Write and flush a sibling temporary file, then rename it over the target |
| State directory or network filesystem stalls during quit | The process could remain blocked after the terminal is restored | Drain for a bounded grace period and detach the worker after the limit |
| State file is missing or cannot be parsed | The related remembered choice is lost for that run | Load an empty record and continue startup |
| Snapshot command has no selected resource or has an unknown format | No snapshot is created and the user receives a warning | Require a resource and accept only text, JSON, or YAML format names |
| Snapshot file cannot be created or written | The requested table is not available as a saved artifact | Create the destination directory and return the write error to the active view |
| Snapshot is treated as live data | An engineer may act on an old cluster view | Mark opened snapshots as point-in-time and likely stale |
| Bundle collection lacks events, owner, metrics, or logs | The handoff has less evidence than expected | Render bounded or empty sections and record included counts in the manifest |
| Bundle contains Secret data or credential-like metadata | Sharing the handoff could expose sensitive values | Redact before YAML rendering and list the redactions |
| Bundle is saved before review | The user may share an artifact without noticing its scope or redactions | Keep assembly and file save as separate :bundle and :bundle-save steps |
Key files
| File | Why to read it |
|---|---|
| src/diagnostics.rs | Defines the state, snapshot, and bundle directory roles |
| src/atomicfile.rs | Defines the crash-safe whole-file replacement used by persistent state |
| src/state_writer.rs | Defines ordered background writes, coalescing, shutdown, and failure reporting |
| src/nsmem.rs | Shows the namespace memory contract and its launch behavior |
| src/sortmem.rs | Shows the per-resource sort memory contract |
| src/fleet.rs | Shows the fleet membership state that overlays configuration |
| src/snapshot.rs | Defines snapshot data, formats, names, and storage location |
| src/…/snapshot.rs | Connects snapshot capture, browsing, stale review, and deletion to the application |
| src/bundle.rs | Defines redaction and the Markdown document model |
| src/…/bundle.rs | Connects evidence gathering, preview, and bundle saving to the application |
| src/…/lifecycle.rs | Handles asynchronous save results and persistent-state errors |
| src/config.rs | Defines bundle limits and anonymization settings |