From the architecture review, "The decision pipeline: the heuristics", under "The steps after the answer are ordered by defer": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next, where discriminator is now waf. Line numbers are that commit's.
The review calls this independent of its other proposals for the heuristics.
What is there
answerQuestion (internal/waf/waf.go:164) registers up to five defers. Their reverse order is the order of the work, and two comments explain it ("The last deferred runs first").
An allowed request does runAfterAnswer, finish, holdForReport.
A refused one does runAfterAnswer, countAnomalies, addToHistory, finish, holdForReport.
finishWith (waf.go:470) does the matching steps for a reported request, as plain statements: the onReport list, countAnomalies, addToHistory.
Why it matters
Whether a broken refusal limit is in the client's history depends on this order. A reader gets it only by reversing the defers in their head, and the same steps are coded two ways.
What changes
One function does the steps in order, as plain statements: the list of heuristics that only ban, then countAnomalies, then addToHistory. A refused request's decision and an allowed request's report both call it, each with its own list.
answerQuestion keeps one defer, for the log line and the hold for the report.
Before (waf.go):
// The last deferred runs first: runAfterAnswer before addToHistory, so that// a broken refusal limit is in the client's history.deferrq.addToHistory()deferrq.countAnomalies()deferrq.runAfterAnswer(r.Context())
Today the steps also happen when a check panics. With plain statements, only what the remaining defer does still happens: the log line is written and the decision held, and the request is not counted in its client's history or for the anomaly thresholds.
The review names this as the proposal's catch.
What stays
The order of the steps on each path, as listed above.
Go's server sends the answer only once answerQuestion returns, so the decision is still held before its report can come.
Done when
the steps after the answer are plain statements in one function that both paths call, and answerQuestion has one defer;
every existing test passes with no assertion changed;
make check passes.
Model: fable-5-2
From the architecture review, "The decision pipeline: the heuristics", under "The steps after the answer are ordered by `defer`": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173833. Approved for building: https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`, where `discriminator` is now `waf`. Line numbers are that commit's.
The review calls this independent of its other proposals for the heuristics.
### What is there
- `answerQuestion` (`internal/waf/waf.go:164`) registers up to five `defer`s. Their reverse order is the order of the work, and two comments explain it ("The last deferred runs first").
- An allowed request does `runAfterAnswer`, `finish`, `holdForReport`.
- A refused one does `runAfterAnswer`, `countAnomalies`, `addToHistory`, `finish`, `holdForReport`.
- `finishWith` (`waf.go:470`) does the matching steps for a reported request, as plain statements: the `onReport` list, `countAnomalies`, `addToHistory`.
### Why it matters
Whether a broken refusal limit is in the client's history depends on this order. A reader gets it only by reversing the `defer`s in their head, and the same steps are coded two ways.
### What changes
- One function does the steps in order, as plain statements: the list of heuristics that only ban, then `countAnomalies`, then `addToHistory`. A refused request's decision and an allowed request's report both call it, each with its own list.
- `answerQuestion` keeps one `defer`, for the log line and the hold for the report.
Before (`waf.go`):
```go
// The last deferred runs first: runAfterAnswer before addToHistory, so that
// a broken refusal limit is in the client's history.
defer rq.addToHistory()
defer rq.countAnomalies()
defer rq.runAfterAnswer(r.Context())
```
After:
```go
rq.runAfterAnswer(ctx)
rq.countAnomalies()
rq.addToHistory()
```
### One behaviour changes
- Today the steps also happen when a check panics. With plain statements, only what the remaining `defer` does still happens: the log line is written and the decision held, and the request is not counted in its client's history or for the anomaly thresholds.
- The review names this as the proposal's catch.
### What stays
- The order of the steps on each path, as listed above.
- Go's server sends the answer only once `answerQuestion` returns, so the decision is still held before its report can come.
### Done when
- the steps after the answer are plain statements in one function that both paths call, and `answerQuestion` has one `defer`;
- every existing test passes with no assertion changed;
- `make check` passes.
Model: fable-5-2
clawbot
self-assigned this 2026-11-19 17:14:27 +01:00
banAndCount runs the heuristics that only ban, then countAnomalies, then addToHistory. The refused path and the report both call it. answerQuestion keeps one defer, for finish and holdForReport. No test changed.
Judgement call: runAfterAnswer is removed, and the allowed path calls runBanningHeuristics with afterAnswer() directly.
Model: opus-5-5
PR: https://git.eeqj.de/sneak/smallwebwaf/pulls/471, branch `issue-445-after-answer-statements`.
`banAndCount` runs the heuristics that only ban, then `countAnomalies`, then `addToHistory`. The refused path and the report both call it. `answerQuestion` keeps one `defer`, for `finish` and `holdForReport`. No test changed.
Judgement call: `runAfterAnswer` is removed, and the allowed path calls `runBanningHeuristics` with `afterAnswer()` directly.
Model: opus-5-5
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
From the architecture review, "The decision pipeline: the heuristics", under "The steps after the answer are ordered by
defer": #283 (comment). Approved for building: #283 (comment). The code was read at809d266onnext, wherediscriminatoris nowwaf. Line numbers are that commit's.The review calls this independent of its other proposals for the heuristics.
What is there
answerQuestion(internal/waf/waf.go:164) registers up to fivedefers. Their reverse order is the order of the work, and two comments explain it ("The last deferred runs first").runAfterAnswer,finish,holdForReport.runAfterAnswer,countAnomalies,addToHistory,finish,holdForReport.finishWith(waf.go:470) does the matching steps for a reported request, as plain statements: theonReportlist,countAnomalies,addToHistory.Why it matters
Whether a broken refusal limit is in the client's history depends on this order. A reader gets it only by reversing the
defers in their head, and the same steps are coded two ways.What changes
countAnomalies, thenaddToHistory. A refused request's decision and an allowed request's report both call it, each with its own list.answerQuestionkeeps onedefer, for the log line and the hold for the report.Before (
waf.go):After:
One behaviour changes
deferdoes still happens: the log line is written and the decision held, and the request is not counted in its client's history or for the anomaly thresholds.What stays
answerQuestionreturns, so the decision is still held before its report can come.Done when
answerQuestionhas onedefer;make checkpasses.Model: fable-5-2
PR: #471, branch
issue-445-after-answer-statements.banAndCountruns the heuristics that only ban, thencountAnomalies, thenaddToHistory. The refused path and the report both call it.answerQuestionkeeps onedefer, forfinishandholdForReport. No test changed.Judgement call:
runAfterAnsweris removed, and the allowed path callsrunBanningHeuristicswithafterAnswer()directly.Model: opus-5-5