[HELD — independent review pending] Release v0.51.340 — bg_task agent wakeup (trio #2968+#2971+#2979) (#3867)
Some checks failed
Release & Docker / release (push) Has been cancelled

* stage bg_task trio combined (#2979 superset) on master for deep review

* fix(bg_task): unsubscribe SessionChannel on header-write failure (Codex deep-review catch) + regression test

* test: realign on-subscribe-recovery anchor to subscribe_to_session_channel after leak fix

* CHANGELOG: bg_task trio as v0.51.340 LD (HELD pending independent review)

* bg_task trio: apply 3 independent-review (greptile) fixes

1. start_session_turn now threads the session PROFILE model defaults
   (_read_profile_model_config) into the wakeup model-resolve, so a brand-new
   session with an empty model falls back to the profile default not global
   DEFAULT_MODEL. Updated the white-box spy test signature accordingly.
2. /api/session/stream omits the Connection header (HTTP/1.1 keep-alive
   default) to match the #3103 long-lived-SSE pattern.
3. Reaper now prunes _LAST_EMIT_TS for collected sessions so the coalesce
   timestamp map can't grow one permanent entry per session forever.

nesquena APPROVED the PR; these are the 3 non-blocking greptile suggestions.

* test: realign _start_session_turn adapter stub lambda to new profile-defaults signature
This commit is contained in:
nesquena-hermes
2026-06-08 22:36:18 -07:00
committed by GitHub
parent c031cf5c6d
commit 26e133e3e8
27 changed files with 7317 additions and 95 deletions

View File

@@ -586,6 +586,27 @@ def main() -> None:
except Exception as e:
print(f'[!!] WARNING: Gateway watcher failed to start: {e}', flush=True)
# Start the bg_task_complete drain thread for terminal(notify_on_complete=true)
# agent wakeup. Reads tools.process_registry.completion_queue and emits SSE
# bg_task_complete events (canonical name; legacy process_complete alias is
# still emitted for back-compat) to the matching session's stream.
try:
from api.background_process import start_drain_thread
if start_drain_thread():
print('[ok] bg_task_complete drain thread started', flush=True)
except Exception as e:
print(f'[!!] WARNING: bg_task_complete drain failed to start: {e}', flush=True)
# Start the SessionChannel reaper for the persistent per-session SSE
# endpoint (/api/session/stream). Runs every 60s, collects channels with
# no subscribers past the grace period or past the idle TTL cap.
try:
from api.background_process import start_session_channel_reaper
if start_session_channel_reaper():
print('[ok] SessionChannel reaper thread started', flush=True)
except Exception as e:
print(f'[!!] WARNING: SessionChannel reaper failed to start: {e}', flush=True)
# Load WebUI dashboard plugins
try:
from api.plugins import load_plugins
@@ -633,6 +654,20 @@ def main() -> None:
drain_all_on_shutdown()
except Exception:
logger.debug("Failed to drain lifecycle on shutdown", exc_info=True)
# Stop bg_task_complete drain + SessionChannel reaper (ours-original).
# The drain thread emits the canonical ``bg_task_complete`` event
# (with ``process_complete`` kept as a temporary backward-compat
# alias for older clients — see start_drain_thread comment above).
try:
from api.background_process import stop_drain_thread
stop_drain_thread()
except Exception:
logger.debug("Failed to stop bg_task_complete drain thread during shutdown", exc_info=True)
try:
from api.background_process import stop_session_channel_reaper
stop_session_channel_reaper()
except Exception:
logger.debug("Failed to stop SessionChannel reaper during shutdown", exc_info=True)
if __name__ == '__main__':
main()