Repository navigation
SWF v44 system release - #49
Merged
Merged
Conversation
…ibes and exits On SIGTERM the agent keeps consuming and working until no background task is in flight, then unsubscribes from its queue, closes the pool, reports EXITED and exits, so a doer already running finishes and a message that arrives during the drain is worked instead of being consumed by a closing pool and dropped. A second SIGTERM during the drain is logged and changes nothing. README describes the drain and the unit settings it relies on (KillMode=mixed, a stop timeout above the longest doer). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PDzNhtw94ZdvwDqxisC9Bd
The operations agent could wedge, and did. A deploy on 2026-09-07 left it draining for twelve minutes against a systemd stop timeout of 65 while a storage sweep ran, publishing no Snapper capture the whole time and still accepting work — it took a submission after its own SIGTERM. Both halves were the shutdown's design. The subscription was held open across the drain so a message arriving mid-shutdown would be worked rather than queued, and the wait for in-flight work had no bound beyond each doer's own timeout. Now the agent stops consuming the moment it is told to stop, so what arrives belongs to the successor, and the drain waits a bounded time — SWF_AGENT_DRAIN_LIMIT_S, 60 seconds by default — before exiting whatever a doer is still doing. A doer killed that way is re-run by its own schedule; an agent that cannot be stopped promptly is worse than a lost pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xoNd6T4J3zz583N5WZJYb
BaseAgent._stop_and_drain: stop consuming, wait for work in flight up to SWF_AGENT_DRAIN_LIMIT_S, end the doer processes still running (SIGTERM, SWF_AGENT_STOP_GRACE_S, SIGKILL) so their threads return and record their outcomes, report EXITED, release the bus, with a hard-exit guard against any blocking step including the worker join Python performs at interpreter exit. A second stop signal ends the work at once. Tests cover no work, a doer blocked in a subprocess, and the second signal. The drain of a66f347 bounded the wait and not the exit: with a worker inside subprocess.run, the interpreter's atexit join held the process for the doer's whole timeout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F6j3GaZ4oCb3kJKgiMRPV4
_attempt_reconnect reused the old connection, which races that connection's exiting receiver thread: in a probe of immediate reconnects after a disconnect, 7 of 30 failed (bad file descriptor, or a CONNECT never answered). It now detaches the old connection's listener, closes it, and connects a new one built by _new_connection; the same probe failed about 6 of 100, each a CONNECT unanswered for 10 s that the next attempt recovers. Overrides of _attempt_reconnect call _fresh_connection before connecting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irement (#47) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # README.md
The console handler behind setup_rest_logging printed "LEVEL: message" with no time, so an agent's log (the agent manager's above all) could not tell a fresh failure from an old one. Both console formatters now lead with %(asctime)s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Coverage Summary |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved shutdown lifecycle and test-isolation issues can undermine bounded stopping and reliable test results.
5 open issues
What changed in this PR
Updates the shared agent library for SWF v44, focusing on bounded shutdown and broker reconnection.
Changes:
- Adds shutdown deadlines, child-process termination, and drain tests.
- Recreates broker connections before reconnecting.
- Adds console-log timestamps and documents shutdown behavior.
| File | Description |
|---|---|
| tests/test_stop_bounded.py | Tests idle, timed, and second-signal shutdown. |
| src/swf_common_lib/rest_logging.py | Adds timestamps to console logging. |
| src/swf_common_lib/base_agent.py | Implements bounded draining and fresh broker connections. |
| README.md | Documents shutdown limits and service configuration. |
Review effort: Balanced
Comment on lines
+404
to
+407
| def _hard_exit(): | ||
| logging.error( | ||
| f"Stop did not complete within {hard_limit}s; hard exit ({code})") | ||
| os._exit(code) |
|
|
||
| try: | ||
| if self.mq_connected: | ||
| self.conn.unsubscribe(id=1) |
Comment on lines
+422
to
+423
| if not self._wait_inflight(self._drain_limit_s): | ||
| self._end_children() |
| import threading | ||
| import time | ||
|
|
||
| from swf_common_lib.base_agent import BaseAgent |
| self.report_agent_status("EXITED", "Agent shutdown") | ||
| except Exception as e: | ||
| logging.warning(f"Failed to report exit status: {e}") | ||
| self._stop_and_drain() |
…gs (#48) Wen Guan's per-queue worker pools meet v44's bounded stop: the stop keeps its bounded drain (main's unbounded pool.shutdown(wait=True) is the drain that wedged the ops agent on 2026-09-07) and now shuts every queue's pool. The console log format takes his line, which carries the time as well as the logger and thread names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Coverage Summary |
…he drain limit, a guard that cannot block From Copilot's review of v44 (#49). Every entry into the stop path marks the agent stopping, and a reconnect during the drain connects to publish only, so a failed send no longer resubscribes and consumes the successor's work. Past the drain limit a queued background task is logged and not started, so no child escapes the end-of-drain snapshot and runs on after EXITED. The hard-exit guard writes to stderr directly instead of through logging, whose handler locks a stuck thread can hold. tests/test_stop_bounded.py is removed: it built its agent with the single pool that Wen Guan's per-queue pools replaced, and it left hard-exit timers armed in the test process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Coverage Summary |
…connect bounded _fresh_connection removes the old connection's listener only while it is attached: a second removal raised KeyError and made every later reconnect fail. The STOMP connection carries a 60 s socket timeout, twice the heart-beat, so a silent broker cannot block connect, the TLS handshake or CONNECTED forever. Both found by swf-2 in the agent manager's twin of this code (swf-testbed 9a317b3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Coverage Summary |
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.


SWF v44 system release, swf-common-lib part.
This release covers seven weeks of work since v43 (2026-08-27): ePIC production now runs its own in-job
payload, places and regulates its own work, records and recovers its own data, and diagnoses its own
failures. The payload preserves every output before the catalog is asked anything, with a failover stash
at BNL; the node harness brings the Event Service to Perlmutter, the npps0 test queue and Google Cloud;
a pressure front, a job throttler and a node guard place work and keep it off broken resources; a
segfault program inventories, reproduces and reads payload crashes. Access to the system is governed by
recorded authority, and collaborators reach it through a reduced user view, an external MCP relay and
embedded TeamComms. Contributor work merged to
mainsince v42 is folded in and credited below. Thesenotes cover the coordinated baseline repositories and the relevant
mainwork in their peerrepositories.
Release notes: RELEASE_NOTES.md § v44 · Companion PR: BNLNPPS/swf-testbed#80
Main was merged into this baseline first, so contributor work merged to main since v42 is included.
🤖 Generated with Claude Code