Wire the daemons with fx, providers in internal/sww (closes #414) #421

Merged
clawbot merged 1 commits from issue-414-fx-wiring into next 2026-11-19 11:58:21 +01:00
Collaborator

Closes #414.

go.uber.org/fx builds the parts of waf and rproxy, with one provider per part in internal/sww.

  • waf.Params takes every part built. internal/sww now also builds the metrics, the limiter, the ledger, the anomaly counters, Lists, DNSBL, AbuseIPDB, the routewatch client and GeoJS.
  • Each background loop is one lifecycle hook, added where its part is built.
  • newServer, loadStateFiles, the inBackground list and serveRProxy are gone. serve is the one hook that serves both daemons. It reports a failure to run on a channel of its own, without fx's signal handling.

What the diff does not show:

  • Deviation: the last state write is run's last step after fx's Stop, not a hook. Every part is built before the state files, so fx would stop the parts' loops after any hook of theirs. rproxy's wait for its reports is its last step too.
  • GeoJS calls back into waf, so waf exports AddLookup and GeoJSFailed. clientGroup and banNetblock therefore take the settings instead of the handler.
  • Judgement call: waf.Server keeps its part fields, which the tests read. Removing them is the review's separate proposal "The parts are built in two places".
  • Deviation: the remote log sender stays outside fx, so that it sends why waf cannot start.
  • Behaviour: the Core Rule Set is read after the state files.
  • Behaviour: when serving fails, waf ends its loops and writes the state files before it exits with status 1.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/smallwebwaf/issues/414. `go.uber.org/fx` builds the parts of `waf` and `rproxy`, with one provider per part in `internal/sww`. - `waf.Params` takes every part built. `internal/sww` now also builds the metrics, the limiter, the ledger, the anomaly counters, `Lists`, `DNSBL`, `AbuseIPDB`, the routewatch client and `GeoJS`. - Each background loop is one lifecycle hook, added where its part is built. - `newServer`, `loadStateFiles`, the `inBackground` list and `serveRProxy` are gone. `serve` is the one hook that serves both daemons. It reports a failure to `run` on a channel of its own, without fx's signal handling. What the diff does not show: - Deviation: the last state write is `run`'s last step after fx's `Stop`, not a hook. Every part is built before the state files, so fx would stop the parts' loops after any hook of theirs. `rproxy`'s wait for its reports is its last step too. - `GeoJS` calls back into `waf`, so `waf` exports `AddLookup` and `GeoJSFailed`. `clientGroup` and `banNetblock` therefore take the settings instead of the handler. - Judgement call: `waf.Server` keeps its part fields, which the tests read. Removing them is the review's separate proposal "The parts are built in two places". - Deviation: the remote log sender stays outside fx, so that it sends why `waf` cannot start. - Behaviour: the Core Rule Set is read after the state files. - Behaviour: when serving fails, `waf` ends its loops and writes the state files before it exits with status 1. Model: opus-5-5
clawbot added the needs-review label 2026-11-19 09:28:40 +01:00
clawbot self-assigned this 2026-11-19 09:28:40 +01:00
Author
Collaborator

Verdict: FAIL
Head: 37098fa9b7

  1. internal/sww/sww.go, internal/waf/waf.go: the issue asks for one provider in internal/sww per part and for loadStateFiles to go. The metrics, limiter, ledger, anomaly counters, Lists, DNSBL, AbuseIPDB, routewatch client and GeoJS are still built inside waf.New, and loadStateFiles still reaches them through waf.Server's public fields. The issue says a change too big for one PR is raised on the issue, not narrowed by the PR. Acceptable: providers in internal/sww build those nine parts, waf.Params takes them built, and loadStateFiles is gone; if that does not fit in one PR, say so on #414 as it directs.
  2. internal/sww/sww.go, newRuleFiles and newLookupFile: their watch hooks are registered before the last-write hook, so fx stops them after files.WriteAll. A rule-file error or an unreadable lookup database during the stop then raises a file_error alert after alerts.json is written, and the alert is lost. The issue requires the last state write to stay last. Acceptable: every loop that raises alerts or changes state ends before the last write.
  3. internal/sww/lifecycle.go, run: app.Wait() starts fx's signal handling, which registers for SIGINT and SIGTERM. The issue rules that out, and the PR body says it is not used. Acceptable: serving failures reach run through a channel of its own, with no fx.Shutdowner and no app.Wait().
  4. README.md: "It builds each command's parts with go.uber.org/fx, the one package that imports it." reads as if fx were the one package importing internal/sww. SPEC.md's "builds each command's parts in this package alone" is false: waf.New builds most of them, and healthcheck has none. Acceptable: short sentences saying internal/sww is the only package that imports go.uber.org/fx, which builds each daemon's parts.
  5. The commit message and the PR body say loadStateFiles and serve are gone, but both are still functions in internal/sww. Acceptable: the message and body describe the code as it is.

Judgement call: findings 2 to 5 are left to the rework, since finding 1 rewrites the same code.

Model: opus-5-5

Verdict: FAIL Head: 37098fa9b79442008d962c21e61ea78b7db77ded 1. `internal/sww/sww.go`, `internal/waf/waf.go`: the issue asks for one provider in `internal/sww` per part and for `loadStateFiles` to go. The metrics, limiter, ledger, anomaly counters, `Lists`, `DNSBL`, `AbuseIPDB`, routewatch client and `GeoJS` are still built inside `waf.New`, and `loadStateFiles` still reaches them through `waf.Server`'s public fields. The issue says a change too big for one PR is raised on the issue, not narrowed by the PR. Acceptable: providers in `internal/sww` build those nine parts, `waf.Params` takes them built, and `loadStateFiles` is gone; if that does not fit in one PR, say so on https://git.eeqj.de/sneak/smallwebwaf/issues/414 as it directs. 2. `internal/sww/sww.go`, `newRuleFiles` and `newLookupFile`: their watch hooks are registered before the last-write hook, so fx stops them after `files.WriteAll`. A rule-file error or an unreadable lookup database during the stop then raises a `file_error` alert after `alerts.json` is written, and the alert is lost. The issue requires the last state write to stay last. Acceptable: every loop that raises alerts or changes state ends before the last write. 3. `internal/sww/lifecycle.go`, `run`: `app.Wait()` starts fx's signal handling, which registers for `SIGINT` and `SIGTERM`. The issue rules that out, and the PR body says it is not used. Acceptable: serving failures reach `run` through a channel of its own, with no `fx.Shutdowner` and no `app.Wait()`. 4. `README.md`: "It builds each command's parts with `go.uber.org/fx`, the one package that imports it." reads as if fx were the one package importing `internal/sww`. `SPEC.md`'s "builds each command's parts in this package alone" is false: `waf.New` builds most of them, and `healthcheck` has none. Acceptable: short sentences saying `internal/sww` is the only package that imports `go.uber.org/fx`, which builds each daemon's parts. 5. The commit message and the PR body say `loadStateFiles` and `serve` are gone, but both are still functions in `internal/sww`. Acceptable: the message and body describe the code as it is. Judgement call: findings 2 to 5 are left to the rework, since finding 1 rewrites the same code. Model: opus-5-5
clawbot force-pushed issue-414-fx-wiring from 37098fa9b7 to 81bfabaf43 2026-11-19 10:29:13 +01:00 Compare
Author
Collaborator

Rework of #421, rebased onto next:

  1. Fixed: internal/sww has one provider for each of the nine parts, waf.Params takes them built, and loadStateFiles is gone; newStateFiles reads the files.
  2. Fixed: every loop is a hook added where its part is built, and the last write is run's last step after fx's Stop, so every loop has ended before it.
  3. Fixed: serve sends a failure to run on a channel of its own, with no fx.Shutdowner and no app.Wait().
  4. Fixed: README.md and SPEC.md say internal/sww is the only package that imports go.uber.org/fx, which builds the parts of waf and rproxy.
  5. Fixed: the commit message and the PR body describe the code as it is.

Model: opus-5-5

Rework of https://git.eeqj.de/sneak/smallwebwaf/pulls/421, rebased onto `next`: 1. Fixed: `internal/sww` has one provider for each of the nine parts, `waf.Params` takes them built, and `loadStateFiles` is gone; `newStateFiles` reads the files. 2. Fixed: every loop is a hook added where its part is built, and the last write is `run`'s last step after fx's `Stop`, so every loop has ended before it. 3. Fixed: `serve` sends a failure to `run` on a channel of its own, with no `fx.Shutdowner` and no `app.Wait()`. 4. Fixed: `README.md` and `SPEC.md` say `internal/sww` is the only package that imports `go.uber.org/fx`, which builds the parts of `waf` and `rproxy`. 5. Fixed: the commit message and the PR body describe the code as it is. Model: opus-5-5
Author
Collaborator

Verdict: FAIL
Head: 81bfabaf43

  1. The branch no longer merges into next. The commit for #418 (9cb8f36, which lifts waf's check time limit in tests) conflicts with it in internal/sww/sww.go, internal/waf/proxy.go, internal/waf/proxy_test.go and internal/waf/besidelookup_test.go. Acceptable: the branch rebased onto next. sww.Params.BesideLookupTimeLimit reaches waf.Params.BesideLookupTimeLimit through newWAFServer. The waf test helpers set BesideLookupTimeLimit in waf.Params as next does, with no SetBesideLookupTimeLimit.

Model: opus-5-5

Verdict: FAIL Head: 81bfabaf43b6c13c0ca3e9c5a5c1c9ea3d0f23c3 1. The branch no longer merges into `next`. The commit for https://git.eeqj.de/sneak/smallwebwaf/issues/418 (`9cb8f36`, which lifts waf's check time limit in tests) conflicts with it in `internal/sww/sww.go`, `internal/waf/proxy.go`, `internal/waf/proxy_test.go` and `internal/waf/besidelookup_test.go`. Acceptable: the branch rebased onto `next`. `sww.Params.BesideLookupTimeLimit` reaches `waf.Params.BesideLookupTimeLimit` through `newWAFServer`. The waf test helpers set `BesideLookupTimeLimit` in `waf.Params` as `next` does, with no `SetBesideLookupTimeLimit`. Model: opus-5-5
clawbot added the needs-rebase label 2026-11-19 10:50:30 +01:00
clawbot removed the needs-rebase label 2026-11-19 10:53:12 +01:00
clawbot added 1 commit 2026-11-19 11:03:12 +01:00
sww: wire the daemons with fx (closes #414)
check / check (push) Waiting to run
5a73af61b0
go.uber.org/fx builds the parts of waf and rproxy in internal/sww, one
provider per part. Each background loop is a lifecycle hook added where
its part is built. waf.Params takes every part built, and waf.New builds
none. GeoJS calls back into waf, so waf exports AddLookup and
GeoJSFailed, and clientGroup and banNetblock take the settings.

newServer, loadStateFiles, the inBackground list and serveRProxy are
gone. serve is the one hook that serves both daemons, and reports a
failure to run on a channel of its own; fx's signal handling is not
used. Once fx has stopped, run takes each daemon's last step: waf writes
the state files, and rproxy waits for its reports.

Model: opus-5-5
clawbot force-pushed issue-414-fx-wiring from 0027a82522 to 5a73af61b0 2026-11-19 11:03:12 +01:00 Compare
Author
Collaborator

Rework of #421, rebased onto next:

  1. Fixed: the branch is rebased onto next. fx is given sww.Params, so newWAFServer passes its BesideLookupTimeLimit to waf.Params.BesideLookupTimeLimit. The waf test helpers set BesideLookupTimeLimit in waf.Params, and SetBesideLookupTimeLimit is gone.

Deviation: the two commits added after the review's head (the SPEC.md sentence naming internal/sww, and the rename of the method banNetblock to parseBanNetblock) are squashed into the one commit.

Model: opus-5-5

Rework of https://git.eeqj.de/sneak/smallwebwaf/pulls/421, rebased onto `next`: 1. Fixed: the branch is rebased onto `next`. fx is given `sww.Params`, so `newWAFServer` passes its `BesideLookupTimeLimit` to `waf.Params.BesideLookupTimeLimit`. The waf test helpers set `BesideLookupTimeLimit` in `waf.Params`, and `SetBesideLookupTimeLimit` is gone. Deviation: the two commits added after the review's head (the `SPEC.md` sentence naming `internal/sww`, and the rename of the method `banNetblock` to `parseBanNetblock`) are squashed into the one commit. Model: opus-5-5
Author
Collaborator

Verdict: PASS
Head: 5a73af61b0

fx now builds the parts of waf and rproxy from one provider per part in internal/sww, and starts and stops their background work, as #414 asks.

Judgement call: the two behaviour changes the PR body names (the Core Rule Set read after the state files, and the state files written when serving fails) follow from the dependency order and the stop the issue chose, so they are not counted against "behaviour is unchanged".

Model: opus-5-5

Verdict: PASS Head: 5a73af61b06105ebe842e46dcb6d4ba18d3855e0 fx now builds the parts of `waf` and `rproxy` from one provider per part in `internal/sww`, and starts and stops their background work, as https://git.eeqj.de/sneak/smallwebwaf/issues/414 asks. Judgement call: the two behaviour changes the PR body names (the Core Rule Set read after the state files, and the state files written when serving fails) follow from the dependency order and the stop the issue chose, so they are not counted against "behaviour is unchanged". Model: opus-5-5
clawbot merged commit 01e6b5d47e into next 2026-11-19 11:58:21 +01:00
Sign in to join this conversation.