-
Notifications
You must be signed in to change notification settings - Fork 52.4k
fix(gateway): rewind MarkdownV2-escaped pipe tables in cron Telegram deliveries #53661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kewe63
wants to merge
8
commits into
NousResearch:main
Choose a base branch
from
Kewe63:fix/53175-v7-final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
469397e
fix(gateway): centralize agent cleanup pipeline with executor offload…
Kewe63 c954ff4
test(gateway): update shutdown cache cleanup tests for async cleanup …
Kewe63 5d13d5d
fix(gateway): ensure _finalize_shutdown_agents uses safe_schedule_thr…
Kewe63 2407649
fix(gateway): ensure _finalize_shutdown_agents runs sync cleanup in t…
Kewe63 a1d3ff8
ci(docker-publish): skip arm64/amd64 build jobs on fork PRs (no packa…
Kewe63 20502a4
ci(docker): fix fork PR skip condition for reusable workflow calls
Kewe63 e54620d
fix(gateway): rewind MarkdownV2-escaped pipe tables in cron Telegram …
Kewe63 07f1470
fix(tools): tolerate PID race in test_entire_tree_is_sigkilled_not_ju…
Kewe63 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| ## Summary | ||
|
|
||
| Fixes gateway event loop zombie state (#53175) where `agent.close()` and | ||
| `shutdown_memory_provider()` blocked the event loop during subprocess | ||
| teardown, causing silent message processing death (16 crashes in ~30h). | ||
|
|
||
| Replaces 7 scattered synchronous `_cleanup_agent_resources()` call sites | ||
| with one centralized `_cleanup_agent_async()` that offloads all blocking | ||
| I/O to a thread pool executor with per-context timeouts and structured | ||
| logging. | ||
|
|
||
| ## Problem | ||
|
|
||
| Issue #53175: the gateway enters a zombie state where the process stays | ||
| alive, platform status shows "connected," but the event loop silently | ||
| stops processing inbound messages. Root cause: `_cleanup_agent_resources()` | ||
| runs synchronous blocking code (`agent.close()`, `shutdown_memory_provider()`) | ||
| inside async handlers. Three bare `except Exception: pass` blocks made the | ||
| blockage invisible. | ||
|
|
||
| Each zombie crash was preceded by long responses (>100s) + session | ||
| reset (`/new`), exactly when agent cleanup is triggered on a loaded LLM | ||
| client with active subprocesses and network connections. | ||
|
|
||
| ## Solution | ||
|
|
||
| ### New `_CleanupContext` enum | ||
| Categorizes all 7 cleanup triggers for selective timeout & logging: | ||
|
|
||
| | Context | Default timeout | Trigger | | ||
| |---|---|---| | ||
| | `SHUTDOWN` | 30s | Gateway stop/restart | | ||
| | `SESSION_EXPIRY` | 30s | 5-min watchdog finalization | | ||
| | `SESSION_HYGIENE` | 30s | Post-auto-compress eviction | | ||
| | `IDLE_CACHE_EVICTION` | 30s | Shutdown idle cached agents | | ||
| | `BACKGROUND_TASK` | 15s | After executor-run background task | | ||
| | `CACHE_FALLBACK` | 10s | `_release_evicted_agent_soft` fallback | | ||
|
|
||
| ### `_cleanup_agent_async(agent, context, session_key)` | ||
| Centralized async cleanup: | ||
| ```python | ||
| await asyncio.wait_for( | ||
| self._run_in_executor_with_context( | ||
| self._cleanup_agent_resources, agent | ||
| ), | ||
| timeout=self._get_cleanup_timeout(context), | ||
| ) | ||
| ``` | ||
| - Runs blocking ops in thread pool → event loop never stalls | ||
| - Timeout per context (configurable) → stuck agent can't take down gateway | ||
| - Structured logging with `session_id` + `context` → debuggable | ||
| - `TimeoutError` → warning + continue (preserves liveness) | ||
| - `Exception` → warning + continue (replaces silent `pass`) | ||
|
|
||
| ### `_cleanup_agent_resources()` (updated) | ||
| Replaced 3 silent `except Exception: pass` with `logger.warning()` that | ||
| includes session_id and operation name: | ||
| - `shutdown_memory_provider()` failure → logged | ||
| - `agent.close()` failure → logged | ||
| - `cleanup_stale_async_clients()` failure → logged | ||
|
|
||
| ### 7 call sites migrated | ||
| | # | Call site | Old | New | | ||
| |---|---|---|---| | ||
| | 1 | `_finalize_shutdown_agents()` | sync `_cleanup_agent_resources` | `_cleanup_agent_async` + threadpool (SHUTDOWN) | | ||
| | 2 | `_session_expiry_watcher()` | sync `_cleanup_agent_resources` | `await _cleanup_agent_async` (SESSION_EXPIRY) | | ||
| | 3 | Shutdown idle cache cleanup | sync `_cleanup_agent_resources` | `await _cleanup_agent_async` (IDLE_CACHE_EVICTION) | | ||
| | 4 | Session hygiene | sync `_cleanup_agent_resources` | `await _cleanup_agent_async` (SESSION_HYGIENE) | | ||
| | 5 | Background task executor | sync `_cleanup_agent_resources` | kept sync (already in executor thread) + comment | | ||
| | 6 | `_release_evicted_agent_soft()` fallback | sync `_cleanup_agent_resources` | kept sync (already in daemon thread) + comment | | ||
| | 7 | Cross-process cache invalidation | sync `_cleanup_agent_resources` | kept sync (already in daemon thread) + comment | | ||
|
|
||
| ### `_finalize_shutdown_agents` sync fallback | ||
| When `_gateway_loop` is None (tests), runs cleanup synchronously so unit | ||
| tests can verify `close()` was called immediately. Simplified the previous | ||
| `asyncio.get_running_loop()` fallback chain. | ||
|
|
||
| ### Optional config | ||
| ```yaml | ||
| gateway: | ||
| cleanup_timeouts: | ||
| shutdown: 30.0 | ||
| session_expiry: 30.0 | ||
| session_hygiene: 30.0 | ||
| idle_cache: 30.0 | ||
| background_task: 15.0 | ||
| cache_fallback: 10.0 | ||
| ``` | ||
|
|
||
| ## Files changed | ||
|
|
||
| | File | Changes | | ||
| |---|---| | ||
| | `gateway/run.py` | +191/-43 — `_CleanupContext` enum, `_cleanup_agent_async()`, `_get_cleanup_timeout()`, updated `_cleanup_agent_resources()`, migrated 7 call sites | | ||
| | `tests/gateway/test_shutdown_cache_cleanup.py` | +44/-43 — updated for async cleanup pattern, 8/8 passing | | ||
| | `.github/workflows/docker-publish.yml` | +13/-3 — skip Docker build on fork PRs (no `packages: write`) | | ||
|
|
||
| ## Commits | ||
|
|
||
| 1. `5724c4e` — fix(gateway): centralize agent cleanup pipeline with executor offload (#53175) | ||
| 2. `deedb4b` — test(gateway): update shutdown cache cleanup tests for async cleanup pattern | ||
| 3. `cd63145` — fix(gateway): ensure _finalize_shutdown_agents uses safe_schedule_threadsafe with sync fallback | ||
| 4. `fbf7e44` — fix(gateway): ensure _finalize_shutdown_agents runs sync cleanup without _gateway_loop | ||
| 5. `522ad29` — ci(docker-publish): skip arm64/amd64 build jobs on fork PRs | ||
|
|
||
| Closes #53175 |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explicitly skips fence isolation, but the subsequent row-level replacement mutates matching
\|content inside a fenced code block. Please preserve fenced regions and add a negative regression; the adapter does not extract fences until after this DeliveryRouter transform.