Jack Lau
ab7f48d4b0
feat(state): support the context-manager protocol on SessionDB
...
A SessionDB handle cannot be released by dropping the last reference.
Once its background token writer starts, the instance pins ITSELF two
ways: the writer thread's target is a bound method, and
queue_token_counts registers atexit.register(_drain_token_queue_at_exit),
which only close() unregisters. A dropped-but-pinned handle keeps its
state.db/-wal/-shm descriptors for the life of the process, and __del__
never runs for it, so the existing safety net is dead code for exactly
the instances that leak.
That is why owning call sites are expected to close explicitly, in those
words, in the ownership comments in run_agent.py and
tui_gateway/methods_session.py. This adds the ergonomic half of that
contract so an owner can scope a handle and be exception-safe by
construction:
with SessionDB(path) as db:
db.append_message(...)
Purely additive. __enter__ returns self, __exit__ closes and returns
False so a caller's exception always propagates, and close() is already
idempotent, so a scope that closes early still exits cleanly. Nothing
changes for callers that already close directly.
Four regressions cover the scope closing the handle, __enter__ returning
the instance itself, the failure path closing while still propagating,
and an early close leaving the exit clean. They assert on the
sqlite_safe_read tracking registry rather than raw descriptor counts,
matching test_session_db_read_conn_pool.py, because SQLite's unix VFS
parks a closed descriptor on a per-inode reuse list and makes raw counts
lag the real connection count.
Refs #88033
2026-08-16 19:52:21 -07:00
..
2026-08-02 20:21:59 -07:00
2026-08-08 04:19:49 -07:00
2026-08-16 18:31:54 -07:00
2026-08-12 13:30:01 -05:00
2026-08-16 15:57:33 +05:30
2026-08-09 22:09:49 -04:00
2026-07-29 13:39:40 -07:00
2026-08-16 06:29:03 -07:00
2026-07-29 13:39:40 -07:00
2026-08-01 10:52:34 -07:00
2026-07-28 08:25:25 -07:00
2026-08-15 13:35:32 -07:00
2026-08-16 06:31:07 -07:00
2026-08-16 19:50:07 -07:00
2026-08-16 06:38:38 -07:00
2026-08-13 23:43:15 +05:30
2026-08-04 17:36:26 -04:00
2026-08-08 18:11:02 -07:00
2026-08-03 20:35:47 +05:30
2026-08-16 11:12:05 -07:00
2026-08-13 11:11:53 -07:00
2026-08-16 10:51:11 -07:00
2026-08-13 02:38:28 -07:00
2026-08-12 19:13:32 -07:00
2026-08-13 22:09:44 -07:00
2026-08-15 23:37:22 -07:00
2026-08-08 12:33:19 -07:00
2026-08-16 18:30:53 -07:00
2026-08-16 01:28:26 -07:00
2026-08-07 10:11:05 -07:00
2026-07-31 22:33:11 -07:00
2026-08-15 02:20:13 -07:00
2026-08-12 17:25:30 -05:00
2026-08-06 05:00:17 +05:30
2026-08-13 22:44:23 +05:30
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-01 15:05:05 +05:30
2026-08-16 01:50:20 -07:00
2026-07-29 13:10:23 -07:00
2026-07-23 07:24:46 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-02 00:11:50 -07:00
2026-08-15 23:37:22 -07:00
2026-07-25 07:17:52 -07:00
2026-07-29 13:10:23 -07:00
2026-07-23 11:44:43 -07:00
2026-08-15 00:25:00 -07:00
2026-07-29 15:12:28 -07:00
2026-08-14 22:23:00 -07:00
2026-08-14 15:41:38 -05:00
2026-08-03 17:19:49 -07:00
2026-07-29 13:10:23 -07:00
2026-08-14 21:48:14 -07:00
2026-07-29 13:10:23 -07:00
2026-08-02 00:11:50 -07:00
2026-08-08 05:21:09 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-03 20:30:32 +05:30
2026-07-29 13:10:23 -07:00
2026-08-12 19:13:32 -07:00
2026-08-16 06:29:53 -07:00
2026-08-09 22:09:49 -04:00
2026-08-15 00:36:03 -07:00
2026-07-29 13:10:23 -07:00
2026-08-09 22:09:49 -04:00
2026-08-15 23:37:22 -07:00
2026-08-09 22:09:49 -04:00
2026-07-29 13:10:23 -07:00
2026-07-29 18:13:09 -07:00
2026-08-16 01:55:25 -07:00
2026-07-29 18:55:10 -07:00
2026-08-13 23:43:15 +05:30
2026-08-13 23:43:15 +05:30
2026-07-29 17:35:16 -05:00
2026-07-26 19:30:32 -07:00
2026-08-13 02:38:28 -07:00
2026-08-14 21:35:30 -07:00
2026-08-14 22:33:58 -07:00
2026-08-08 19:46:35 -07:00
2026-08-14 21:58:09 -07:00
2026-08-14 21:58:09 -07:00
2026-08-14 21:58:09 -07:00
2026-08-16 11:34:40 -07:00
2026-07-31 22:39:11 -07:00
2026-07-26 16:06:50 -05:00
2026-08-13 02:38:28 -07:00
2026-08-13 18:39:54 +00:00
2026-08-13 18:39:54 +00:00
2026-08-14 21:58:09 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-24 09:49:00 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 18:13:09 -07:00
2026-08-15 01:55:22 -07:00
2026-08-15 01:55:22 -07:00
2026-07-29 13:10:23 -07:00
2026-08-07 19:44:35 +05:30
2026-07-29 13:10:23 -07:00
2026-07-29 21:30:53 -07:00
2026-07-29 19:53:17 -07:00
2026-08-11 17:06:15 -05:00
2026-08-14 21:41:26 -07:00
2026-07-30 00:08:28 -05:00
2026-07-29 13:10:23 -07:00
2026-08-03 17:38:13 +05:30
2026-08-14 21:36:41 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 15:12:28 -07:00
2026-07-31 07:18:02 -07:00
2026-07-31 22:35:16 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-09 22:09:49 -04:00
2026-07-29 13:10:23 -07:00
2026-08-14 21:45:08 -07:00
2026-08-14 21:50:48 -07:00
2026-08-13 11:49:14 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 19:48:37 -07:00
2026-08-14 13:51:26 -07:00
2026-08-14 13:51:26 -07:00
2026-08-12 18:55:14 -07:00
2026-08-10 17:02:56 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 21:30:53 -07:00
2026-08-08 12:33:19 -07:00
2026-07-29 13:10:23 -07:00
2026-08-07 00:41:58 -04:00
2026-07-22 07:56:47 -07:00
2026-08-02 10:04:48 -07:00
2026-08-16 19:52:21 -07:00
2026-08-10 17:02:56 -07:00
2026-08-10 17:02:56 -07:00
2026-07-29 13:10:23 -07:00
2026-08-03 20:37:17 +05:30
2026-08-02 21:32:13 +05:30
2026-07-22 21:14:44 -07:00
2026-07-31 23:18:12 -07:00
2026-08-06 07:49:42 -07:00
2026-08-04 11:26:15 +05:30
2026-08-12 19:43:29 -07:00
2026-08-12 19:43:41 -07:00
2026-08-15 02:22:58 -07:00
2026-08-08 14:18:26 +05:30
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-15 00:36:03 -07:00
2026-07-29 13:10:23 -07:00
2026-08-13 09:36:02 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-08-07 09:44:21 -07:00
2026-07-29 13:10:23 -07:00
2026-08-16 06:26:37 -07:00
2026-08-06 23:08:23 -05:00
2026-08-16 06:26:37 -07:00
2026-07-29 13:10:23 -07:00
2026-08-06 19:35:47 -06:00
2026-08-09 13:43:14 -07:00
2026-07-28 11:57:37 -07:00
2026-08-12 20:02:07 -07:00
2026-08-02 21:30:54 +05:30
2026-08-02 23:10:28 +05:30
2026-08-14 12:02:05 -04:00
2026-08-13 02:38:28 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-29 13:10:23 -07:00
2026-07-24 23:06:05 -07:00