Skip to content

SWF v44 system release - #49

Merged
wenaus merged 9 commits into
mainfrom
infra/baseline-v44
Oct 19, 2026
Merged

wenaus merged 9 commits into
mainfrom
infra/baseline-v44

Conversation

@wenaus

@wenaus wenaus commented Oct 19, 2026

Copy link
Copy Markdown
Member

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 main since v42 is folded in and credited below. These
notes cover the coordinated baseline repositories and the relevant main work in their peer
repositories.
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

wenaus and others added 6 commits September 5, 2026 12:35
…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>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:08
@github-actions

Copy link
Copy Markdown

Test Coverage Summary

src/swf_common_lib/api_utils.py          87     78    10%   37-75, 94-118, 136-154, 174-198
src/swf_common_lib/base_agent.py        555    400    28%   26-29, 46-51, 57-79, 97-98, 107-111, 149-257, 269-275, 282-368, 405-407, 415-418, 427-429, 437-438, 442-446, 483-485, 507, 512-515, 520-528, 532-533, 536-537, 541-547, 552-577, 587-594, 598-624, 631, 653-676, 697-698, 714-715, 732-743, 779-782, 788, 794-803, 811-812, 818, 824, 842-878, 886-911, 916-946, 950-993, 997-1026, 1030-1040, 1044, 1048-1072
src/swf_common_lib/config_utils.py       30     20    33%   30, 46-83, 86, 102
src/swf_common_lib/episodes.py          188    188     0%   23-379
src/swf_common_lib/logging_utils.py      33      0   100%
src/swf_common_lib/rest_logging.py       80     72    10%   17-27, 31-54, 58-114, 135-157
src/swf_common_lib/rucio_utils.py       139    139     0%   5-341
-------------------------------------------------------------------
TOTAL                                  1112    897    19%
============================== 8 passed in 2.55s ===============================

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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()
Comment thread tests/test_stop_bounded.py Outdated
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>
@github-actions

Copy link
Copy Markdown

Test Coverage Summary

src/swf_common_lib/episodes.py          188    188     0%   23-379
src/swf_common_lib/logging_utils.py      33      0   100%
src/swf_common_lib/rest_logging.py       81     73    10%   17-27, 31-54, 58-114, 135-158
src/swf_common_lib/rucio_utils.py       139    139     0%   5-341
-------------------------------------------------------------------
TOTAL                                  1124    973    13%
=========================== short test summary info ============================
FAILED tests/test_stop_bounded.py::test_long_doer_is_ended_at_the_drain_limit - TypeError: argument of type 'NoneType' is not a container or iterable
FAILED tests/test_stop_bounded.py::test_second_stop_signal_cuts_the_drain_short - TypeError: argument of type 'NoneType' is not a container or iterable
========================= 2 failed, 6 passed in 0.47s ==========================

…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>
@github-actions

Copy link
Copy Markdown

Test Coverage Summary

src/swf_common_lib/api_utils.py          87     87     0%   8-198
src/swf_common_lib/base_agent.py        580    580     0%   5-1134
src/swf_common_lib/config_utils.py       30     30     0%   7-102
src/swf_common_lib/episodes.py          188    188     0%   23-379
src/swf_common_lib/logging_utils.py      33      0   100%
src/swf_common_lib/rest_logging.py       81     81     0%   8-158
src/swf_common_lib/rucio_utils.py       139    139     0%   5-341
-------------------------------------------------------------------
TOTAL                                  1138   1105     3%
============================== 5 passed in 0.41s ===============================

…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>
@github-actions

Copy link
Copy Markdown

Test Coverage Summary

src/swf_common_lib/api_utils.py          87     87     0%   8-198
src/swf_common_lib/base_agent.py        582    582     0%   5-1141
src/swf_common_lib/config_utils.py       30     30     0%   7-102
src/swf_common_lib/episodes.py          188    188     0%   23-379
src/swf_common_lib/logging_utils.py      33      0   100%
src/swf_common_lib/rest_logging.py       81     81     0%   8-158
src/swf_common_lib/rucio_utils.py       139    139     0%   5-341
-------------------------------------------------------------------
TOTAL                                  1140   1107     3%
============================== 5 passed in 0.42s ===============================

@wenaus
wenaus merged commit b97ef2e into main Oct 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants