fix(sessions): preserve Dapr session created_at across writes#3236
fix(sessions): preserve Dapr session created_at across writes#3236adityasingh2400 wants to merge 1 commit intoopenai:mainfrom
Conversation
DaprSession.add_items() rewrote the session metadata on every call, clobbering created_at with the current timestamp. The field is now read back from the metadata key and only initialized on first write, so created_at reflects the true session start while updated_at advances. Also removes a duplicated etag assignment in pop_item().
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7cf43e322e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await self._dapr_client.save_state( | ||
| store_name=self._state_store_name, |
There was a problem hiding this comment.
Guard metadata update with an ETag
This fix reads existing metadata and then overwrites the metadata key without any ETag/concurrency option. With the default eventual reads or two DaprSession instances writing the same session, a stale/missing metadata read leaves created_at = now, and this unconditional save can clobber an older created_at, so the field can still advance across writes despite the commit intent.
Useful? React with 👍 / 👎.
Summary
DaprSession.add_items()rewrote the session metadata on every call, clobberingcreated_atwith the current timestamp on each write. The field now reflects the true session start time, whileupdated_atadvances as expected.created_atif it parses as a dict with that field.etag = getattr(response, "etag", None) or Noneline inpop_item()(dead code).Test plan
test_metadata_preserves_created_atassertscreated_atis stable across twoadd_itemscalls one second apart whileupdated_atadvances.tests/extensions/memory/suite passes (180 passed, 5 skipped).ruff checkandruff format --checkclean on touched files.