Introducing a new way to review your PRs.

Read the announcement

nklmilojevic / sofka

A Kubernetes TUI, reimagined in Rust - built on kube-rs and ratatui, async-first from the ground up.

View on GitHub

19 documents · Updated Nov 4, 2026

docs / persistence-and-support-artifacts

Persistence and support artifacts

Sofka keeps small parts of a session across restarts and turns live cluster data into files that engineers can inspect or share. Its persistence and support paths separate user state, point-in-time views, incident evidence, and runtime diagnostics. They also place redaction and bounded collection around data that can contain credentials or private cluster details.

Artifact model

The system uses different artifact types for different questions. State files answer “what should the next session remember?”, snapshots answer “what did this table show then?”, bundles answer “what evidence explains this object?”, and diagnostics answer “how is this session working?”.

ArtifactMain purposeNormal destination or scope
Session stateRemember namespace, sort, and fleet choicesThe application state directory
SnapshotPreserve one table view with its scope and visible rowsThe state directory’s snapshots area
Diagnostic bundleCollect bounded evidence for one selected objectA preview, then a saved temporary file
Runtime diagnosticsShow build, cluster, request, config, and storage factsThe :info view or a headless report
Application logRecord structured events for later reviewThe state directory’s logs area when enabled

The two child pages provide the detailed paths for these groups: State, snapshots, and bundles covers state and export mechanics, while Diagnostics, logging, and data protection covers runtime evidence and safety controls.

This diagram shows how a live session becomes durable state or support material while passing through the shared data-safety boundary.

flowchart LR
    A[Live session] --> B[Remembered UI state]
    B --> C[State files]
    A --> D[Table capture]
    D --> E[Snapshot file]
    A --> F[Selected object and live evidence]
    F --> G[Bundle preview]
    G --> H[Saved bundle]
    A --> I[Runtime events and request facts]
    I --> J[Diagnostics and logs]
    J --> K[Redaction and bounded output]

Durable session state

Remembered choices

Sofka persists choices that improve the next session without changing the user’s main configuration. It remembers the last namespace for each context, the sort for each resource kind, and the selected fleet additions or removals in separate state files. The configured values remain the base; remembered values act as a session-specific overlay.

References: src/nsmem.rs• L1-9 src/sortmem.rs• L1-9 src/fleet.rs• L14-18

State write lifecycle

State changes leave the event loop and enter one ordered writer. The writer keeps the newest queued value for each destination, replaces each file as a complete unit, and reports failures to the live status area or the exit summary. This keeps disk delay from blocking input while preserving the order of rapid changes.

The state root uses XDG_STATE_HOME when set, then the user’s local state directory, with a temporary fallback when no home is available. Logs and snapshots live below this root, while bundles use the system temporary directory.

References: src/state_writer.rs• L1-12 src/state_writer.rs• L141-167 src/state_writer.rs• L252-287 src/atomicfile.rs• L25-32 src/diagnostics.rs• L35-68

Export artifacts

Table snapshots

A snapshot preserves the current table as a point-in-time record. It includes the active context, cluster, namespace scope, resource, filter, columns, and visible rows. The user can save it as aligned text, JSON, or YAML, then browse, open, or delete saved captures. The browser marks an opened snapshot as stale because it is not a live view.

Snapshot capture uses the table’s displayed columns and visible rows, including current live cell values where available. This keeps the saved view aligned with what the user sees instead of creating a separate cluster query. Snapshots are useful for comparing what the application showed with what the cluster shows later. They are not the same as the one-frame --snapshot mode used for a single captured run.

References: src/snapshot.rs• L1-8 src/snapshot.rs• L44-70 src/snapshot.rs• L176-180 src/…/snapshot.rs• L5-43 src/…/snapshot.rs• L46-83 src/…/snapshot.rs• L85-105 src/…/snapshot.rs• L149-190 src/…/snapshot.rs• L194-214

Diagnostic bundles

A diagnostic bundle gathers bounded evidence about one selected resource into a Markdown document. It joins the resource and owner data with related pods, events, explanation findings, session timeline entries, metrics, and recent logs. The application shows the bundle before saving it, so an engineer can review the evidence and the redaction manifest first.

Bundle scope is controlled by the bundle settings. The settings can hide context and cluster names, limit recent log lines per pod, and limit how many pods contribute logs. The saved file uses a generated name in the temporary directory and is written only after the preview step.

References: src/…/bundle.rs• L8-25 src/…/bundle.rs• L27-81 src/…/bundle.rs• L134-177 src/…/bundle.rs• L196-227 src/…/bundle.rs• L262-305 src/config.rs• L480-507

Diagnostics and logging support

Runtime diagnostics

The :info view is a compact support report for the current session. It brings together build and directory facts, cluster identity, discovery and metrics status, watch health, recent action failures, API request latency, active configuration, logging status, and state-write errors. It also surfaces configuration and discovery warnings so a support report includes problems that may otherwise appear only briefly in the status area.

The report uses identifiers, paths, counts, and bounded error text rather than dumping full cluster objects. Values that can echo a request or credential pass through the shared text safety layer before they reach the view or a headless report. The final diagnostic lines pass through that safety layer as well, which keeps the displayed report consistent when new report sections are added.

References: src/…/diagnostics.rs• L3-12 src/…/diagnostics.rs• L17-75 src/…/diagnostics.rs• L77-145 src/…/diagnostics.rs• L149-171 src/diagnostics.rs• L307-382 src/diagnostics.rs• L411-437

Structured application logs

Application logging is off by default and can be enabled at a chosen level. Enabled logs use one structured line per event and write in the background to a rotating file under the state directory. A bounded queue drops new lines when the writer cannot keep up, so a slow disk cannot freeze the user interface; the diagnostics view reports the drop count.

The log keeps one previous file generation and stops waiting after a short shutdown grace period. This makes logs useful for post-session review without allowing a stuck filesystem to prevent the application from exiting.

References: src/applog.rs• L1-19 src/applog.rs• L32-43 src/applog.rs• L149-186 src/applog.rs• L188-206 src/applog.rs• L274-345

Sensitive data protection

Sensitive data protection is shared across logs, diagnostics, and bundle object data. The redaction layer masks credential-like key values, bearer and basic credentials, JWT-shaped values, URL user information, and literal IP addresses. Bundle object handling also removes noisy management fields, masks credential-like annotations, and replaces all values in Kubernetes Secret data and string data with a redaction marker.

The protections have different coverage. Resource YAML receives object redaction, while structured log and diagnostic text receives text redaction. Bundle log excerpts are limited by count and pod number, but the preview and manifest remain important because bounded evidence is not the same as proof that every log message is safe to share. Optional anonymization hides the selected context and cluster names.

Transport support keeps certificate checks in place when a configured CA is accepted for the supported case. It does not turn a certificate failure into an unverified connection, which protects the path used to gather support evidence.

References: src/redact.rs• L1-13 src/redact.rs• L21-51 src/redact.rs• L72-93 src/bundle.rs• L1-9 src/bundle.rs• L16-63 src/server_tls.rs• L22-49 src/server_tls.rs• L74-108

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the state root rules aligned with every consumer that reports or writes state, logs, snapshots, and bundles.
  • Keep each remembered-state model aligned with its load, save, and state-writer path so a new field does not silently disappear between the UI and disk.
  • Keep snapshot metadata and the table capture path aligned when columns, filters, namespace scope, or row rendering change.
  • Keep snapshot format selection, asynchronous save status, and snapshot browsing aligned when capture or file handling changes.
  • Keep bundle settings, preview text, manifest counts, and saved output aligned when evidence limits or redaction rules change.
  • Keep the redaction vocabulary aligned across free-form diagnostics and structured fields, especially when a new credential-bearing value reaches an output path.
  • Keep logging back-pressure and shutdown behavior visible in diagnostics so dropped or delayed support evidence is not mistaken for a complete record.
  • Keep :info warning sources and their safe display path aligned when configuration, discovery, or session health reporting changes.

Important failure modes

TriggerConsequenceGuard
State directory cannot accept a writeA namespace, sort, or fleet choice may not survive the sessionThe background writer reports the failure in the UI and keeps unacknowledged failures for the exit summary
Crash or power loss during a small state-file updateA remembered choice could otherwise become a partial fileState files are written to a sibling temporary file and replaced as a whole
A slow or wedged log filesystemInput handling could stall or shutdown could hangLogs use a bounded queue, drop-count reporting, rotation, and a bounded shutdown wait
A snapshot save cannot create or write its destinationThe captured table is not available for later reviewThe save runs as a separate task and returns a visible save result instead of treating the capture as durable
A snapshot is used as current cluster truthAn engineer may act on stale rows or scopeThe snapshot browser labels opened captures as point-in-time and likely stale
A bundle includes more evidence than the reviewer expectsThe file may expose cluster identity or sensitive operational textThe app previews the bundle, records included and redacted material, supports anonymization, and bounds log collection
An error or API URL echoes credentialsSupport output could disclose a token or private addressDiagnostics and structured log values pass through shared text redaction before output
A configured CA is used as a reason to skip certificate checksThe support path could connect to an untrusted endpointThe TLS path keeps name, validity, usage, and signature checks and only permits the narrow configured-CA case

Key files

FileWhy to read it
src/diagnostics.rsDefines the shared state, log, snapshot, and bundle locations and the common runtime report sections.
src/atomicfile.rsShows the durability contract for small state-file replacement.
src/state_writer.rsShows how UI state reaches disk without blocking the event loop and how write failures surface.
src/nsmem.rs, src/sortmem.rs, src/fleet.rsDefine the three remembered state models and their restart behavior.
src/snapshot.rs, src/…/snapshot.rsDefine snapshot contents, formats, storage, browsing, and stale-view behavior.
src/bundle.rs, src/…/bundle.rsDefine bundle assembly, object redaction, preview, evidence limits, and save flow.
src/redact.rsDefines the shared rules for masking credentials, URL user information, and IP addresses.
src/applog.rs, src/logfilter.rsDefine structured log output, back-pressure, rotation, shutdown, and log-view filtering.
src/…/diagnostics.rsShows what the engineer can inspect through :info and how the report is made safe to paste.
src/server_tls.rsDefines the certificate-check boundary used when configured CA data supports a connection.