fix(cli/train): bound the training log fetch with a deadline - #2594
Open
spal1 wants to merge 1 commit into
Open
Conversation
`truss train logs` (without --tail) paginates forward from the job's first log with one request per batch of MAX_BATCH_SIZE lines, and had no wall-clock bound. A chatty job outruns any caller timeout, so automation that shells out to the CLI reports its own timeout instead of the job's logs. Concretely: basetenlabs/ml-cookbook's training smoke tests have been red since 2026-06-23, and every run's only visible error is `subprocess.TimeoutExpired: ... 'truss', 'train', 'logs' ... timed out after 300 seconds` — the actual training failure (an HF download 403) was never printed. Add a deadline (60s default, overridable) to BatchedTrainingLogsFetcher. On expiry it stops, returns the logs collected so far, and prints a warning that the view is partial. Also drop a dead termination branch: the `len(batch_logs) == 0` check duplicated the `not batch_logs` check above it, so the "fewer logs than batch size means done" intent in its comment never ran. Terminating on a short batch would be wrong anyway, since the query window is capped at 2h and a longer job still has logs past it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
truss train logs(without--tail) could run essentially forever. It now stops at a deadline and returns the logs it has.Why
The non-tail path paginates forward from the job's first log, one request per
MAX_BATCH_SIZE(1000) lines, with no wall-clock bound (get_training_job_logs_with_pagination). A chatty job needs many sequential requests, so the command outruns whatever timeout the caller imposed, and the caller reports its own timeout instead of the job's logs.This is not hypothetical.
basetenlabs/ml-cookbook's training smoke tests have been red every scheduled run since 2026-06-23, and the only error visible in any of those runs is:The actual failure (an HF weights download returning 403, so
train.pydied withOSError: Can't load the model for 'Qwen/Qwen3-0.6B') never made it to CI output. Six weeks of failures all looked identical and none of them named the cause. I had to pull the logs out of Loki by hand to find it.How
timeout_sec(default 60s) toBatchedTrainingLogsFetcherandget_training_job_logs_with_pagination. On expiry the iterator stops, the caller gets the logs collected so far, and a yellow warning says the view is partial.if len(batch_logs) == 0duplicated theif not batch_logscheck immediately above it, so the "fewer logs than the batch size means we've reached the end" intent stated in its comment never actually ran. Terminating on a short batch would be wrong regardless, since the query window is capped at 2h and a longer-running job still has logs past it, so I corrected the comment to describe what the code does rather than making the code match the old comment.Testing
uv run pytest truss/tests/remote/ -q— 207 passed.test_get_training_job_logs_with_pagination_stops_at_timeoutdrives a fetcher whose batches never run out and asserts the deadline ends the scan with the first batch's logs intact.Follow-ups (not in this PR)
Two things I noticed and deliberately left alone:
test_get_training_job_logs_with_pagination_max_iterationsasserts that a repeated, non-advancing batch producesMAX_ITERATIONS * batch_sizelogs from 10,000 identical API calls. That encodes a pathological case as expected behavior. A guard that stops when the window fails to advance would be the real fix, but it changes that test's contract, so it belongs in its own PR._process_batch_logsdivides byNANOSECONDS_PER_MILLISECOND, i.e. they exercise a window arithmetic that production never produces.Separately, for triaging a failed job the forward
direction: "asc"scan is backwards: you read startup noise first and the error you want is last. A--last Nmode usingdirection: "desc"in a single request would make failure triage instant. Happy to file that if it sounds useful.