Skip to content

fix(relay): make the HTTP fallback work and handle SIGTERM - #82

Merged
Skeyelab merged 1 commit into
masterfrom
fix/relay-http-fallback
Sep 22, 2026
Merged

Skeyelab merged 1 commit into
masterfrom
fix/relay-http-fallback

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Problem

The relay's HTTP fallback (used when the WebSocket is down) has never delivered an event:

  1. It called /api/nodes/pull with GET, but the route only exports POST.
  2. Even with the right method, it expected a bare array. The route returns { ok, nodeId, events }, so Array.isArray(...) was false and it returned silently.

Separately, systemd stops clawproxy-relay.service with SIGTERM, but only SIGINT was handled, so the graceful shutdown path never ran.

Change

  • Pull with POST, a JSON body of { maxEvents }, and read events from the response.
  • registerShutdown() handles both SIGINT and SIGTERM.
  • main() runs only when relay.ts is executed directly, so tests can import it. I checked that yarn tsx relay.ts (the service's ExecStart) and yarn relay both still run main().

Tests (written first)

tests/relay/relay.test.ts:

  • pull uses POST, the bearer token, and maxEvents
  • events from the { events } response are forwarded to Hermes with the right HMAC signature, then acked
  • both SIGTERM and SIGINT are registered

yarn vitest run: all pass. Lint clean, no type errors outside tests.

After merge

On hermes: git pull in ~/projects/clawproxy and systemctl --user restart clawproxy-relay, then confirm Auth ok in the journal.

The relay's HTTP fallback has never delivered anything:
- it called the pull endpoint with GET, but the route only accepts POST
- it expected a bare array, but the route returns { ok, nodeId, events }
It now POSTs { maxEvents } and reads `events` from the response.

systemd stops the service with SIGTERM, but only SIGINT was handled, so the
graceful shutdown never ran. Both signals now go through registerShutdown().

main() now runs only when relay.ts is executed directly, so the module can be
imported by tests.
@strix-security

strix-security Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Strix Security Review

No security issues found.

Updated for ae76a8d.


Reviewed by Strix
Re-run review · Configure security review settings

@Skeyelab
Skeyelab merged commit 3dad5f7 into master Sep 22, 2026
3 checks passed
@Skeyelab
Skeyelab deleted the fix/relay-http-fallback branch September 22, 2026 15:56
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.

1 participant