GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Backstop reminders: the orphan scan logs a refused batch once per run… · scuttletoby/t3code@a0ffdaf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/fork/delegatedResults
    • DelegatedOrphanScan.test.ts
    • DelegatedOrphanScan.ts
    • delegatedResults.test.ts
    • delegatedResults.ts
  • docs/fork
    • README.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/fork/delegatedResults/DelegatedOrphanScan.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/delegatedResults/DelegatedOrphanScan.test.ts
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,39 @@ describe("DelegatedOrphanScan.scan", () => {
527527
}),
528528
);
529529

530+
it.effect("a receipt another thread holds warns once per run, not on every pass", () =>
531+
Effect.gen(function* () {
532+
yield* setClock;
533+
const world = makeWorld();
534+
const lost1 = [{ environmentId: ENV_B, threadId: ThreadId.make("lost-1") }];
535+
const { commandId } = orphanBatchIds(PARENT, lost1);
536+
// The message's command id is taken by another thread's accepted command.
537+
world.receipts.set(commandId, ThreadId.make("thread-other"));
538+
const warnings: Array<string> = [];
539+
const refusals = () => warnings.filter((log) => log.includes("orphan reminder refused"));
540+
const held = {
541+
type: "held",
542+
detail: `Command ${commandId} belongs to thread thread-other.`,
543+
};
544+
const once = scanned((yield* service(world)).scan()).pipe(
545+
Effect.provide(warningLogs(warnings)),
546+
);
547+
expect((yield* once).parents.get(PARENT)).toEqual(held);
548+
expect((yield* once).parents.get(PARENT)).toEqual(held);
549+
expect((yield* once).parents.get(PARENT)).toEqual(held);
550+
expect(refusals()).toHaveLength(1);
551+
expect(refusals()[0]).toContain(commandId);
552+
// After a restart: once more, then not again.
553+
const restarted = scanned((yield* service(world)).scan()).pipe(
554+
Effect.provide(warningLogs(warnings)),
555+
);
556+
expect((yield* restarted).parents.get(PARENT)).toEqual(held);
557+
expect((yield* restarted).parents.get(PARENT)).toEqual(held);
558+
expect(refusals()).toHaveLength(2);
559+
expect(world.sent).toHaveLength(0);
560+
}),
561+
);
562+
530563
it.effect("takes the first scan's message for the same orphans as sent", () =>
531564
Effect.gen(function* () {
532565
yield* setClock;
@@ -896,6 +929,52 @@ describe("DelegatedOrphanScan and agent slots", () => {
896929
}),
897930
);
898931

932+
it.effect(
933+
"a refused message before one that waits for a slot is logged once, also past a day",
934+
() =>
935+
Effect.gen(function* () {
936+
yield* setClock;
937+
const world = makeWorld();
938+
// Eleven orphans: two messages, the first (ten) refused before this start, the second
939+
// (one) waits for a slot. Each pass of the wait finds the first one's refused receipt.
940+
const lost = Array.from({ length: 11 }, (_, index) => ({
941+
threadId: `lost-${String(index).padStart(2, "0")}`,
942+
}));
943+
world.there.set(ENV_B, [...lost, { threadId: "known-1" }]);
944+
const first = lost
945+
.slice(0, 10)
946+
.map((thread) => ({ environmentId: ENV_B, threadId: ThreadId.make(thread.threadId) }));
947+
world.refused.add(orphanBatchIds(PARENT, first).commandId);
948+
world.slots.state.all = true;
949+
const warnings: Array<string> = [];
950+
const refusals = () => warnings.filter((log) => log.includes("orphan reminder refused"));
951+
const scan = yield* service(world, { maxPages: 10, slotRetryDelay: Duration.hours(1) });
952+
const fiber = yield* scan
953+
.run()
954+
.pipe(Effect.provide(warningLogs(warnings)), Effect.forkChild);
955+
yield* settle;
956+
yield* TestClock.adjust(OPTIONS.delay);
957+
yield* settle;
958+
expect(refusals()).toHaveLength(1);
959+
// The slot stays taken for more than a day (the one-day window is from the start).
960+
for (let step = 0; step < 26; step++) {
961+
yield* TestClock.adjust(Duration.hours(1));
962+
yield* settle;
963+
}
964+
expect(world.slots.asks).toHaveLength(27);
965+
expect(refusals()).toHaveLength(1);
966+
expect(world.sent).toHaveLength(0);
967+
// A slot frees: the second message goes, the first stays refused and is not logged again.
968+
world.slots.state.all = false;
969+
yield* TestClock.adjust(Duration.hours(1));
970+
yield* settle;
971+
yield* Fiber.join(fiber);
972+
expect(world.sent).toHaveLength(1);
973+
expect(world.sent[0]!.text).toContain("lost-10");
974+
expect(refusals()).toHaveLength(1);
975+
}),
976+
);
977+
899978
it.effect("a restart while one waits loses nothing: the next start names it once", () =>
900979
Effect.gen(function* () {
901980
yield* setClock;
Collapse file

‎apps/server/src/fork/delegatedResults/DelegatedOrphanScan.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/delegatedResults/DelegatedOrphanScan.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export const make = Effect.fn("DelegatedOrphanScan.make")(function* (
119119
const slotRetryDelay = options.slotRetryDelay ?? Duration.millis(WAKE_SLOT_RETRY_MS);
120120
/** Parents whose own retry runs (`run`): a later scan leaves them to it. */
121121
const waitingForSlot = new Map<ThreadId, ParentOutcome>();
122-
const newRefusal = makeRefusalLog();
122+
// Never forgotten: an orphan batch's ids do not age, and a slot wait checks its parent again for
123+
// as long as the slot stays taken, a day or more. One run per start, so this holds at most the
124+
// refused batches of that run.
125+
const newRefusal = makeRefusalLog(null);
123126
const settings = yield* ServerSettingsService;
124127
const store = yield* DelegatedResultsStore.DelegatedResultsStore;
125128
const forwarding = yield* PeerForwarding.PeerForwarding;
Collapse file

‎apps/server/src/fork/delegatedResults/delegatedResults.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/delegatedResults/delegatedResults.test.ts
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ describe("reminder ids", () => {
254254
expect(newRefusal("command-b", NOW + REMINDER_MAX_AGE_MS + 1)).toBe(false);
255255
});
256256

257+
it("keeps a refusal for the whole process when told never to forget (the orphan scan)", () => {
258+
const newRefusal = makeRefusalLog(null);
259+
expect(newRefusal("command-a", NOW)).toBe(true);
260+
// An orphan batch's ids do not age: a slot wait finds its refused receipt days later too.
261+
expect(newRefusal("command-a", NOW + 3 * REMINDER_MAX_AGE_MS)).toBe(false);
262+
expect(newRefusal("command-b", NOW + 3 * REMINDER_MAX_AGE_MS)).toBe(true);
263+
// A restart is still a new log.
264+
expect(makeRefusalLog(null)("command-a", NOW + 3 * REMINDER_MAX_AGE_MS)).toBe(true);
265+
});
266+
257267
it("finds this parent's first-format ids, from messages and receipts", () => {
258268
const old = firstFormatReminder(PARENT, ["a", "b"]);
259269
const otherParent = firstFormatReminder(ThreadId.make("other"), ["a"]);
Collapse file

‎apps/server/src/fork/delegatedResults/delegatedResults.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/fork/delegatedResults/delegatedResults.ts
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,18 @@ export const isRemindable = (task: OrchestrationV2Subagent, nowMs: number): bool
112112
};
113113

114114
/**
115-
* Whether a refusal is new to this process, so each refused batch is logged once per process: every
116-
* later check finds its refused receipt (or another thread's receipt) again. Not stored, so a
117-
* restart logs a batch still refused once more, also one whose log line a stop cut off. A refusal
118-
* is forgotten after `REMINDER_MAX_AGE_MS`: its tasks ended before it, so none is reminded then.
115+
* Whether a refusal is new to this process (each later check finds its receipt again); a restart
116+
* logs a batch still refused once more. `forgetAfterMs`: when a logged id can no longer come back
117+
* (the reminder's tasks ended before the refusal, so none is reminded a day later); `null` keeps
118+
* every id for the process.
119119
*/
120-
export const makeRefusalLog = () => {
120+
export const makeRefusalLog = (forgetAfterMs: number | null = REMINDER_MAX_AGE_MS) => {
121121
const logged = new Map<string, number>();
122122
return (commandId: string, nowMs: number): boolean => {
123-
for (const [id, atMs] of logged) {
124-
if (nowMs - atMs > REMINDER_MAX_AGE_MS) logged.delete(id);
123+
if (forgetAfterMs !== null) {
124+
for (const [id, atMs] of logged) {
125+
if (nowMs - atMs > forgetAfterMs) logged.delete(id);
126+
}
125127
}
126128
if (logged.has(commandId)) return false;
127129
logged.set(commandId, nowMs);
Collapse file

‎docs/fork/README.md‎

Copy file name to clipboardExpand all lines: docs/fork/README.md
+12-11Lines changed: 12 additions & 11 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,18 @@ becomes owed later (the later message names only the new task); a message names
187187
A message the thread refuses holds back only its own tasks (until the set changes); the other
188188
messages of that check are still sent. Each refused message is logged once per server run, not on
189189
each later check (also when another thread holds its id); after a restart a message still refused
190-
is logged once more, so a refusal whose log line a stop cut off is still logged. A reminder sent before per-task ids (one id for the whole set) is split into its tasks
191-
from its text, so after an upgrade a task it named is not reminded again; only tasks past the first
192-
ten of such a message, which it never named, may be reminded once more. Such a message whose text
193-
cannot be read is left out alone: its tasks may be reminded once more, and the parent's other
194-
reminders still go. The check at start and a check after an event never run at once for one parent.
195-
It never goes to a stopped or archived thread, and never for results older than a day. A parent is busy, and
196-
waits for its own run end, while a run of it goes or a question of it is open (an open question
197-
holds the reminder until that run ends); background work it left running does not hold it. At
198-
start, every parent with a result unread from the last day is checked once, also when upstream had
199-
reserved no wake for it. Upstream's wake can land just before the reminder, so the message says the
200-
result _may_ not have arrived.
190+
is logged once more, so a refusal whose log line a stop cut off is still logged. A reminder sent
191+
before per-task ids (one id for the whole set) is split into its tasks from its text, so after an
192+
upgrade a task it named is not reminded again; only tasks past the first ten of such a message,
193+
which it never named, may be reminded once more. Such a message whose text cannot be read is left
194+
out alone: its tasks may be reminded once more, and the parent's other reminders still go. The check
195+
at start and a check after an event never run at once for one parent. It never goes to a stopped or
196+
archived thread, and never for results older than a day. A parent is busy, and waits for its own run
197+
end, while a run of it goes or a question of it is open (an open question holds the reminder until
198+
that run ends); background work it left running does not hold it. At start, every parent with a
199+
result unread from the last day is checked once, also when upstream had reserved no wake for it.
200+
Upstream's wake can land just before the reminder, so the message says the result _may_ not have
201+
arrived.
201202

202203
The server makes a thread in a linked environment before it records the task here, so a server that
203204
stops in between leaves a thread there that no task here follows. At start (a few minutes after,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.