mirror of
https://github.com/luxfi/aml.git
synced 2026-09-24 00:25:20 +00:00
The defining failure of the last review was not in a plane. It was that there were TWO wirings: cmd/amld assembled a Handler by hand and the tests assembled a different one, so the record fingerprint could be a struct field the suite exercised and no column stored — every retry a permanent 409 in production while every test passed. api.Wire is now the only assembly. It creates every collection, opens every shelf, makes every join and registers what has to run on a cadence; cmd/amld supplies only what an installation answers differently, the tests call the same function, and internal/source.NoLiteral reads cmd/amld to refuse a second copy. Handler completeness is checked by reflection, because a hand-written field list would be the third copy. A retry is not a second transaction. pkg/receipt resolves the identity of an OFFER once, at the top of ingest, before anything is read or written, and returns the prior answer byte for byte — so the ledger, the aggregates, the history, the alerts and the case plane all agree on one transaction instead of the ledger holding one record while the aggregates hold three. Two different facts under one reference is 409 and never 503. Because the answer is kept AFTER the work, a process that dies in between leaves no receipt, so every plane past it also recognises the transaction for itself: history does not append a second row, alerts keep the first judgement, and a judged transaction opens no second case. A bound over a COUNT of caller-sized values is not a bound. types.MaxIdent bounds every identifier at the door, which is what turns the counts downstream into figures in bytes; dictionary.MaxName does the same for a payload key, and dictionary.Ceiling is the product a test WEIGHS a full accumulator against. The field catalog's accumulator moves into roster, which admits and never removes, so per-tenant bounds multiply by ONE number an operator can hold against a pod. engine.Evaluator now keeps no compiled rules at all. A candidate's text arrives on the wire at /v1/aml/rules/test, so a compiled-rule table there was keyed by a string a caller wrote, sized by how many distinct ones a caller sends, with no cap and no removal, in the memory every institution's ingest runs in — an OOM from one authenticated caller, which on this deployment is every control off at once. A rule's compiled form is a value with an owner: the installed library, or one replay. Nothing shared, nothing to grow. Found here, not reported. Handler.history is the one function that materialises a whole retained history, so it now REQUIRES a *topology.Grant, and a Grant comes from Budget.Admit and nowhere else. An ungated whole-history read is something a caller has to write on purpose rather than something a new door can forget. The rule replay and the activation rate fold take the same one budget the model studies take. Reaching a bound is allowed; reaching it quietly is not. GET /v1/aml/load is the one door for "is anything of mine quietly degraded": the tenant's aggregates against its own ceiling in bytes with a grade, whether it has a behavioural model at all, the field catalog's pressure, and the process's counts of institutions held and refused. It names no other institution. Closing R1-R8 from the review plus R11, the two recurring classes, and the silent degradation the load door answers. Twenty-four mutations, twenty-four killed. Co-authored-by: Hanzo Dev <[email protected]>
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/luxfi/aml/pkg/replay"
|
|
"github.com/luxfi/aml/pkg/topology"
|
|
)
|
|
|
|
// The budget bounds the machine AND the memory, and it can only do the second
|
|
// if the hold is taken by whatever does the reading.
|
|
//
|
|
// A study's expensive half is not the arithmetic. It is the read: in the
|
|
// deployment this shelf runs in, the Source materialises up to a hundred
|
|
// thousand retained records, opens every sealed body, unmarshals each one and
|
|
// asks the alert store about each event. A token taken after that read bounds
|
|
// the trials and nothing else, so eight tenants queued behind a budget of one
|
|
// worker held eight whole histories at once — the memory scaled with the number
|
|
// of TENANTS studying rather than with the budget, which is precisely what the
|
|
// budget's own documentation promised it would not.
|
|
|
|
// counted is a Source that reports how many histories are being held at once.
|
|
type counted struct {
|
|
inner Source
|
|
// live is how many reads are in flight; peak is the most there have ever
|
|
// been. A read is "in flight" from the moment it starts until the study that
|
|
// asked for it is done, because that is how long the events stay in memory.
|
|
live, peak atomic.Int64
|
|
release chan struct{}
|
|
}
|
|
|
|
func (c *counted) History(ctx context.Context, org string, held *topology.Grant) (replay.History, error) {
|
|
n := c.live.Add(1)
|
|
for {
|
|
was := c.peak.Load()
|
|
if n <= was || c.peak.CompareAndSwap(was, n) {
|
|
break
|
|
}
|
|
}
|
|
<-c.release // hold the events, as a study computing over them does
|
|
return c.inner.History(ctx, org, held)
|
|
}
|
|
|
|
// TestNoStudyReadsAHistoryItHasNotPaidFor is red's measurement, as a property.
|
|
func TestNoStudyReadsAHistoryItHasNotPaidFor(t *testing.T) {
|
|
const tenants = 8
|
|
|
|
s := shelf(t)
|
|
source := &counted{inner: s.History, release: make(chan struct{})}
|
|
s.History = source
|
|
s.Cores = topology.NewBudget(1)
|
|
|
|
var wg sync.WaitGroup
|
|
for i := range tenants {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
// Each tenant is its own institution, so no gate refuses any of them:
|
|
// what holds them back must be the budget or nothing.
|
|
org := tenant(i)
|
|
_, _ = s.Fit(context.Background(), org, &FitIn{
|
|
Topology: shape, Options: topology.Options{Seed: 7}, By: "a.mensah",
|
|
})
|
|
}()
|
|
}
|
|
|
|
// Let every goroutine reach whatever is going to stop it — the budget, or
|
|
// the read — and then look at how many histories are being held.
|
|
settle(source)
|
|
peak := source.peak.Load()
|
|
close(source.release)
|
|
wg.Wait()
|
|
|
|
if budget := int64(s.Cores.Size()); peak > budget {
|
|
t.Errorf("budget = %d worker(s); peak concurrent history reads = %d. A study waiting for the machine is holding a tenant's whole history while it waits.",
|
|
budget, peak)
|
|
}
|
|
}
|
|
|
|
func tenant(i int) string {
|
|
return "hanzo/org-" + string(rune('a'+i))
|
|
}
|
|
|
|
// settle waits until the number of reads in flight has stopped moving. Polling
|
|
// rather than a barrier, because what is being measured is how many goroutines
|
|
// GET to the read: a barrier they never reach is a test that hangs instead of
|
|
// one that fails.
|
|
func settle(c *counted) {
|
|
last, still := int64(-1), 0
|
|
for range 400 {
|
|
n := c.live.Load()
|
|
if n == last {
|
|
if still++; still >= 20 {
|
|
return
|
|
}
|
|
} else {
|
|
last, still = n, 0
|
|
}
|
|
time.Sleep(5 * time.Millisecond)
|
|
}
|
|
}
|