_drain called finish_result synchronously on the owner loop while holding live.event_stream.lock. That covered outcome flags, compaction, recursive redaction, JSON encoding, an SQLite write that can wait up to _WRITE_PATIENCE_S (20 s) for the writer lock, and media cleanup. Every session on the gateway stalled for that time once per turn. Settlement now runs in a worker thread (commit_and_publish). It is tracked with track_mutation and shielded, like the recovery stamp, so drain cancellation or profile retirement waits for the write instead of abandoning it. The CPU-only preparation (prepare_result) runs before the stream lock is taken. The lock covers only the transaction and the message.complete frame, so replay and attach never see a terminal row without its completion. Ordering is unchanged: commit, then message.complete, then idle session.info (_publish_pending, back on the loop because bot-receipt wakeups create tasks), then waiters. The committed (settled, response) is handed back before publication, so a failed publish still counts as a commit. afb23c38520b's failure path (retain the captured result, mark the claim unknown, publish a commit-then-error once) is untouched. Loop-latency probe: real _drain, a 500-turn captured result (880 KB), another session pinged every 2 ms. On origin/pr135061 the loop was blocked for 41 ms (2000 turns: 112 ms). With a writer holding the lock for 1.5 s it was blocked for 1588 ms. After this change the worst stall is 6 ms (2000 turns: 6 ms) and 10 ms under 1.5 s of writer contention. Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5456384314
19 lines
504 B
Python
19 lines
504 B
Python
"""Stop the actual owner after the result commit, before any publication."""
|
|
import os
|
|
import runpy
|
|
import signal
|
|
from gateway import session_results
|
|
|
|
finish = session_results.finish_result
|
|
|
|
|
|
def stop_after_commit(db, *, row, **kwargs):
|
|
receipt = finish(db, row=row, **kwargs)
|
|
if row['payload'].get('text') == 'BLOCK_STARTED':
|
|
os.kill(os.getpid(), signal.SIGSTOP)
|
|
return receipt
|
|
|
|
|
|
session_results.finish_result = stop_after_commit
|
|
runpy.run_module('gateway.run', run_name='__main__')
|