fix(P001): pin fire-and-forget task refs in audit_log + phases to prevent GC drop#465
Merged
cirwel merged 1 commit intoMay 19, 2026
Conversation
…vent GC drop Per asyncio docs (Python 3.11+): bare loop.create_task(coro) returns a Task that CPython GC can collect mid-await if no caller holds a reference. Three sites in the codebase had this hazard, all flagged by Watcher (#69f2ccbc, #0a0616c2, #acfc7012 — 2026-05-18): 1. src/audit_log.py _write_entry — fire-and-forget PG audit tail. Coroutine awaits asyncpg via append_audit_event_async; GC mid-await would silently drop the row that backs audit.events queries (the same surface §129 reads from). 2. src/mcp_handlers/updates/phases.py — _persist_thread_identity_async (per check-in, high frequency). 3. src/mcp_handlers/updates/phases.py — _persist_inferred_purpose_async (per check-in, high frequency). All three fixed using the established 'module-local set + add_done_callback' pattern already in src/coordination_failure_emit.py:_inflight_dedicated_writes and src/mcp_handlers/support/pause_ttl.py:_inflight_persistence_tasks. Regression tests in tests/test_p001_task_refs.py pin the pattern at each new helper. These were pre-existing bugs surfaced during the pause-ttl work (PR #464); they predate that change and live on master. Watcher fingerprints will be resolved against this commit per the audit-trail convention in CLAUDE.md.
✅ Documentation Validation PassedTool Count: 7 tools tools All documentation is synchronized with the codebase. |
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.
Auto-shipped by ship.sh — runtime path. Auto-merge is enabled; CI gate applies.