Skip to content

Linter for action reads in state, function-based-actions #407

Description

@elijahbenizzy

Is your feature request related to a problem? Please describe.
I want to be able to quickly fail should I attempt to read the wrong state item.

@action(reads=["foo"], ...)
def my_action(state: State) -> State:
    bar = state["bar"] # not in reads...
    ...

We know for sure that this should fail.

Describe the solution you'd like
A checker to warn this. We won't be able to catch all cases (for whatever reason), but given the following assumptions (that we can check for), we should be able to get it working to be correct.

  1. The state parameter is not overwritten with another state parameter
  2. Only strings in reads
  3. State access is done with brackets

Then we can walk through the AST to (a) ensure this and (b) check that all state parameters if that's the case.

Describe alternatives you've considered
Having a better error message, adding that as well.

Additional context
Just developing and liked this idea

This is not an easy bit of coding (I'm sure chatGPT can help), but it's self-contained and very testable, so should be doable for most engineers.

Activity

  1. elijahbenizzy commented on Oct 24, 2024

    @elijahbenizzy
    ContributorAuthor
  2. fediazgon commented on Jan 13, 2026

    @fediazgon

    Hey, is this still an issue? If that's the case I would like to work on it @elijahbenizzy

  3. Smitaambiger commented on Feb 9, 2026

    @Smitaambiger
    Contributor

    Hi @elijahbenizzy

    I’d like to work on this issue if it’s still open.

    I understand the goal is to statically detect undeclared state reads in function-based actions (under the assumptions listed). I’ll take some time to go through the action and state internals and come back with a concrete proposal before starting implementation.

    Please let me know if that sounds good.

  4. Smitaambiger commented on Feb 9, 2026

    @Smitaambiger
    Contributor

    Hi @elijahbenizzy

    I’d like to work on this issue if it’s still open.

    Based on a quick pass through the function-based action implementation, this seems feasible via a scoped AST check:

    • Target FunctionBasedAction / FunctionBasedStreamingAction
    • Parse the source of the originating function
    • Detect state["<key>"] accesses with string literals
    • Compare against the declared reads=[...]
    • Fail fast when undeclared reads are detected

    I’d plan to run this validation at application build time (not decorator import time) and scope it strictly to the assumptions listed in the issue.

    Before starting, can you confirm:

    1. Build-time validation is the right hook?
    2. Hard error vs warning for the initial behavior?

    Thanks!

  5. Smitaambiger commented on Feb 11, 2026

    @Smitaambiger
    Contributor

    Thanks for assigning! I’ll start implementing the AST-based validation and follow up with a PR once I have initial tests in place.

  6. Smitaambiger commented on Feb 12, 2026

    @Smitaambiger
    Contributor

    @elijahbenizzy
    Opened PR: #656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions