Repository navigation
Kaggle CI: dispatch the kernel and collect it later, instead of holding a runner - #10183
Conversation
…ng a runner The GPU jobs waited for their Kaggle kernel in a poll loop: 41.5 minutes for the notebook leg and 18.7 for Studio, measured on runs 33479481067 and 33486360729, almost all of it a runner doing nothing while Kaggle worked. Against a repository queue measured at 400-670 deep that is two machines per commit spent waiting on a third-party service. They now push and exit. `launch.py --dispatch` leaves the kernel running and returns in minutes; the result is collected afterwards by two independent routes: the next GPU run on the same account collects before it dispatches, and `kaggle-collect.yml` does it on a schedule, which is what covers a quiet repository. The account is the queue. There is no artifact, branch or database between the dispatching job and the collecting one; the SLUG carries the commit and the workflow, so a collector rediscovers everything from Kaggle's own listing: unsloth-t4-ci-n1a2b3c4d-9f8e kind, commit, uniqueness The prefix is unchanged, because that is what the gate's session survey matches to tell our kernels from a human's, and with the GitHub concurrency group no longer bounding anything it is the only thing left counting sessions against Kaggle's 2-per-account cap. Four consequences that had to be designed for rather than discovered: - The dispatching job succeeds by DISPATCHING, so it can no longer mean "the GPU tests passed". The verdict is a commit status, kaggle-t4-notebook or kaggle-studio-gpu, posted against the sha in the slug. Branch protection must require those contexts and not the jobs. A pending status goes up at dispatch so a required check that has not reported reads as waiting rather than as nothing. `dispatched` is deliberately not `pass`. - Orphans bill. The pushing job used to delete on every path out; the scheduled collector replaces that, with a 3h reap ceiling well under Kaggle's 12. - A commit already in flight is not dispatched again. - Results land on the sha in the slug, never on HEAD. collect.py touches only kernels `parse_slug` recognises. It enumerates a shared account and deletes what it collects, so anything unrecognised is invisible rather than skipped-with-a-warning. Evidence is downloaded before any delete, and a download that fails leaves the kernel alone for the next pass. infra and partial verdicts stay green: a red the author cannot act on is how a required check gets removed. tests/kaggle 951 passed. 22 mutations, 22 caught.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| # workflows: a ternary here would hand over the other account's token | ||
| # whenever this secret is empty, and the collector would then delete | ||
| # kernels belonging to an account it is not reporting for. | ||
| KAGGLE_API_TOKEN: ${{ secrets[matrix.secret_name] }} |
| id: collect | ||
| if: steps.recheck.outputs.should_run == 'true' | ||
| env: | ||
| KAGGLE_API_TOKEN: ${{ secrets[matrix.secret_name] }} |
| id: collect | ||
| if: steps.recheck.outputs.should_run == 'true' | ||
| env: | ||
| KAGGLE_API_TOKEN: ${{ secrets[matrix.secret_name] }} |
Run 33628507954 dispatched correctly and its summary still said
### Kaggle T4 smoke: PARTIAL
### Unsloth GPU smoke: PARTIAL
The reporters were gated on `hashFiles('kaggle_evidence/**')`, which is TRUE on
a dispatching run: launch.py writes launch_result.json into that directory
before it exits. The reporters then read a directory holding no executed
notebooks and print "half a comparison" for a kernel that is still queued.
PARTIAL is not red, so this was not going to block anything, but it is a
verdict about a run that has not happened, on the one workflow whose whole
failure mode is a result that reads as something it is not.
The condition now names the thing a report is made of. A dispatching run cannot
have an executed notebook; a collected one always does.
The guard was rewritten with the measurement in its docstring, because the
version that shipped accepted exactly the state that produced this: it asserted
the presence of the evidence DIRECTORY, which a dispatch creates and does not
fill. Mutation-tested by restoring the directory check.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6a7acf1b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CI_SLUG_RE = re.compile( | ||
| r"^(?:(?P<owner>[^/]+)/)?" | ||
| + re.escape(SLUG_PREFIX) | ||
| + r"(?:(?P<kind>[a-z])(?P<sha>[0-9a-f]{8})-(?P<uid>[0-9a-f]{4})" |
There was a problem hiding this comment.
Reject slugs with unknown workflow kind codes
The regex accepts every lowercase kind code, but parse_slug() returns a record even when that code is absent from CODE_KINDS. An older scheduled collector encountering a kernel dispatched by a newer workflow kind will therefore download and delete it, after which statuses_from() drops the record because its kind is None; this is especially plausible during the PR that introduces the new kind, since the dispatcher checks out the PR head while the scheduled collector runs the default branch. Return None for unknown non-legacy kind codes so an older collector leaves such kernels for a version that understands how to report them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed. Only two kinds exist and the dispatcher and the collector ship in the same commit; a kind added later can tighten the pattern in the change that adds it.
…status
Found by driving the real collector against a real finished kernel and then
running the workflow's own posting loop over what it emitted.
The slug carries 8 hex characters of the commit, because a full 40-character
sha plus the `unsloth-t4-ci-` prefix and the uniqueness suffix does not fit in
the 50 characters `_slugify` produces. The statuses API refuses that:
POST /repos/{owner}/{repo}/statuses/2ecb19df
422 "Sha must be a valid hex object ID"
Measured against a real repository, not inferred.
So every collected verdict would have 422'd, the `|| echo` beside the call
would have turned that into a warning nobody reads, and the commit would have
kept a PENDING check forever while the collection quietly succeeded and deleted
the kernel. Collection working and reporting nothing is the precise failure
this design exists to prevent, and it was one call from shipping.
The dispatching side was unaffected and hid it: "Mark the dispatch pending"
posts `steps.ref.outputs.ref`, which is the full sha, so the pending status
appeared correctly on hardware and looked like proof that posting worked.
Each posting loop now resolves the abbreviation through
`gh api repos/{repo}/commits/{sha} -q .sha` and posts the result. A commit that
no longer resolves -- a force-push while the kernel ran -- is REPORTED as a
warning naming the sha and skipped, rather than dropped silently, since a
silent skip is indistinguishable from a collection that found nothing.
Two guards, three mutations, all caught: posting to the abbreviation, removing
the lookup, and removing the unresolvable-commit warning.
tests/kaggle 953 passed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 135775b46f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if args.sha: | ||
| want = args.sha.strip().lower()[:8] | ||
| result["in_flight_for_sha"] = any( | ||
| k.get("sha") == want | ||
| and k.get("verdict") == "pending" | ||
| and (not args.kind or k.get("kind") == args.kind) | ||
| for k in result["kernels"] |
There was a problem hiding this comment.
Check all matching kernels before allowing another dispatch
When earlier terminal kernels consume the collection budget, the loop stops before appending the remaining entries from ours, but this duplicate guard searches only result["kernels"]. If a queued or running kernel for --sha appears after several slow evidence downloads, in_flight_for_sha is incorrectly left false and the calling workflow dispatches another session for the same commit; the gate can permit this because one existing CI kernel still leaves Kaggle's second slot free. Prioritize matching SHA/kind entries or determine their states independently of the evidence-collection budget.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed. ours is newest first and the kernel for the sha being dispatched is among the newest, so reaching it needs the whole 900s budget spent on newer kernels' downloads first. Not a case worth a code path.
…op the scheduled collector lying green Review round on the dispatch-and-collect design. Every change here is a verdict that could be wrong, lost, or posted for a kernel that does not exist: - The scheduled collector pinned kaggle==1.7.4.5, whose authenticate() cannot read KAGGLE_API_TOKEN (#9535), so every pass failed to authenticate; and an auth failure was a green no-op. It now installs the 2.2.4 the GPU workflows install and passes --require-auth, which makes an auth failure red with an error annotation. A fork job without the secret still skips. - The collector deleted a kernel before its status was posted, so a transient GitHub failure lost the verdict for good and left the commit pending forever. Collection now runs with --no-delete, post_statuses.py posts (a shared script: every field is its own gh argument, the slug's 8-character sha is expanded first, an unresolvable commit is reported and released), and collect.py --delete-collected releases only the kernels whose status was delivered. The three copies of the shell loop are gone. - fetch_evidence reports a spent budget or a lost notebook by flag, not by raising, and the flag was never read: the short set was judged and the kernel deleted. An incomplete download now judges nothing and keeps the kernel for the next pass. - Three workflows collect on one account and nothing serialises them. A kernel that vanishes under a collector (the other one deleted it) is now `gone` and posts nothing, so the loser of that race cannot post an infra success over the winner's real failure. - The scheduled pass judged every kernel against --expect 1, so a five-payload kernel that lost four passed. The driver now writes the count it was built for into the kernel log (KAGGLE_T4_CI_DRIVER_EXPECT) and the collector reads it off the evidence, the only record that survives dispatch; a kernel without the sentinel keeps the caller's number. - A malformed T4_SMOKE_REPORT line (a list, a bare string) raised out of extract_reports before the collector wrote a result, wedging every later pass on the same evidence. The extractor skips non-object lines and the collector records an unreadable report as infra and releases the kernel. - The pending status was posted whenever launch.py exited 0, which it does for every infrastructure stand-down, so a run that pushed nothing left a pending check no collector could ever replace. Gated on the launcher's own verdict output being `dispatched`. - The Studio workflow passed a raw workflow_dispatch ref as --commit-sha; slug_name silently fell back to the legacy unattributable form and the kernel ran, billed, and reported to nobody. The workflow now resolves the ref the way the notebook one does, and launch.py refuses a non-hex commit in dispatch mode. - The account walk stopped at twice the reap ceiling, so a pass delayed past that (an Actions outage, a deep queue) never saw the wedge it exists for. Recognised kernels are never aged out; the walk is bounded by pages. - Two kernels for one commit under one context (notebook slot 1 and slot 2) posted two statuses and the last one won. One status per (sha, context), a failure wins, and both kernels are released when it is delivered. Also drops out/launch_result.json, a local run's scratch that was committed by mistake, and ignores /out/. Merges main; the Report Studio gate keeps both conditions (evidence present and the kernel carried Studio).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0986e89cd4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| nothing: there is no commit to attribute it to, and inventing one is worse | ||
| than staying silent. | ||
| """ | ||
| out: dict[tuple[str, str], dict] = {} |
There was a problem hiding this comment.
Preserve failures across separate collection passes
The failure-wins aggregation exists only in this invocation's in-memory out dictionary. When two supported slot dispatches for the same SHA/context finish in different scheduled passes—or land on the two independently collected accounts—the first kernel is posted and deleted before the second is seen; a later passing kernel can therefore overwrite an earlier failure for the same required context. Fresh evidence in the current code is that aggregation is scoped to one collect_result.json, while delivered kernels are immediately removed, so no state remains to combine later results. Give concurrent experiments distinct contexts or retain a durable aggregate until every matching kernel completes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. Slot 2 is a manual dispatch-only opt-in, and the collector is stateless by design: it judges only what is on the account right now. Making a failure sticky across passes would leave a red on a commit after a flaky kernel (the GRPO leg crashes 44 percent of sessions) with no way to clear it short of hand-deleting statuses. A re-run replacing the status with the latest result is the intended behaviour.
| gh api "repos/$GITHUB_REPOSITORY/statuses/${{ steps.ref.outputs.ref }}" \ | ||
| -f state=pending -f context=kaggle-t4-notebook \ |
There was a problem hiding this comment.
Prevent a late pending status from replacing the verdict
The kernel becomes visible to independent scheduled and GPU collectors as soon as launch.py finishes its push, but this pending status is posted only after the launcher step returns. If a kernel fails quickly and another collector posts and deletes its terminal result before this step runs, this later pending update becomes the newest status for the context; with the kernel already deleted, no future pass can replace it and the commit remains pending indefinitely. The Studio workflow has the same post-dispatch ordering, so publishing pending and exposing the kernel to collectors must be made atomic or otherwise ordered against terminal publication.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable in practice. The pending status is posted seconds after the push returns, and a kernel needs minutes to boot, install and run before the collector can have a terminal verdict for it. The collector also only judges kernels whose status is complete or error, so it cannot post a result for a kernel that has just been dispatched.
…a definitive missing commit A download failure in collect_one was judged "infra", which post_statuses turns into a green status and --delete-collected then releases. One transient listing failure became the permanent loss of a real result. It is now "pending": no status, not deletable, retried next pass. resolve_sha collapsed every failed lookup into "the commit is gone". GitHub answers a genuinely missing commit with HTTP 422 "No commit found for SHA" (measured); a 5xx or a rate limit says nothing about the commit. The lookup is now tri-state and only the measured answer releases the kernel; anything else lands in the poster's failed set, which keeps the kernel for the next pass. Tests: the download-failure case asserts pending, not in DELETABLE and no status; a transient lookup keeps the kernel; resolve_sha separates ok, missing and error. Both mutations caught.
…solved sha, unknown plan is never a pass gate.py: every candidate account with a readable quota is surveyed for a kernel of this commit and kind BEFORE the selection loop picks one. The selection loop used to check only the account it was about to choose and returned on the first clear one, so a retry that found the preferred account free again dispatched a duplicate while the other account was still running the commit. Surveys are taken once per account and reused by the selection loop. collect.py / post_statuses.py: the collector no longer merges statuses whose shas are merely prefix-compatible. Whether an eight-character slug and a twelve-character one name one commit is a question only the commits API can answer, so post_statuses resolves every sha to its full form first and merges per (full sha, context) there, failure winning, slug lists unioned. collect.py: a notebook kernel with no KAGGLE_T4_CI_DRIVER_EXPECT line has an unknown plan rather than the caller's default. A failing report still fails; a clean set is reported as infra with the reason, so a kernel that lost legs cannot read as a pass. Studio kernels carry one report and keep the default. Guards: a gate driven end to end with stub surveys that reproduces the duplicate dispatch, both slug forms for one commit posting once, two commits sharing eight characters posting twice, and the unknown-plan verdicts. Each mutation-tested.
…ery client, cover the reaper window gate.py: `--slot`. Slot 2 is the documented opt-in for a second session on the same ref beside slot 1, so a kernel already running the commit is the point rather than a duplicate and no longer stands the run down; the notebook GPU job likewise withholds the sha from the collector's in-flight check on slot 2. The cross-account sweep asks every account with a usable client, whatever its launch eligibility: the account that just dispatched the commit is exactly the one likely to be short of quota, and skipping it handed the retry to the other account. All the surveys share ONE budget, so two slow accounts cannot outlive the job. Both workflows: the gate job names the commit the GPU job will test, resolving `unsloth_ref` the same way the GPU job does, instead of keying on github.sha; the gate job timeout is 15 minutes for the two-account worst case, asserted from the constants. Studio: `--budget-hours 4`. The kernel ceiling stopped being the worst case when the job stopped deleting its own kernel; a kernel that ignores its timeout is left to the collector's 3h age ceiling plus its schedule and job timeout, derived in the test for both legs. The evidence unpack is best effort like its siblings, and collect_evidence.py no longer raises on JSON that is not a notebook. Every guard mutation-tested.
… to a horizon, a reaped kernel is released not deleted launch.py / gate.py / collect.py: a slot-2 kernel carries its slot in the slug (`-2<uid>`; absent means slot 1, so every earlier slug still reads), and the in-flight check in the gate and in the collector matches on commit, kind AND slot. Slot 2 is a deliberate second session beside slot 1, so a slot-1 kernel no longer counts against it, while a retry of the slot-2 run itself, after its dispatcher exited with the kernel still up, is recognised as the duplicate it is. The unconditional slot-2 bypass is gone; the notebook workflow passes the slot to the gate, the collector and the launcher. collect.py: the account walk is no longer capped at five pages from page 1 every pass. The account is shared and human kernels are never deleted, so enough newer records above an uncollected kernel of ours made it unreachable forever. The walk now ends at the first page that is entirely older than a seven-day horizon with none of ours on it, at the pass deadline, or at a fifty-page backstop. collect.py: a reaped kernel's status says it is released for deletion, and says it was deleted only after a confirmed delete; the workflows collect with --no-delete and delete in a later step that can fail. Eight mutations caught.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3aac6e5d36
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| --label-name kaggle-studio-gpu-ci \ | ||
| --kernels 1 \ | ||
| --budget-hours 2 \ | ||
| --budget-hours 4 \ |
There was a problem hiding this comment.
Reserve for delayed scheduled collection
In a quiet repository, the scheduled collector is the only process that enforces the three-hour reap ceiling, but a ten-minute cron interval does not bound how long the workflow waits before a runner starts. If Actions delays scheduled jobs—especially relevant to the runner congestion described in these workflows—a wedged kernel can bill well beyond the 4 hours reserved here, despite the change explicitly noting that Kaggle's own timeout may not stop it. Base this budget on an independently enforced upper bound (or at least Kaggle's maximum exposure), rather than adding only the cron interval and collector runtime to three hours.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this one. There is no independently enforced upper bound to derive the budget from: the collector's ceiling is ours precisely because Kaggle's own 12h kill has been seen failing (a kernel two hours past its -t still RUNNING), and a delayed scheduled run is likewise unbounded. Pricing 12h into every admission would stand the Studio gate down below 22h remaining on a 60h account, for an exposure the reserve exists to absorb: BUDGET.md is explicit that the rate sets the expected spend and the reserve sets the ceiling, whatever the per-run arithmetic got wrong. The budget covers the reap window of a behaving system, and the derivation is documented in the workflow comment and BUDGET.md.
…d notebook cannot hide a failing report, an absent second account is not a broken one Both workflows: the gate job resolves `unsloth_ref` once and exports the commit; the GPU job's "Resolve the ref under test" takes that answer and keeps only the reachability fetch. Resolving a moving branch a second time after the job queued could name a commit the gate never keyed the account draw or the in-flight check on, and that commit's own run may already be out on the other account. The executable resolve tests now drive the gate's step for every shape of ref and the GPU step for the handoff, the empty answer and an unreachable commit. launch.py: extract_reports skips a notebook that is not an object and any cell or output that is not one. One malformed file used to raise out of the reader after a failing report had been parsed from its neighbour; the collector then replaced every report with none, judged the kernel infra, posted success and released it. collect.py: under --require-auth an EMPTY token is an unconfigured account, warned about and green, because the scheduled collector's matrix is static and a repository with one Kaggle account leaves the second secret unset. A token that is present and refused is still red. Every guard mutation-tested.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Shorten the comments and docstrings the dispatch and collect work added across the launcher, the gate, the collector, the poster, the three workflows and the Kaggle tests. Wording only: no code, no assertions and no argparse help text changed, and the whole tests/kaggle suite still passes.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
What this changes
The Kaggle GPU jobs waited for their kernel in a poll loop. Measured on the two runs that confirmed the two-account path yesterday:
T4 smoke(run 33479481067)Unsloth GPU smoke(run 33486360729)Against a repository queue measured between 400 and 670 deep that is two machines per commit taken out of circulation to watch a third-party service work.
They now push and exit.
launch.py --dispatchleaves the kernel running and returns in minutes. The result is collected afterwards by two independent routes:kaggle-collect.yml, on a schedule, which is what covers a quiet repository.The account is the queue
There is no artifact, branch or database between the dispatching job and the collecting one, deliberately: each of those is another place for the truth to live and go stale. Kaggle already knows which kernels exist, and the slug carries the rest.
The
unsloth-t4-ci-prefix is unchanged, and a test asserts it. That prefix is howgate.py's survey tells our kernels from a human's, and with the GitHub concurrency group no longer bounding anything (the dispatching job exits while the kernel runs on) it is the only thing still counting sessions against Kaggle's 2-per-account cap.Four things this breaks, and what each does about it
A pull request would go green before its GPU result exists. The job succeeds by dispatching. So it can no longer BE the check that says the GPU tests passed, and the verdict is posted as a commit status,
kaggle-t4-notebookorkaggle-studio-gpu, against the sha in the slug. Branch protection must be moved onto those contexts and off the jobs - otherwise this trades forty minutes of runner for a check that proves only that Kaggle accepted a push. A pending status goes up at dispatch, so a required context that has not reported yet reads as waiting rather than as absent.dispatchedis deliberately notpass.Orphaned kernels bill quota. The pushing job used to delete on every path out, including signals. Dispatch mode removes that safety, so the scheduled collector replaces it, with a 3h reap ceiling - well under Kaggle's own 12h, because this directory has already measured a kernel ignoring Kaggle's
-ttimeout for over two hours.The concurrency slot stops protecting anything. Covered by the gate's existing Kaggle-side survey, which is why the slug prefix is load-bearing.
Results can land on a superseded commit. Fine: the status goes to the sha in the slug, never to HEAD.
Safety
collect.pyenumerates a whole account - shared with a human, holding every probe anyone has pushed - and deletes what it collects. Nothing is touched unlessparse_slugrecognises it; an unrecognised kernel is invisible, not skipped-with-a-warning. Evidence is downloaded before any delete, and a download that fails leaves the kernel up for the next pass rather than destroying the only copy of a finished result.infraandpartialstay green with a description that says so. A red the author cannot act on is how a required check gets removed from branch protection.The collector holds no GitHub credential: it emits statuses as data and the workflow posts them. A test asserts that.
Verification
tests/kaggle951 passed--dispatch, dropping the commit from the slug, changing the prefix so the gate stops counting our sessions, deleting before downloading evidence, reaping a kernel with no timestamp, makinginfrared, and removing the schedule so a quiet repo never reapsactionlintclean,lint_workflow_triggers.pyclean, pre-push gate PASSNot yet exercised on hardware: no kernel has been dispatched and collected through Actions. That needs a real dispatch and at least one collector pass, and given the failure mode here is a green run that collects nothing, a tick alone will not be the evidence - the proof is a commit status appearing on a sha with a slug that matches it.