Skip to content

fix: apply post-check propagation delay per file with elapsed-time credit#224

Closed
javi11 wants to merge 2 commits into
mainfrom
claude/wonderful-lehmann-d539dd
Closed

fix: apply post-check propagation delay per file with elapsed-time credit#224
javi11 wants to merge 2 commits into
mainfrom
claude/wonderful-lehmann-d539dd

Conversation

@javi11
Copy link
Copy Markdown
Owner

@javi11 javi11 commented May 9, 2026

Summary

  • Add + "postedAt time.Time" + to + "Post" + ; set in + "postLoop" + after upload success.
  • In + "checkLoop" + , replace the + "firstPost" + -gated single wait with a per-file residual: + "remaining = RetryDelay - time.Since(post.postedAt)" + , clamped to 0.
  • Each file now actually gets its own propagation grace period before STAT, while files that sat in the queue long enough still pay no extra wait.

Why

Refs #184. The previous behavior only sleeped before file 1's check; files 2..N within a multi-file + "Post()" + call were STAT'd immediately. With small/fast files that risks false-negative + "STAT" + results that trigger needless reposts. This is the first half of the fix javi11 outlined in the issue's penultimate comment ("propagation delay for all the post file instead of just one article").

Out of scope

Async lifecycle refactor (move + "postLoop" + / + "checkLoop" + off + "Post()" + 's critical path so + "Post()" + returns after upload, not after check) — needed to actually fix throughput at + "MaxConcurrentUploads=1" + . Tracked separately.

Test plan

  • + "go build ./internal/poster/..." +
  • + "go test -race -count=1 ./internal/poster/..." + (passes, 1.5s)
  • Manual smoke: post_check enabled with delay=10s, multi-file post — verify each file shows ~10s wait deadline only when its post completion is within the delay window.

javi11 added 2 commits May 9, 2026 10:52
…edit

Track postedAt on each Post when its upload completes, and in checkLoop
wait only the remainder of PostCheck.RetryDelay that hasn't already
elapsed since that file finished posting. Removes the firstPost-gated
single wait, which caused files 2..N within a multi-file Post() call to
skip the propagation grace period entirely while file 1 paid the full
delay.

Refs #184.
Issue #184: with MaxConcurrentUploads=1, every uploaded file paid the full
PostCheck.RetryDelay because each file was its own Post() call that spawned
a fresh per-call checkLoop and only returned after STAT verification.

Refactor postLoop and checkLoop to be poster-lifetime goroutines spawned
once (lazily) per poster instance, sharing the postQueue and checkQueue.
Post() now returns as soon as all uploads complete; the propagation delay
and STAT verification run in the background on the long-lived checkLoop.

Permanent verification failures (articles exhausting MaxRePost) are now
surfaced via a per-call CheckExhaustedCallback set on the Postie wrapper
via SetVerificationCallback. The processor wires this callback to
queue.AddPendingArticleChecks, so the existing PostCheckRetryWorker keeps
draining failures from the deferred-check DB queue exactly as before.

Behavior changes:
- Post() no longer returns DeferredCheckError synchronously; verification
  results are reported asynchronously through the existing deferred path.
- Non-deferred verification exhaustion (post_check.deferred_check_delay=0)
  is now logged-only instead of returned as an error from Post(); the
  upload itself still succeeds.
- poster.Close() now drains the long-lived loops with a 30s soft timeout
  before force-cancelling.

Compile-time API additions:
- poster.Poster gains PostWithCallback(ctx, files, rootDir, nzbGen,
  relativePaths, completedItemID, onCheckExhausted).
- pkg/postie.Postie gains SetVerificationCallback(itemID, cb).

Existing call sites in pkg/postie and the CLI keep working unchanged
because callbacks default to nil (matches the legacy "drop on failure"
behavior). DeferredCheckError type and the old synchronous catch sites
in pkg/postie + processor remain as harmless dead code; can be removed
in a follow-up.

Refs #184. Builds on #224 (Phase 1, per-file postedAt).
@javi11 javi11 closed this May 9, 2026
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.

1 participant