Skip to content

debug: identify the writer that persists NextUID via flush()/createFresh() (#644/#647)#652

Merged
0kaba0hub merged 1 commit into
mainfrom
debug/flush-createfresh-caller-breadcrumbs
Jul 19, 2026
Merged

debug: identify the writer that persists NextUID via flush()/createFresh() (#644/#647)#652
0kaba0hub merged 1 commit into
mainfrom
debug/flush-createfresh-caller-breadcrumbs

Conversation

@0kaba0hub

Copy link
Copy Markdown
Owner

Summary

Live evidence on 2.1.13 (after #645 and #648): the properly-locked reload (locked=true) already observes NextUID=1 on disk at the moment it reads — the regression is committed to the base .index file before that read, not caused by it. This rules out withFolderRO's unlocked reload (#647) as the direct writer in this specific instance and points back to whichever flush()/createFresh() call persisted the bad value in the first place.

This PR

  • flush() now logs its caller (via runtime.Caller) and the NextUID/MessagesCount it's about to persist — the single choke point that writes fs.file.Header as ground truth and discards the log, called from compactLogIfNeeded, SaveFolder, RecomputeVSize, and reload's indexid-mismatch recovery.
  • createFresh() now logs its caller and requested UIDValidity on every invocation, at WARN (survives without needing debug level enabled) — it unconditionally resets NextUID to 1, correct only for a genuinely first-ever OpenFolder or the documented post-corruption fallback. An invocation on an already-established folder (one that delivered mail earlier in the same run) is the bug.

Purely additive logging — no behavior change. go test ./... green.

…esh() (#644/#647)

Live evidence on 2.1.13: the properly-locked reload (locked=true) already
observes NextUID=1 on disk at the moment it reads — the regression is
committed to the base .index file BEFORE that read, not caused by it. This
rules out withFolderRO's unlocked reload (#647) as the direct writer in this
instance and points back to whichever flush()/createFresh() call persisted
the bad value in the first place.

flush() now logs its caller (via runtime.Caller) and the NextUID/
MessagesCount it's about to persist — the single choke point that writes
fs.file.Header as ground truth and discards the log, called from
compactLogIfNeeded, SaveFolder, RecomputeVSize, and reload's
indexid-mismatch recovery.

createFresh() now logs its caller and requested UIDValidity on every
invocation, at WARN — it unconditionally resets NextUID to 1, correct only
for a genuinely first-ever OpenFolder or the documented post-corruption
fallback. An invocation on an already-established folder (one that has
delivered mail earlier in the same run) is the bug.

Purely additive logging behind LOG_LEVEL=debug (WARN for createFresh, to
survive without needing debug level enabled) — no behavior change.
@0kaba0hub
0kaba0hub merged commit 7dee7e6 into main Jul 19, 2026
3 checks passed
@0kaba0hub
0kaba0hub deleted the debug/flush-createfresh-caller-breadcrumbs branch July 19, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants