forked from unom/punktfunk
Two bugs in the log shipper, both found by re-reading it rather than by a failing test, and both of the kind where the symptom is a missing log line — which is the one failure a logging path must not have. The recursion guard was held across the whole `await fetch`, and `enqueue` checked it. So every line logged while a POST was open was dropped, silently. That window is milliseconds when the host is healthy and much longer when it is not, and the lines lost are whatever a busy plugin happened to be saying — so the shipper was least reliable exactly when it was most needed. The flag now guards flush re-entry only (the interval can fire while a slow POST is still open, and two concurrent flushes would splice disjoint batches out of one queue and deliver them out of order). Nothing on the shipping path logs, so the recursion it was guarding cannot form; that is now a stated rule at the top of the file rather than a flag that costs real lines. An explicit `flush()` hit that same re-entry guard and returned having sent nothing. That is the shutdown path: the runner flushes once more after its units' finalizers have run, and those last lines are the ones that say whether the shutdown was clean. It now waits for an in-flight flush before starting its own. Both are covered by tests that fail against the previous code. The first needed a server that signals when it has the request — logging merely "after calling flush()" passes against the bug, because flush yields at its own awaits long before the fetch starts. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>