Skip to content

Stop EntityAgent reusing stale pre-act values after a failed step - #383

Closed
codewithfourtix wants to merge 2 commits into
google-deepmind:mainfrom
codewithfourtix:fix-stale-pre-act-cache-after-failed-step
Closed

codewithfourtix wants to merge 2 commits into
google-deepmind:mainfrom
codewithfourtix:fix-stale-pre-act-cache-after-failed-step

Conversation

@codewithfourtix

Copy link
Copy Markdown
Contributor

Fixes #382.

A failed act()/observe() returns to READY without running UPDATE, so ActionSpecIgnored components keep their cached pre-act value and a retried act() reuses it.

  • On failure, run update() before returning to READY. Errors from it are logged so the original exception still propagates (keeps the intent of 326d918).
  • Check the phase inside ActionSpecIgnored's cache lock, so an in-flight pre_act can't re-cache a stale value after cleanup.
  • Add entity_agent_test.py. The stale-value, update-phase and lock tests fail on main.

When act() or observe() raises, EntityAgent returns to READY without going
through UPDATE, so components never get their update() call. Components that
cache per-step values keep them: ActionSpecIgnored clears its pre-act value
only in update(), so after a failed act() every such component silently
serves the value from the failed step on the next successful act(), e.g.
a memory summary or plan from an earlier point in the simulation.

On failure, run the UPDATE phase before returning to READY, so components can
drop per-step state. Errors raised by update() during this recovery are
logged, not raised, so the original exception still propagates unchanged (the
reason set_phase() is used here, see 326d918).

Add the first tests for EntityAgent's failed-step handling: no stale value on
the next act(), the original exception is re-raised for act() and observe(),
update() runs in the UPDATE phase, an error in update() does not hide the
original error, and the agent can act again afterwards.
The agent does not wait for components' in-flight calls when a step fails,
so a pre_act call can still be running during the cleanup added in the
previous commit. get_pre_act_value() checked the phase before taking the
lock, so a call that passed the check and then waited for the lock while
update() cleared the cache would compute and cache a value from the failed
step once it got the lock, leaving a stale value in a READY agent.

Check the phase while holding the lock, so such a call raises instead.

Add a regression test that holds the cache lock while a reader is waiting
for it and ends the step before releasing it.
@jzleibo

jzleibo commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Closing this for the reason described on the corresponding issue: #382

@jzleibo jzleibo closed this Sep 30, 2026
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.

EntityAgent reuses stale pre-act values after a failed act()

2 participants