diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3f707..1e34512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ What changed in each release, for people who use attend. The npm package `@acqui ## Unreleased +- Set `settle.deliveryRetryBackoffMs` (`delivery_retry_backoff_ms` in Python) to give the sink its own retry delays and exhaustion budget. Omit it to keep using the judge schedule. Both runtimes save the option at reducer revision 8. + - Closing events can set a per-event `quietForMs` for their output. A consequence can carry `settles: true` when that output is complete, including through serial intake. Both runtimes persist the fields at reducer revision 7. See [closing duration and completion](docs/reference.md#closing-duration-and-completion). ## 0.3.0 (2026-11-14) diff --git a/conformance/fixtures/scenarios.json b/conformance/fixtures/scenarios.json index bf60fbc..e0e4f11 100644 --- a/conformance/fixtures/scenarios.json +++ b/conformance/fixtures/scenarios.json @@ -1,5 +1,2433 @@ { "scenarios": [ + { + "scenario": { + "name": "a short sink backoff unblocks later deliveries while a judge backs off", + "start": 100, + "kinds": { + "close": "closing", + "say": "flush", + "drag": "continuous", + "look": "passive", + "out": "consequence", + "said": "context" + }, + "settle": { + "retryBackoffMs": [ + 1000 + ], + "deliveryRetryBackoffMs": [ + 10 + ] + }, + "judge": { + "*": { + "rules": [ + { + "has": [ + "provider" + ], + "once": true, + "answer": { + "fail": "provider unavailable" + } + }, + { + "answer": { + "route": "note" + } + } + ] + } + }, + "sink": { + "*": { + "attempts": [ + { + "fail": "store unavailable" + } + ] + } + }, + "steps": [ + { + "push": "s", + "events": [ + { + "id": "first", + "name": "say", + "text": "say first" + } + ] + }, + { + "advance": 0 + }, + { + "advance": 1 + }, + { + "push": "s", + "events": [ + { + "id": "next", + "name": "say", + "text": "say next" + } + ] + }, + { + "advance": 0 + }, + { + "advance": 1 + }, + { + "push": "s", + "events": [ + { + "id": "provider", + "name": "say", + "text": "say provider" + } + ] + }, + { + "advance": 0 + }, + { + "inspect": "s" + }, + { + "advance": 8 + }, + { + "inspect": "s" + }, + { + "advance": 992 + } + ] + }, + "expected": { + "judgeCalls": { + "s": [ + { + "scope": "s", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [], + "now": 100 + }, + { + "scope": "s", + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + } + ], + "now": 101 + }, + { + "scope": "s", + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "now": 102 + }, + { + "scope": "s", + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "now": 1102 + } + ] + }, + "deliveries": { + "s": [ + { + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "outcome": "Error: store unavailable" + }, + { + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "outcome": "ok" + }, + { + "decision": { + "id": "5fc4d8db379e8b70", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "at": 101 + }, + "outcome": "ok" + }, + { + "decision": { + "id": "4708d8c9622d2c78", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "at": 1102 + }, + "outcome": "ok" + } + ] + }, + "deadLetterCalls": {}, + "traces": { + "s": [ + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "28b47bfc372e3386", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "28b47bfc372e3386", + "attempt": 1, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "28b47bfc372e3386", + "route": "note" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 1 + }, + { + "kind": "retrying", + "scope": "s", + "stage": "sink", + "id": "28b47bfc372e3386", + "attempt": 1, + "at": 110, + "message": "store unavailable" + }, + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "attempt": 1, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "route": "note" + }, + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "4708d8c9622d2c78", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "4708d8c9622d2c78", + "attempt": 1, + "offerWait": false + }, + { + "kind": "retrying", + "scope": "s", + "stage": "judge", + "id": "4708d8c9622d2c78", + "attempt": 1, + "at": 1102, + "message": "provider unavailable" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 2 + }, + { + "kind": "delivered", + "scope": "s", + "deliveryId": "28b47bfc372e3386" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "5fc4d8db379e8b70", + "attempt": 1 + }, + { + "kind": "delivered", + "scope": "s", + "deliveryId": "5fc4d8db379e8b70" + }, + { + "kind": "judging", + "scope": "s", + "batchId": "4708d8c9622d2c78", + "attempt": 2, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "4708d8c9622d2c78", + "route": "note" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "4708d8c9622d2c78", + "attempt": 1 + }, + { + "kind": "delivered", + "scope": "s", + "deliveryId": "4708d8c9622d2c78" + } + ] + }, + "results": [ + { + "step": 0, + "error": null + }, + { + "step": 3, + "error": null + }, + { + "step": 6, + "error": null + } + ], + "inspections": [ + { + "step": 8, + "scope": "s", + "record": { + "version": 10, + "scope": "s", + "cursors": {}, + "seen": [ + "first", + "next", + "provider" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": { + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "phase": { + "phase": "retrying", + "attempt": 1, + "failures": 1, + "at": 1102, + "offerWait": false + } + }, + "outbox": { + "decisions": [ + { + "item": { + "id": "28b47bfc372e3386", + "kind": "decision", + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + } + }, + "phase": { + "phase": "retrying", + "attempt": 1, + "failures": 1, + "at": 110 + } + }, + { + "item": { + "id": "5fc4d8db379e8b70", + "kind": "decision", + "decision": { + "id": "5fc4d8db379e8b70", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "at": 101 + } + }, + "phase": { + "phase": "retrying", + "attempt": 0, + "failures": 0, + "at": 101 + } + } + ], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "dueAt": 110 + } + }, + { + "step": 10, + "scope": "s", + "record": { + "version": 13, + "scope": "s", + "cursors": {}, + "seen": [ + "first", + "next", + "provider" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": { + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "phase": { + "phase": "retrying", + "attempt": 1, + "failures": 1, + "at": 1102, + "offerWait": false + } + }, + "outbox": { + "decisions": [], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "dueAt": 1102 + } + } + ], + "records": { + "s": { + "version": 16, + "scope": "s", + "cursors": {}, + "seen": [ + "first", + "next", + "provider" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": null, + "outbox": { + "decisions": [], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + }, + { + "id": "4708d8c9622d2c78", + "route": "note", + "at": 1102 + } + ], + "dueAt": null + } + }, + "log": [ + { + "kind": "decision", + "id": "28b47bfc372e3386", + "scope": "s", + "at": 100, + "route": "note", + "body": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "position": "1" + }, + { + "kind": "decision", + "id": "5fc4d8db379e8b70", + "scope": "s", + "at": 101, + "route": "note", + "body": { + "id": "5fc4d8db379e8b70", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "at": 101 + }, + "position": "2" + }, + { + "kind": "decision", + "id": "4708d8c9622d2c78", + "scope": "s", + "at": 1102, + "route": "note", + "body": { + "id": "4708d8c9622d2c78", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "4708d8c9622d2c78", + "events": [ + { + "id": "provider", + "at": 0, + "name": "say", + "data": {}, + "text": "say provider", + "kind": "flush", + "seenAt": 102 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 102 + }, + "at": 1102 + }, + "position": "3" + } + ] + } + }, + { + "scenario": { + "name": "sink exhaustion and dead-letter handler retries use separate schedules", + "start": 100, + "kinds": { + "close": "closing", + "say": "flush", + "drag": "continuous", + "look": "passive", + "out": "consequence", + "said": "context" + }, + "settle": { + "retryBackoffMs": [ + 200, + 500 + ], + "deliveryRetryBackoffMs": [ + 10 + ] + }, + "judge": { + "*": { + "answers": [ + { + "route": "note" + } + ] + } + }, + "sink": { + "*": { + "attempts": [ + { + "fail": "store unavailable" + }, + { + "fail": "still unavailable" + } + ] + } + }, + "deadLetter": { + "*": { + "attempts": [ + { + "fail": "handler unavailable" + } + ] + } + }, + "steps": [ + { + "push": "s", + "events": [ + { + "id": "first", + "name": "say", + "text": "say first" + } + ] + }, + { + "advance": 0 + }, + { + "advance": 1 + }, + { + "push": "s", + "events": [ + { + "id": "next", + "name": "say", + "text": "say next" + } + ] + }, + { + "advance": 0 + }, + { + "advance": 9 + }, + { + "inspect": "s" + }, + { + "advance": 200 + } + ] + }, + "expected": { + "judgeCalls": { + "s": [ + { + "scope": "s", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [], + "now": 100 + }, + { + "scope": "s", + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + } + ], + "now": 101 + } + ] + }, + "deliveries": { + "s": [ + { + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "outcome": "Error: store unavailable" + }, + { + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "outcome": "Error: still unavailable" + }, + { + "decision": { + "id": "5fc4d8db379e8b70", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "at": 101 + }, + "outcome": "ok" + } + ] + }, + "deadLetterCalls": { + "s": [ + { + "letter": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "still unavailable", + "permanent": false, + "attempts": 2, + "at": 110 + }, + "outcome": "Error: handler unavailable" + }, + { + "letter": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "still unavailable", + "permanent": false, + "attempts": 2, + "at": 110 + }, + "outcome": "ok" + } + ] + }, + "traces": { + "s": [ + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "28b47bfc372e3386", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "28b47bfc372e3386", + "attempt": 1, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "28b47bfc372e3386", + "route": "note" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 1 + }, + { + "kind": "retrying", + "scope": "s", + "stage": "sink", + "id": "28b47bfc372e3386", + "attempt": 1, + "at": 110, + "message": "store unavailable" + }, + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "attempt": 1, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "5fc4d8db379e8b70", + "route": "note" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 2 + }, + { + "kind": "deadLettered", + "scope": "s", + "letter": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "still unavailable", + "permanent": false, + "attempts": 2, + "at": 110 + } + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "5fc4d8db379e8b70", + "attempt": 1 + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 3 + }, + { + "kind": "delivered", + "scope": "s", + "deliveryId": "5fc4d8db379e8b70" + }, + { + "kind": "retrying", + "scope": "s", + "stage": "deadLetter", + "id": "28b47bfc372e3386", + "attempt": 3, + "at": 310, + "message": "handler unavailable" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 4 + }, + { + "kind": "delivered", + "scope": "s", + "deliveryId": "28b47bfc372e3386" + } + ] + }, + "results": [ + { + "step": 0, + "error": null + }, + { + "step": 3, + "error": null + } + ], + "inspections": [ + { + "step": 6, + "scope": "s", + "record": { + "version": 11, + "scope": "s", + "cursors": {}, + "seen": [ + "first", + "next" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": null, + "outbox": { + "decisions": [], + "deadLetters": [ + { + "item": { + "id": "28b47bfc372e3386", + "kind": "deadLetter", + "letter": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "still unavailable", + "permanent": false, + "attempts": 2, + "at": 110 + } + }, + "phase": { + "phase": "retrying", + "attempt": 3, + "failures": 1, + "at": 310 + } + } + ] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "dueAt": 310 + } + } + ], + "records": { + "s": { + "version": 13, + "scope": "s", + "cursors": {}, + "seen": [ + "first", + "next" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": null, + "outbox": { + "decisions": [], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + }, + { + "id": "5fc4d8db379e8b70", + "route": "note", + "at": 101 + } + ], + "dueAt": null + } + }, + "log": [ + { + "kind": "decision", + "id": "28b47bfc372e3386", + "scope": "s", + "at": 100, + "route": "note", + "body": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "position": "1" + }, + { + "kind": "decision", + "id": "5fc4d8db379e8b70", + "scope": "s", + "at": 101, + "route": "note", + "body": { + "id": "5fc4d8db379e8b70", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "5fc4d8db379e8b70", + "events": [ + { + "id": "next", + "at": 0, + "name": "say", + "data": {}, + "text": "say next", + "kind": "flush", + "seenAt": 101 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 101 + }, + "at": 101 + }, + "position": "2" + }, + { + "kind": "deadLetter", + "id": "28b47bfc372e3386", + "scope": "s", + "at": 110, + "route": "note", + "body": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "still unavailable", + "permanent": false, + "attempts": 2, + "at": 110 + }, + "position": "3" + } + ] + } + }, + { + "scenario": { + "name": "an empty sink schedule dead-letters an expired first attempt", + "start": 100, + "kinds": { + "close": "closing", + "say": "flush", + "drag": "continuous", + "look": "passive", + "out": "consequence", + "said": "context" + }, + "settle": { + "retryBackoffMs": [ + 200 + ], + "deliveryRetryBackoffMs": [], + "deliveryTimeoutMs": 10 + }, + "judge": { + "*": { + "answers": [ + { + "route": "note" + } + ] + } + }, + "sink": { + "*": { + "attempts": [ + { + "hang": true + } + ] + } + }, + "steps": [ + { + "push": "s", + "events": [ + { + "id": "first", + "name": "say", + "text": "say first" + } + ] + }, + { + "advance": 0 + }, + { + "advance": 10 + }, + { + "inspect": "s" + } + ] + }, + "expected": { + "judgeCalls": { + "s": [ + { + "scope": "s", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "routes": [ + { + "route": "interrupt" + }, + { + "route": "queue" + }, + { + "route": "note" + }, + { + "route": "ask" + }, + { + "route": "skip" + } + ], + "predicates": [], + "facts": {}, + "recent": [], + "now": 100 + } + ] + }, + "deliveries": { + "s": [ + { + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "outcome": "Error: aborted" + } + ] + }, + "deadLetterCalls": {}, + "traces": { + "s": [ + { + "kind": "ingested", + "scope": "s", + "count": 1, + "duplicates": 0 + }, + { + "kind": "settled", + "scope": "s", + "batchId": "28b47bfc372e3386", + "reason": "flush", + "count": 1, + "merged": false + }, + { + "kind": "judging", + "scope": "s", + "batchId": "28b47bfc372e3386", + "attempt": 1, + "offerWait": false + }, + { + "kind": "judged", + "scope": "s", + "batchId": "28b47bfc372e3386", + "route": "note" + }, + { + "kind": "delivering", + "scope": "s", + "deliveryId": "28b47bfc372e3386", + "attempt": 1 + }, + { + "kind": "deadLettered", + "scope": "s", + "letter": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "delivery lease expired", + "permanent": false, + "attempts": 1, + "at": 110 + } + }, + { + "kind": "stale", + "scope": "s", + "input": "deliveryFailed", + "why": "no live delivery attempt 1 for 28b47bfc372e3386" + } + ] + }, + "results": [ + { + "step": 0, + "error": null + } + ], + "inspections": [ + { + "step": 3, + "scope": "s", + "record": { + "version": 4, + "scope": "s", + "cursors": {}, + "seen": [ + "first" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": null, + "outbox": { + "decisions": [], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + } + ], + "dueAt": null + } + } + ], + "records": { + "s": { + "version": 4, + "scope": "s", + "cursors": {}, + "seen": [ + "first" + ], + "buffer": { + "entries": [], + "dropped": 0, + "gap": false, + "forcedAt": null + }, + "batch": null, + "outbox": { + "decisions": [], + "deadLetters": [] + }, + "recent": [ + { + "id": "28b47bfc372e3386", + "route": "note", + "at": 100 + } + ], + "dueAt": null + } + }, + "log": [ + { + "kind": "decision", + "id": "28b47bfc372e3386", + "scope": "s", + "at": 100, + "route": "note", + "body": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "position": "1" + }, + { + "kind": "deadLetter", + "id": "28b47bfc372e3386", + "scope": "s", + "at": 110, + "route": "note", + "body": { + "id": "28b47bfc372e3386", + "scope": "s", + "stage": "sink", + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "decision": { + "id": "28b47bfc372e3386", + "scope": "s", + "route": "note", + "probabilities": { + "interrupt": 0, + "queue": 0, + "note": 1, + "ask": 0, + "skip": 0, + "wait": 0 + }, + "predicates": {}, + "confidence": null, + "window": { + "id": "28b47bfc372e3386", + "events": [ + { + "id": "first", + "at": 0, + "name": "say", + "data": {}, + "text": "say first", + "kind": "flush", + "seenAt": 100 + } + ], + "reason": "flush", + "waits": 0, + "dropped": 0, + "gap": false, + "settledAt": 100 + }, + "at": 100 + }, + "message": "delivery lease expired", + "permanent": false, + "attempts": 1, + "at": 110 + }, + "position": "2" + } + ] + } + }, { "scenario": { "name": "closing combines default grace with explicit deadlines", diff --git a/docs/reference.md b/docs/reference.md index 9aa76b0..f75af63 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -208,6 +208,12 @@ One accepted source batch is still one admission. It can exceed the counted trig The pair persists with the snapshot at reducer revision 5. Tails and inspection use the saved policy. Adding, removing or changing the pair is refused before writes or effects while open entries or an unresolved batch remain. Empty scopes may adopt it while retaining recent decisions and outbox work. Old records without the pair keep scalar behavior. Coordinate writer versions: this is not a fence against older code that lacks the check. +## Delivery retry schedule + +Set `settle.deliveryRetryBackoffMs` (`delivery_retry_backoff_ms` in Python) to give the sink its own retry delays. Supply a list of finite, nonnegative millisecond values. Its length is the number of retries after the first attempt, including failures from expired delivery leases. An empty list dead-letters on the first failure. Permanent failures dead-letter immediately. + +Omit the option to use `retryBackoffMs` for the sink. Judges and sources continue to use `retryBackoffMs`, which also provides the base delays for the dead-letter handler's capped backoff. Pending deliveries retain their committed retry deadlines on restart. A policy change applies to subsequent failures after replay under the saved policy. + ## Guarantees - **One snapshot and a short tail per scope.** The snapshot holds the open window, the judge slot and the outbox. A write appends the inputs that changed state, and a snapshot replaces the tail once it grows past the snapshot's own size. A source's cursor commits in the same write as the events it covers. @@ -215,7 +221,7 @@ The pair persists with the snapshot at reducer revision 5. Tails and inspection - **Effects only after a committed write.** attend calls the judge and the sink only for state it has persisted. `push` and `flush` persist and return; the runner settles, judges and delivers. If a process crashes after a write and before its effect, the work stays in the store, and a runner retries it when its lease expires. - **The decision log is the delivery for subscribers.** The decision row commits with the state change that made it. Subscribers read it by cursor, so a reconnect resumes where it stopped; a cursor that fell behind retention is reported as `truncated`, never silently skipped. - **At-least-once delivery with stable ids.** A decision's id is a hash of the scope and its window's event ids, so a redelivery carries the same id and no two scopes share one. Deliveries in one scope run one at a time, oldest first. -- **Dead letters are never dropped.** The judge and the sink each get `retryBackoffMs.length` retries. A window that still fails becomes a dead letter, which attend retries with capped backoff until `deadLetter` accepts it. A lane that fills to its cap (`maxOutbox` decisions, `maxDeadLetters` dead letters) makes `push` and a source's `emit` reject until it drains. +- **Dead letters are never dropped.** The judge and sink each get as many retries as their schedule has entries. A window that still fails becomes a dead letter, which attend retries with capped backoff until `deadLetter` accepts it. A lane that fills to its cap (`maxOutbox` decisions, `maxDeadLetters` dead letters) makes `push` and a source's `emit` reject until it drains. - **Crash-tested at every commit boundary.** `crashSuite` runs a scripted session once, then once more for each commit with a crash just before it and again just after it. Every run must deliver the same decision ids and dead-letter ids. CI runs it against the memory, SQLite, Postgres and Redis stores. ## Defaults @@ -234,7 +240,8 @@ These are round starting points, not tuned values. Override any of them with `se | `maxWindowMs` | 60000 | Age of the first act at which the window settles | | `windowShare` (a `createAttend` option) | 0.5 | Share of the judge's context budget a window may fill before it settles with reason `size` | | `actThreshold` (a `createAttend` option) | off | Act when p(interrupt) + p(ask) reaches it | -| `retryBackoffMs` | `[1000, 4000, 16000]` | Backoff before each retry of a judge call, a delivery or a source. Its length is the retry budget for judges and sinks; a source repeats the last rung. | +| `retryBackoffMs` | `[1000, 4000, 16000]` | Backoff for judges and sources, the default for sink delivery, and the base delays for the dead-letter handler. A source repeats the last rung. | +| `deliveryRetryBackoffMs` | `retryBackoffMs` | Backoff for sink delivery. Its length is the sink retry budget. | | `judgeTimeoutMs` | 15000 | Aborts a judge call. The judge's lease is twice this. | | `deliveryTimeoutMs` | 10000 | Lease on one delivery. An expired lease counts as a failed attempt. | | `recentCount` | 8 | Recent verdicts the judge sees | diff --git a/docs/sinks.md b/docs/sinks.md index 737b6a9..cd4c649 100644 --- a/docs/sinks.md +++ b/docs/sinks.md @@ -2,6 +2,8 @@ A sink delivers decisions to the agent. attend calls `sink.deliver(decision, signal)` at least once per decision, one decision at a time per scope, oldest first. After a crash it can deliver the same decision again with the same id, so make the sink idempotent on `decision.id`, which is unique across scopes. Throw to retry, or throw a `PermanentError` to dead-letter at once. +Use `settle.deliveryRetryBackoffMs` to give the sink a shorter retry schedule when judge failures need longer backoff. A failed decision stays at the head of its scope's delivery queue until it succeeds or becomes a dead letter. See the [delivery retry schedule](reference.md#delivery-retry-schedule). + For a host-prepared result, return [`Judgment.data`](judges.md#carry-a-result-to-the-sink) from the custom judge and read `decision.data` here. The outbox owns that JSON value through retries and recovery, so the sink does not need a separate pending-result cache. The sink receives a detached copy. The default notice remains based on event lines and ignores this field. A sink can be one function, `(decision, signal) => …`, that gets every delivered decision. `routes()` builds a sink from one handler per delivered route instead, so a route you forgot fails to typecheck. A sink never sees `skip` or `wait`. This excerpt from [`examples/postgres-worker.ts`](../examples/postgres-worker.ts) writes every decision to an inbox table that the agent's runtime reads: diff --git a/docs/storage.md b/docs/storage.md index ae56ba9..fc58103 100644 --- a/docs/storage.md +++ b/docs/storage.md @@ -47,3 +47,5 @@ Each adapter also has an `EventLog`: `memoryLog`, `sqliteLog`, `postgresLog` and [Judgment data](judges.md#carry-a-result-to-the-sink) uses reducer revision 6. Optional data stays in logged judgments, decisions and recent verdicts. Old records without it remain readable. Use compatible readers and writers before returning data; replay on a version mismatch does not fence older processes or make them retain the field. [Closing durations and completion](reference.md#closing-duration-and-completion) use reducer revision 7. Upgrade every reader and writer sharing a store before using either field. Replay uses the saved policy for default grace and the logged event times for explicit deadlines. A tail logged under a snapshot from an older revision keeps `settles` as plain metadata, since older revisions gave it no meaning; only input logged at revision 7 or later ends a window with it. + +[Delivery retry schedules](reference.md#delivery-retry-schedule) use reducer revision 8. Tails replay under their saved policy, and pending retries keep their committed deadlines. Upgrade readers and writers sharing a store before setting the sink schedule. diff --git a/python/src/aqi_attend/attend.py b/python/src/aqi_attend/attend.py index fbeb477..499d88b 100644 --- a/python/src/aqi_attend/attend.py +++ b/python/src/aqi_attend/attend.py @@ -6,6 +6,7 @@ import contextlib import inspect import math +import sys import uuid from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine, Mapping, Sequence from typing import Any, Literal, Protocol, TypedDict, cast, runtime_checkable @@ -115,6 +116,7 @@ def subscribe(self, cursor: str | None, emit: Callable[[SourceBatch], Awaitable[ "max_events": "maxEvents", "max_window_ms": "maxWindowMs", "retry_backoff_ms": "retryBackoffMs", + "delivery_retry_backoff_ms": "deliveryRetryBackoffMs", "judge_timeout_ms": "judgeTimeoutMs", "delivery_timeout_ms": "deliveryTimeoutMs", "recent_count": "recentCount", @@ -139,6 +141,18 @@ def _event_limits(value: object) -> EventLimits: return {"counted": counted, "background": background} +def _delivery_retry_backoff(value: object) -> list[float]: + message = "attend: deliveryRetryBackoffMs requires an array of finite nonnegative numbers" + if not isinstance(value, (list, tuple)): + raise TypeError(message) + delays: list[float] = [] + for delay in cast(Sequence[object], value): + if isinstance(delay, bool) or not isinstance(delay, (int, float)) or not 0 <= delay <= sys.float_info.max: + raise TypeError(message) + delays.append(delay) + return delays + + def settle_policy(settle: Mapping[str, Any] | None = None) -> SettlePolicy: """The defaults with ``settle`` (snake_case names, as ``create_attend`` takes them) applied.""" if settle is not None and "event_limits" in settle and (settle.get("continuation") != "accumulate" or "max_events" in settle): @@ -151,7 +165,13 @@ def settle_policy(settle: Mapping[str, Any] | None = None) -> SettlePolicy: raise TypeError(f"attend: unknown settle option {name!r}") if name == "continuation" and (not isinstance(value, str) or value not in ("separate", "accumulate")): raise ValueError("attend: continuation must be separate or accumulate") - policy[key] = list(value) if name == "retry_backoff_ms" else _event_limits(value) if name == "event_limits" else value + if name == "delivery_retry_backoff_ms": + value = _delivery_retry_backoff(value) + elif name == "retry_backoff_ms": + value = list(value) + elif name == "event_limits": + value = _event_limits(value) + policy[key] = value return cast(SettlePolicy, policy) diff --git a/python/src/aqi_attend/core/reducer.py b/python/src/aqi_attend/core/reducer.py index a440209..92bc1b3 100644 --- a/python/src/aqi_attend/core/reducer.py +++ b/python/src/aqi_attend/core/reducer.py @@ -49,9 +49,12 @@ window_shed, ) -REDUCER_VERSION = 7 +REDUCER_VERSION = 8 """Bumped whenever a release changes a transition. Stored with every snapshot.""" +DELIVERY_RETRY_REVISION = 8 +"""The first revision that applies the saved sink retry policy.""" + COMPLETION_REVISION = 7 """The first revision whose logged inputs give ``settles`` its meaning.""" @@ -683,10 +686,11 @@ def _fail_delivery(ctx: _Ctx, state: ScopeState, lane: OutboxLane, message: str, attempt = phase["attempt"] failures = phase["failures"] + 1 ctx.out.changed = True - backoff = ctx.config.policy["retryBackoffMs"] + policy = ctx.config.policy if item["kind"] == "deadLetter": - delay: float | None = _dead_letter_delay(ctx.config.policy, failures) + delay: float | None = _dead_letter_delay(policy, failures) else: + backoff = policy.get("deliveryRetryBackoffMs", policy["retryBackoffMs"]) delay = None if permanent or failures - 1 >= len(backoff) else backoff[failures - 1] if delay is not None: at = ctx.now + delay diff --git a/python/src/aqi_attend/core/types.py b/python/src/aqi_attend/core/types.py index caa7ec0..afe0d27 100644 --- a/python/src/aqi_attend/core/types.py +++ b/python/src/aqi_attend/core/types.py @@ -68,6 +68,7 @@ class SettlePolicy(TypedDict): maxEvents: int maxWindowMs: float retryBackoffMs: list[float] + deliveryRetryBackoffMs: NotRequired[list[float]] judgeTimeoutMs: float deliveryTimeoutMs: float recentCount: int diff --git a/python/src/aqi_attend/shell/read.py b/python/src/aqi_attend/shell/read.py index fa6c7d4..52fea45 100644 --- a/python/src/aqi_attend/shell/read.py +++ b/python/src/aqi_attend/shell/read.py @@ -5,7 +5,7 @@ from typing import cast from .._json import clone -from ..core.reducer import COMPLETION_REVISION, apply +from ..core.reducer import COMPLETION_REVISION, DELIVERY_RETRY_REVISION, apply from ..core.state import from_record, initial_state, to_record from ..core.types import DEFAULT_POLICY, ApplyConfig, ApplyOutput, DeliveryMode, ScopeRecord, ScopeState from ..store.types import ScopeStore, StoredScope @@ -15,6 +15,9 @@ def replay(scope: str, stored: StoredScope, decisions: DeliveryMode, dead_letter """Replays immutable stored data under the snapshot's policy, ignoring effects and appends.""" snapshot = stored["snapshot"] policy = snapshot["policy"] if snapshot is not None else DEFAULT_POLICY + if snapshot is not None and snapshot["reducer"] < DELIVERY_RETRY_REVISION and "deliveryRetryBackoffMs" in policy: + policy = policy.copy() + del policy["deliveryRetryBackoffMs"] state = from_record(snapshot["record"], policy) if snapshot is not None else initial_state(scope) # A tail under an older snapshot was logged by an older reducer, where ``settles`` meant nothing. completion = snapshot is None or snapshot["reducer"] >= COMPLETION_REVISION diff --git a/python/tests/scenario.py b/python/tests/scenario.py index b2b2e41..b39b944 100644 --- a/python/tests/scenario.py +++ b/python/tests/scenario.py @@ -43,6 +43,7 @@ def event_spec(spec: Mapping[str, Any]) -> Event: "maxEvents": "max_events", "maxWindowMs": "max_window_ms", "retryBackoffMs": "retry_backoff_ms", + "deliveryRetryBackoffMs": "delivery_retry_backoff_ms", "judgeTimeoutMs": "judge_timeout_ms", "deliveryTimeoutMs": "delivery_timeout_ms", "recentCount": "recent_count", diff --git a/python/tests/test_continuation.py b/python/tests/test_continuation.py index 80f8e03..d744311 100644 --- a/python/tests/test_continuation.py +++ b/python/tests/test_continuation.py @@ -226,7 +226,7 @@ async def test_revision_three_read_and_mode_boundary(item: dict[str, Any]) -> No stored = await store.load("scope") assert stored is not None and stored["snapshot"] is not None assert stored["snapshot"]["policy"].get("continuation") == "accumulate" - assert stored["snapshot"]["reducer"] == 7 + assert stored["snapshot"]["reducer"] == 8 record = await engine.inspect("scope") assert record is not None and record["recent"] == item["expected"]["recent"] else: diff --git a/python/tests/test_continuous_quiet.py b/python/tests/test_continuous_quiet.py index 590c518..7010fa7 100644 --- a/python/tests/test_continuous_quiet.py +++ b/python/tests/test_continuous_quiet.py @@ -254,7 +254,7 @@ async def test_revision_two_snapshot_and_mixed_tail_rebuild_end_times() -> None: assert loaded is not None and loaded["dueAt"] == 200 assert [(event["id"], event.get("quietForMs"), event["seenAt"]) for event in loaded["buffer"]["entries"]] == [("a", None, 100), ("b", 90, 120), ("c", None, 120)] stored = await store.load("s") - assert stored is not None and stored["snapshot"] is not None and stored["snapshot"]["reducer"] == 7 + assert stored is not None and stored["snapshot"] is not None and stored["snapshot"]["reducer"] == 8 finally: await attend.stop() await store.close() diff --git a/python/tests/test_delivery_retry.py b/python/tests/test_delivery_retry.py new file mode 100644 index 0000000..5c6f46a --- /dev/null +++ b/python/tests/test_delivery_retry.py @@ -0,0 +1,71 @@ +"""The saved sink retry policy controls recovery and exhaustion.""" + +import asyncio + +import pytest + +from aqi_attend import AbortSignal, create_attend, memory_store +from aqi_attend.attend import settle_policy +from aqi_attend.core.types import Decision, JudgeInput, Judgment, Kind +from aqi_attend.shell.read import replay +from aqi_attend.testing import fake_clock + + +async def test_resume_sink_retry_with_a_changed_schedule() -> None: + clock = fake_clock() + store = memory_store() + kinds: dict[str, Kind] = {"message": "flush"} + + async def judge(_input: JudgeInput, _signal: AbortSignal) -> Judgment: + return {"route": "note"} + + async def fail(_decision: Decision, _signal: AbortSignal) -> None: + raise RuntimeError("store unavailable") + + schedule = [10] + first = create_attend(clock=clock, store=store, kind=kinds, judge=judge, sink=fail, settle={"retry_backoff_ms": [1000], "delivery_retry_backoff_ms": schedule}) + schedule[0] = 500 + running = asyncio.create_task(first.run()) + try: + await first.push("s", {"id": "a", "name": "message"}) + await clock.advance(0) + record = await first.inspect("s") + assert record is not None + assert record["outbox"]["decisions"][0]["phase"] == {"phase": "retrying", "attempt": 1, "failures": 1, "at": 10} + saved = await store.load("s") + assert saved is not None and saved["snapshot"] is not None + assert saved["snapshot"]["policy"].get("deliveryRetryBackoffMs") == [10] + assert any(logged["input"]["kind"] == "deliveryFailed" for logged in saved["tail"]) + legacy = saved.copy() + legacy["snapshot"] = {**saved["snapshot"], "reducer": 7} + assert replay("s", legacy, "lane", "log").due_at == 1000 + finally: + await first.stop() + await running + + attempts: list[float] = [] + + async def sink(_decision: Decision, _signal: AbortSignal) -> None: + attempts.append(clock.now()) + if len(attempts) == 1: + raise RuntimeError("store unavailable") + + second = create_attend(clock=clock, store=store, kind=kinds, judge=judge, sink=sink, settle={"retry_backoff_ms": [1000], "delivery_retry_backoff_ms": [50, 60]}) + resumed = asyncio.create_task(second.run()) + try: + await clock.advance(9) + assert attempts == [] + await clock.advance(1) + assert attempts == [10] + await clock.advance(60) + assert attempts == [10, 70] + finally: + await second.stop() + await resumed + await store.close() + + +@pytest.mark.parametrize("value", [None, 10, "10", [True], ["10"], [-1], [float("nan")], [float("inf")], [10**310]]) +def test_refuses_invalid_delivery_retry_schedule(value: object) -> None: + with pytest.raises(TypeError, match="deliveryRetryBackoffMs"): + settle_policy({"delivery_retry_backoff_ms": value}) diff --git a/python/tests/test_event_limits.py b/python/tests/test_event_limits.py index 35c6ba9..f2424fc 100644 --- a/python/tests/test_event_limits.py +++ b/python/tests/test_event_limits.py @@ -257,7 +257,7 @@ async def test_revision_four_snapshots_and_tails_keep_saved_policy(item: dict[st await write stored = await store.load("s") assert stored is not None and stored["snapshot"] is not None - assert stored["snapshot"]["reducer"] == 7 + assert stored["snapshot"]["reducer"] == 8 assert stored["snapshot"]["policy"].get("eventLimits") == {"counted": 3, "background": 2} record = await engine.inspect("s") assert record is not None and record["recent"] == item["expected"]["recent"] diff --git a/python/tests/test_event_limits_interop.py b/python/tests/test_event_limits_interop.py index f7acebc..a3e4876 100644 --- a/python/tests/test_event_limits_interop.py +++ b/python/tests/test_event_limits_interop.py @@ -127,7 +127,7 @@ async def test_independent_limits_continue_across_runtimes(kind: str, phase: str written = await (python(owned, "write", scope, phase) if writer == "python" else typescript(kind, prefix, "write", scope, phase)) stored = await owned.load(scope) assert stored is not None and stored["snapshot"] is not None - assert stored["snapshot"]["reducer"] == 7 and stored["tail"] + assert stored["snapshot"]["reducer"] == 8 and stored["tail"] assert stored["snapshot"]["policy"].get("eventLimits") == {"counted": 3, "background": 2} read = await (typescript(kind, prefix, "read", scope, phase) if writer == "python" else python(owned, "read", scope, phase)) assert read["record"] == written["record"] diff --git a/python/tests/test_interop.py b/python/tests/test_interop.py index db2daf9..3878c1f 100644 --- a/python/tests/test_interop.py +++ b/python/tests/test_interop.py @@ -156,7 +156,7 @@ async def test_intake_snapshot_and_tail_continue_without_intake_in_other_runtime assert written["record"]["cursors"] == {"feed": "3"} stored = await owned.load(scope) assert stored is not None and stored["snapshot"] is not None - assert stored["snapshot"]["reducer"] == 7 and stored["tail"] + assert stored["snapshot"]["reducer"] == 8 and stored["tail"] encoded = json.dumps(stored) assert all(field not in encoded for field in ('"catchUp"', '"catch_up"', '"prepare"', '"owner"')) read = await (typescript(kind, prefix, "read", scope) if writer == "python" else python(owned, "read", scope)) diff --git a/python/tests/test_observation_time.py b/python/tests/test_observation_time.py index 0c9686b..360a0f5 100644 --- a/python/tests/test_observation_time.py +++ b/python/tests/test_observation_time.py @@ -259,7 +259,7 @@ async def test_prior_reducer_snapshot_and_tail_keep_ingestion_deadlines() -> Non assert loaded is not None and loaded["dueAt"] == 2100 assert [(event["id"], event["seenAt"], event.get("observedAt")) for event in loaded["buffer"]["entries"]] == [("a", 1000, None), ("b", 1100, None)] stored = await store.load("s") - assert stored is not None and stored["snapshot"] is not None and stored["snapshot"]["reducer"] == 7 + assert stored is not None and stored["snapshot"] is not None and stored["snapshot"]["reducer"] == 8 finally: await attend.stop() await store.close() diff --git a/src/attend.ts b/src/attend.ts index 4689f5c..45d17be 100644 --- a/src/attend.ts +++ b/src/attend.ts @@ -36,6 +36,13 @@ export function createAttendInternal(config: AttendConfig, snapshot: 'ratio' | ' throw new RangeError('attend: judgeConcurrency must be a positive integer'); } const policy: SettlePolicy = { ...DEFAULT_POLICY, ...config.settle }; + if (policy.deliveryRetryBackoffMs !== undefined) { + const message = 'attend: deliveryRetryBackoffMs requires an array of finite nonnegative numbers'; + if (!Array.isArray(policy.deliveryRetryBackoffMs)) throw new TypeError(message); + const backoff = [...policy.deliveryRetryBackoffMs]; + if (backoff.some((delay) => !Number.isFinite(delay) || delay < 0)) throw new TypeError(message); + policy.deliveryRetryBackoffMs = backoff; + } if (policy.continuation !== undefined && policy.continuation !== 'separate' && policy.continuation !== 'accumulate') { throw new TypeError('attend: continuation must be separate or accumulate'); } diff --git a/src/core/reducer.ts b/src/core/reducer.ts index 7fab744..f861cd5 100644 --- a/src/core/reducer.ts +++ b/src/core/reducer.ts @@ -9,7 +9,10 @@ import { seenAdmit, seenRelease, seenTrim } from './seen.js'; import { estimateRenderedBytes, isBackground, observationTime, openWindow, shedEntries, windowAppend, windowCompact, windowDeadline, windowEntries, windowPrune, windowShed, windowSize } from './window.js'; /** Bumped whenever a release changes a transition. Stored with every snapshot. */ -export const REDUCER_VERSION = 7; +export const REDUCER_VERSION = 8; + +/** The first revision that applies the saved sink retry policy. */ +export const DELIVERY_RETRY_REVISION = 8; /** The first revision whose logged inputs give `settles` its meaning. */ export const COMPLETION_REVISION = 7; @@ -466,8 +469,9 @@ function failDelivery(ctx: Ctx, state: ScopeState, lane: OutboxLane, message: st const { attempt } = d.phase; const failures = d.phase.failures + 1; ctx.out.changed = true; - const delay = item.kind === 'deadLetter' ? deadLetterDelay(ctx.config.policy, failures) - : permanent ? undefined : ctx.config.policy.retryBackoffMs[failures - 1]; + const policy = ctx.config.policy; + const delay = item.kind === 'deadLetter' ? deadLetterDelay(policy, failures) + : permanent ? undefined : (policy.deliveryRetryBackoffMs ?? policy.retryBackoffMs)[failures - 1]; if (delay !== undefined) { const at = ctx.now + delay; state.outbox[lane][0] = { item, phase: { phase: 'retrying', attempt, failures, at } }; diff --git a/src/core/types.ts b/src/core/types.ts index b0626ce..45c4a1e 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -81,8 +81,10 @@ export interface SettlePolicy { maxEvents: number; /** A window settles this long after its first act however busy it is; older act-less entries are pruned. */ maxWindowMs: number; - /** Backoff before each retry of a judge call, a delivery or a source; its length is the retry budget for the first two. */ + /** Judge and source backoff, also used for deliveries by default and as the base for dead-letter handler retries. */ retryBackoffMs: number[]; + /** Sink retry delays in ms. Omit to use retryBackoffMs. The length is the sink retry budget. */ + deliveryRetryBackoffMs?: number[]; /** Aborts a judge call. Its lease is twice this, so a slow call is never duplicated while live. */ judgeTimeoutMs: number; /** Lease on a delivery. Expiry counts as one failed attempt. */ diff --git a/src/shell/read.ts b/src/shell/read.ts index 2d22079..1ae4855 100644 --- a/src/shell/read.ts +++ b/src/shell/read.ts @@ -1,11 +1,15 @@ -import { apply, COMPLETION_REVISION, newOutput } from '../core/reducer.js'; +import { apply, COMPLETION_REVISION, DELIVERY_RETRY_REVISION, newOutput } from '../core/reducer.js'; import { fromRecord, initialState, toRecord } from '../core/state.js'; import { DEFAULT_POLICY, type ApplyConfig, type ScopeRecord, type ScopeState } from '../core/types.js'; import type { ScopeStore, StoredScope } from '../store/types.js'; /** Replays immutable stored data under the snapshot's policy, ignoring effects and appends. */ export function replay(scope: string, stored: StoredScope, modes: Pick): ScopeState { - const policy = stored.snapshot?.policy ?? DEFAULT_POLICY; + let policy = stored.snapshot?.policy ?? DEFAULT_POLICY; + if (stored.snapshot && stored.snapshot.reducer < DELIVERY_RETRY_REVISION && Object.hasOwn(policy, 'deliveryRetryBackoffMs')) { + policy = { ...policy }; + delete policy.deliveryRetryBackoffMs; + } const state = stored.snapshot ? fromRecord(stored.snapshot.record, policy) : initialState(scope, policy); // A tail under an older snapshot was logged by an older reducer, where `settles` meant nothing. const completion = !stored.snapshot || stored.snapshot.reducer >= COMPLETION_REVISION; diff --git a/test/conformance/scenarios.ts b/test/conformance/scenarios.ts index 38c039a..762566e 100644 --- a/test/conformance/scenarios.ts +++ b/test/conformance/scenarios.ts @@ -14,6 +14,42 @@ const advance = (ms: number) => ({ advance: ms }); const T = 'test/attend.test.ts'; export const SCENARIOS: Scenario[] = [ + { + name: 'a short sink backoff unblocks later deliveries while a judge backs off', + start: 100, kinds: KINDS, + settle: { retryBackoffMs: [1000], deliveryRetryBackoffMs: [10] }, + judge: { + '*': { rules: [{ has: ['provider'], once: true, answer: { fail: 'provider unavailable' } }, { answer: { route: 'note' } }] }, + }, + sink: { '*': { attempts: [{ fail: 'store unavailable' }] } }, + steps: [ + push('s', ev('first', 'say')), advance(0), + advance(1), push('s', ev('next', 'say')), advance(0), + advance(1), push('s', ev('provider', 'say')), advance(0), { inspect: 's' }, + advance(8), { inspect: 's' }, advance(992), + ], + }, + { + name: 'sink exhaustion and dead-letter handler retries use separate schedules', + start: 100, kinds: KINDS, + settle: { retryBackoffMs: [200, 500], deliveryRetryBackoffMs: [10] }, + judge: { '*': { answers: [{ route: 'note' }] } }, + sink: { '*': { attempts: [{ fail: 'store unavailable' }, { fail: 'still unavailable' }] } }, + deadLetter: { '*': { attempts: [{ fail: 'handler unavailable' }] } }, + steps: [ + push('s', ev('first', 'say')), advance(0), + advance(1), push('s', ev('next', 'say')), advance(0), + advance(9), { inspect: 's' }, advance(200), + ], + }, + { + name: 'an empty sink schedule dead-letters an expired first attempt', + start: 100, kinds: KINDS, + settle: { retryBackoffMs: [200], deliveryRetryBackoffMs: [], deliveryTimeoutMs: 10 }, + judge: { '*': { answers: [{ route: 'note' }] } }, + sink: { '*': { attempts: [{ hang: true }] } }, + steps: [push('s', ev('first', 'say')), advance(0), advance(10), { inspect: 's' }], + }, { name: 'closing combines default grace with explicit deadlines', start: 100, kinds: KINDS, diff --git a/test/continuation.test.ts b/test/continuation.test.ts index 2d141d3..a06cd45 100644 --- a/test/continuation.test.ts +++ b/test/continuation.test.ts @@ -170,7 +170,7 @@ test.each(legacy.cases)('reads revision-3 $name and refuses an unresolved mode s await pending; const stored = await store.load('scope'); expect(stored?.snapshot?.policy.continuation).toBe('accumulate'); - expect(stored?.snapshot?.reducer).toBe(7); + expect(stored?.snapshot?.reducer).toBe(8); expect((await engine.inspect('scope'))?.recent).toEqual(item.expected.recent); } else { await expect(pending).rejects.toThrow('continuation'); diff --git a/test/continuous-quiet.test.ts b/test/continuous-quiet.test.ts index a741cc8..8f58630 100644 --- a/test/continuous-quiet.test.ts +++ b/test/continuous-quiet.test.ts @@ -204,7 +204,7 @@ test('a revision-two snapshot and mixed tail rebuild continuous end times', asyn const loaded = await attend.inspect('s'); expect(loaded?.dueAt).toBe(200); expect(loaded?.buffer.entries.map((event) => [event.id, event.quietForMs, event.seenAt])).toEqual([['a', undefined, 100], ['b', 90, 120], ['c', undefined, 120]]); - expect((await store.load('s'))?.snapshot?.reducer).toBe(7); + expect((await store.load('s'))?.snapshot?.reducer).toBe(8); } finally { await attend.stop(); } diff --git a/test/core-inputs.test.ts b/test/core-inputs.test.ts index 6dcb62f..5ee82f2 100644 --- a/test/core-inputs.test.ts +++ b/test/core-inputs.test.ts @@ -379,7 +379,7 @@ test('assertInvariants identifies corrupt counts, rings, summaries, sizes, hashe lane.outbox.decisions.push(lane.outbox.decisions[0]!); lane.dueAt = nextDue(policy, lane); assert.throws(() => assertInvariants(lane, policy), /^Error: outbox: more than one in flight/); - assert.equal(REDUCER_VERSION, 7); + assert.equal(REDUCER_VERSION, 8); }); test('fromRecord accepts frozen oracle snapshots without changing them', () => { diff --git a/test/delivery-retry.test.ts b/test/delivery-retry.test.ts new file mode 100644 index 0000000..8d6c1c5 --- /dev/null +++ b/test/delivery-retry.test.ts @@ -0,0 +1,61 @@ +import { expect, test } from 'vitest'; +import { createAttend, memoryStore, type AttendConfig } from '../src/index.js'; +import { replay } from '../src/shell/read.js'; +import { fakeClock } from '../src/testing.js'; + +test('delivery retries replay at the committed deadline under a changed writer policy', async () => { + const clock = fakeClock(); + const store = memoryStore(); + const config = { clock, store, kind: { message: 'flush' }, judge: async () => ({ route: 'note' }) } satisfies Omit; + const schedule = [10]; + const first = createAttend({ + ...config, settle: { retryBackoffMs: [1000], deliveryRetryBackoffMs: schedule }, + sink: () => { throw new Error('store unavailable'); }, + }); + schedule[0] = 500; + const running = first.run(); + try { + await first.push('s', { id: 'a', name: 'message' }); + await clock.advance(0); + expect((await first.inspect('s'))?.outbox.decisions[0]?.phase).toMatchObject({ phase: 'retrying', failures: 1, at: 10 }); + const saved = await store.load('s'); + expect(saved?.snapshot?.policy.deliveryRetryBackoffMs).toEqual([10]); + expect(saved?.tail.some(({ input }) => input.kind === 'deliveryFailed')).toBe(true); + if (!saved?.snapshot) throw new Error('expected a saved policy'); + const legacy = { ...saved, snapshot: { ...saved.snapshot, reducer: 7 } }; + expect(replay('s', legacy, { decisions: 'lane', deadLetters: 'log' }).dueAt).toBe(1000); + } finally { + await first.stop(); + await running; + } + + const attempts: number[] = []; + const second = createAttend({ + ...config, settle: { retryBackoffMs: [1000], deliveryRetryBackoffMs: [50, 60] }, + sink: () => { + attempts.push(clock.now()); + if (attempts.length === 1) throw new Error('store unavailable'); + }, + }); + const resumed = second.run(); + try { + await clock.advance(9); + expect(attempts).toEqual([]); + await clock.advance(1); + expect(attempts).toEqual([10]); + expect((await second.inspect('s'))?.outbox.decisions[0]?.phase).toMatchObject({ phase: 'retrying', failures: 2, at: 70 }); + await clock.advance(60); + expect(attempts).toEqual([10, 70]); + } finally { + await second.stop(); + await resumed; + } +}); + +test.each([null, 10, '10', [true], ['10'], [-1], [NaN], [Infinity], Array(1)])('invalid delivery retry schedule %j is refused', (value: unknown) => { + expect(() => createAttend({ + kind: { message: 'flush' }, judge: async () => ({ route: 'note' }), sink: 'log', + // @ts-expect-error decoded input can violate the declared type + settle: { deliveryRetryBackoffMs: value }, + })).toThrow('deliveryRetryBackoffMs'); +}); diff --git a/test/event-limits.test.ts b/test/event-limits.test.ts index 0856c6f..16481dd 100644 --- a/test/event-limits.test.ts +++ b/test/event-limits.test.ts @@ -177,7 +177,7 @@ test.each(legacy.cases)('revision-four $name snapshot and tail retain their save if (item.name === 'complete') { await write; const stored = await store.load('s'); - expect(stored?.snapshot?.reducer).toBe(7); + expect(stored?.snapshot?.reducer).toBe(8); expect(stored?.snapshot?.policy.eventLimits).toEqual({ counted: 3, background: 2 }); expect((await engine.inspect('s'))?.recent).toEqual(item.expected.recent); } else { diff --git a/test/observation-time.test.ts b/test/observation-time.test.ts index f72c130..43f54f0 100644 --- a/test/observation-time.test.ts +++ b/test/observation-time.test.ts @@ -207,7 +207,7 @@ test('a prior reducer snapshot and tail retain ingestion-time deadlines on upgra const loaded = await attend.inspect('s'); expect(loaded?.dueAt).toBe(2100); expect(loaded?.buffer.entries.map((event) => [event.id, event.seenAt, event.observedAt])).toEqual([['a', 1000, undefined], ['b', 1100, undefined]]); - expect((await store.load('s'))?.snapshot?.reducer).toBe(7); + expect((await store.load('s'))?.snapshot?.reducer).toBe(8); } finally { await attend.stop(); } diff --git a/test/recovery.test.ts b/test/recovery.test.ts index 8f3826a..71d8510 100644 --- a/test/recovery.test.ts +++ b/test/recovery.test.ts @@ -69,7 +69,7 @@ test('recovers every committed write under all snapshot cadences and policy chan let tailInputs = 0; let snapshotBytes = JSON.stringify(latest.record).length; const replay = (snapshot: Snapshot, through: number, expected: ScopeRecord): void => { - assert.equal(snapshot.reducerVersion, 7); + assert.equal(snapshot.reducerVersion, 8); const restored = fromRecord(deepFreeze(json(snapshot.record)), snapshot.policy); let bound = Math.max(snapshot.policy.seenCount, restored.seen.size); assertInvariants(restored, { ...snapshot.policy, seenCount: bound });