The file /Users/jan/prg/ClusterCockpit/cc-backend/pkg/metricstore/metricstore.go has been updated successfully. (file state is current in your context — no need to Read it back)

	if Keys.Checkpoints.FileFormat == "wal" {
		// WAL files are deleted per-host inside ToCheckpointWAL workers.
		files, _, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())
	} else {

	if Keys.Checkpoints.FileFormat == "wal" {
		var successDirs []string
		files, successDirs, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())
		// The final binary snapshot now captures all in-memory data for these
		// hosts, making their current.wal redundant. The staging goroutines have
		// already exited, so remove the WAL files directly (the channel-based
		// RotateWALFiles is no longer safe to call). Without this, current.wal
		// files survive shutdown and keep growing across restarts.
		RotateWALFilesAfterShutdown(successDirs)
	} else {

-    // WAL files are deleted per-host inside ToCheckpointWAL workers.

-    files, _, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())

+    files, successDirs, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())

+    // The final binary snapshot now captures all in-memory data for these

+    // hosts, making their current.wal redundant. The staging goroutines have

+    // already exited, so remove the WAL files directly (the channel-based

+    // RotateWALFiles is no longer safe to call). Without this, current.wal

+    // files survive shutdown and keep growing across restarts.

+    RotateWALFilesAfterShutdown(successDirs)

files, err = ms.ToCheckpoint(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())


Bash

go build ./pkg/metricstore/... && echo "BUILD OK" && go vet ./pkg/metricstore/ 2>&1 | head


BUILD OK


Inefficient string concatenation in call to WriteString


Build passes. (The `walCheckpoint.go:659` lint warning is pre-existing in `joinSelector`, unrelated to this change.)

## Done

The fix is in `pkg/metricstore/metricstore.go`, `Shutdown()`:

```go
if Keys.Checkpoints.FileFormat == "wal" {
    var successDirs []string
    files, successDirs, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix())
    // ... remove now-redundant current.wal files directly ...
    RotateWALFilesAfterShutdown(successDirs)
} else {
    ...
}
```

**What was wrong:** On graceful shutdown the final `.bin` snapshot was written, but the `successDirs` return was discarded (`_`) and the WAL was never rotated. The old comment claimed `ToCheckpointWAL` deletes WAL files — it doesn't. The purpose-built `RotateWALFilesAfterShutdown` helper existed but was never called. So `current.wal` survived every clean shutdown, got replayed *and re-appended to* on the next start, and only ever reset at the 12h periodic checkpoint — hence unbounded growth across restarts.

**The change:** capture `successDirs` and rotate exactly those hosts' WAL files (mirroring the periodic-checkpoint path; staging goroutines are already stopped, so the direct-removal variant is correct here). Hosts with no fresh snapshot are deliberately left untouched so no uncaptured records are dropped.

You can verify end-to-end per the plan: start → ingest → stop (confirm `<ts>.bin` appears and `current.wal` is gone for active hosts) → restart/ingest/stop again → confirm WAL size resets each clean shutdown instead of accumulating.