You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AdvancedSQLiteSession.store_run_usage() records a phantom usage row for turn 0 when the current branch has no turn #4821
On an empty session, or on a branch whose turns were all popped, store_run_usage() inserts a turn_usage row for user_turn_number = 0. get_session_usage() then reports total_turns: 1 while get_items() is []. test_empty_session_operations and the method docstrings say usage is never recorded against a turn that has no rows.
store_run_usage (:618-655) calls _capture_current_turn (:657-686), which on a branch without turns returns user_turn_number = 0 (COALESCE(MAX(...), 0)) and turn_anchor = None (MIN(id) of no rows).
_update_turn_usage_internal (:1883-1970) only runs the removed-turn guard under if turn_anchor is not None:, so a None anchor skips the guard and the INSERT OR REPLACE lands.
The same happens after add_items followed by pop_item until the branch is empty. A later real turn plus store_run_usage(requests=2) then reports requests: 3, total_turns: 2 instead of requests: 2, total_turns: 1.
Root cause
A None anchor means "no turn on this branch", but _update_turn_usage_internal treats it as "no guard requested" and writes unconditionally.
Activity