feat: un dépôt est traité vingt secondes après, sans attendre son destinataire

Un dépôt attendait la prochaine connexion de son destinataire — potentiellement
des heures. Un vrai NextGraph aura un service qui traite les inbox en continu ;
il n'existe pas. On l'émule : après une écriture dans une inbox, une échéance
unique de vingt secondes draine l'inbox DE LA CIBLE.

C'est une usurpation d'identité, possible seulement parce qu'un portefeuille
partagé détient toutes les identités virtuelles. Elle est acceptable parce que
l'application n'apprend rien de faux : elle observe que les dépôts finissent par
converger, ce qui restera vrai avec un vrai service. Ce qui ne doit pas fuir,
c'est le mécanisme.

Trois gardes, tenues par du code et non par des consignes.

Rien n'atteint la surface publiée : les exports sont épinglés par un test, et
publier ceci reviendrait à publier un appel qui traite l'inbox d'autrui — après
quoi il ne resterait rien du modèle de confidentialité.

Le drainage agit avec un détenteur EXPLICITE, jamais l'identité ambiante. Le
propriétaire vient d'un enregistrement de routage (shim:inboxOwner), et cet
identifiant est passé à chaque étape. C'était le vrai danger : readLinks et
myInboxes demandent getCurrentUser() au moment où elles s'exécutent, donc un
drainage lancé pendant la session d'Alice aurait classé les capacités de Bob
chez elle. Le test l'épingle — après le drainage, Alice n'a aucune capacité sur
le document concerné, et les deux Links sont bien chez Bob, durablement.

Et les échecs remontent au journal d'accès au lieu de disparaître. Une boucle
différée qui avale ses erreurs, c'est la famille retirée en 8c8ade7 et e32b6d0.

Coalescence : une seule échéance en attente par cible, et deux drainages d'une
même inbox ne se chevauchent jamais — processInbox écrit ce qu'il applique.

Limite assumée : si la page disparaît avant l'échéance, le dépôt attend la
prochaine connexion. C'est le comportement honnête d'une émulation qui tient la
place d'un service absent.
This commit is contained in:
Sylvain Duchesne
2026-08-16 15:17:49 +02:00
parent 9e7aeef269
commit 07dfe68473
12 changed files with 1082 additions and 60 deletions
@@ -60,12 +60,24 @@ import type { Nuri } from "../model/types";
* Inert until the first cap exists (`caps.isEnforcing()`), so a consumer that never
* touches caps keeps working. Once ANY cap has been issued the boundary applies to
* every user, including one holding nothing: that is the isolation.
*
* ── Whose possession, when it is not the connected identity's ─────────────
* `holderKey` names the ring to consult instead of the connected one. Exactly one caller
* passes it: the emulated inbox processor (`inbox-processor.ts`), which drains an inbox on
* behalf of its OWNER while another identity holds the session. Left out — which is every
* other call site — the question is asked of whoever is connected, unchanged.
*
* It does not WIDEN the boundary: the named holder must hold the cap just the same. What it
* fixes is which ring the question is about, so that work decided for one identity is not
* judged against another's possession.
*/
export function mayReach(nuri: Nuri): boolean {
export function mayReach(nuri: Nuri, holderKey?: string): boolean {
const caps = getCaps();
if (!caps.isEnforcing()) return true;
const target = targetOf(nuri);
return caps.capFor(target) !== undefined;
const held =
holderKey === undefined ? caps.capFor(target) : caps.capForHolder(holderKey, target);
return held !== undefined;
}
/**
@@ -77,11 +89,16 @@ export function mayReach(nuri: Nuri): boolean {
*
* Deliberately duplicated with rule 2 below — see {@link mustNotAttempt}. Two rules,
* two places, one criterion: a lapse in either is caught by the other.
*
* `holderKey` asks the question of a NAMED ring rather than the connected one — see
* {@link mayReach}. The refusal names it too, or a processor's refusal would read as the
* connected identity's, which is the one thing nobody would then go and check.
*/
export function assertMayReach(nuri: Nuri, op: string): void {
if (mayReach(nuri)) return;
export function assertMayReach(nuri: Nuri, op: string, holderKey?: string): void {
if (mayReach(nuri, holderKey)) return;
const who = holderKey === undefined ? "the connected user" : `holder ${JSON.stringify(holderKey)}`;
throw new Error(
`[ng-eventually] ${op}: refused — the connected user does not hold this document's ` +
`[ng-eventually] ${op}: refused — ${who} does not hold this document's ` +
"cap. Naming a document does not grant access to it: a cap is looked up in what " +
`you hold, or it was delivered to you. ${JSON.stringify(nuri)}`,
);
@@ -155,7 +172,9 @@ export async function assertMayWrite(nuri: Nuri, op: string): Promise<void> {
*
* Practically it also stops the library from asking the broker for documents it has
* no business asking about, which is work, noise, and a leak of intent.
*
* `holderKey` names the ring the question is about — see {@link mayReach}.
*/
export function mustNotAttempt(nuri: Nuri): boolean {
return !mayReach(nuri);
export function mustNotAttempt(nuri: Nuri, holderKey?: string): boolean {
return !mayReach(nuri, holderKey);
}