Skip to content

Conversation

@akshayka
Copy link
Contributor

@akshayka akshayka commented Nov 7, 2025

This PR prunes logic in state resolution which eagerly marked cells as stale and enqueued a stale cell request whenever a setter was called; in the main thread, running cells made stale by a state update is handled by the main cell execution loop.

Eager execution of state updates only needs to happen when running state updates in a mo.Thread object (either manually or via the mo.watch APIs). This PR updates conditions how state resolution happens based on whether the current thread is a mo.Thread.

Additionally, instead of relying on the state registry to find bound names, which does not work when a state update is called in the cell that defined it, we just scan globals to find cells that have the state object in their refs (similar to what CellRunner does).

Closes #7060
Closes #6847
Closes #5311
Closes #5139

This PR prunes logic in state resolution which eagerly marked cells as
stale and enqueued a stale cell request whenever a setter was called;
in the main thread, running stale cells in the main cell execution loop.

Eager execution of state updates only needs to happen when running state
updates in a mo.Thread object (either manually or via the mo.watch
APIs). This PR updates conditions how state resolution happens based
on whether the current thread is a mo.Thread.

Additionally, instead of relying on the state registry to find bound
names, which does not work when a state update is called in the cell
that defined it, we just scan globals to find cells that have the state
object in their refs (similar to what CellRunner does).
@akshayka akshayka requested a review from dmadisetti as a code owner November 7, 2025 07:23
@vercel
Copy link

vercel bot commented Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 7, 2025 9:32pm

@dmadisetti
Copy link
Collaborator

dmadisetti commented Nov 7, 2025

Nice! I can grab the side-effect issue to take it off your plate if needed

@akshayka
Copy link
Contributor Author

akshayka commented Nov 7, 2025

Nice! I can grab the side-effect issue to take it off your plate if needed

Thanks @dmadisetti -- is the fix relatively simple/easy for you? If so, feel free to push it up to this PR. If not, I can look into it in my downtime.

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

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

Re triggered the tests- flaky windows one started an early failure- but looks good. Much better than mocking out the whole execution queu

(tmp_path / "test.txt").touch()
await asyncio.sleep(0.25)
await k.run([])
assert len(control_requests) == 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, this is a good check too

@akshayka akshayka merged commit b9fa7f4 into main Nov 7, 2025
35 of 77 checks passed
@akshayka akshayka deleted the aka/fix-state-threading branch November 7, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants