Public: anyone can read this; the crew can change it.

A child forge cannot bring back an ask the owner put aside by flooding new ones #15058

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15042-a-child-forge-cannot-bring-back-an-ask-t → main 1 commit fork

  • Merged. scout/15042-a-child-forge-cannot-bring-back-an-ask-t was merged into main as ad6beef.

Review

Sign in to review this change.
2 files changed +36 −3
src/core/child_reach.ts +10 −3
@@ -123,7 +123,8 @@ export const RAISE_AGAIN_MS = 24 * 3_600_000;
123123 /**
124124 * Keep one ask per forge and name. A repeat refreshes the one row (its time,
125125 * its reason, who asked) and never adds another; one an admin put aside
126 * stays aside for a day. Past `ASKS_PER_FORGE` waiting, the oldest gives way.
126 * stays aside for a day. Past `ASKS_PER_FORGE` waiting, the oldest waiting
127 * ask gives way; a put-aside inside its day never does.
127128 */
128129 export function keepAsk(
129130 db: Database,
@@ -155,10 +156,16 @@ export function keepAsk(
155156 at,
156157 again,
157158 );
159 // Only waiting asks give way. A put-aside still inside its day is the
160 // admin's answer: evicting it would let a flood of new names wipe it,
161 // and the next repeat would come back as a fresh ask. Its number is
162 // bounded by the admin's own clicks, one per name.
158163 db.query(
159164 `DELETE FROM child_reach_ask WHERE body_id = ?1 AND rowid IN (
160 SELECT rowid FROM child_reach_ask WHERE body_id = ?1 ORDER BY last_at DESC, rowid DESC LIMIT -1 OFFSET ?2)`,
161 ).run(input.bodyId, ASKS_PER_FORGE);
165 SELECT rowid FROM child_reach_ask
166 WHERE body_id = ?1 AND NOT (state = 'later' AND answered_at > ?3)
167 ORDER BY last_at DESC, rowid DESC LIMIT -1 OFFSET ?2)`,
168 ).run(input.bodyId, ASKS_PER_FORGE, again);
162169 })();
163170 return askFor(db, input.bodyId, input.host)!;
164171 }
test/ask-to-reach.test.ts +26
@@ -32,10 +32,13 @@ import { hostAllowed, startEgress, type Egress } from "../src/apps/egress.ts";
3232 import {
3333 addGrant,
3434 askableHost,
35 askFor,
3536 ASKS_PER_FORGE,
3637 keepAsk,
3738 listAsks,
3839 listGrants,
40 putAsideAsk,
41 RAISE_AGAIN_MS,
3942 } from "../src/core/child_reach.ts";
4043 import { asksOfUser } from "../src/core/reach_ask.ts";
4144 import { createToken } from "../src/core/tokens.ts";
@@ -804,6 +807,29 @@ describe("for every hosted forge, not now, and across restarts", () => {
804807 expect(kept).not.toContain("h0.many.invalid");
805808 parent.db.query("DELETE FROM child_reach_ask").run();
806809 });
810
811 test("a flood of new asks cannot push out one an admin put aside: re-sent, it is still held", () => {
812 const t0 = Date.now();
813 const ask = (host: string, at: number) =>
814 keepAsk(
815 parent.db,
816 { bodyId: maria.bodyId, child: "maria", host, why: "", askedBy: "ana" },
817 at,
818 );
819 ask("aside.many.invalid", t0);
820 expect(putAsideAsk(parent.db, maria.bodyId, "aside.many.invalid", "alice", t0)).toBe(true);
821 for (let i = 0; i < ASKS_PER_FORGE + 5; i++)
822 ask(`f${i}.many.invalid`, t0 + 1 + i);
823 expect(askFor(parent.db, maria.bodyId, "aside.many.invalid")?.state).toBe("later");
824 const waiting = listAsks(parent.db).filter(
825 (a) => a.bodyId === maria.bodyId && a.state === "asked",
826 );
827 expect(waiting).toHaveLength(ASKS_PER_FORGE);
828 expect(ask("aside.many.invalid", t0 + 100).state).toBe("later");
829 // Past its day it is an ordinary ask again, and may give way like one.
830 expect(ask("aside.many.invalid", t0 + RAISE_AGAIN_MS + 1).state).toBe("asked");
831 parent.db.query("DELETE FROM child_reach_ask").run();
832 });
807833 });
808834
809835 describe("the terminal's door", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs