feat(guardrails): context-aware flock slot + dispatch guardrail integration (#28) #35

Merged
jacisjake merged 2 commits from task/28-dispatch-guardrails into main 2026-10-28 12:48:07 +00:00
jacisjake commented 2026-10-28 12:46:57 +00:00 (Migrated from github.com)

What was addressed

  • Flock.reserve(ctx) — context-aware flock slot; replaces the 5 unconditional f.sem <- sites in ask, classify, ClassifyMode, ClassifyKind, ClassifyDivergence. A saturated flock no longer wedges a caller forever; it gives up when the context ends.
  • dispatch_test.go: TestDispatchCallsGoThroughFlock (semaphore + prob-logged flight event + saturation must not answer), TestConspiracyInviteCapInFlight (invites capped by MaxCrowsInFlight), TestDispatchGuardrailsEndToEnd (conspiracy request → claims → nudge, atomic peak ≤ cap, mode/tag/flight kinds in the log).
  • serve test helper for mounting a *Server handler.

How to test / validate

  • go test -race -count=1 -run 'TestDispatch|TestConspiracyInviteCap' . passes
  • go vet ./... and gofmt -l . are clean
  • Revert flock.go/jev.go to main and go test -timeout 15s -run TestDispatchCallsGoThroughFlock . fails (red: unconditional sem send hangs past the test timeout)

Configurations or dependencies

  • None beyond C1–C6 (#22–#27), all merged.

Closes #28

## What was addressed - `Flock.reserve(ctx)` — context-aware flock slot; replaces the 5 unconditional `f.sem <-` sites in `ask`, `classify`, `ClassifyMode`, `ClassifyKind`, `ClassifyDivergence`. A saturated flock no longer wedges a caller forever; it gives up when the context ends. - `dispatch_test.go`: `TestDispatchCallsGoThroughFlock` (semaphore + prob-logged flight event + saturation must not answer), `TestConspiracyInviteCapInFlight` (invites capped by `MaxCrowsInFlight`), `TestDispatchGuardrailsEndToEnd` (conspiracy request → claims → nudge, atomic peak ≤ cap, mode/tag/flight kinds in the log). - `serve` test helper for mounting a `*Server` handler. ## How to test / validate - [ ] `go test -race -count=1 -run 'TestDispatch|TestConspiracyInviteCap' .` passes - [ ] `go vet ./...` and `gofmt -l .` are clean - [ ] Revert `flock.go`/`jev.go` to main and `go test -timeout 15s -run TestDispatchCallsGoThroughFlock .` fails (red: unconditional sem send hangs past the test timeout) ## Configurations or dependencies - [ ] None beyond C1–C6 (#22–#27), all merged. Closes #28
Sign in to join this conversation.