Commit Graph
5 Commits
Author SHA1 Message Date
sam db18d2675a feat(ratelimit): wire per-identity inbound rate limiting into the gateway
internal/ratelimit was fully built (sliding-window limiter, ticker-driven
eviction) but had no consumer, leaving multi-identity deployments with no
inbound request budget on any channel (archie-core-6wxb / GH #797).

Adds Message.SenderID (Telegram numeric user ID, SMTP from address, or
webhook route path -- the closest thing webhook has to a caller identity),
threads it into Router.Route/RouteStream via a shared checkRateLimit, and
wires an opt-in [chat.rate_limit] config section through bootstrap with the
documented EvictStale ticker.
2026-09-15 01:24:20 +10:00
sam f820a89e32 fix(channels): call MarkRunning once a channel is actually up
channels.Manager.MarkRunning was never called for telegram, email, or
webhook -- every start path only called MarkStarting then MarkFailed
on error, so the dashboard showed a working channel stuck on
"Starting" forever (confirmed live: Telegram polling and delivering
messages while /api/channels still reported "starting").

Adds gateway.Lifecycle{Starting, Running func()}, threaded through
Gateway.Start(ctx, router, lifecycle). Email and webhook report
Running once their listener actually binds -- webhook moves off
http.Server.ListenAndServe's internal bind to an explicit
net.ListenConfig.Listen so binding is observable before Serve.
Telegram reports Running after StartWebhook launches in webhook mode,
or after the first successful getUpdates response in long-poll mode,
observed via a pollReadinessClient http.Client wrapper since the
go-telegram/bot library keeps polling errors inside its own worker
goroutine. Restart re-reports Starting/Running each cycle.
2026-09-02 20:47:01 +10:00
sam 543b657472 feat(webhookguard): shared HMAC, rate-limit, and redaction mechanics
archie-core-7d5u.3 -- storage-agnostic building blocks for vetting inbound
webhook-shaped requests, extracted rather than duplicated:

- VerifyHMAC: behavior-preserving extraction of internal/channels/webhook's
  private validateHMAC. internal/channels/webhook now calls it instead of
  keeping its own copy; all 10 of that package's existing tests still pass
  unmodified, and the one now-redundant unit test was removed with a
  comment pointing to where its coverage relocated.
- RateLimiter: per-source token bucket. Source IDs come from a registered,
  operator-controlled set, not unbounded attacker input, so the bucket map
  is not itself bounded -- documented explicitly rather than left implicit.
- RedactPayload: key-name-based redaction, matching gateway/stream.go's
  sensitiveParameterKey marker list. Deliberately does NOT reuse that
  function's actual behavior: it replaces every string value regardless of
  key, correct for a bounded chat summary and wrong here -- a captured
  payload exists to be inspected for field mapping (t2db.3), so only values
  under a sensitive-looking key are touched.

Narrowed from 7d5u.3's original scope, which bundled capture storage and an
approval state machine into this package. Both moved to the beads that own
that state (t2db.1's capture store depends on 7d5u.2's still-open NATS
storage decision; t2db.4's binding is the only consumer of approval state
today) rather than building shared abstractions ahead of a second real
consumer.

Adversarially reviewed by a fresh subagent with zero surviving findings:
token-bucket math hand-traced on two scenarios and race-clean under -race,
the redaction/gateway-stream.go behavioral divergence verified by reading
both functions side by side, both the redaction and rate-limit guards
mutation-tested by disabling each and confirming the suite catches it.

task check exit 0, golangci-lint 0 issues, gofumpt clean.
2026-08-22 01:28:58 +10:00
sam 1da24232af fix(tests): add contexts to HTTP test requests 2026-08-15 23:43:55 +10:00
sam 20a1210d0e feat: webhook platform + persona registry (items 5+6)
Webhook platform (internal/channels/webhook):
- Gateway adapter with HTTP server, HMAC validation, dot-notation template extraction
- Per-route configuration with secret-based signing
- Deliver-to-origin mode for sync responses
- 11 tests, race-clean

Persona registry (internal/gateway/persona.go):
- PersonaRegistry with per-session active persona selection
- DefaultPersonas(): helpful, concise, technical, creative, teacher
- Persona prompt prepended to system prompt in LLMResponder
- Thread-safe, 5 tests

Config: ChatConfig.WebhookAddr added for webhook listen address.
All 39 packages pass with -race.

Closes abg.5.3, abg.34.
2026-07-26 10:39:58 +10:00