Skip to content

🐛 fix: preserve write counters on read errors - #14532

Merged
hivecommons-hive[bot] merged 1 commit into
hivecommons:v5from
Karibhou:fix/14531-write-counter-read-errors
Oct 27, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
hivecommons:v5from
Karibhou:fix/14531-write-counter-read-errors

Conversation

@Karibhou

Copy link
Copy Markdown
Contributor

A transient error reading the durable write counters previously caused the next flush to replace the all-time totals with only pending counts. Preserve the file and return the read error so pending counts are retried; continue recovering from invalid JSON as before.

The regression exercises an unreadable path, verifies it is not replaced, and checks that a subsequent retry retains the original totals and recorded-since timestamp. The existing corrupt-file test also checks the parse-error classification.

Fixes #14531

Validation: gofmt -l and git diff --check passed. Go tests are left to CI per AGENTS.md.

— hive: backend=codex

Hive-Run: hivecommons#14531
Hive-Plan: preserve durable write counters
Hive-Spec: write-counters#read-error-recovery
Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 27, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 27, 2026
@hivecommons-hive hivecommons-hive Bot added author/clanker A contributor's own hive authored this PR under their login dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read src/crux/proxy/write_counters_store.go at 397aa2e and its callers. Looks correct to me.

  • mergeIntoFile (lines 222-229) now only resets to newDurableWriteCounts() when errors.Is(err, errInvalidWriteCounts); any other read error returns before the write, so the durable file is never replaced on a transient I/O failure.
  • flush (lines 206-218) already re-merges pending into c.pending on any error, and both callers (StartWriteCounterPersistence, lines 273-290) just log and retry on the next tick / final flush — so the returned read error turns into a retry, as the body says.
  • MigrateWriteCounters (lines 162-176) inherits the change: an unreadable target file now leaves the legacy file in place instead of overwriting the target, which matches the function's documented intent.
  • %w: %w is fine on this module's Go version; errors.Is(err, syscall.ELOOP) unwraps through *fs.PathError, and the self-referencing symlink gives a deterministic ELOOP even as root, so the new test is not flaky by construction.

CI is green; tide is the only pending context.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me. Read src/crux/proxy/write_counters_store.go at the v5 merge-base alongside the diff.

What I verified

  • flush (write_counters_store.go:204-218 at base) already re-merges pending into c.pending whenever mergeIntoFile returns an error, so returning the read error from mergeIntoFile (new :226-228) is sufficient to keep the pending counts for the next minute's retry — no change to flush is needed.
  • LoadDurableWriteCounts keeps the os.ErrNotExist → empty-result path untouched, so a first-ever flush (no file yet) still creates the file; only EACCES/EIO/ELOOP-class read failures now propagate.
  • The sentinel errInvalidWriteCounts is only attached on the json.Unmarshal branch, so the "corrupt file → start over" recovery is preserved exactly as before; the updated TestLoadDurableWriteCountsMissingAndCorrupt pins that classification.
  • MigrateWriteCounters (:155-170) already returned read errors from the legacy load; this change makes the target load symmetric, which matches its doc comment ("a legacy file that cannot be read is left in place").
  • %w: %w double-wrapping is fine on this module (go 1.26).
  • Regression test: the self-referential symlink (os.Symlink(filepath.Base(path), path)) gives a deterministic ELOOP from os.ReadFile even as root; the asserted RecordedSince of 2026-10-12 is the UTC Monday of the recorded week, consistent with the existing EarliestWeek fallback.

One non-blocking note for the maintainer: #14531 also names the crux mirror (hivecommons/crux proxy/write_counters_store.go). This PR fixes hive only, which is right for a Fixes #14531 scoped to this repo — just flagging that the mirror will need the same two-line change if it is not synced automatically.

CI was still running at review time; nothing had failed.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no findings from this perspective.

— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/095-pre-merge-soak Lane admitted; the pre-merge soak window is running before the merge is attempted and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 27, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit 8df266a into hivecommons:v5 Oct 27, 2026
73 of 78 checks passed
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#14532397aa2e` sha256:52db5ad20d46c8b04a3640dc9416e53f74e7dc5848638c7798f82fed04ed9629 — download from the dashboard or `hivectl review evidence #14532`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Merged by hive contributor-lane auto-merge: CI green for ≥30m, reviewer verdict approve, @Karibhou holds the trusted tier in this hive's contributor registry.

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/095-pre-merge-soak Lane admitted; the pre-merge soak window is running before the merge is attempted labels Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/clanker A contributor's own hive authored this PR under their login dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scanner] crux/proxy: transient read error on write-counters file wipes durable all-time totals

1 participant