core(logging): offload stderr/file log writes to dedicated background thread #129

Manually merged
github merged 1 commit from gh-pr/129/head into gh-pr/129/base 2026-12-01 20:11:59 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 13:37 UTC · original
Androtim:feat/iter130-logging-background-writer-thread → main · +160 −14 · 1 files · 1 commits · merged 2026-11-29 14:10 UTC

Summary

  • Offload stderr/console pipe and VICTORY_LOG_FILE writes onto a dedicated victory-log background thread fed via a bounded sync_channel (16,384 lines) in crates/victory-core/src/logging.rs, preventing submitting and title threads from blocking when log readers stall on 5-second telemetry bursts.
  • Count dropped lines non-blockingly in DROPPED and report them on the writer thread once it drains; preserve synchronous inline writes when VICTORY_LOG_SYNC=1 (or if spawning the writer thread fails).
  • Add queued_lines_deliver_and_full_queues_count_drops_without_blocking unit test.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy: asset policy: 303 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-core --lib --locked: 14 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings and --features diagnostics: 0 code warnings
**@⁠Androtim** on GitHub · 2026-11-29 13:37 UTC · [original](https://github.com/Androtim/MiniVI/pull/129) `Androtim:feat/iter130-logging-background-writer-thread` → `main` · +160 −14 · 1 files · 1 commits · merged 2026-11-29 14:10 UTC ## Summary - Offload stderr/console pipe and `VICTORY_LOG_FILE` writes onto a dedicated `victory-log` background thread fed via a bounded `sync_channel` (`16,384` lines) in `crates/victory-core/src/logging.rs`, preventing submitting and title threads from blocking when log readers stall on 5-second telemetry bursts. - Count dropped lines non-blockingly in `DROPPED` and report them on the writer thread once it drains; preserve synchronous inline writes when `VICTORY_LOG_SYNC=1` (or if spawning the writer thread fails). - Add `queued_lines_deliver_and_full_queues_count_drops_without_blocking` unit test. ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy`: `asset policy: 303 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-core --lib --locked`: **14 passed; 0 failed** - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` and `--features diagnostics`: **0 code warnings**
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:11:57 +00:00
github manually merged commit 080c87c40d into gh-pr/129/base 2026-12-01 20:11:59 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 14:07 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Review Summary

crates/victory-core/src/logging.rs cleanly offloads stderr and VICTORY_LOG_FILE writes to a dedicated victory-log thread fed by a bounded std::sync::mpsc::sync_channel (QUEUE = 16_384), preserving the pub fn init(default_level: &str) API and providing an opt-out via VICTORY_LOG_SYNC=1 (as well as a synchronous fallback in init_sync if spawning the thread fails).

  • Non-blocking hot path: Queued::make_writer returns a Line buffer whose Drop uses SyncSender::try_send, incrementing DROPPED on Full/Disconnected without blocking calling threads.
  • Lifecycle safety: If try_init() fails (e.g. subscriber already initialized), the SyncSenders are dropped and write_lines exits cleanly.
  • Tests & CI: CI is passing and the new unit test queued_lines_deliver_and_full_queues_count_drops_without_blocking exercises both delivery and non-blocking drop accounting.

Minor Non-Blocking Notes

  • Process exit tail: Because the victory-log thread is detached and the global tracing subscriber holds the SyncSenders for the process lifetime, lines still queued in the channel at exit may not be flushed (for short-lived runs or fatal diagnostics, VICTORY_LOG_SYNC=1 remains available).
  • Shared console/file drain & drop-notice cadence: write_lines services both To::Console and To::File on one thread, so a prolonged console pipe stall will also delay VICTORY_LOG_FILE writes until the queue fills; additionally, checking DROPPED.swap(0, Ordering::Relaxed) on every popped line can emit a [log] ... lines dropped line after each item during sustained saturation.

No blockers found; looks ready as a merge candidate pending maintainer review.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 14:07 UTC · [original](https://github.com/Androtim/MiniVI/pull/129#issuecomment-7257053984) <!-- minivi-triage v1 head=080c87c40d01c208e18e5be169bea7a6411a9812 verdict=merge-candidate ci=passing at=2026-11-29T14:07:41Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Review Summary `crates/victory-core/src/logging.rs` cleanly offloads stderr and `VICTORY_LOG_FILE` writes to a dedicated `victory-log` thread fed by a bounded `std::sync::mpsc::sync_channel` (`QUEUE = 16_384`), preserving the `pub fn init(default_level: &str)` API and providing an opt-out via `VICTORY_LOG_SYNC=1` (as well as a synchronous fallback in `init_sync` if spawning the thread fails). - **Non-blocking hot path:** `Queued::make_writer` returns a `Line` buffer whose `Drop` uses `SyncSender::try_send`, incrementing `DROPPED` on `Full`/`Disconnected` without blocking calling threads. - **Lifecycle safety:** If `try_init()` fails (e.g. subscriber already initialized), the `SyncSender`s are dropped and `write_lines` exits cleanly. - **Tests & CI:** CI is passing and the new unit test `queued_lines_deliver_and_full_queues_count_drops_without_blocking` exercises both delivery and non-blocking drop accounting. ### Minor Non-Blocking Notes - **Process exit tail:** Because the `victory-log` thread is detached and the global tracing subscriber holds the `SyncSender`s for the process lifetime, lines still queued in the channel at exit may not be flushed (for short-lived runs or fatal diagnostics, `VICTORY_LOG_SYNC=1` remains available). - **Shared console/file drain & drop-notice cadence:** `write_lines` services both `To::Console` and `To::File` on one thread, so a prolonged console pipe stall will also delay `VICTORY_LOG_FILE` writes until the queue fills; additionally, checking `DROPPED.swap(0, Ordering::Relaxed)` on every popped line can emit a `[log] ... lines dropped` line after each item during sustained saturation. No blockers found; looks ready as a merge candidate pending maintainer review. --- _Generated with Antigravity CLI (`agy`)._
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Androtim--MiniVI!129
No description provided.