fix(tui): log the refused shared-handle transfer and pin _get_db caching
This commit is contained in:
@@ -241,6 +241,19 @@ def test_transfer_is_refused_for_the_shared_launch_handle(monkeypatch):
|
||||
assert agent._owns_session_db is False
|
||||
|
||||
|
||||
def test_get_db_returns_the_cached_instance(monkeypatch):
|
||||
"""The identity defense (``db is _get_db()``) only works while _get_db
|
||||
hands out ONE process-wide instance. Pin the caching semantics: once a
|
||||
handle exists, repeated calls return the same object rather than
|
||||
constructing per-call wrappers (review finding on #91631)."""
|
||||
sentinel = types.SimpleNamespace(closed=0)
|
||||
monkeypatch.setattr(server, "_db", sentinel)
|
||||
monkeypatch.setattr(server, "_db_error", None)
|
||||
|
||||
assert server._get_db() is sentinel
|
||||
assert server._get_db() is server._get_db()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 3. The deferred builder — _start_agent_build
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1478,6 +1478,10 @@ def _transfer_db_to_agent(agent, db) -> bool:
|
||||
# explicitly even if a caller invokes the transfer incorrectly; the
|
||||
# caller's own `owns_db` gate is the first line of defense.
|
||||
if db is _get_db():
|
||||
logger.warning(
|
||||
"Refused transfer of the shared launch SessionDB to a session "
|
||||
"agent — the caller's owns_db gate should have prevented this."
|
||||
)
|
||||
return False
|
||||
agent._owns_session_db = True
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user