Repository navigation
perf(tui_gateway): bound heavy SessionDB reads off the event loop - #441
Merged
Merged
Conversation
Share a loop-local async SessionDB heavy-read gate between dashboard REST reads and WebSocket session-list RPCs. The gate reads dashboard.heavy_read_max_concurrency lazily, queues with a bounded wait, logs queue_wait, exposes shed stats, and returns retryable backend-busy errors on saturation.\n\nVerified:\n- scripts/run_tests.sh tests/test_web_server_sessiondb_eventloop.py -v (14 passed)\n- scripts/run_tests.sh -j 16 tests/tui_gateway tests/test_tui_gateway*.py tests/test_web_server*.py tests/hermes_cli/test_web_server*.py (1133 passed)\n- git diff --check\n- /Users/alexgierczyk/.hermes/hermes-agent/venv/bin/python -m py_compile hermes_cli/session_db_heavy_gate.py hermes_cli/web_server.py tui_gateway/server.py tui_gateway/ws.py\n\nNot pushed.
Collaborator
Author
FleetReviewConfidence: 2/5 Findings
FleetReview provenance · models: B=gpt-5.6-sol, C=claude-code-opus-4-8, F=gpt-5.6-sol, G=grok-4.5 · cost: $9.48 · duration: 20m 55s · rounds: 1 · files examined: 6 |
Kyzcreig
added a commit
that referenced
this pull request
Sep 25, 2026
… 3 premises re-checked (t_2a1bd9cd) #115 DROP->KEEP (swiftui-skills skill is live), #215/#441 DROP->UNRESOLVED (tui_gateway/ws.py still consumes the gate; dashboard live), nopr:8a8b81638c UPSTREAM->UNRESOLVED (leak needs the fork-only auto-attach detector). Branches: 5 revert branches built + targeted pytest green; upstream-617 and upstream-466 hand-ported onto upstream/main with tests green.
This was referenced Sep 26, 2026
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.
Symptom
A single Discord voice message posted its 🎙️ transcript echo twice — two identical messages 4.3s apart. The gateway log confirms the same
.oggwas transcribed twice:Root cause
Echo dedupe was keyed on Python object identity.
_gateway_pending_stt_echo_sentis set viasetattron aMessageEvent, but one platform message reaches the echo path as two distinct event objects:merge_pending_message_eventmay have replaced, and whose cached STT attrs_invalidate_pending_stt_cachedeliberately clears.Neither guard survives that hand-off.
There was also a second, independent emitter:
_prepare_inbound_message_textsent the echo inline with its own loop, never consulting the once-flag at all — so the drain leg re-posted even when the flag was intact.Fix
Whole bug class, not just the one site — all 6 echo call sites now funnel through the single deduped helper:
message_idwhen present, else the concrete downloaded audio paths — held in a bounded LRU on the runner, so the guard survives across event objects._prepare_inbound_message_textthrough_echo_pending_stt_transcripts_onceinstead of sending inline.Test-gate honesty
New
tests/gateway/test_stt_transcript_echo_dedupe.pyasserts the invariant (one platform message → exactly one echo), plus the negative cases: distinct messages still each echo, a fresh voice message still echoes, quiet-STT stays silent, and the LRU stays bounded. 4 of the 7 fail without this fix.test_all_gateway_transcript_echo_sends_are_gatedwas rewritten from a fixed 12-line proximity window to an AST-resolved enclosing function check. The config gate is a property of the function; the window check broke as soon as unrelated logic landed between the gate and the send. Verified by mutation — injecting an ungated echo site still fails the test.Verification
tests/gateway/suite run.test_readiness,test_systemd_notify,test_api_server::test_health_detailed_returns_ok) reproduce identically on cleanmainin a separate baseline worktree — pre-existing and unrelated (test_systemd_notifyneeds Linux abstract sockets).