Skip to content

fix(agent): bound per-session file state lifecycle - #5370

Open
yu-xin-c wants to merge 1 commit into
HKUDS:mainfrom
yu-xin-c:contrib/file-state-lifecycle
Open

fix(agent): bound per-session file state lifecycle#5370
yu-xin-c wants to merge 1 commit into
HKUDS:mainfrom
yu-xin-c:contrib/file-state-lifecycle

Conversation

@yu-xin-c

Copy link
Copy Markdown
Contributor

Why

FileStateStore retains one FileStates object 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

  • make FileStateStore a least-recently-used table bounded to the same 128-session budget as SessionManager
  • add explicit per-session discard semantics
  • discard file state on /new, runtime session disposal, and SDK clear() / delete()
  • keep active turns safe: their context variable retains the selected FileStates object even if its idle cache entry is evicted
  • cover LRU ordering, explicit discard, unified /new, transient session disposal, and SDK lifecycle paths

LRU 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

@chengyongru chengyongru added bug Something isn't working fix performance priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix performance priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants