Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
`compute_state_delta_for_rewind` rebuilt the state at the rewind point by replaying the deltas of the events it keeps, then deleted every key of the current state that the replay did not produce. State seeded by `create_session` never appears in an event delta -- it is written straight into the session's state bucket -- so it was taken to be "added after the rewind point" and set to None. Rewinding a session therefore erased the state the session had been created with, which `rewind_async` cannot restore because no delta records it. A key now becomes a deletion only when one of the rewound events introduces it, since an event delta is the only way a key can be added after the rewind point.
ecae737 to
15d085f
Compare
|
thanks for putting together the fix and the tests, @lisry-1. #7118 landed the same change in dfd534a, where rewinding now only clears keys written by an undone event. state passed to create_session survives now, and both of your new tests pass on main. it's on main and not in a release yet, so i'm going to close this one out. if you see this happening again, please open a new issue. |
Problem
Runner.rewind_async()— and_rewind_utils.rewind_session()beneath it — deletesevery session-state key that was seeded by
create_session(). WithInMemorySessionService:Before the fix:
cartwas created with the session, is unrelated toinv2, and is gone afterthe rewind. The value is unrecoverable: no event delta records it, so nothing
can replay it, and the
Noneis written into the session's state bucket by therewind event like any other delta.
The same happens with any state bucket key seeded at creation time — including
initial_state.jsonseeding inadk web,statepassed toRunner.run_async's session bootstrap, andstateseeded by anInMemorySessionService/DatabaseSessionServicecaller.Root cause
compute_state_delta_for_rewind()rebuilds the state at the rewind point byreplaying the
state_deltaof the events it keeps, and then treated "absentfrom that replay" as "added after the rewind point":
That inference does not hold.
create_session()writes initial state straightinto the session's state bucket without recording an event, so a key that
predates every event is absent from the replay and was deleted.
Fix
A key can be added after the rewind point only if one of the discarded
events introduces it — every state write reaches the session through an event
delta, so a key that none of the discarded events mentions cannot have been
created by them. The deletion branch now requires that:
Restoration of keys that changed after the rewind point (the first loop) is
untouched, so
rewindstill reverts every key an event wrote.This also removes the deletion of keys that a rewind event itself had
restored earlier, which had the same shape: a restored key is not in
state_at_rewind_pointfor a later rewind to an earlier point, so a secondrewind used to delete it.
Known limitation (unchanged by this PR)
If a key is seeded at creation, then overwritten by a rewound event, the value
it had at the rewind point is not recoverable from the event history, and the
key is still removed. Recording the initial state as a delta on a synthetic
first event would fix that too; it is a larger, storage-visible change and is
deliberately left out of this bug fix.
Tests
tests/unittests/sessions/test_rewind_utils.py:test_rewind_keeps_state_seeded_at_session_creation— end-to-end throughrewind_session(): a seeded key, and a seededuser:key, survive a rewind;the key written by the kept invocation is still restored. Fails before the
fix (
{'cart': None}).test_compute_state_delta_still_clears_keys_a_rewound_event_adds— thenegative case: a key introduced by a discarded event is still deleted, so the
fix does not simply stop deleting keys. Fails before the fix (it also
reported the seeded key for deletion).
Checklist
compute_state_delta_for_rewindapp:/user:/temp:keys