fleet-bus
Agent Bus (PGMQ) operations — queue inspection, DLQ management, message recovery, auth, and health diagnostics. Covers the Postgres-backed message queue that replaces the legacy file inbox.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4
- Forks
- 1
01 前言 Front Matter
- name
- fleet-bus
- author
- Steadfaste Fleet
- version
- 1.3.0
- category
- devops
- metadata
- { "hermes": { "tags": [ "bus", "pgmq", "dlq", "messaging", "queue", "postgres", "recovery" ], "related_skills": [ "system-remediation", "steadfaste-fleet-deployment" ] } }
- platforms
- [ "linux" ]
- description
- Agent Bus (PGMQ) operations — queue inspection, DLQ management, message recovery, auth, and health diagnostics. Covers the Postgres-backed message queue that replaces the legacy file inbox.
02 资源文件 2
- 参考文档references/agent-registry.md8.6 KB
- 参考文档references/forwarder-peer-resolution.md3.2 KB
03 SKILL.md 正文
<!-- renamed from skills/devops/cortex-bus/SKILL.md in the cortex-to-fleet sweep; content predates the range (commit 353c3d54) -->
Agent Bus — PGMQ Operations
Overview
The Agent Bus is a Postgres-native message queue (lib/pgmq implementation with SKIP LOCKED) running on port :8903, proxied through nginx. All inter-agent communication flows through it. It replaces the old file-based agent inbox.
📐 Architecture reference:
docs/reference/fleet-bus-config.md,docs/bus-architecture.md,docs/orch-bus-setup.md,docs/esther-bus-setup.md— these live on the orchestrator hosts' private repo (moses/esther) and may NOT exist on this host or in the public repo. Check before opening:ls ~/steadfaste-fleet/docs/reference/fleet-bus-config.md 2>/dev/null || echo "not on this host — request from orchestrator via inbox_orchestrator". This skill covers operational diagnostics only.
⚠️ Postgres access (post-2026-08-05 migration): the
legacy Postgrescontainer was replaced bymycortex-postgres(role/dbmycortex, port still:15432). All psql examples below use the new container/role:sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex ...". The oldmycortexrole does NOT exist in the new container — using it fails withFATAL: role "mycortex" does not exist.
Key architectural facts:
- Bus server processes at
~/steadfaste-fleet/core/fleet_bus/server.py(modulefleet_bus.server:app, servicefleet-bus.service) - Queue module at
~/steadfaste-fleet/core/fleet_bus/queue.py - Postgres schema
bus.*in the shared mycortex database (:15432) - MCP tools
mcp__fleet_bus__*route through the bus via HTTP - Health check:
curl http://127.0.0.1:8903/healthreturns 200 - Bearer token auth: token from
FLEET_BUS_TOKENin.env
When to Use
- Diagnosing message delivery failures between agents
- Inspecting queue depth or DLQ buildup
- Recovering stuck
processingmessages - Fixing bus auth or permission issues
- Investigating why an agent isn't receiving messages
Message Contract (strict input formatting)
Every /api/pgmq/send is validated at ingestion (2026-09-02, anti-poisoning/anti-spam at fleet scale). Violations → 400 + reason; over quota → 429.
| Field | Rule |
|---|---|
from |
Required, lowercase agent name, must equal the authenticated sender (spoofing rejected with 400 "from '<X>' does not match authenticated agent '<Y>'") |
subject |
Required, ^[A-Z][A-Z0-9_]{0,63}$ (EXEC, PING, DOCTOR_TEST, …) |
body |
Required, object or string |
to / correlation_id / timestamp / type / priority / forwarded_from |
Optional; priority int 0-100 — string values ("normal", "urgent") are rejected with 400. Map via dict before sending. forwarded_from set by the bus forwarder when relaying a message between bus instances (preserves the original sender). |
| Unknown keys | Rejected — no field smuggling |
| Size | 64 KiB max/message |
| Rate | 600 sends/hr/agent (FLEET_BUS_RATE_LIMIT_PER_HOUR), sliding window |
workflow_step_result queue uses its own schema (workflow_id step_id status result error) — agents post step results without an envelope.
Implementation: core/fleet_bus/validate.py + core/fleet_bus/ratelimit.py, tests in tests/test_bus_validate.py. Sending messages: use bus_send() / the MCP inbox tools — they build conforming envelopes.
Inbox Message Decision Framework
Classify each inbox message on two axes, then act per the matrix. Priority (error=None priority): critical | urgent | normal | notification. Scope: Simple (<3 items) | Moderate (3–10) | Complex (>10) | Multi-agent.
| Prio → | Simple | Moderate | Complex | Multi-agent |
|---|---|---|---|---|
| critical | AUTO-ACT | AUTO-ACT | AUTO-ACT + notify | Delegate + notify |
| urgent | AUTO-ACT | AUTO-ACT | AUTO-ACT + report | Delegate + report |
| normal | AUTO-ACT | AUTO-ACT | Escalate | Escalate |
| notification | Acknowledge | Acknowledge | Acknowledge | Forward |
After-action: deliver what was done, how it was verified, the evidence, and the cycle ID.
Diagnosing Bus State
1. Queue Overview
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT queue_name, state, COUNT(*) as count
FROM bus.messages
GROUP BY queue_name, state
ORDER BY queue_name, state;
\""
Shows every queue with its message counts broken down by state:
| State | Meaning |
|---|---|
pending |
Ready for dequeue — normal state |
processing |
Currently dequeued, within visibility timeout |
archived |
Successfully processed (or auto-archived) |
2. DLQ Inspection (Dead Letter Queue)
Messages that exceeded max_retries (default 3) move to {queue}_dlq. DLQ messages older than 6 hours are auto-archived by bus.recover_timeouts().
# DLQ depth by queue
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT queue_name, state, COUNT(*) as count,
MIN(enqueued_at)::timestamptz(0) as oldest,
MAX(enqueued_at)::timestamptz(0) as newest
FROM bus.messages
WHERE queue_name LIKE '%dlq%'
GROUP BY queue_name, state
ORDER BY queue_name, state;
\""
# DLQ message content — who sent it, what about, how many retries
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT
queue_name,
COALESCE(body->>'from', '(empty)') as sender,
body->>'subject' as subject,
body->>'topic' as topic,
retry_count,
error,
enqueued_at::timestamptz(0)
FROM bus.messages
WHERE state = 'pending' AND queue_name LIKE '%dlq%'
ORDER BY queue_name, enqueued_at DESC
LIMIT 50;
\""
3. Check Queue Schema Integrity
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT name, is_dlq, parent_queue, max_retries FROM bus.queues ORDER BY name;
\""
Every queue ending in _dlq MUST have is_dlq = true. If false, the auto-archive and chain-deletion break silently.
4. Run Recovery
# Returns count of messages recovered/archived
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT bus.recover_timeouts();
\""
The recover_timeouts() function does three things:
- Recovers processing→pending for messages below
max_retries - Moves over-retry processing messages to DLQ (or deletes if already in a DLQ)
- Auto-archives DLQ messages older than 6 hours
5. Interpreting Recovery Counts
The orch-bus-recover-timeouts cron (every 5m) calls bus.recover_timeouts() and reports results. The silent threshold is 50 — below that, no notification is sent (routine timeouts are normal).
| Recovery count | Meaning |
|---|---|
| 0–5 | Normal — routine visibility timeouts |
| 5–50 | Mild backlog — catching up, no action needed |
| 50+ | Moderate+ backlog — worth investigating |
6. Normal DLQ Baselines
DLQ messages < 6 hours old are normal — they auto-archive on each recover_timeouts() tick.
| DLQ depth | State |
|---|---|
| < 50 | Normal — transient backlog |
| 50–200 | Moderate — check sender breakdown |
| 200+ | Elevated — investigate with DLQ content query (section 2) |
If messages older than 6 hours are present, is_dlq may be broken (see Common Issues below).
The threshold (50) is set in ops/scripts/orch-bus/orch-bus-recover-timeouts.sh as RECOVER_THRESHOLD=50.
7. Health Report Monitoring (orch-bus-confirmation-poller.py report)
The orch-bus-confirmation-alert cron (every 60m) runs orch-bus-confirmation-poller.py report producing a combined bus health report covering message tracker status + queue depths + DLQ health.
Report behaviour:
- Silent when healthy — no output if no DLQ backlog, no overdue confirmations, no pending messages. Zero stdout = zero notification.
- Alerts on DLQ backlog — checks both
depth(pending) ANDprocessingstate in DLQ queues. Messages stuck in processing count as a backlog. - Reports on overdue confirmations — tracked messages past their confirmation deadline.
Common gotcha — processing messages in DLQ hidden from alerts:
The DLQ alert code in cmd_report() at ops/scripts/orch-bus/orch-bus-confirmation-poller.py initially only checked depth > 0 for DLQ queues. Messages in processing state were invisible. The fix adds or processing > 0 to both the marker and dlq_issues detection.
# Before (missed processing messages):
marker = " ⚠️ DLQ" if is_dlq and depth > 0 else ""
if depth > 0: dlq_issues.append(name)
# After (checks both):
marker = " ⚠️ DLQ" if is_dlq and (depth > 0 or processing > 0) else ""
if depth > 0 or processing > 0: dlq_issues.append(name)
Silent-when-clean pattern — the report collects all data first, then only prints if there's something to report:
# At the end of data collection:
if not overdue and not dlq_issues and not pending:
return # completely silent
8. Cron Alert Design: Silent-When-Clean
A general principle for no_agent cron scripts that produce health/status reports:
- No output = no notification. The user should only hear from a cron when there's something to act on.
- Collect data first, print only if there's a signal. Build the entire report into variables (
queue_lines,dlq_issues), then check whether anything needs attention before printing. - Silence is the default, not a special mode. The healthy state should produce zero stdout. Don't print "✅ All clean" — that's noise.
- Thresholds belong in the script, not hardcoded in docs. The
RECOVER_THRESHOLDvariable in the script defines what's actionable. Docs reference the variable name, not the value.
This pattern applies to: health reports, watchdog crons, depth monitors, alert crons, and any periodically-running agent script that checks system state.
9. Stuck Pending Messages at Max Retries
The recover_timeouts() function only moves messages from processing → pending/DLQ. Messages that were never dequeued while it ran remain in pending with their retry count unchanged. This means messages can sit in pending with retry_count = max_retries without ever being promoted to the DLQ.
These are truly stuck: the message was dequeued up to max_retries times, timed out each time, but no agent subsequently dequeued it again, so it never re-entered processing state for recover_timeouts() to catch.
Detection query:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT queue_name, retry_count, COUNT(*) as count,
MIN(enqueued_at)::timestamptz(0) as oldest,
MAX(enqueued_at)::timestamptz(0) as newest,
COALESCE(body->>'from', '(null)') as sender,
body->>'subject' as subject,
body->>'topic' as topic
FROM bus.messages
WHERE state = 'pending'
AND retry_count >= (SELECT COALESCE(max_retries, 3) FROM bus.queues WHERE name = bus.messages.queue_name)
GROUP BY queue_name, retry_count, body->>'from', body->>'subject', body->>'topic'
HAVING COUNT(*) > 0
ORDER BY COUNT(*) DESC
LIMIT 20;
\"" 2>&1
Remediation:
⚠️ bus.dlq_move(msg_id) does NOT exist in the schema. Attempting to call it produces ERROR: function bus.dlq_move(uuid) does not exist. Use bus.archive() instead.
The correct approach requires getting the message ID first, then archiving it individually — bus.archive() takes a single msg_id.
Step 1 — Get the stuck message IDs:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT msg_id::text, queue_name, body->>'subject' as subject,
retry_count, enqueued_at::timestamptz(0)
FROM bus.messages
WHERE state = 'pending'
AND retry_count >= (SELECT max_retries FROM bus.queues WHERE name = bus.messages.queue_name)
AND queue_name = 'inbox_target'
ORDER BY enqueued_at;
\"\" 2>&1
Step 2 — Archive each via bus.archive() with explicit ::uuid cast:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -c \"
SELECT bus.archive('inbox_target', '<msg_id>'::uuid, 'esther-remediation');
\"\" 2>&1
Repeat for each stuck message ID. Verify the queue is clean afterward with the detection query from Step 1.
Bulk fallback (bypasses proper archive function — use only when you're sure all are orphaned):
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -c \"
UPDATE bus.messages SET state = 'archived', archived_at = NOW()
WHERE state = 'pending'
AND retry_count >= (SELECT max_retries FROM bus.queues WHERE name = bus.messages.queue_name)
AND queue_name = 'inbox_target';
\"\" 2>&1
Why individual archiving:
bus.archive()logs the action viabus.audit()and handles DLQ chain metadata correctly. The direct UPDATE is faster for bulk cleanup but skips audit logging — acceptable for known-orphaned messages where you want to clear a backlog fast.
Root cause: Target agent stopped dequeuing. The message was picked up by visibility timeout (default 30s), retried, exhausted max_retries, and the agent never dequeued it again. Fix by clearing backlog or restarting the agent's consumer.
10. Raw-Field Wrapper Messages
Some bus senders wrap the payload inside a raw field, producing messages like:
{"raw": "{\"from\": \"moses\", \"to\": \"moses\", \"topic\": \"health\"}"}
This means body->>'from' evaluates to NULL at the top level. The sender data is nested inside body->'raw'->>'from' after a JSON decode of the inner string.
Detection query:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT COUNT(*) as count, queue_name
FROM bus.messages
WHERE state = 'pending'
AND body->>'from' IS NULL
AND body ? 'raw'
GROUP BY queue_name
ORDER BY COUNT(*) DESC;
\"" 2>&1
Reading actual content:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT msg_id, queue_name,
body->'raw'->>'from' as actual_sender,
body->'raw'->>'subject' as actual_subject,
body->'raw'->>'topic' as actual_topic,
enqueued_at::timestamptz(0)
FROM bus.messages
WHERE state = 'pending'
AND body->>'from' IS NULL
AND body ? 'raw'
ORDER BY enqueued_at DESC
LIMIT 20;
\"" 2>&1
11. Fleet-Wide Queue Scan During Inbox Processing
When an inbox-processing cron runs, scan all queues for a fleet-wide health picture — even though you can only act on your own queue. This surfaces backlogs in other agents.
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT queue_name, state, COUNT(*) as count,
MIN(enqueued_at)::timestamptz(0) as oldest,
MAX(enqueued_at)::timestamptz(0) as newest
FROM bus.messages
GROUP BY queue_name, state
ORDER BY queue_name, state;
\"" 2>&1
Compare depths:
- 0: Clean
- 1–50: Normal backlog
- 50–200: Moderate — flag in report
- 200+: Elevated — escalate
Note: PSQL access is via local sg docker gateway. For remote agents, use the bus API at /api/pgmq/queues (lists all queues but not per-message detail).
Inspecting the bus from a cron/unattended tick (governance-gated shell)
The governance enforcer classifies curl …, sg docker -c "docker exec … psql …"
and execute_code as WRITE-CLASS, so a cron tick with no active governance lock
cannot run them — and opening a cycle for a read-only inspection is noise.
Working ungated alternatives:
mcp__agent_bus__bus_inbox_peek— the non-destructive inspection tool (queue,limit,archived). It issues onlyGET /api/pgmq/peek/{queue}//api/pgmq/archives/{queue}and never dequeues, so it is safe on a queue another consumer owns; each entry carriessubjectandcorrelation_id, which is what a dispatch RESULT is matched on (the 6-checkpoint rule). Usearchived: truefor a result the handler has already processed — archived messages are invisible to a pending-only peek, which is the usual reason "the result was never sent".mcp__agent_bus__inbox_read/inbox_watch/inbox_list_agents— inbox + agent liveness, served over the bus, never gated (they are deferred MCP tools, not shell).inbox_readDEQUEUES (POST /api/pgmq/read, 60 s visibility timeout) from your own queue only — it is a consuming read, not an inspection primitive, and it can never see another agent's queue or the orchestrator queue.browser_exec:http://127.0.0.1:8903/healthis unauthenticated and reports{"status":"ok",…,"queues":N}; the dashboard at/renders/api/bus/dashboard,/api/pgmq/queues,/api/workflows, ALL of which need a Bearer token — opened without creds the dashboard showsERROR Cannot read properties of undefined (reading 'total'), which is an auth artifact, NOT a bus fault./metricsis 404.- Read-only primitives (
ls,cat,grep,find,git status/log/diff) stay lock-free for state files, e.g.~/.steadfaste-fleet/state/bus-forwarder-state.json— checklast_runandtotal_local_to_peer/total_peer_to_localto prove the LOCAL write path is alive. - Do not
read_filebus-forwarder-state.jsonin full: it is ~770 KB of dedup keys and will flood context — grep it for the three scalar fields instead.
Common Issues
DLQ Messages Accumulating Without Auto-Archive
Symptom: DLQ depth grows without bound, old messages (6h+) stay in pending state.
Root cause: The is_dlq flag was not set on DLQ queues — bus.recover_timeouts() Step 3 (auto-archive) checks WHERE q.is_dlq = true and silently skips queues where it's false. Also Step 2 cannot chain-delete exhausted DLQ messages, causing _dlq_dlq accumulation.
Fix:
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -c \"
UPDATE bus.queues SET is_dlq = true WHERE name LIKE '%_dlq%' AND is_dlq = false;
\"" 2>&1
# Run recovery to immediately clear old messages
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -t -c \"
SELECT bus.recover_timeouts();
\""
After fix, the cron orch-bus-recover-timeouts (every 5m) auto-maintains the DLQ. Verify with queue overview query.
Prevention: The queue creation code at core/fleet_bus/queue.py:create_queues_for_agent() already sets is_dlq = true — the bug only affects queues created before the column was added to the schema.
recover_timeouts Fails with messages_queue_name_fkey (missing DLQ row)
Symptom: orch-bus-recover-timeouts cron (every 5m) fails with Script exited with code 1; running the function directly shows:
ERROR: insert or update on table "messages" violates foreign key constraint "messages_queue_name_fkey" — Key (queue_name)=(inbox_orchestrator_dlq) is not present in table "queues".
Root cause: a queue exists in bus.queues but its <queue>_dlq row was
never seeded. The seed creates inbox_orchestrator without its DLQ
(core/fleet_bus/schema/auth.sql, 2026-08-12), while agent inboxes get DLQs
via create_queues_for_agent(). recover_timeouts() Step 2b moves exhausted
processing messages to queue_name || '_dlq' — the FK fails and kills the
whole run, so the cron never recovers anything.
Fix (2026-08-12): two layers, both in the repo:
- Seed —
auth.sqlnow insertsinbox_orchestrator_dlq(is_dlq=true,parent_queue='inbox_orchestrator') next to the shared inbox. - Defensive —
recover_timeouts()Step 2b now auto-creates any missing_dlqqueue row before the move:INSERT INTO bus.queues (name, is_dlq, parent_queue) SELECT DISTINCT m.queue_name || '_dlq', true, m.queue_name FROM bus.messages m LEFT JOIN bus.queues q ON q.name = m.queue_name || '_dlq' WHERE q.name IS NULL AND m.state = 'processing' AND m.timeout_at < now() AND m.retry_count >= m.max_retries ON CONFLICT (name) DO NOTHING;
Apply to a live DB (schema changes deploy via file copy, not auto-applied):
sg docker -c "docker exec -i mycortex-postgres psql -U mycortex -d mycortex -v ON_ERROR_STOP=1 -f -" < core/fleet_bus/schema/queue.sql
sg docker -c "docker exec -i mycortex-postgres psql -U mycortex -d mycortex -v ON_ERROR_STOP=1 -f -" < core/fleet_bus/schema/auth.sql
Verify: SELECT bus.recover_timeouts(); returns a number (not an error), and
SELECT name FROM bus.queues WHERE name = '<queue>_dlq'; exists for every
non-DLQ queue. Check for other missing DLQ rows: SELECT name FROM bus.queues WHERE is_dlq = false AND name || '_dlq' NOT IN (SELECT name FROM bus.queues).
Pitfall — string priority rejected with 400. The bus API expects "priority" as an integer (0-100). Passing "normal", "urgent", or "critical" as strings produces a 400. Always map string priorities to int before sending:
priority = {"normal": 0, "urgent": 10, "critical": 20}.get(priority_str, 0)
The same 400 is returned when the from field doesn't match the authenticated user — "from 'moses' does not match authenticated agent 'esther'". Each agent must send as themselves, not as another agent.
All Bus Tools Return 401 (Not 200)
The MCP bus tools (mcp__fleet_bus__*) return HTTP 401 when:
FLEET_BUS_TOKENin.envdoesn't match the hash inbus.tokenstable- The token is missing entirely from the PG table
Diagnostic:
# Check which tokens exist
sg docker -c "docker exec mycortex-postgres psql -U mycortex -d mycortex -c \"
SELECT agent_name, substring(token_hash::text, 1, 20) as token_prefix, rotated_at
FROM bus.tokens ORDER BY agent_name;
\""
# Verify your .env token matches
grep FLEET_BUS_TOKEN ~/steadfaste-fleet/.env
Bus Unreachable (Connection Refused)
Symptom: curl http://127.0.0.1:8903/health fails.
Check:
# Is the bus process running?
ss -tlnp | grep 8903
# Is the systemd service active?
systemctl --user status fleet-bus.service
# Restart if needed
systemctl --user restart fleet-bus.service
Note: The bus at :8903 is a direct local connection. It's also proxied through nginx at the orchestrator's bus port (e.g. :13004 for Moses, :14004 for Esther) with Bearer auth. The MCP tools route through nginx, not directly.
Client fail-fast on 4xx — BusPermanentError, never outboxed (2026-09-09)
ops/scripts/lib/fleet_bus.py classifies 4xx responses as PERMANENT, not retryable:
lib._bus_postraisesBusPermanentErroron any 4xx — except 401/403 while the Basic-auth fallback still has a try left.- On a permanent rejection
bus_sendreturns{queued: false, permanent: true}and never writes the outbox file. Do not layer retry-on-4xx logic on top: permanent means permanent (bad subject/format/ACL — e.g. a lowercase subject thatvalidate.pyrejects with HTTP 400). - The inner Basic-auth fallback propagates any non-401/403 server response as permanent too. A 400 behind nginx now fails fast instead of looping.
- The outbox sweep quarantines permanently-rejected files on the first attempt instead of burning retry budget — a poison message no longer retries 12× over 17h (the incident that motivated this contract).
Verification pattern: send a live poison message (lowercase subject), assert
exactly one rejection and zero outbox writes (US-001, 8/8 tests, commit
4dd90223).
Forwarder: role-aware PEER resolution (2026-08-03)
Symptom: Esther's orch-bus-forwarder.py silently self-synced (Esther↔Esther) — the "mirror of Moses' bus" never existed, and the forwarder skipped sync since Jul 31 (peer_downed_at stuck).
Root cause: PEER_URL defaulted to FLEET_BUS_FALLBACK_URL — which on Esther's host is HER OWN external URL (:14004). The fallback URL is "my bus when primary is down", NOT "the other orchestrator".
Fix (commit fc9aafdb): role-aware peer resolution in both module-level and main() config resolution:
- On Esther: peer = Moses =
FLEET_BUS_URL(:13004) - On Moses: peer = Esther =
FLEET_BUS_FALLBACK_URL(:14004) PEER_AUTHfalls back toFLEET_BASIC_AUTH(nginx Basic creds — external peer = nginx, Bearer gets 401)
Verify: run the forwarder; state file ~/.steadfaste-fleet/state/bus-forwarder-state.json should show peer_downed_at cleared and "Peer recovered — drained N→local, N→peer".
Config resolution (commit c8c54b4b, 2026-08-05): the forwarder reads its
config (LOCAL_URL/TOKEN, PEER_URL/AUTH/TOKEN) in env → .env →
~/steadfaste-fleet/.env order. Before this fix it read os.environ ONLY
despite the docstring claiming conf/.env fallback — so cron runs (no env)
resolved empty PEER_URL/PEER_AUTH/LOCAL_TOKEN and the LOCAL→PEER drain
failed silently (failover messages sat on the backup bus even after the primary
returned). Symptom: orch-bus-forwarder-sync cron reports LOCAL→PEER: N failed every tick, or total_local_to_peer stops advancing. Fix keeps every
config key resolvable from the conf in a bare env; _load_config_file /
_resolve_var are defined above the config block (were after use — NameError
at import). Verify: run the forwarder in a bare env and confirm PEER_URL
resolves from .env; a manual drain run pushes stranded messages
(total_local_to_peer increments) and worker inboxes empty locally.
ACL prerequisite (2026-08-03): the backup orchestrator's orch-bus-forwarder
mirrors ALL inbox_* queues to the peer, so its bus.permissions row on the
PRIMARY's bus needs every inbox queue in can_read + can_write. Without it,
LOCAL→PEER drain fails with 403 — Agent 'esther' does not have write access to queue 'inbox_gisu' (per-queue ACL at core/fleet_bus/server.py
_check_permission). Grant SQL: docs/esther-bus-setup.md Step 7. Symptom:
orch-bus-forwarder-sync cron alerts LOCAL→PEER: N failed every tick while
the messages sit in the local queues indefinitely.
Dedup: consumed copies are never re-forwarded (2026-08-12)
Symptom: a single fleet send gisu EXEC "…fleet-doctor.py…" produced 3
identical EXECs in inbox_gisu with the same correlation_id
(send-ba7f68e22d6a) at 00:04/00:06/00:11 KST. Gisu's handler archived all
three (corr-idempotent), but the duplicate-delivery race left a task row
pending ~10h. The same window showed duplicated UPDATE_REQUESTs / EXECs on
every agent's inbox (joseph 3×, kustos/titus/moses 2–3×).
Root cause: _sync_direction in orch-bus-forwarder.py skipped a message
whose dedup key already existed on the destination without recording it in
seen — the old comment said "the mirror should warm it again next tick".
But when the real consumer (the worker's agent-message-handler) archives the
destination copy, the next tick re-forwarded the lingering backup copy back to
the primary: fresh msg_id, same corr. Repeat every consumer tick.
Fix: the dest-hit skip now does seen.add(dkey) — each logical message
forwards at most once per direction per host. A consumed copy is a DELIVERED
message, not a gap to re-warm. Regression test:
tests/test-bus-forwarder-dedup.py (RED on old code, GREEN on fix).
fleet bus on hosts without the local bus schema (2026-08-12): fleet bus
reads the LOCAL Postgres via docker exec — on hosts whose mycortex-postgres
lacks bus.messages/bus.queues (or container down), cmd_bus used to
traceback with UnboundLocalError because the queue-summary block was skipped.
Fixed in 6876e47c: total_pending/total_proc initialized up front,
local_db_ok flag set on error, and the final branch prints
⚠️ Local bus DB unavailable instead of crashing or a false "No activity".
fleet bus --all never crashed (different branch) — that's why it slipped
through. The remote bus itself is healthy; use fleet status/fleet depth for the
fleet view.
Inspect for duplicates (per-agent, recent window):
cd ~/steadfaste-fleet/ops/scripts && python3 -c "
import sys, json; sys.path.insert(0, '.')
from lib.fleet_bus import bus_archives
for a in ('gisu','joseph','kustos','titus','moses'):
arch = bus_archives(f'inbox_{a}', limit=400, since_minutes=720)
corrs = {}
for m in arch:
b = m.get('body') or {}; c = b.get('correlation_id') or '?'
corrs.setdefault((c, b.get('subject')), 0)
corrs[(c, b.get('subject'))] += 1
dups = {k: v for k, v in corrs.items() if v > 1}
print(a, 'duplicates:', len(dups))
"
Token rotation (Bearer, hbus_*)
- Hash scheme:
bus.tokens.token_hash=hashlib.pbkdf2_hmac("sha256", token, b"hermes-bus-salt", 100000).hex()(core/fleet_bus/auth.py hash_token). - Rotate: generate
"hbus_" + secrets.token_hex(32)→ update~/steadfaste-fleet/.envAND~/steadfaste-fleet/.env(both carryFLEET_BUS_TOKEN; the forwarder'sLOCAL_TOKENreads the conf) →UPDATE bus.tokens SET token_hash='<pbkdf2(new)>', rotated_at=NOW() WHERE agent_name='<agent>'→ verify Bearer against the LOCAL bus (127.0.0.1:8903): new → 200, old → 401. - Verify Bearer on the LOCAL bus only. Testing Bearer against the external nginx port (
:13004/:14004) is meaningless — nginx validates Basic auth and setsX-Forwarded-User; a Bearer header sent through nginx is ignored (401 for missing Basic). A token that "401s" through nginx can still be LIVE on the local bus. - Never delete
FLEET_BUS_TOKENfrom.envbecause Bearer "401s through nginx". The local raw bus (127.0.0.1:8903) REQUIRES that Bearer token; a 401 through nginx only proves the request lacked Basic auth. Removing it silently breaks every local-bus consumer —orch-bus-forwarderexits 1 withLOCAL_URL and LOCAL_TOKEN required,orch-bus-inbox-relayprintscannot relay, the confirmation-poller goes deaf. The systemd bridge runner (fleet-bus-bridge-run.py) returns 0 regardless of the script's exit code, so the timer showssuccesswhile the job crashes — the tells are a FROZEN~/.steadfaste-fleet/state/bus-forwarder-state.jsonlast_runand a growing BACKUP-businbox_orchestratordepth (stale-mirror sweep stopped). Restore the token (verify against127.0.0.1:8903→ 200), then re-run the forwarder. - Identity mapping pitfall: a token found in another agent's docs/config may be a DIFFERENT agent's row — the esther setup guide carried MOSES' token (esther's
.envseeded with it), so it authenticated as moses with full queue privileges. Before rotating, look up the identity by hash:SELECT agent_name FROM bus.tokens WHERE token_hash='<pbkdf2(leaked)>' AND is_active=true. Rotate the MAPPED row (or sync it to the owner's real token hash). - Peer-bus consistency: each orchestrator's Postgres is independent; if the peer's token row on your bus doesn't match his real token, sync it from his bus (
SELECT token_hash FROM bus.tokens WHERE agent_name='moses'on his host, then UPDATE your row) so a leaked token dies on your bus too. - Rotation order (configs first): update consumer configs (
.env,.env) BEFORE the token table so the forwarder/MCP never hit a dead token mid-rotation.
Stale-mirror sweep — backup bus no longer grows forever (2026-08-14)
Symptom: inbox_orchestrator (or any inbox_*) on the BACKUP orchestrator's
bus accumulates pending messages monotonically — 74→94→196 over days, 3rd
fleet sighting (joseph escalation). The primary bus stays clean; the backup's
own queue-depth watchdogs never cover it (depth-watchdog checks only own
inbox; confirmation-poller checks only the primary URL).
Root cause: the backup bus is a warm-standby MIRROR: the forwarder copies
pending messages from the primary (PEER→LOCAL) and nothing consumes them while
the primary is up (the backup's handler polls the primary by design). The
2026-08-12 dedup fix (record dest-hit in seen) stopped duplicate
re-forwarding but stranded every mirrored-back copy forever: a copy whose
dedup key was in seen was skipped every tick and NEVER archived.
Fix (commit ea833284): stale-mirror sweep in _sync_direction — on a
BACKUP source (can_archive_source=True), a copy whose key is already in
seen (forwarded once or dest-hit-confirmed) is archived once the peer
CONFIRMS it no longer holds the original (consumed). Failover-safe:
_dest_has_key is tri-state (True/False/None); a copy is kept when the
original is still pending on the primary, or when the peer is unreachable
(None — never archive blind during an outage; the local copy may be the only
snapshot of an unconsumed message). Tests 4-6 in
tests/test-bus-forwarder-dedup.py (RED on old code, GREEN on fix).
Diagnostic: SELECT queue_name, state, COUNT(*) FROM bus.messages GROUP BY 1,2
on the backup's Postgres — a growing pending count of topic='reports'
mirrors (skill/learning reports, each ×2: original + mirror) is the signature.
Forwarder must rewrite from to match the forwarding agent's auth identity
Symptom: forwarder-sync cron reports PEER->LOCAL: N failed with
400 Invalid message: from 'moses' does not match authenticated agent 'esther'.
Root cause: the forwarder copies messages from the peer bus and sends them
to the local bus preserving the original sender's from field. The destination
bus validates from against the authenticated agent — when Esther's forwarder
forwards Moses' messages, it authenticates as esther but sends from: moses.
Fix: two changes in orch-bus-forwarder.py:
-
Resolve
LOCAL_AGENTfromagent.envat module load — reads~/.steadfaste-fleet/agent.envforAGENT_NAME=. Falls back to"unknown"if the file is missing. -
Before
_send_bus(), rewritebody["from"]toLOCAL_AGENTand preserve the original sender asbody["forwarded_from"]:
original_from = body.get("from", "")
if original_from and original_from != LOCAL_AGENT:
body["forwarded_from"] = original_from
body["from"] = LOCAL_AGENT
Why forwarded_from: consumers that need to know who actually sent the
message (e.g. the orchestrator processing a worker's escalation) can read
forwarded_from. The old approach (just body["from"] = _HOST) lost the
original sender identity entirely.
Envelope allowlist: the bus server's ENVELOPE_KEYS in
core/fleet_bus/validate.py includes forwarded_from — the field passes
validation and does not trigger "unknown envelope field" rejection. Without
this, a forwarded message with forwarded_from gets 400.
Detection: check the forwarder cron output for "Invalid message: from 'X' does not match authenticated agent 'Y'" errors. The fix applies to both PEER->LOCAL and LOCAL->PEER directions since both authenticate as the forwarding agent.
Shared orchestrator inbox (inbox_orchestrator, 2026-08-03)
Workers' fix requests to inbox_moses are invisible to Esther — each agent
only polls its own inbox. The backup orchestrator literally cannot see worker
escalations when the primary is down. Fix: a shared inbox_orchestrator queue
both orchestrators read/write — now the default target for all agent →
orchestrator traffic:
- Schema:
core/fleet_bus/schema/auth.sqlseeds the queue idempotently (also auto-creates on first send) - Handler:
agent-message-handler.pyon orchestrators pollsinbox_orchestratoras a secondary queue — archive from the SOURCE queue (source_queue, not the hardcoded own-inbox name) - Workers:
contact-orchestrator.shdefaults toinbox_orchestrator(override withFLEET_INBOX_TARGETonly for point-to-point replies) - Docs: ACL table in
docs/bus-architecture.md+docs/reference/fleet-bus-config.md(orchestrators readinbox_orchestrator; workerscan_sendit)
ACL model: BOTH buses use the canonical per-queue array ACLs
(can_read/can_write TEXT[] + is_admin) in bus.permissions — unified
2026-08-04. The old boolean model (can_send/can_archive/can_requeue,
ops/services/fleet-bus/server.py) is deleted. If a 403 appears, check
the agent's can_write array, not boolean flags.
Reading a pending message's FULL body (evaluating an inbox message)
The peek responses carry METADATA only (msg_id, from, subject,
correlation_id) — but the raw /api/pgmq/peek/<queue> response DOES include
each message's body (the MCP tool trims it). To evaluate a pending request
(an escalation, a handoff, a SKILL_DRIFT_RECOVERY_REQUEST), three rules decide
where the body is and how to read it:
- Read it with
curl -u "$FLEET_BASIC_AUTH" "$FLEET_BUS_URL/api/pgmq/peek/<queue>?limit=100"and parsemessages[].body. Basic auth, not Bearer: nginx on the external URL ignores Bearer and requires Basic; the Bearer token only works on the local raw bus. - Peer-enqueued messages are NOT in the local store. For the BACKUP
orchestrator,
FLEET_BUS_URLpoints at the PEER's bus (esther → moses:13004), so a psql query against the localmycortex-postgresor a curl to the local:8903returns NOTHING for a message the MCP peek just showed — that reads as "not found" but means "on the peer". Curl the URL the MCP actually talks to (FLEET_BUS_URL), never the local bus, to find a peer-enqueued message. - A message that vanished from peek moved to ARCHIVES — check who consumed it
before acting.
/api/pgmq/archives/<queue>carriesarchived_at; a freshly-archived request means the orchestrator handler (or the peer) already took it. Verify the work is not in flight on their side (git log, working tree, an unmerged diff) before duplicating it — acting on a copy whose original was consumed is how two sessions race to land the same change.
fleet send: the self-test gate, and which subjects reach an agent
- Every send to a fleet agent is REFUSED until the identical flow ran on
yourself.
fleet send <agent> <subject> <body>demands: send to your own agent, runagent-message-handler.py --once, verify the handler processed it, then re-send with--self-tested. That gate proves the TRANSPORT — it says nothing about whether the subject has correct semantics, so a passing self-test does not mean the message will reach the agent's session. - Unknown subjects bounce: the handler archives the message and answers
with an error result — it never reaches the agent's session. Sending
an ad-hoc subject (a grant notice, a custom request label) produces
exactly that bounce. The subjects that reach an agent are the protocol
set (
EXEC,UPDATE_REQUEST,TASK_REQUEST, ...) plusFLEET_NOTICE, which the handler explicitly notifies + archives + answersFLEET_NOTICE_RESULTon. For an informational message to a worker, useFLEET_NOTICE, and afterwards verify the msg_id is PENDING in the target queue (peek), never trusting the send confirmation alone.
Bus tokens silently expire at T+90d — rotation does NOT refresh expires_at (2026-10-14)
Symptom: every authenticated endpoint on the LOCAL bus returns
401 {"detail":"Invalid or expired token"} for a token that is correct, while
GET /health still returns 200 (it is unauthenticated). Downstream: the
orch-bus-forwarder's LOCAL leg silently returns 0 messages (_peek_bus maps a
non-200 to []), so LOCAL→PEER never drains and the mirror looks idle;
bus-inbox-inspect.py reports inspection_error: queue fetch failed: 401 for
the local bus; the bridge runner still exits 0 (it ignores the script's exit
code), so systemd shows success.
Diagnosis: query the token table, not the HTTP layer — expires_at is the
usual culprit and is_active stays true:
# psycopg from the bus venv is the reliable route when `docker exec` is
# blocked in cron mode and the host port refuses a raw psql connection.
~/.hermes/hermes-agent/venv/bin/python3 - <<'PY'
import psycopg
c=psycopg.connect(host='127.0.0.1',port=15432,dbname='mycortex',user='mycortex',password='<FLEET_BUS_PG_PASS>')
with c.cursor() as cur:
cur.execute("SELECT agent_name,is_active,rotated_at,expires_at,(expires_at<=now()) FROM bus.tokens ORDER BY expires_at")
[print(r) for r in cur.fetchall()]
PY
Compare hash_token(<FLEET_BUS_TOKEN>) (core/fleet_bus/auth.py) with the
row's token_hash to confirm the secret is right and only the expiry is stale.
Root cause (two layers):
issue_token_for_agent()'sON CONFLICT (agent_name) DO UPDATErefreshestoken_hash/rotated_atbut notexpires_at— a row inserted 2026-07-16 (defaultnow() + INTERVAL '90 days') keeps that original expiry forever, so every rotation silently inherits the first row's deadline. All rows seeded on the same day expire at the same instant.ops/scripts/token-expiry-alert.pyexists but was never wired to a cron or timer, so the pre-expiry warning never fired — the first signal is the T+90d hard failure.
Fix (restore, per agent):
UPDATE bus.tokens SET expires_at = GREATEST(rotated_at, created_at) + INTERVAL '90 days'
WHERE agent_name = '<agent>' RETURNING agent_name, expires_at;
Verify: Bearer GET /api/pgmq/queues → 200, then run the deployed forwarder via
fleet-bus-bridge-run.py --name orch-bus-forwarder-sync --script orch-bus-forwarder.py --deliver local and confirm total_local_to_peer
advances in ~/.steadfaste-fleet/state/bus-forwarder-state.json (proves the LOCAL
write path, not just the DB row). Real fix for the class: add
expires_at = now() + INTERVAL '90 days' to the ON CONFLICT clause, and
schedule token-expiry-alert.py daily.
Do not "fix" this by deleting FLEET_BUS_TOKEN — the local bus legitimately
requires it; extend/rotate instead.
References
references/forwarder-peer-resolution.md— role-aware PEER fix detail (2026-08-03)references/credential-rotation.md,references/dlq-monitor-fix.md,references/cross-server-architecture.md— may exist on orchestrator hosts only (checkls ~/.hermes/skills/devops/fleet-bus/references/first)core/fleet_bus/queue.py— Queue creation, DLQ logic, send/read/archivecore/fleet_bus/server.py— HTTP API, auth, dashboard
04 同仓库更多 Skills
macbook-linux-maintenance
Legacy MacBook Linux fixes: GPU wedge, reboot hang, thermal.
governance-regression-triage
Triage a host's governance issues: what changed.
enforcement-immutability
Use when enforcement files lose their immutable flag.
steadfaste-fleet-repo-deploy
Use when committing to the steadfaste-fleet repo.
steadfaste-fleet-maintenance
Maintain an installed Steadfaste Fleet instance — update both the upstream Hermes Agent and the fleet repo layer, merge diverged histories, sync skills safely, and troubleshoot common issues. Covers the dual-update workflow (hermes update + fleet-update.sh), encrypted brain data backup, mycortex import, and recovery techniques.
fleet-preflight
DEPRECATED alias — merged into survey-before-action (2026-08-20). Load survey-before-action instead; its "Repo-Specific Pre-Flight" section covers git search, Hermes boundary, and deployment verification.