Skip to content

fix: close leaked SQLite connections in delivery, delegation, verification, and cron execution ledgers - #70985

Merged
teknium1 merged 4 commits into
mainfrom
fix/sqlite-ledger-connection-leaks
Jul 24, 2026
Merged

fix: close leaked SQLite connections in delivery, delegation, verification, and cron execution ledgers#70985
teknium1 merged 4 commits into
mainfrom
fix/sqlite-ledger-connection-leaks

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Long-running gateway and cron processes no longer leak one SQLite fd per ledger operation — connections in delivery_ledger, async_delegation, verification_evidence, the cron executions ledger, and the gateway readiness probe now close deterministically.

Changes

Validation

Targeted ledger/cron suites green; fd-count regression tests assert no growth across repeated operations.

Supersedes #69785, #70530, #70918, #70917 (duplicates of the two base PRs).

Fixes #69678
Fixes #69567

Infographic

sqlite-ledger-connection-leaks

dhruvraajeev and others added 4 commits July 24, 2026 13:21
…, delegation, and verification ledgers

Three durable ledgers used `with _connect() as conn:` where the sqlite3
connection context manager commits/rolls back but never closes, leaking the
db/-wal/-shm file descriptors on every call. On a long-running gateway this
exhausts RLIMIT_NOFILE and fails unrelated components with
`[Errno 24] Too many open files`. Same bug class as the cron execution ledger
(#69567 / PR #69594), which the connection helpers here are modeled on.

Fix: route every ledger operation through a `_transaction()` context manager
that guarantees `conn.close()` on exit. `_connect()` keeps its
schema-on-connect contract (several tests call it directly) and now self-closes
if schema init fails.

Adds per-module regression tests asserting every opened connection is closed,
including the no-op-update and exception-mid-transaction paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sibling of the #69678/#69567 ledger leak class found while widening the
sweep: _probe_state_db used 'with sqlite3.connect(...)', whose context
manager only commits/rolls back and never closes, leaking one connection
(db fd) per health poll in the long-running gateway. Wrap the connection
in contextlib.closing so every probe closes deterministically.
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 672dd0d

all good!

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery tool/delegate Subagent delegation P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 24, 2026
@teknium1
teknium1 merged commit 214099d into main Jul 24, 2026
39 checks passed
@teknium1
teknium1 deleted the fix/sqlite-ledger-connection-leaks branch July 24, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

4 participants