fix: dire le pari comme un pari, et distinguer deux manques d'inbox que rien ne distinguait
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
|
||||
import { getCaps, getCurrentUser } from "../shared-wallet/bootstrap";
|
||||
import { accessLogPrefix, logStage, shortNuri } from "../shared-wallet/access-log";
|
||||
import { enumerateMyInboxes, type InboxEnumeration } from "./branch-registers";
|
||||
import { enumerateMyInboxes, type InboxEnumeration, type InboxRegister } from "./branch-registers";
|
||||
import { drainInboxSerially, drainsSettled } from "./inbox-drain";
|
||||
import { lookupAccount } from "../shared-wallet/account-registry";
|
||||
import { processInbox } from "../surface/inbox";
|
||||
@@ -83,7 +83,7 @@ interface Observation {
|
||||
/** A trigger that arrived mid-cycle: the running one repeats once rather than lose it. */
|
||||
enumerateAgain: boolean;
|
||||
/**
|
||||
* True while the shortfall reported by the last enumeration is still the SAME one — so a
|
||||
* WHICH shortfall was reported last, or `null` when the last list came back WHOLE — so a
|
||||
* register that stays unreadable is reported once, not once per cycle.
|
||||
*
|
||||
* Every signal this observation listens to runs a full cycle, and a persistent shortfall
|
||||
@@ -91,8 +91,17 @@ interface Observation {
|
||||
* is nudged: one deposit produced three copies of the same line. That is what buries the
|
||||
* report that matters under the report that repeats. Cleared the moment a list comes back
|
||||
* WHOLE, so a shortfall that goes away and returns is a new occurrence and says so.
|
||||
*
|
||||
* ── The register, and not a bare "already said something" ─────────────────
|
||||
* There are TWO shortfalls, they are disjoint, and one is far worse than the other: the
|
||||
* account record failing leaves this identity with NOTHING watched, its own two inboxes
|
||||
* included, while the User branch failing leaves those two watched and only the
|
||||
* per-document inboxes missing ({@link InboxEnumeration.incomplete}). A boolean here made
|
||||
* the second silence the first — the condition CHANGED, to a materially different one, and
|
||||
* the log said nothing because something had already been said. Keyed by register, a
|
||||
* change of shortfall is what it is: news.
|
||||
*/
|
||||
shortfallReported: boolean;
|
||||
shortfallReported: InboxRegister | null;
|
||||
/** Enumerations and applications in flight — what {@link observationSettled} waits on. */
|
||||
pending: Set<Promise<void>>;
|
||||
}
|
||||
@@ -116,6 +125,22 @@ function reportUnobserved(what: string, error: unknown): void {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a shortfall on `register` leaves unwatched, in the words the log uses.
|
||||
*
|
||||
* The two lines have to READ differently, not merely be counted differently: a reader who
|
||||
* sees the second one after the first has to be able to tell that the condition changed, and
|
||||
* two identical sentences make an escalation look like a repeat. Both keep the phrase the
|
||||
* report has always ended on, because it is the one thing this line is scanned for.
|
||||
*/
|
||||
function shortfallSaid(register: InboxRegister): string {
|
||||
return register === "account-record"
|
||||
? "the inboxes to watch could not all be listed (the account record — your own two " +
|
||||
"inboxes, where a share addressed to you by name lands, are NOT among the ones watched)"
|
||||
: "the inboxes to watch could not all be listed (the register of the inboxes opened on " +
|
||||
"documents — your own two are watched)";
|
||||
}
|
||||
|
||||
/** Is `obs` still the live observation, for the identity it belongs to? */
|
||||
function current(obs: Observation): boolean {
|
||||
return observation === obs && getCurrentUser() === obs.holder;
|
||||
@@ -193,7 +218,10 @@ async function applyWhatArrived(obs: Observation, inbox: Nuri): Promise<void> {
|
||||
* Once per OCCURRENCE, though, not once per enumeration — see
|
||||
* {@link Observation.shortfallReported}. The retry that repairs it is also what re-reads it,
|
||||
* so a condition that persists is re-discovered by every signal; reporting each discovery
|
||||
* says "it happened again" about the single thing that never stopped happening.
|
||||
* says "it happened again" about the single thing that never stopped happening. An
|
||||
* occurrence is per REGISTER, because the two shortfalls are two conditions: the list going
|
||||
* from "missing the document inboxes" to "missing your own two" is not the same fault
|
||||
* continuing, it is a worse one starting.
|
||||
*/
|
||||
async function watchTheInboxes(obs: Observation): Promise<void> {
|
||||
if (!current(obs)) return;
|
||||
@@ -207,10 +235,10 @@ async function watchTheInboxes(obs: Observation): Promise<void> {
|
||||
}
|
||||
if (!current(obs)) return;
|
||||
if (listed.incomplete === null) {
|
||||
obs.shortfallReported = false;
|
||||
} else if (!obs.shortfallReported) {
|
||||
obs.shortfallReported = true;
|
||||
reportUnobserved("the inboxes to watch could not all be listed", listed.incomplete.error);
|
||||
obs.shortfallReported = null;
|
||||
} else if (obs.shortfallReported !== listed.incomplete.register) {
|
||||
obs.shortfallReported = listed.incomplete.register;
|
||||
reportUnobserved(shortfallSaid(listed.incomplete.register), listed.incomplete.error);
|
||||
}
|
||||
for (const inbox of listed.inboxes) {
|
||||
if (obs.inboxes.has(inbox)) continue;
|
||||
@@ -373,7 +401,7 @@ export async function startObservingInboxes(): Promise<void> {
|
||||
holdings: null,
|
||||
enumerating: false,
|
||||
enumerateAgain: false,
|
||||
shortfallReported: false,
|
||||
shortfallReported: null,
|
||||
pending: new Set(),
|
||||
};
|
||||
observation = obs;
|
||||
|
||||
Reference in New Issue
Block a user