Repository navigation
Python: Keep sessions pending when a consolidation pass did not cover them #9294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shivam Sharma (ShivamSharma43)
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
ShivamSharma43:fix/9218-consolidation-pending-sessions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4a53aa0
Python: Keep sessions pending when a consolidation pass did not cover…
ShivamSharma43 480eea4
Python: Register a memory session even when its extraction fails or i…
ShivamSharma43 069de84
Python: Record a distinct pending marker for each finished memory turn
ShivamSharma43 0b7c363
Merge remote-tracking branch 'upstream/main' into fix/9218-consolidat…
ShivamSharma43 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shivam Sharma (@ShivamSharma43) this still uses a de-duplicated
session.session_idas the only pending-work marker. If a consolidation pass snapshotscovered_session_idswhilesession-1is already pending, then a second overlappingagent.run(..., session=AgentSession(session_id="session-1"))can finish extraction and reach this block whilesession-1is still in the list, so line 1435 records no new marker. When the older pass succeeds, lines 1599-1603 removesession-1because it was in the snapshot, leaving the later turn’s newly written topic out of the pending window even though it was not in that snapshot.Agent.rundoes not serialize callers perAgentSession, so the marker needs to distinguish completions rather than just membership by session id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, thanks. Fixed in 069de84. The marker now changes with every finished turn, so it no longer depends on the session id alone.
uuid4id for its session in a new state field,pending_turn_ids({session_id: id of the latest finished turn}). This happens in the samefinallyblock, under the state lock, even when the session is already pending.session-1turn replaces the id, so the older pass leavessession-1pending. Ids are never reused, so this also holds when two passes overlap and the other one retires and re-adds the session in between.sessions_since_consolidationkeeps its format: a de-duplicated list of session ids.consolidation_min_sessionsstill counts distinct sessions, matching its docstring ("Number of sessions required") and the de-duplication the provider already did. Overlapping turns of one session don't move the threshold forward any faster.read_statefills inpending_turn_idsas{}when it's missing. A session that's pending without an id is retired by a pass that saw it, unless a newer turn has recorded an id by the time the pass finishes.Tests:
test_automatic_consolidation_keeps_overlapping_turn_of_covered_session_pendingfollows your interleaving. Two overlappingagent.run(..., session=AgentSession(session_id="session-1"))calls run through the real automatic passes. The first pass, which snapshottedsession-1, finishes after the second turn wrote and registered its topic, andsession-1stays pending. The second pass then covers the new topic and retires it. On 480eea4 the pending list ends up[]at that point.test_memory_consolidation_retires_only_turns_in_its_snapshotis now parametrized. A turn registered during the pass is kept in each case: for a new session, for a pending session without an id (older state), and for a pending session with an id.Memory, file-memory, sessions and background-agents tests: 302 passed, 1 skipped. The 1 failure is the Windows path-length case (
test_opaque_session_id_round_trips_through_safe_filename), which also fails onmain. Ruff, pyright (source) and mypy, ty, pyrefly (tests) are clean on the changed files.