Skip to content

fix: decorator invalidation for caching#8171

Merged
mscolnick merged 3 commits intomainfrom
dm/decorator-invalidation
Feb 9, 2026
Merged

fix: decorator invalidation for caching#8171
mscolnick merged 3 commits intomainfrom
dm/decorator-invalidation

Conversation

@dmadisetti
Copy link
Collaborator

📝 Summary

Closes #8155

ast.Function.body does not include parent decorator information. As such hashing the ast produced invalid cache hits when inner decorators changed. As a work around, we artificially append the decorator statements into the function body for module hashing. Additionally, to prevent cache invalidations between:

@app.function
@mo.cache # observed ast from imported module
def fn(): ...

and

@mo.cache # observed ast from kernel
def fn(): ...

we scan the decorators and remove all prior (and including) the caching wrap.

@vercel
Copy link

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 9, 2026 8:45pm

Request Review

@dmadisetti dmadisetti added the bug Something isn't working label Feb 7, 2026
mscolnick
mscolnick previously approved these changes Feb 7, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates marimo’s caching/hash computation so that changes to decorator expressions (including decorator-factory arguments and referenced variables) properly invalidate caches, addressing cases where ast.FunctionDef.body omits decorator information.

Changes:

  • Introduce get_hashable_ast() to include decorator AST (as synthetic statements) when building hashable modules, with support for skipping cache decorators and any outer decorators.
  • Switch cache/base block hashing and hash_function() to use get_hashable_ast() instead of strip_function().
  • Add unit and E2E tests covering decorator-parameter hashing and decorator ref tracking.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
marimo/_ast/transformers.py Adds get_hashable_ast() and decorator handling to ensure decorator changes participate in hashing.
marimo/_save/save.py Uses get_hashable_ast(..., skip_decorators={...}) for cached function base-block hashing.
marimo/_save/hash.py Updates hash_function() to hash via get_hashable_ast() rather than the removed helper.
tests/_ast/test_transformers.py Renames/updates transformer tests and adds coverage for decorator inclusion/skipping.
tests/_save/test_hash.py Adds regression/E2E tests to confirm decorator param/ref changes affect cache hashes as intended.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mscolnick mscolnick merged commit a02f8a0 into main Feb 9, 2026
30 of 45 checks passed
@mscolnick mscolnick deleted the dm/decorator-invalidation branch February 9, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working merge when ready

3 participants