Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

quota-burn: null-safe observed-block predicate

[._.]/ Adam Eivy4365d8635815
diff --git a/server/lib/quotaReset.js b/server/lib/quotaReset.js
index 70d29427a8..fdcc311ca4 100644
--- a/server/lib/quotaReset.js
+++ b/server/lib/quotaReset.js
@@ -207,7 +207,11 @@ export function parseObservedReset(text, { now = Date.now() } = {}) {
* `quotaBurnDenials.js`); each supplies its own TTL, but the predicate — and the
* reason `until`-alone is wrong — lives once. Pure.
*/
-export function isObservedBlockActive({ at, until } = {}, { now = Date.now(), ttlMs } = {}) {
+export function isObservedBlockActive(block, { now = Date.now(), ttlMs } = {}) {
+ // Read through `?.` rather than destructuring with a default: a default
+ // parameter only covers `undefined`, and an absent block legitimately arrives
+ // as `null` from a ledger lookup that already normalized it.
+ const at = block?.at;
if (!at) return false;
- return until ? until > now : now - at < ttlMs;
+ return block.until ? block.until > now : now - at < ttlMs;
}
diff --git a/server/services/quotaBurnDenials.test.js b/server/services/quotaBurnDenials.test.js
index 25916b99ac..27a2460d24 100644
--- a/server/services/quotaBurnDenials.test.js
+++ b/server/services/quotaBurnDenials.test.js
@@ -111,6 +111,9 @@ describe('recordQuotaBurnDenial', () => {
expect(entry.until).toBeNull();
expect(isBlockActive(entry, NOW + UNKNOWN_BLOCK_TTL_MS - 1)).toBe(true);
expect(isBlockActive(entry, NOW + UNKNOWN_BLOCK_TTL_MS)).toBe(false);
+ // An absent block arrives as either shape from a ledger lookup.
+ expect(isBlockActive(undefined, NOW)).toBe(false);
+ expect(isBlockActive(null, NOW)).toBe(false);
});
it('never clobbers a ledger it could not read', async () => {