pgmq-consumer-patterns
Use when fixing bus consumers or false-unreachable agents.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4
- Forks
- 1
01 前言 Front Matter
- name
- pgmq-consumer-patterns
- author
- Steadfaste Fleet
- version
- 1.0.0
- metadata
- { "hermes": { "tags": [ "bus", "pgmq", "consumers", "migration", "health" ], "related_skills": [ "fleet-bus", "agent-health-monitoring" ] } }
- description
- Use when fixing bus consumers or false-unreachable agents.
02 资源文件 2
03 SKILL.md 正文
PGMQ Consumer Patterns
Class-level patterns for building and debugging PGMQ bus consumers, learned from the inbox→PGMQ migration (2026-08). Applies to any queue where one process drains and others need the data.
Pattern 1: The Drainer Must Persist — Consumers Read State, Not the Live Queue
Rule: Any queue that one cron drains is invisible to other consumers. PGMQ
read pops only pending messages; a consumer that runs after the drainer
will find the queue empty every time. Never have a second consumer race the
drainer on the live queue — especially an hourly consumer vs a 10-minute
drainer.
Correct design:
producer ──send──> queue ──drainer (every 10m)──> archive
└── persist latest per key ──> state.json
consumer (hourly) ──reads state.json──> data
consumer fallback: bus_read(queue, vt=60) peek for not-yet-drained pings
Example (health pings, fixed 2026-08-04, commit 87df0c73):
orch-clean-health-queue.pydrainsinbox_health_checkevery 10m; while archiving it persists each agent's latest vector+ts to~/.steadfaste-fleet/state/inbox-health-state.jsonand updateslast-seen.json.orch-health-report.pyreads that state file; livebus_readis only a fallback for pings the drainer hasn't caught yet.
Symptoms of violating this rule: "agent 🔴 unreachable despite healthy
pushes", stale last-seen.json for days/weeks, queue depth near 0 at consumer
time.
Pattern 2: Transport-Migration Sweep — Silent-404 Consumers
Rule: When a transport migrates (file inbox → PGMQ bus, HTTP → gRPC, etc.), the old endpoint often disappears with no error to callers. Any consumer still hitting the retired surface gets a silent 404 → returns None → downstream false alarms. Docs and skills lag too.
Sweep checklist (grep the whole repo, not just the obvious dirs):
grep -rn "api/inbox\|api/delete\|MOSES_INBOX_URL\|moses-inbox.conf" ops/ scripts/ skills/ docs/
Also grep for removed script names (e.g. orch-team-health) — docs reference
them long after deletion.
Verify claims against LIVE code before fixing: the proposal said a skill was
stale; confirmation required checking (a) the deployed bus server's route table
(no /api/inbox), (b) the actual push script's endpoint, (c) which consumer
still called the old API, (d) whether the referenced poller was removed from the
repo (git log --diff-filter=D).
Pattern 3: Verify End-to-End, Not Just Unit
After a consumer fix, prove the full path with real messages:
- Seed:
bus_send("inbox_health_check", {"from": "<agent>", "subject": "health", "body": "{...}"}) - Drain: run the drainer exactly as cron does (set
FLEET_REPOandPYTHONPATH=ops/scripts— directpython3 path/to/script.pyfrom another cwd fails thehermes_pathsimport). - Consume: run the report script; confirm the agent shows ✅.
Pattern 4: Alert-Stop ≠ Success — the Mirror-Race / Consumer-Took-It Check
Rule: A mirror/forwarder failure alert disappearing does NOT mean the peer delivery succeeded. Any consumer that takes the same message off the source queue makes the next mirror tick silent.
Verified example (2026-08-07, orch-bus-forwarder-sync): the alert
⚠️ LOCAL→PEER: 1 failed • inbox_orchestrator/ee8d75afb2 fired on 2 ticks for
a kustos PROPOSAL, then stopped — not because the peer received it, but
because the backup orchestrator's agent-message-handler polls the shared
inbox_orchestrator directly and archived the message from the source queue
(bus.archives.archived_by='esther', 3 min after enqueue). The mirror never
delivered it.
Correct diagnosis:
- Frequency across ALL ticks first (
~/.hermes/cron/output/<job_id>/): one message alerting 2–3 ticks then silent = consumed or transient; the same message alerting EVERY tick = persistent auth/ACL problem. - Find who really took it:
bus.archive()INSERTs intobus.archivesthen DELETEs frombus.messages— archived rows persist witharchived_at+archived_by.archived_by=estheroninbox_orchestrator= backup consumed directly, never mirrored.bus.delete()hard-purges with zero trace;bus.recover_timeouts()never touches fresh pending main-queue messages. - Hash-suffix alert IDs: the forwarder's bullet is
queue/dkey[-10:], dkey =corr:<correlation_id>orhash:<sha256(json.dumps(body, sort_keys=True, default=str))[:32]>. A hash ID is computed at runtime and matches NOTHING in the DB — recompute it over candidate archived bodies and compare the tail. Corr-based IDs ARE searchable via thecorrelation_idcolumn. - The alert omits the HTTP status — a persistent per-queue 403 (peer-bus ACL grant needed) and a transient 5xx/timeout look identical from the alert alone; the tick-frequency pattern is the discriminator.
Full worked example (timeline, SQL queries, hash-recompute snippet):
references/forwarder-failure-diagnosis.md.
Pitfalls
- Direct script runs mislead. A no_agent cron gets
PYTHONPATHfrombuild_subprocess_env(); a barepython3 script.pyfrom a random cwd willModuleNotFoundError: hermes_paths. Reproduce the cron env (FLEET_REPO=~/steadfaste-fleet PYTHONPATH=~/steadfaste-fleet/ops/scripts). - A queue drained before the consumer runs is NOT proof of a dead producer. Check the drainer's persistence file before blaming the push side.
- Deployed copies of scripts/skills are copies. Fix the repo source, deploy
via
fleet-update.sh, then verify the deployed file (SOURCE header differs from repo raw MD5 — hash comparison must strip the header).
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.