Skip to content

fix(cache): recompute tasks with missing local outputs - #3469

Open
1fanwang wants to merge 4 commits into
flyteorg:masterfrom
1fanwang:1fannnw/refresh-missing-local-cache
Open

1fanwang wants to merge 4 commits into
flyteorg:masterfrom
1fanwang:1fannnw/refresh-missing-local-cache

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Tracking issue

Related to flyteorg/flyte#6393.

Why are the changes needed?

A local workflow can fail on its second run after a consumer renames a cached output file. The cache returns the old path, and input conversion fails before the consumer runs:

TypeTransformerFailedError: Error encountered while converting inputs of
'repro_6393.process_file':

What changes were proposed in this pull request?

Treat missing local artifact references as cache misses so the producer runs again. Valid cached results and remote references retain their behavior. Other filesystem errors still propagate.

This does not isolate in-place edits or inspect paths embedded in opaque serialized values.

How was this patch tested?

Testing Done

The real workflow runs twice against the same local cache. Each consumer renames its output file; the second run detects the missing cached artifact and runs the producer again.

Scenario Command Result
First run pyflyte run cache_artifact_repro.py wf Producer runs; consumer renames the file
Second run, same HOME and cache pyflyte run cache_artifact_repro.py wf Producer runs again; workflow completes
Reproducer source: cache_artifact_repro.py
import os
import tempfile

from flytekit import Cache, FlyteFile, task, workflow


@task(cache=Cache(version="cache-artifact-probe-1"))
def create_file() -> FlyteFile:
    with tempfile.NamedTemporaryFile(mode="wb", delete=False, dir=os.environ["HOME"]) as file:
        file.write(b"Hello, world!")
        print("PRODUCER_EXECUTED")
        return FlyteFile(path=file.name)


@task
def process_file(file: FlyteFile) -> None:
    path = file.download()
    with open(path, "rb") as source:
        assert source.read() == b"Hello, world!"
    os.rename(src=path, dst=path + ".processed")
    print("CONSUMER_RENAMED_FILE")


@workflow
def wf() -> None:
    process_file(file=create_file())
pyflyte run cache_artifact_repro.py wf
pyflyte run cache_artifact_repro.py wf
PRODUCER_EXECUTED
CONSUMER_RENAMED_FILE
first_run_exit_code=0
PRODUCER_EXECUTED
CONSUMER_RENAMED_FILE
second_run_exit_code=0

The original comparison failed on the second base run, then completed against that same cache after the change:

PRODUCER_EXECUTED
CONSUMER_RENAMED_FILE
exit_code=0
TypeTransformerFailedError: Error encountered while converting inputs of
'repro_6393.process_file':
exit_code=1
PRODUCER_EXECUTED
CONSUMER_RENAMED_FILE
exit_code=0

Setup process

Python 3.12 with the SDK development environment. Use an isolated HOME and keep it unchanged between the two invocations.

Screenshots

Not applicable.

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

None.

Docs link

The cache lookup docstring describes missing-artifact handling.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 17.14286% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.72%. Comparing base (d0c64d5) to head (bd3bc4d).

Files with missing lines Patch % Lines
flytekit/core/local_cache.py 17.14% 29 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3469      +/-   ##
==========================================
+ Coverage   46.34%   47.72%   +1.37%     
==========================================
  Files         327      217     -110     
  Lines       28868    23000    -5868     
  Branches     3039     3049      +10     
==========================================
- Hits        13379    10976    -2403     
+ Misses      15388    11415    -3973     
- Partials      101      609     +508     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: 1fanwang <1fannnw@gmail.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.

1 participant