fix(agent): bound per-session file state lifecycle - #5370
Open
yu-xin-c wants to merge 1 commit into
Open
Conversation
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.
Why
FileStateStoreretains oneFileStatesobject for every session key for the lifetime of the agent loop. High-cardinality API or temporary sessions therefore grow the table without a bound.The same state also survived session lifecycle boundaries. After
/new, runtime discard, or SDK clear/delete, a fresh conversation could inherit the previous conversation's read-dedup and read-before-edit state even though that read was no longer present in its context.What changed
FileStateStorea least-recently-used table bounded to the same 128-session budget asSessionManager/new, runtime session disposal, and SDKclear()/delete()FileStatesobject even if its idle cache entry is evicted/new, transient session disposal, and SDK lifecycle pathsLRU eviction only removes an optimization and safety hint from a future turn; it does not interrupt an active turn or alter persisted conversation history.
Verification
uv run --extra dev pytest tests/tools/test_read_enhancements.py tests/tools/test_edit_enhancements.py tests/tools/test_edit_advanced.py tests/agent/test_loop_session_policy.py tests/agent/test_unified_session.py tests/agent/test_loop_save_turn.py -q(151 passed)uv run --extra dev pytest tests/test_nanobot_facade.py::test_session_helpers_get_list_export_clear_delete_flush tests/agent/test_unified_session.py tests/agent/test_loop_session_policy.py tests/tools/test_file_state_store.py -q(30 passed)uv run --extra dev ruff check ...uv run --extra dev basedpyright nanobot/sdk/clients.py nanobot/agent/tools/file_state.py nanobot/agent/loop.py nanobot/command/builtin.py