Repository navigation
Conversation
This branch has not been deployed
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.
Fixes #3076
Problem
When running
task --offlinewith anoptional: trueremote include that has not been cached locally, Task fails and exits instead of skipping the missing optional include.Steps to reproduce:
Taskfile.ymlcontaining a remote include marked withoptional: true(without caching it beforehand).--offlineflag (e.g.,task --offline <local-task>).Actual behavior:
Task aborts immediately with a cache miss error and exits with code
106(TaskfileCacheNotFound).Expected behavior:
Task should gracefully skip the uncached optional remote include and continue executing the remaining local tasks.
Root Cause
Currently, the
Optionalcheck only happens during the node initialization phase (NewNode). For remote nodes, offline cache resolution occurs later during the node reading phase (Node.Read()). When a cache miss occurs in offline mode, the error bypasses theNewNodecheck and is unconditionally propagated up by the recursiveinclude()call inreader.go.Changes
reader.go'sinclude()flow, explicitly check for the offline cache miss error wheninclude.Optionalistrueand skip further processing for that branch.Node.Read(), remove the failed vertex from the graph before skipping. If removing the vertex fails, fall back to returning the original read error.optional: false) still fail with exit code106on an offline cache miss.Design Decisions
Why scope the check narrowly to offline cache misses instead of matching the broad
if include.Optional { return nil }check inNewNode?During
NewNode(primarily localos.Statresolution), an error reliably indicates that the target file does not exist. By the time execution reachesreader.go, however,Node.Read()and subsequent steps can fail for many other reasons (e.g., YAML syntax errors, invalid schema, network/timeout issues in online mode, or checksum mismatches). Catching all errors whenOptionalis true at this stage would silently swallow legitimate configuration or parsing errors. Narrowly targeting the offline cache miss error fixes the bug without masking real failures.Why remove the vertex on failure instead of refactoring to "read node first, add vertex second"?
The current
include()pipeline relies on adding the vertex and edge before recursing so that cycle detection (dag.AddEdge) happens prior to reading and parsing child Taskfiles. Reordering this to read before adding the vertex would either break cycle detection or require a broader restructuring of how the reader builds and traverses the dependency graph. Removing the dangling vertex exclusively on this specific error path is minimal, localized, and keeps cycle detection intact.Known Limitations
include()runs concurrently viaerrgroup, if the exact same uncached remote Taskfile is included by two parent Taskfiles simultaneously, the second goroutine may attach an edge to the shared vertex before the first goroutine removes it on a cache miss. In that race window, removing the vertex will fail due to the remaining edge and gracefully fall back to returning the original cache miss error rather than skipping.Testing
testdataverifying that an uncachedoptional: trueremote include is skipped under--offlineand local tasks succeed.optional: false) verifying that an uncached remote include under--offlinestill returns the expected cache miss error.TestIncludesRemote,TestIncludeCycle,TestIncludesMultiLevel, andgo test ./taskfile/...).golangci-lint(gofumpt+gciwith 0 issues), committed as a single Conventional Commit.AI Usage Disclosure
AI tools were used to assist in root-cause analysis, drafting the code changes in
reader.go, and designing the test cases. I have manually reviewed and verified all changes, fully understand how the implementation works, and wrote this PR description myself.Checklist