fix(contexts): durably persist writeable-context writeback (bucket + summary/updated_at) - #2324
Merged
Merged
Conversation
…summary/updated_at)
Writeable-context writeback overlaid a run's edits onto local disk and
triggered the durable object-storage sync (sync_refreshed_context_pack
hook), but never refreshed the pack's cached summary. Operator listings
(GET /contexts/{name}/files and the Library rows) read file_count / size
/ updated_at from metadata[name]["summary"] via _context_summary's fast
path, so a run's edits left those fields stale until the next explicit
write.
Add a shared best-effort helper refresh_context_summary_after_writeback()
in contexts.py and call it from both drivers' _persist_writeable_contexts
(e2b + agent), inside the active use_context_scope block, right after a
successful sync. Mirrors the refresh-then-sync ordering the system-asset
refresh path already uses. The helper never raises: a summary-refresh
failure is logged but never fails the run or undoes durable persistence.
Tests: assert the writeback refreshes the cached summary + updated_at for
a writeable pack (e2b + agent drivers, mocked and end-to-end) and that a
read-only context triggers neither refresh nor durable sync.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
When a worker run writes files into a writeable local context, the writeback overlays the run's edits onto local disk (
context_dir(name)) but never refreshes the pack's cached summary. Operator listings (GET /contexts/{name}/filesand the Library rows) readfile_count/ size /updated_atfrommetadata[name]["summary"]via_context_summary's fast path, so a run's edits leave those fields stale until the next explicit write.The durable object-storage upload half of this (files lost on container recycle) is already handled on current
mainby thesync_refreshed_context_packrefresh hook (#2320). The remaining gap was the local summary /updated_atrefresh, so the run's writeback stayed invisible to the operator listing.Fix
refresh_context_summary_after_writeback(name, *, log_fn=None)incontexts.py._persist_writeable_contexts(e2b_driver,agent_driver), once per successfully-persisted writeable context, inside the activeuse_context_scope(...)block, right after the successful durable sync.services/system_assets.py) already uses.Tests
apps/api/tests/test_agent_driver_contexts.py: writeback refreshes summary + triggers durable sync (mocked); an end-to-end assertion that the cached summary (file_count,updated_at) is actually written; and a read-only context triggers neither.tests/test_e2b_artifact_collection.py: e2b writeback refreshes the cached summary end-to-end.Context-suite regression:
test_worker_context_attach.py test_contexts_sensitive.py test_1433_context_mount_selection.py-> 47 passed.