fix(memory): skip usage for empty sessions - #4843
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Fixes #4821
Bug
AdvancedSQLiteSession.store_run_usage()could insert aturn_usagerow for user turn 0 when the current branch had no conversation turn. This made an empty session report usage andtotal_turns: 1even though it contained no items. The same could happen after all turns on a branch were popped.Root cause
_capture_current_turn()correctly returnedturn_anchor=Nonewhen nomessage_structurerow existed, butstore_run_usage()still passedcurrent_turn=0to the write path. The write path only guarded anchored stale writes, so it inserted the phantom row.Fix
Return without writing when the captured turn has no anchor. This preserves the existing stale-write protection and prevents usage from being attributed to a nonexistent turn.
Validation
PYTHONPATH=src .../python -m pytest -q tests/extensions/memory/test_advanced_sqlite_session.py(130 passed)ruff check src/agents/extensions/memory/advanced_sqlite_session.py tests/extensions/memory/test_advanced_sqlite_session.pyruff format --check src/agents/extensions/memory/advanced_sqlite_session.py tests/extensions/memory/test_advanced_sqlite_session.pyPYTHONPATH=src .../python -m mypy src/agents/extensions/memory/advanced_sqlite_session.pyThe regression tests cover both an initially empty session and a branch whose only turn has been popped.