Skip to content

fix!: raise GokartBuildError for MISSING_EXT and NOT_RUN in gokart.build - #684

Merged
hirosassa merged 5 commits into
masterfrom
fix/build-missing-ext-not-run
Nov 23, 2026
Merged

hirosassa merged 5 commits into
masterfrom
fix/build-missing-ext-not-run

Conversation

@hirosassa

@hirosassa hirosassa commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ BREAKING CHANGE

gokart.build now raises GokartBuildError for every LuigiStatusCode other than SUCCESS / SUCCESS_WITH_RETRY. Previously MISSING_EXT and NOT_RUN were silently treated as success.

Who is affected: callers whose build currently ends with MISSING_EXT (an ExternalTask dependency's output is missing, so the requested task never ran) or NOT_RUN. These calls used to return normally (None, or a later unrelated load() error with return_value=True); they will now raise GokartBuildError.

Migration: make sure external dependencies exist before building, or catch GokartBuildError where the old silent behavior was relied on. The new GokartBuildError.status (a luigi.LuigiStatusCode, default None) lets callers tell MISSING_EXT / NOT_RUN (empty raised_exceptions) apart from a crashed task; existing GokartBuildError(...) calls stay compatible.

Summary

  • _build_task in gokart/build.py now uses a success allow-list (SUCCESS, SUCCESS_WITH_RETRY) instead of a failure deny-list of three statuses.
  • GokartBuildError gains an optional status attribute.
  • docs/intro_to_gokart.rst is updated.

Tests

  • Reproduction tests written first (red): missing ExternalTask output (return_value True/False), NOT_RUN reproduced for real via resources, and status on the error.
  • test/test_build.py: 22 passed; ruff, ruff format, pyright clean.
  • Note: in my local sandbox some GCS/network-dependent test modules hang at collection (and ProcessTaskInfoTest hangs); they are unrelated to this change, so please rely on CI for the full suite.

Follow-ups

Closes #681

🤖 Generated with Claude Code

@kitagry kitagry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up. Switching from a deny-list to an allow-list is the right direction. I checked it against luigi 3.8.1 and ran the new tests: all three fail on the base build.py and pass with this change, and test/test_build.py passes (22 passed).

1. SUCCESS_WITH_RETRY can still hide MISSING_EXT / NOT_RUN / SCHEDULING_FAILED (pre-existing, but the new comment claims otherwise)

luigi's _tasks_status checks ever_failed and not failed first. So if any task failed and then succeeded on a retry, luigi returns SUCCESS_WITH_RETRY even when other tasks are still waiting on a missing external input, were never run, or failed scheduling. I measured this with keep_alive=true and a task with retry_count:

scenario status root complete gokart.build (this PR)
retried dep + missing ExternalTask (return_value=False) SUCCESS_WITH_RETRY False returns None
same (return_value=True) SUCCESS_WITH_RETRY False raw FileNotFoundError
retried dep + complete() raises SUCCESS_WITH_RETRY False returns None
retried dep + resource never granted SUCCESS_WITH_RETRY False returns None

base behaves the same way, so this PR does not cause it. But the new WHY comment ("only SUCCESS / SUCCESS_WITH_RETRY mean the requested task finished") isn't accurate. I'd reword it, for example:

# WHY: MISSING_EXT / NOT_RUN mean the requested task did not run. Note that luigi reports
# SUCCESS_WITH_RETRY even if other problems remain, as long as every failed task was retried successfully.

The robust fix is to check the root task itself, as gokart/run.py (_run_with_retcodes) already does: root_task not in task_sets['completed'] and root_task not in task_sets['already_done']. It uses the worker's task history, so it needs no extra complete() I/O. I'm fine with doing that in a follow-up issue. If we do, it would be good to ship it in the same release as this PR, so users see one behavior change instead of two.

2. Release: I'd target 2.0.0

  • gokart has no CHANGELOG. Release notes are the auto-generated "What's Changed" list of PR titles, with no .github/release.yml categories, so the ! in the title is not highlighted anywhere in the notes.
  • Recently we deprecate first and remove in 2.0.0: #550, #558, #605, #637, #646 and #459 all add a DeprecationWarning or FutureWarning, and #685 collects the removals. Earlier 1.x releases did include breaking changes without a warning (#504 in v1.12.1, dropping Python 3.9 in v1.10.3), but that is the older practice.
  • master already has an unreleased breaking change, build!: move redis to the optional extra gokart[redis] (#642), so the next release from master is breaking anyway.

So my suggestion is to list this under "Breaking change candidates for 2.0.0" in #685 and merge it for 2.0.0. If we cut another 1.x release from master before that, a small 1.x change that emits a FutureWarning for MISSING_EXT / NOT_RUN ("this will raise GokartBuildError in 2.0.0") would match how we handled #459 and #646. The old behavior is a silent failure, so I don't think the warning is strictly necessary. Whichever release this goes in, please add a "Breaking changes" note to the release notes by hand, using the migration paragraph from this PR description.

3. Docs

docs/intro_to_gokart.rst:171 still says "When some tasks are failed, gokart.build raises GokartBuildError." Could you update it to say that it also raises when an external dependency is missing or a task was not run?

Nits (optional)

  • The two MISSING_EXT tests differ only in return_value. A subTest loop over (True, False) would cover both.
  • test_build_raises_on_not_run sits in TestBuildMissingExternal, and it mocks luigi.build. NOT_RUN can be reproduced for real with resources = {'r': 2} on a task and [resources] r=1, which also covers gokart's own worker.
  • Consider adding status=result.status to GokartBuildError. For MISSING_EXT / NOT_RUN, raised_exceptions is empty, so callers can't tell "missing input" apart from "task crashed" without matching on the summary text.

hirosassa and others added 2 commits November 23, 2026 10:55
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nt and docs, reproduce NOT_RUN for real

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hirosassa
hirosassa force-pushed the fix/build-missing-ext-not-run branch from 7d4b3b4 to 51c6e54 Compare November 23, 2026 01:56
@hirosassa

Copy link
Copy Markdown
Collaborator Author

Thanks for the thorough review! All addressed in 51c6e54:

  1. WHY comment: reworded along your suggestion (luigi reports SUCCESS_WITH_RETRY even if other problems remain, as long as every failed task was retried successfully). The root-task check is split out to gokart.build: SUCCESS_WITH_RETRY can hide an incomplete root task; check the root task like gokart.run does #690 and referenced from the comment, so it is not part of this PR.
  2. Docs: docs/intro_to_gokart.rst now says GokartBuildError is also raised for a missing external dependency or a task that was not run.
  3. Nits: the two MISSING_EXT tests are merged into one with subTest over return_value in (True, False). The NOT_RUN test no longer mocks luigi.build; it reproduces it for real with resources = {'r': 2} and [resources] r=1, in its own test class.
  4. status: added GokartBuildError(message, raised_exceptions, status=None) (backward compatible, default None), populated with result.status. Tests assert MISSING_EXT / NOT_RUN / FAILED and an empty raised_exceptions for the first two. The PR description is updated accordingly.
  5. Release: agreed on targeting 2.0.0; it is noted in 2.0.0 removals #685.

Gate (ruff, format, pyright, test/test_build.py) passes, and the branch is rebased onto the latest origin/master.

@kitagry kitagry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick update. I re-checked everything in 51c6e54 and it all looks good:

  • The WHY comment now says correctly that SUCCESS_WITH_RETRY can hide other problems, and points to #690.
  • docs/intro_to_gokart.rst covers the new raise cases and status.
  • The MISSING_EXT tests are merged with subTest, and NOT_RUN is reproduced for real.
  • status is optional and comes last, so existing GokartBuildError(message, raised_exceptions) calls and subclasses keep working.
  • The 2.0.0 note is in #685.

I checked the tests locally. With the base build.py, the 5 new tests fail (both MISSING_EXT subtests fail, NOT_RUN fails with "GokartBuildError not raised", and both status tests fail). With this branch, test/test_build.py passes (23 passed) with -n 0, and with -n auto five times in a row.

LGTM. A few optional nits:

  1. TestBuildNotRun.setUp can go. luigi treats a resource that is not configured as having 1 unit (available_resources.get(resource, 1) in Scheduler._has_resources), so resources = {'r': 2} alone already gives NOT_RUN with an empty raised_exceptions. I checked this without the setUp. Dropping it also removes the global config change. Right now that change leaves an empty [resources] section behind, and if a value for r already existed, it deletes it instead of restoring it. A name nobody would configure, such as _gokart_test_not_run, would also keep a developer's own luigi.cfg from interfering.
  2. The NOT_RUN test could also assert cm.exception.raised_exceptions == {}, as the MISSING_EXT test does, since the docs now promise this.
  3. A small wording point on "raised_exceptions is empty" for MISSING_EXT / NOT_RUN. raised_exceptions is created outside _build_task, so it keeps exceptions from earlier attempts across HasLockedTaskException retries. In addition, SCHEDULING_FAILED also comes with an empty raised_exceptions, because luigi emits BROKEN_TASK, not FAILURE. Saying that raised_exceptions holds the exceptions from failed task runs, and that status is the authoritative signal, would be more accurate. Alternatively, create the dict inside _build_task.

Unrelated to this PR, and not a blocker: GokartBuildError can't be pickled. Exception.__reduce__ rebuilds it as cls(message), and raised_exceptions is required. So a GokartBuildError raised inside a multiprocessing / ProcessPoolExecutor worker turns into a TypeError in the parent. This is the same on master. I can open a separate issue for it.

@kitagry

kitagry commented Nov 23, 2026

Copy link
Copy Markdown
Member

Opened #701 for the pickling issue with GokartBuildError that I mentioned in my review. It is the same on master and does not block this PR.

…view

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hirosassa

Copy link
Copy Markdown
Collaborator Author

Thanks for the re-review! Addressed the optional nits in the latest commit:

  1. Dropped TestBuildNotRun.setUp (no global config change). The task now uses an unconfigured resource name _gokart_test_not_run with 2 units, relying on luigi's default of 1 unit.
  2. The NOT_RUN test now asserts raised_exceptions == {}.
  3. Reworded the GokartBuildError docstring and docs: raised_exceptions holds the exceptions of failed task runs, and status is the authoritative signal (also mentions SCHEDULING_FAILED).

ruff, format, pyright and test/test_build.py pass locally.

@hirosassa
hirosassa enabled auto-merge (squash) November 23, 2026 20:28
@hirosassa
hirosassa merged commit 8d5d9cf into master Nov 23, 2026
7 checks passed
@hirosassa
hirosassa deleted the fix/build-missing-ext-not-run branch November 23, 2026 20:31
kitagry added a commit that referenced this pull request Nov 23, 2026
Resolve the conflict with #684 in test/test_build.py by keeping both
sets of tests, and check that the status added by #684 survives the
pickle round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

gokart.build treats MISSING_EXT / NOT_RUN as success

2 participants