Skip to content

[None][test] Scan server logs incrementally while waiting for readiness - #22782

Open
chenfeiz0326 wants to merge 1 commit into
NVIDIA:mainfrom
chenfeiz0326:chenfeiz/perf-sanity-incremental-log-scan
Open

chenfeiz0326 wants to merge 1 commit into
NVIDIA:mainfrom
chenfeiz0326:chenfeiz/perf-sanity-incremental-log-scan

Conversation

@chenfeiz0326

@chenfeiz0326 chenfeiz0326 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

wait_for_endpoint_ready read every server log in full at each check, every 30 s. In a disaggregated perf-sanity e2e case, the benchmark rank waits this way on another node than the srun that appends the ctx and gen worker logs on Lustre:

  • each full read takes the log's locks away from that srun, which then forwards the ranks' stdout slowly;
  • a rank whose stdout pipe fills blocks until it drains, and the other ranks wait for it in their collectives.

MiniMax-M3's gen worker logs about 300 MB in its warmup, so its e2e startup ran up to 1,977 s longer than the same server in gen_only, which scans its log on its own node.

LogScanner (tests/test_common/error_utils.py) keeps each log's scanned offset and line count, so a scan reads only what the log gained since the last one. wait_for_endpoint_ready uses one per wait; check_error keeps its full scan.

Test Coverage

Case main #22374 #21628 gen_only: main / #22374 / #21628
TP2 + TP4 con1 1,854 → 1,886 2,396 → 1,420 3,353 → 1,408 1,825 / 1,408 / 1,376
TP2 + TP4 con64 1,638 → 1,563 1,436 → 1,186 952 → 940 1,533 / 1,156 / 917
TP2 + TP8 con1 2,102 → 1,549 1,167 → 1,170 2,027 → 1,165 1,542 / 1,144 / 1,153
TP2 + DEP8 con128 1,068 → 1,060 1,816 → 802 571 → 579 1,050 / 798 / 569

With this change every e2e gen server starts within 61 s of its gen_only server (before: up to +1,977 s). Sampled during the warmup, the thread of the srun that writes the gen log waited on Lustre locks in 37 of 40 samples before this change, and in none of 40 after it.

PR Checklist

  • Please check this after reviewing the above items as appropriate for this PR.

🤖 Generated with Claude Code

Dev Engineer Review

  • Incremental scan (LogScanner): Each scan call reads only bytes appended since the previous call. It advances the offset only past complete lines.
  • Partial-line duplicates: An incomplete trailing line is checked on the current scan. It is checked again after it completes, because the offset does not advance past it. An error keyword in that line is reported twice. Confirm that duplicate reports are acceptable, or skip the partial line.
  • Rotation and truncation gap: The reset runs only when size < offset. If a log is replaced and grows past the old offset between scans, the scanner skips the new content from the start of the file. Note this limit in the docstring or handle it with an inode or identity check.
  • Line handling: The bytes are split on \n, then decoded through TextIOWrapper. This matches the earlier text-mode behavior for \n endings. A file that uses only \r line endings is not split the same way.
  • check_error refactor: Keyword matching moved into _error_lines. check_error keeps its full-scan behavior.
  • wait_for_endpoint_ready: It creates one scanner per wait and calls it for each check file. The error-reporting path is unchanged.
  • Scope: Both changes are in test helper code under tests/test_common/. No production code changed.

QA Engineer Review

  • Files changed: tests/test_common/error_utils.py (modified) and tests/test_common/http_utils.py (modified). Both are test helpers. No test functions, test IDs, or waivers changed in this diff.
  • Test lists: No test-db/ or qa/ list entries changed.
  • Coverage gap: The diff adds no unit tests for LogScanner. The cases below are not covered by changes in this diff:
    • Partial trailing line, then completion.
    • Log shrink or reset.
    • Missing file and size-lookup error.
    • Repeated scans with no new content.
  • Reported test: The PR objectives cite tests/unittest/others/test_http_utils_fail_fast.py. That file is not in this diff. Its result cannot be confirmed from this diff.
  • Coverage verdict: insufficient

Per-File QA Perspective

  • tests/test_common/error_utils.py: Check that check_error results match the old output. Check that an error line split across two scans is reported once, or document the double report. Check that a truncated log restarts from line 1.
  • tests/test_common/http_utils.py: Check that a failing server log still stops the wait and prints the server-log tail. Check that repeated checks report new errors only.

wait_for_endpoint_ready re-read every server log in full at each check
(every 30 s). In disaggregated perf-sanity e2e runs the benchmark rank
polls from another node than the srun that appends the ctx and gen
worker logs, on Lustre: each full re-read takes the file's locks away
from that srun, which then forwards the ranks' stdout slowly, and a rank
whose stdout pipe fills blocks until it drains, with the other ranks
waiting for it in their collectives. MiniMax-M3's gen worker logs about
300 MB in its warmup, and its e2e startup lost up to 33 minutes this way.

LogScanner keeps each log's scanned offset and line count, so a scan
reads only what the log gained since the last one; check_error keeps
its full scan.

Signed-off-by: chenfeiz0326 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change centralizes error-line matching, adds a stateful scanner that reads newly appended log content, and uses one scanner during endpoint-readiness polling. The scanner tracks offsets and line numbers per path and rechecks incomplete trailing lines on the next scan.

Changes

Incremental log scanning

Layer / File(s) Summary
Shared matching and incremental scanning
tests/test_common/error_utils.py
_error_lines centralizes keyword matching for check_error and LogScanner. The scanner tracks offsets and line numbers per path, handles log shrinkage, and rechecks incomplete trailing lines.
Readiness polling integration
tests/test_common/http_utils.py
wait_for_endpoint_ready creates one LogScanner for its polling loop and uses it to scan each existing server log.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: bowenfu

Merge Risk: Minimal · up to 209ab

This change makes endpoint-readiness polling read only newly appended server log content, which reduces log contention in perf-sanity runs. It affects test utilities only, and no concrete defect was established, so merge risk is minimal.

Security architecture risk: Low · up to 209ab

The change is limited to test startup checks. If a log is replaced during a wait, the check can miss an error and allow the test to proceed. No expansion of production access or permissions was identified.

Retained concerns

  • Low · reliability · observed: A replacement or truncate-and-regrow at the same path can leave the scanner using a cursor from the old contents. If the file is at least as large as the saved offset, the next poll skips the prefix that the base implementation would have checked. This can let a test proceed after a missed startup error if the health endpoint returns 200.
Security review details

Security Blast Radius

  • inferred — The observed effect is confined to readiness decisions in repository test and performance-harness callers. The change does not add a network listener, a file writer, or state shared across waits.

Trust Boundaries and Controls

  • observed — In the inspected distributed caller, the harness supplies the log filenames from its job output directory. The health response determines readiness but does not select which files are scanned.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: log scanning in wait-for-readiness now reads only new content (incremental). It follows the repository template with [None][test] and a short summary. It matches the c…
Description check Passed The description covers the problem, the fix (LogScanner with per-log offsets and line counts), test coverage (a unit test run plus before/after e2e timing tables), and the checklist. It explains what …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: log scanning in wait-for-readiness now reads only new content (incremental). It follows the repository template with [None][test] and a short summary. It matches the changeset, which adds LogScanner and wires it into wait_for_endpoint_ready.

Full details: Description check

Explanation

The description covers the problem, the fix (LogScanner with per-log offsets and line counts), test coverage (a unit test run plus before/after e2e timing tables), and the checklist. It explains what and why. It does not follow the template's exact section layout for the Test Coverage and PR Checklist items, since the checklist is only ticked with a generic box and the template's review items are not addressed one by one. These gaps are minor, and the core content is complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e5768a2 and 209ab19.

Files selected for processing: 2

  • tests/test_common/error_utils.py
  • tests/test_common/http_utils.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@brnguyen2 brnguyen2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The before/after table makes a clear case for the incremental scan. Two things should change before merge:

  1. Partial trailing line: see the inline comment. Scanning it can false-fail on benign pip-retry lines.

  2. No tests for LogScanner: tests/unittest/others/test_http_utils_fail_fast.py already has tmp_path fixtures for check_error. Please add a few cases that append to a log between scan() calls, and check:

    • only new lines are reported, with correct absolute line numbers;
    • a line written without its newline is handled (whatever the policy ends up being);
    • a pip-retry line split across two scans is not reported;
    • a truncated or shrunk log is rescanned from line 1.

    Running the existing pip-retry/benign parametrizations against both check_error and LogScanner.scan would lock in parity cheaply.

# A last line without its newline is checked now, and read again once it is complete.
complete = data.rfind(b"\n") + 1
lines = _text_lines(data[:complete])
error_lines = _error_lines(lines, num_lines + 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scanning the unfinished last line can fail the wait on a benign line. is_benign_line doesn't work on a prefix: the pip rule is PIP_TIMEOUT_RETRY.fullmatch(line). If a poll lands while WARNING: Retrying (...) after connection broken by 'ReadTimeoutError(...)': /simple/... is half-written, the prefix doesn't match, TimeoutError hits, and wait_for_endpoint_ready aborts on that first hit. Worker stdout redirected to a file is block-buffered and forwarded by srun, so cut-off lines at EOF are common, especially in the high-volume warmup this PR targets.

The tail is rescanned once its newline arrives, so dropping these two lines loses nothing except an error line with no trailing newline from a process that has already exited, and fail_if_proc_died covers that case. If you keep scanning the tail, add a test that splits a pip-retry line across two scan() calls.

This branch has not been deployed

No deployments
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