fix(docs): deflake memories.py doc example (async-consolidation race) - #2152
Merged
Conversation
…curation steps The memories.py API doc example ran update_memory edit → edit-fields → invalidate → restore back-to-back on the same unit. Each edit re-embeds and re-consolidates in the background (a tracked consolidation op), so a later step could race that work and 404 on a unit mid-rewrite — the restore intermittently failed with "Memory unit not found". The fixed sleep(3) after the seed retains was also unreliable under CI load with a live LLM. Replace the sleep with a wait_for_idle() helper that polls list_operations until the bank has no pending/processing operations, and drain between each curation step. All waits sit outside the [docs:...] blocks, so the rendered documentation snippets are unchanged.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
test-doc-examples (python)CI job has been intermittently red on thememories.pyAPI example, failing with:This is a pre-existing main-side flake (the example was introduced in #1976) that surfaces on any PR touching
.github/**, since the example is main-owned and re-runs there.Root cause
The example curates one unit with four back-to-back calls: edit text → edit fields → invalidate → restore. Each
update_memoryedit re-embeds and re-consolidates in the background (a trackedconsolidationoperation, plus graph maintenance / mental-model refreshes). The next step fired immediately, racing that background work — so a later call (most often the restore) could hit the unit while it was mid-rewrite and 404. The fixedawait asyncio.sleep(3)after the seed retains was also unreliable under CI load with a live LLM.Fix
Add a small
wait_for_idle()helper that pollslist_operationsuntil the bank has nopending/processingoperations, and drain between each curation step (and after the seed retains, replacing thesleep(3)).wait_for_idle()call sits outside the# [docs:...]blocks that get rendered into the docs site.Verification
python -m py_compilepasses.update_memory→submit_async_consolidationcreates a tracked operation visible tolist_operations(so the poll actually drains the racing work).wait_for_idleinside any[docs:...]marker.test-doc-examples (python)job on this PR.🤖 Generated with Claude Code