Skip to content

Add task-level cache max age support - #1501

Merged
pvditt merged 2 commits into
mainfrom
pvditt/max-cache-age
Sep 1, 2026
Merged

Add task-level cache max age support#1501
pvditt merged 2 commits into
mainfrom
pvditt/max-cache-age

Conversation

@pvditt

@pvditt pvditt commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add Cache.max_age as a task-level cache policy, accepting a nonnegative timedelta or integer number of seconds
  • serialize the setting to TaskMetadata.cache_max_age, preserving the distinction between unset and explicit zero
  • round-trip and override the setting through remote task details
  • validate positive, zero, unset, negative, and invalid-type behavior

None uses the platform default, zero disables age-based expiration, and a positive value limits the age of cached results that the task will reuse.

IDL dependency

This depends on TaskMetadata.cache_max_age from flyteorg/flyte#7938 (commit). The dependency pin is intentionally not changed in this PR, so CI is expected to fail against flyteidl2==2.0.44 until a new IDL version is published and the SDK pin is bumped.

Testing

Using a locally built flyteidl2==2.0.45.dev0 wheel:

  • pytest -q tests/user_api/test_cache.py tests/flyte/internal/runtime/test_task_serde.py tests/flyte/remote/test_task.py tests/flyte/test_image.py — 177 passed
  • Ruff passed for all changed source and test files
  • git diff --check passed

Dogfood validation

Validated against dogfood/flytesnacks/development and the leaseworker implementation in unionai/cloud#18043. The expiring task template contained cacheMaxAge: 60s; the normal-cache task omitted the field.

Scenario Run Cache status Execution marker
Initial 60s cache expiring-3 CACHE_MISS 04:46:48.396163Z
Immediate repeat expiring-4 CACHE_HIT Same marker
Repeat after 163s expiring-5 CACHE_MISS 04:49:31.529448Z
Immediate repeat of refreshed result expiring-6 CACHE_HIT Same refreshed marker
Normal cache initial normal-1 CACHE_MISS 04:47:39.246597Z
Normal cache immediate repeat normal-2 CACHE_HIT Same marker
Normal cache after the wait normal-3 CACHE_HIT Still the original marker

Dogfood workers were still using an older SDK without the task-side constructor argument, so the probe used this SDK build for registration and an import-time compatibility guard for the older task runtime. Cache lookup and expiration occur in leaseworker before task execution.

@wild-endeavor wild-endeavor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't we need to bump something in pyproject? or did someone else already do that? what's the min idl version needed for this?

@wild-endeavor

Copy link
Copy Markdown
Contributor

oh you were waiting on a new version - looks like someone published https://pypi.org/project/flyteidl2/2.0.45/

Signed-off-by: Paul Dittamo <pvdittamo@gmail.com>
Signed-off-by: Paul Dittamo <pvdittamo@gmail.com>
@pvditt
pvditt force-pushed the pvditt/max-cache-age branch from 2067aa2 to 05822e4 Compare September 1, 2026 19:27
@pvditt
pvditt merged commit 1b0e40a into main Sep 1, 2026
59 checks passed
@pvditt
pvditt deleted the pvditt/max-cache-age branch September 1, 2026 22:26
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.

2 participants