diff --git a/docs/changelog/fix-left-writer-listing.md b/docs/changelog/fix-left-writer-listing.md new file mode 100644 index 00000000..cf350726 --- /dev/null +++ b/docs/changelog/fix-left-writer-listing.md @@ -0,0 +1,3 @@ +### Corrigido + +- Os leitores voltam a aceitar o escritor de quem saiu de um grupo antes de o semeador guardá-lo (PR `fix/left-writer-listing`, #350): o semeador lista esse escritor, e também o liberado por um corte, pela última entrada ligada no grupo, e não mais pela entrada desligada, que os nós no app, na web e na CLI recusavam e contavam contra o semeador. Uma listagem já guardada com a entrada desligada se corrige no próximo escaneamento do diário. Só o semeador muda: os apps instalados continuam como estão. Verificação em `docs/verification/fix-left-writer-listing.md`. diff --git a/docs/protocol.md b/docs/protocol.md index 0f8d0ce6..59d6604f 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -2125,7 +2125,7 @@ A group post carries photos with the v2 key set of `group-post` ("Records" above - Core node (member data dir): `data/community-create.json` = `{ "v": 1, "community": "", "communityNonce": "", "group": "", "groupNonce": "", "name": , "join": "open" | "approval", "at": }`, mode `0o600`, written through `writeJsonAtomic` by `community.create` after the two cores are opened (their keys are then known, nothing is appended yet) and deleted after the last step; the browser keeps the same shape in kv `communityCreate`. The steps are: the community root header, its `groups.json` entry and the diary `group-join` for C; the Geral root header (`kind: 'group'`, `community: C`, `member: C`, `visibility: 'public'`, `join: 'open'`, `name: 'Geral'`), its entry and join; a `group-create { group: Geral, seen: null }` in C's root (root seq 1); then the record is deleted. A later `community.create` call on the device while the record exists repeats the steps, each skipped when already done, through the normal mutating path (the browser's write gate syncs the diary first), and answers the recorded keys instead of creating another community. `community.info` never writes: while the record exists it answers the community as pending. Nothing retries without a call. If the first step never ran, a later `community.create` with other parameters discards the record and starts over. - Core node (member data dir): `data/community-leave.json` = `{ "v": 2, "notes": [{ "community": "", "writer": "", "seq": = 1>, "digest": "", "roots": [{ "group": "", "cut": = 0> }] }] }`, one note per community, mode `0o600`, written through `writeJsonAtomic` and removed when the list is empty; the browser keeps the same shape in kv `communityLeave` (v 2), cleared with the rest of the group state on identity wipe. For C's creator, `community.leave` writes the note BEFORE appending the C leave: `writer` its CW, `seq` the CW length then, `digest` the `leaveDigest` of the leave it is about to append, and `roots` exactly the group roots the leave marks, each at its held length (read after the creator's own group leaves): the roots of C's catalogue the creator's diary bound that are held, unforked and non-empty (rpc.md 5.64, including `force`). After the append the block at `seq` must be that leave, else the note is kept and the call fails. The note is cleared after the `group-confirm` and the off join. A later `community.leave`, and `community.info`'s `leavePending`, act only on the leave the note names (at `note.seq` on an unforked own CW, with `note.digest`): a leave on the own CW that does not match the note is never confirmed by this device (rpc.md 5.59, 5.64). - Core node (member data dir): `data/group-seen.json` = `{ "v": 1, "marks": [{ "group": "", "at": , "writer": "", "seq": = 1> }] }`, mode `0o600`, written through `writeJsonAtomic` by `group.seen` (rpc.md 5.82) only when a mark moves forward: this device's seen mark per group, the position of the post marked: the screen's cut-off when the call carried one, else the newest readable post; always a post the node listed at the time. Newest last, at most 512 marks: a group marked again moves to the end and the least recently marked is dropped first, then counts as never seen. It holds only keys, an ISO time and a seq, never post text. A missing or malformed file reads as no marks, and an invalid mark is dropped on read. `community.info` reads it for `unread` (rpc.md 5.59) and never writes it. Local only: it is never replicated, sent to a peer or the seeder, or synced to other devices, with one exception: the browser node shares these marks with the other devices of the same passkey through the encrypted seen blob (section 14, which the service stores). No peer or seeder sees them. The browser keeps the same shape in kv `groupSeen`, cleared with the other group kv on identity reset. -- Seeder data dir: `admitted.json` gains `"groups": { "": { "diary": "", "group": "", "seq": = 1>, "by"?: "", "bound"?: true, "issuer"?: "" } }` next to `admitted` and `media`. For a writer W the entry names its diary D, its group G and the seq of D's join block; for a root the entry is `{ diary: D0, group: G, seq, by }` with `group` equal to the key and `by` the diary whose live join caused the admission (never taken from the header; read only when hex64, so an older file without it charges the root to nobody; `issuer` is read only with `bound: true`). The file also gains `groupHeaders` (section 1). A missing `groups` reads as `{}`. The same write-ahead rule as media applies: listed before the core is opened, purged before it leaves the file, a purge failure fatal. +- Seeder data dir: `admitted.json` gains `"groups": { "": { "diary": "", "group": "", "seq": = 1>, "by"?: "", "bound"?: true, "issuer"?: "" } }` next to `admitted` and `media`. For a writer W the entry names its diary D, its group G and the seq of D's newest `on: true` join of W to G that the scan has read, also once W left, was released or is no longer listed ("Seeder group admission", "Scan"); until the scan reads one, the entry keeps the seq it was stored with; for a root the entry is `{ diary: D0, group: G, seq, by }` with `group` equal to the key and `by` the diary whose live join caused the admission (never taken from the header; read only when hex64, so an older file without it charges the root to nobody; `issuer` is read only with `bound: true`). The file also gains `groupHeaders` (section 1). A missing `groups` reads as `{}`. The same write-ahead rule as media applies: listed before the core is opened, purged before it leaves the file, a purge failure fatal. - Browser node: kv `groupWriters` `{ "v": 1, "entries": [{ "group", "key", "nonce", "rootNonce" }] }` (plus `kind: 'community'` on every entry whose `group` is a community: the root this device created (`writer === group`) or the CW of a joined community (`writer` is the CW key); absent means a group; the core node skips an entry with another kind, the browser rejects it; the entry of a community this device created is never evicted, the entry of a joined community can be given up like a group's once left) (one entry per group or community, at most `MAX_GROUPS_PER_DIARY`; the entry of a joined community has `rootNonce: null`; `rootNonce` is the root's nonce for a group this device created, kept apart from the current writer's so that a creator who left and rejoined can still write root-only records, else null; created groups are never evicted), kv `groupReplicas` `{ "v": 1, "keys": [...] }` (foreign group cores and former own writers) and kv `groupDiaries` `{ "v": 1, "keys": [...] }` (binding diaries of accepted foreign writers, never in `follows`) and kv `groupCores` `{ "v": 1, "keys": [...] }` (a write-ahead list of every group core key, written before a core is created and cleared on purge); no secret is ever stored in a persisted header. **Identity reset** deletes every core listed in `groupCores`, every group core named in `groupWriters` (roots with a `rootNonce` included), every core in `groupReplicas` and every replica in `groupDiaries` that is not in `follows`, then clears the lists (cores created by older builds of this branch are not in `groupCores`), so the next person on a shared device inherits no group data. Kv `groupCerts` `{ "v": 1, "entries": [["", ""]] }` holds the binding certificate (block 0) of the diary behind each accepted group core, newest last, at most `MAX_GROUP_REPLICAS`, so a revocation can be judged after a restart and after the binding diary itself is gone; it is deleted with the lists above on an identity reset. - Core node (member data dir): `group-certs.json` = `{ "v": 1, "certs": [["", ""], ...] }`, mode `0o600`: the binding certificate (block 0) of the diary behind each foreign writer or root activated here, newest last, at most (groups listed x `MAX_GROUP_WRITERS`) entries (the oldest dropped), written when a foreign writer or root activates and pruned at start of entries no stored core names. An unreadable or malformed file reads as none. A revoked issuer takes a stored writer or root even when its binding diary's block 0 is not stored, by the recorded certificate (the browser keeps the same in kv `groupCerts`). - Core node (member data dir): `group-box.json` = `{ "v": 1, "publicKey": "", "secretKey": "" }`, mode `0o600`: the device's X25519 box key pair for private groups ("Private groups"), created once with an exclusive create (never overwritten) by the first group operation that needs it and read only by group operations; `publicKey` must equal the key derived from `secretKey`. A malformed or mismatched file is refused (private group operations fail) and never replaced, because a new key would lose every epoch sealed to the old one. It is never printed or logged. @@ -2136,7 +2136,7 @@ A group post carries photos with the v2 key set of `group-post` ("Records" above Mirrors "Seeder media admission" (section 5) with the same invariants, plus the root. Nothing travels on `varanda/admission/1`: no `announce`, no `have`, no new message type for group keys. -- **Scan.** The diary scan folds `group-join` records into the diary's declared set (`groupDecls`, the newest join per writer) with the media scan's rules (raw reads from block 1, `decodeBlock` + `validRecordCopy`, never trusting a peer), and keeps the newest `on: true` join per writer as the binding (`groupBound`, which survives a later `on: false`). A creator's `on: true` join for its root key G (writer = group = G) binds G for good: a later `on: true` join naming G as a writer of another group does not unbind it, matching the fold, which counts any historical `on: true` join of the pair. The scan also steps each `group-join` and `group-cut` of the diary, in seq order, into its slot walk for that group (`groupWalks`, "Limits"); a deleted one counts like a live one (section 2 "Deletion"), and one that arrives after the scan passed its seq is placed at that seq (section 5, `_pageArrived`). Only a live join of a writer the walk counts live or frozen (or of a root joined by its own key, the root slot) picks a group, and the per-diary cap keeps the 64 EARLIEST such joins by diary join seq, the same way on every scan and as `diaryGroupKeys` picks them. A counted writer whose newest join is off, and a writer the walk released (whatever its join, held whole, "Cut writers"), are kept too, marked left, in those groups and in any group where the diary has no live join: their records stay in the group's history, and readers wait for them, but their join never picks a group, fetches a root or supports one (a root already held stays under "Retention"). A writer turned off by a later join keeps its slot, so leaving or withdrawing frees nothing; only the diary's own cut does. Joins past the caps are never admitted and never indexed. +- **Scan.** The diary scan folds `group-join` records into the diary's declared set (`groupDecls`, the newest join per writer) with the media scan's rules (raw reads from block 1, `decodeBlock` + `validRecordCopy`, never trusting a peer), and keeps the newest `on: true` join per writer as the binding (`groupBound`, which survives a later `on: false`). A creator's `on: true` join for its root key G (writer = group = G) binds G for good: a later `on: true` join naming G as a writer of another group does not unbind it, matching the fold, which counts any historical `on: true` join of the pair. The scan also steps each `group-join` and `group-cut` of the diary, in seq order, into its slot walk for that group (`groupWalks`, "Limits"); a deleted one counts like a live one (section 2 "Deletion"), and one that arrives after the scan passed its seq is placed at that seq (section 5, `_pageArrived`). Only a live join of a writer the walk counts live or frozen (or of a root joined by its own key, the root slot) picks a group, and the per-diary cap keeps the 64 EARLIEST such joins by diary join seq, the same way on every scan and as `diaryGroupKeys` picks them. A counted writer whose newest join is off, and a writer the walk released (whatever its join, held whole, "Cut writers"), are kept too, marked left, in those groups and in any group where the diary has no live join: their records stay in the group's history, and readers wait for them, but their join never picks a group, fetches a root or supports one (a root already held stays under "Retention"). Such a writer is listed (admission, `admitted.json` and the writer pages) with the seq of its newest `on: true` join for that group, which the scan keeps per writer the walk counts or released (the walk counts a writer only after such a join): readers check the page item's seq against an `on: true` `group-join` naming the writer, so the seq of an `on: false` join would be refused as `unbound` and charged to the seeder. A binding stored with another seq takes this one at the diary's next scan, and so does a binding the scan no longer lists (its diary named W in another group, or the group is past the cap), from the walk of its group once the scan has read that join. A writer turned off by a later join keeps its slot, so leaving or withdrawing frees nothing; only the diary's own cut does. Joins past the caps are never admitted and never indexed. - **Writer W for D in G.** Admitted when D is served, gated and not blocked, D's live join names W, G is not blocked, the blocklist is not held (`_blocklistHeld`: reason `blocklist-pending`) and a group slot is free (bound + reserved < `maxGroupCores`, default `maxServed`, and fewer than 512 cores of G, else `group-rejected` `group-full`). Admission also counts the writer cores bound or reserved for D: `group-full` at 32 in one group (8 live, `MAX_FROZEN_WRITERS_PER_DIARY` = 8 frozen and the `MAX_WRITER_RELEASES_PER_DIARY` = 16 released, each held whole) or at `MAX_GROUP_CORES_PER_DIARY` (64 x 16 = 1024, released ones included) in total, left ones included. A root is charged to its binding's `by`, not to the header diary (any header can name any diary): at most `MAX_GROUPS_PER_DIARY` roots and `MAX_GROUP_CORES_PER_DIARY` cores in total (writers and roots, in-flight included) per diary, else `group-full`. The charge stays after the join is withdrawn and is restored at startup from `admitted.json`. Retry waits (`GROUP_BACKOFF_MS`): a `timeout`, `no-peers` or `group-full` refusal is remembered per (D, key) with waits of 2 s, 10 s, 30 s, 60 s, 5 min, then 15 min; the wait lasts until the core's header verifies in the main store (not until admission), so a core whose block 0 is then withheld keeps growing its wait across repeated admissions (the wait is kept while the core is served awaiting its header, and cleared when the header verifies or the core is dropped definitively before it), which lets its group stop waiting for it after the retry; a success clears it. A raw connection retries only `no-peers`; each `timeout` wait arms its own retry timer, so the join is retried when the wait ends without depending on a peer's `hello` (when the wait ends while the timed-out core is still being purged, the retry runs once the purge settles); blocklist adoption reconciles every diary (bounded by the caps below). After a fetch, a `quota` verdict is remembered per (D, key, join seq): the same join is never fetched again (a quota change needs a new join). A root refused because its creator (the header's diary) is blocked is remembered in a bounded map and refused without a fetch while the creator stays blocked; adopting a new blocklist clears the map, so lifting the block lets the same join admit the root. A late (pre-fetch) `group-full` backs off like `timeout` (a refused writer may wait up to the backoff after space frees). Admissions in flight are capped at `GROUP_INFLIGHT_MAX` = 32 overall (option `maxGroupInflight`) and `GROUP_INFLIGHT_PER_DIARY` = 2; a diary over the cap waits in `_groupDeferred`, a FIFO of diaries: a freed slot serves the head diary, which is queued again at the tail if it still waits. `/index/group`, `/index/groups/` and `/index/group-search` answer `complete: false` while a join waits for an admission slot, while a join holds a first `timeout` backoff (not yet retried) or a `group-full` backoff caused by the seeder's own capacity (`maxGroupCores`, `maxGroupWriters`): the seeder must not claim a final page while it refuses a writer for capacity. A join whose retry past the first wait also timed out is still retried but stops counting (pages, search, a diary's group list), until an admission succeeds, even under a new join seq. Per-diary budget refusals (`MAX_GROUP_CORES_PER_DIARY`, `MAX_GROUP_WRITERS_PER_DIARY`, `MAX_GROUPS_PER_DIARY`) never hold pages back. A refusal is logged once per change of (key, reason, join seq), not per attempt. A wait left by a first `timeout` is cleared when the join ends in a final refusal (header or size verdict, no longer wanted), so the group's answers become complete again. Admission order: (1) still wanted; (2) a quarantine fetch of block 0 attached to the sockets of ALL connected peers, `GATE_TIMEOUT_MS` (no peer -> `no-peers`, timeout -> `timeout`); (3) verdict: block 0 a valid `group-writer` (`header-invalid`) naming G and D (`wrong-group`, `wrong-diary`) and the fetched length / bytes within the per-core limits (`quota`, on the whole log for a cut writer too); (4) `admitted.json.groups[W] = { diary, group, seq }` persisted BEFORE the open, with media's rollback (`admission-failed`, a stored core purged first, a purge failure fatal); (5) after the open: still wanted, `fork === 0`, within quota; (6) served: live download, fork watcher, quota on every append, `swarm.join(discoveryKey)`, log `{ event: 'group-admitted', key, diary, group, length }`. An admitted group core whose block 0 never reaches the main store is dropped and purged after the gate timeout (15 s, constructor option `groupHeaderTimeoutMs`) with `group-rejected` reason `timeout`, and its join backs off; after a timeout on the retry it no longer holds the group's pages or global search incomplete. - **Root G.** Admitted by the same steps as a writer (including quarantine, persistence before the open and the held blocklist) when its block 0 is a valid `group-header` and some served, gated, unblocked diary has a live join for G (the creator's join with `writer == group` is the normal path). **Root binding.** The header's diary counts as the root's creator (and as support) only when that diary is served, not dropped, not blocked and has its own `on: true` `group-join` for writer = G. Otherwise the root is supported only by real member joins, and `/index/group/` answers `creator: null` (also during the startup window before the creator's scan). **Support:** a served root stays while at least one served, unblocked diary keeps it: the creator if it bound the root, a diary with a bound writer in it, or a live join. Withdrawing every join does not drop a root that still has a bound writer. At startup a root does not survive just because its creator's diary is kept: decisions that find a root unsupported are deferred until the startup scans of the served diaries end, and it is judged after them; an unsupported root is then dropped with reason `unbound`. **Blocked or revoked creator:** a served root is purged for a blocked diary, or one whose certificate issuer is revoked, only when that diary BOUND the root (`bound: true`: its header diary has its own `on: true` join for writer = G). Reason `blocked` (also during the startup window), the root stays refused at admission and at startup while its creator stays gone, even while members support the group. A root whose header merely names a blocked diary that never bound it has no creator and stays while members support it. A creator that is both blocked and from a revoked issuer has that issuer recorded too (`revokedCreators`, and `goneRoots` for its bound roots), and a stored issuer is never replaced by null: lifting only the block keeps its bound roots refused, also after a restart, while the issuer stays revoked. A creator dropped or refused for a revoked issuer is remembered with that issuer (`revokedCreators`, a moderation outcome, also across restarts) and judged against the CURRENT revoked-issuer set: adopting a list that lifts the revocation lifts it. An announce of a revoked-issuer certificate is not remembered at all, not even in memory: only a diary's own block-0 verdict (refused at startup, or dropped as revoked-issuer while served) feeds `revokedCreators`, a `goneRoots` issuer and the refusal of a root at admission for a revoked creator, so a root whose creator was never served on this seeder is not refused for a revoked issuer (the root only names that diary). A repeated revoked announce of the same key from one peer counts as a bad announce; the first does not. A purged root is remembered with its creator and, for a revocation, its issuer (`goneRoots`) and refused again while that creator stays gone; lifting the block or revocation lets the same join admit it, and a root admitted again after that keeps `bound`. A diary admitted with a verifying certificate clears its stale revoked entries (`revokedCreators` and the `goneRoots` entries naming it with an issuer). A root whose header names a currently blocked diary, or a diary whose known issuer is revoked, is refused at admission even without a purge record (a root admitted before the block stays until its binding says otherwise). Roots bound before this version get `bound` only after their creator's next scan. A root its creator bound stays listed on `/index/group/` (and in the writer pages) under that creator diary while members keep it served after the creator is dropped for a reason other than moderation (quota, fork, seeder full), also after a restart; `header.diary` stays `null` then, so no creator authority is shown. Members' own writers stay under the rules above. **Issuer kept with the binding.** A bound root's binding keeps the issuer of its creator's block-0 certificate (`issuer`, taken at the creator's scan). When that issuer is revoked under the current list and the creator is not served, the bound root is purged with reason `revoked-issuer` and remembered like any revoked-issuer drop (`revokedCreators`, `goneRoots`), also at startup and also when the creator left first for another reason, such as its quota, so a member that keeps the root served cannot outlast the revocation. **Header fields kept.** While any core of group G is served or being admitted, the seeder keeps the verified header fields of its root (`kind`, `visibility`, `join`, `community`, `member`, and `name` for a public root) in `groupHeaders`, also after the root was purged or refused or its block 0 is withheld, and drops them once no core of G is left or G is blocked; past the bound the record is not kept. A persisted record without `community` and `member` is a protocol v1 leftover and is dropped at start. - **Protocol v2 admission and scan.** A header whose validator returns `legacy` is `header-invalid` (no new wire reason), and the startup re-gate purges every stored v1 root and writer with that reason. A group root must carry a hex64 `community`; the seeder never checks a writer's `member` or any authorization (the fold does). CWs are admitted like any writer and take part in the writer pages. For a served community root the index folds `group-meta`, `group-admin` and `group-create` from the root only (creates are indexed from C's root alone; a CW is not scanned for them, `group-create` being `root-only` there). A public group root is scanned for `group-meta` only (one scan at a time across group roots, skipping blocks without the bytes `group-meta`) and a private root is not scanned. diff --git a/docs/verification/fix-left-writer-listing.md b/docs/verification/fix-left-writer-listing.md new file mode 100644 index 00000000..1693c487 --- /dev/null +++ b/docs/verification/fix-left-writer-listing.md @@ -0,0 +1,60 @@ +# Escritor de quem saiu, listado pela entrada ligada (branch fix/left-writer-listing) + +Parte da #350. Correção do semeador que entrou na #713 (`feat/writer-slot-walk`, commit 8772d908). + +## O problema + +Desde a #713 o semeador guarda, marcado como `left`, um escritor contado cuja última entrada no diário está desligada, e um escritor liberado por um corte 0. Ele listava esse escritor com a seq da última entrada do diário (`liveGroupJoins` em `packages/core/lib/seeder.js`), que para quem saiu é a entrada desligada (`on: false`). Essa seq vai para a admissão (`admitted.json`, `groups[W].seq`) e para a página de escritores do grupo. Todo leitor confere a seq do item contra o bloco do diário e exige um `group-join` ligado que nomeie o escritor e o grupo: `joinVerdict` em `packages/core/lib/sync.js` e a conferência equivalente em `packages/web-member/lib/sync.js`. Com a entrada desligada, o leitor recusava o escritor como `unbound` e contava a listagem contra o semeador (`badHint`; com 32 listagens recusadas, ele deixa de usar aquele semeador). O leitor do serviço de conta (`apps/cli/lib/account/pages-groups.js`) lê os diários inteiros e não usa a seq do item, então não era afetado. + +Acontecia quando o semeador guardava o escritor depois da saída: uma saída antes de o semeador ver o escritor (entrar e sair entre duas sincronizações, uma busca do escritor que demorou) ou um semeador novo que conhece o diário depois da saída. Um escritor já guardado antes da saída mantinha a seq da entrada ligada. + +## O que mudou + +Só o semeador (`packages/core/lib/seeder.js`); nenhum leitor muda. + +- `groupWalkStep` guarda, na caminhada de cada grupo, a seq da entrada ligada mais nova de cada escritor que a caminhada conta ou liberou (`onSeq`). O mapa nunca passa dos limites da caminhada por grupo (8 vivos, 8 congelados, 16 liberados). +- `liveGroupJoins` lista o escritor que saiu, e o liberado, com essa seq. A caminhada só conta um escritor depois de uma entrada ligada, então ela sempre existe. +- `_reconcileGroups` passa a usar a seq da listagem também para um escritor que saiu: uma ligação guardada com a seq da entrada desligada (pela versão anterior a esta) se corrige no próximo escaneamento do diário, em memória, na página e em `admitted.json`. Uma ligação que o escaneamento não lista (o diário nomeou W em outro grupo, ou o grupo passou do limite de 64) continua com linha na página: ela recebe a entrada ligada mais nova de W naquele grupo pela caminhada, assim que o escaneamento a lê; até lá fica com a seq guardada. O resto fica como estava: a marca `left`, os limites por diário, `groupRefused` pela seq e a caminhada. +- Com a #717 (`fix/group-records-ignore-deletes`) já na `main`, uma entrada apagada que chega depois de o escaneamento passar por ela refaz a caminhada do grupo (`foldGroupRecord`), também pelo `groupWalkStep`. Assim `onSeq` acompanha: um escritor que saiu, cuja entrada ligada apagada chega atrasada, é listado por ela. Esse caminho não precisou de mudança no código, só de um teste. + +Documentos: `docs/protocol.md` seção 10, "Seeder group admission" ("Scan") e "Data-dir files" (`groups` de `admitted.json`). + +## Testes + +Cada arquivo sozinho, a partir da raiz, com `VARANDA_TEST_CONCURRENCY=1 node `: + +- `packages/core/test/seeder-groups-cuts.test.js`: 14/14, 296 asserções. + - Novo: "a stored binding the scan no longer lists gets its on join too, never an off one (#350)": a ligação de W em G guardada com a seq 2 (entrada desligada); o diário depois nomeia W em H, e o escaneamento lista W só em H. `_reconcileGroups` dá à ligação e à linha da página a seq 1 (a entrada ligada em G), marcada `left`. + - "liveGroupJoins: a counted writer whose join is off stays, left; an uncounted one does not (#350)": as duas expectativas que pediam a seq da entrada desligada (10 e 3) agora pedem a da entrada ligada (2 e 2). + - Novo: "liveGroupJoins: a left or released writer is listed by its newest on join for the group, never an off join (#350)": entrou duas vezes e saiu; liberado e depois saiu; entrada ligada em outro grupo antes; saiu, voltou e saiu de novo. + - Novo: "a writer that left before its admission is listed by its on join, and a binding stored with the off join heals at the next start (#350)": B entra com W e sai (uma saída em W e a entrada desligada) antes de o semeador ver W. O item da página e `admitted.json` trazem a seq 1 (entrada ligada) e `left: true`. Depois, com o semeador parado, `admitted.json` recebe a seq 2 (a entrada desligada, como a versão anterior gravava); no reinício o escaneamento devolve a seq 1 à página e ao arquivo, sem descartar W. +- `packages/core/test/sync-groups-7.test.js` (novo): 1/1, 12 asserções. Ponta a ponta com o nó core: Ana cria o grupo, Bia entra, publica e sai pelo `member.groupLeave` antes de sincronizar; depois do semeador, a sincronização de Ana busca o escritor de Bia sem nenhum `group-skipped` e lê a publicação de antes da saída. +- `packages/web-member/test/sync-groups-3.test.js` (novo): 1/1, 14 asserções. O mesmo com o nó do navegador (`ops.groupLeave`) e um terceiro membro lendo pelo semeador via WebSocket. +- `packages/core/test/seeder-delete.test.js`: novo "a deleted on join that arrives after the scan lists its left writer by that join (#350)": o diário entra com W (seq 1), sai (seq 2, entrada desligada) e apaga a entrada (seq 3). O escaneamento lê a seq 2 e passa pela 1 como buraco; quando a 1 chega, W é listado com `{ seq: 1, left: true }`. +- Sem mudança, para conferir que nada mais se moveu, antes do merge com a `main` (3f7e8420): `packages/core/test/seeder-delete.test.js` 30/30 (263), `packages/core/test/sync-groups-3.test.js` 16/16 (71), `packages/core/test/seeder-groups.test.js` 43/43 (262), `packages/core/test/seeder-groups-3.test.js` 6/6 (33), `packages/core/test/seeder-groups-waits.test.js` 12/12 (61) e `packages/web-member/test/sync-groups-2.test.js` 26/26 (130). +- Depois do merge com a `main` (d2294699, com a #717): `seeder-groups-cuts` 13/13 (293), `seeder-delete` 35/35 (288, com o teste novo), `seeder-groups` 44/44 (270), `sync-groups-7` 1/1 (12) e `web-member sync-groups-3` 1/1 (14). +- Com a volta pela caminhada para a ligação não listada: `seeder-groups-cuts` 14/14 (296), `seeder-delete` 35/35 (288), `seeder-groups` 44/44 (270), `sync-groups-7` 1/1 (12) e `web-member sync-groups-3` 1/1 (14). +- `apps/cli/test/changelog.test.js` 9/9 (42) e `npm run lint` limpo. + +## Prova de regressão + +Com `packages/core/lib/seeder.js` da `main` (3f7e8420) e os testes desta branch: + +- `seeder-groups-cuts`: 10/13 (283/293). Falham os dois testes de `liveGroupJoins` acima (por exemplo, "frozen and left: kept for its history, by its on join") e o teste de integração novo: "by its on join, the block readers check" (seq 2 no lugar de 1), "and stored with it", "listed left by its on join again" e o arquivo depois do reinício. +- `sync-groups-7`: 0/1 (7/12). O semeador lista o escritor de Bia com a seq 5 (a entrada desligada; a ligada é 4), e a sincronização de Ana o recusa: `group-skipped` com `reason: 'unbound'` (a listagem contada contra o semeador), sem `group-downloaded`, sem o núcleo guardado e sem a publicação "oi". +- `web-member sync-groups-3`: 0/1 (10/14). O mesmo no nó do navegador: `group-skipped` `unbound`, o escritor não fica guardado e "oi" não aparece. +- `seeder-delete`, com `packages/core/lib/seeder.js` da `main` d2294699: 34/35 (287/288). Falha só o teste novo: "listed left by the late on join, never the off one" dá seq 2 (a entrada desligada) no lugar de 1. +- `seeder-groups-cuts`, com `packages/core/lib/seeder.js` de 55b2ec73 (antes da volta pela caminhada para a ligação não listada): 13/14 (294/296). Falha só o teste da ligação não listada: "the binding takes its on join in G" dá 2 no lugar de 1, e a linha da página também sai com a seq 2. + +Só com a mudança de `_reconcileGroups` desfeita (a de `liveGroupJoins` mantida), `seeder-groups-cuts` dá 12/13 (291/293): depois do reinício a página continua com a seq 2 que o arquivo trazia ("listed left by its on join again" e "and stored with it"). + +Nos dois testes ponta a ponta, sem a correção, a recusa depende de o semeador escanear a entrada desligada antes de admitir o escritor; se ele admitisse com a entrada ligada ainda sozinha no diário, a seq já sairia certa. Nas execuções acima a recusa apareceu toda vez. Os testes do semeador não dependem dessa ordem. + +## Para o operador + +Atualize os semeadores antes (ou no lugar) de qualquer app: a correção é toda do semeador e os apps instalados passam a aceitar a listagem sem atualizar nada. Um semeador já em produção com escritores guardados pela entrada desligada se corrige sozinho no primeiro escaneamento de cada diário depois de reiniciado. + +## Fica de fora + +- Nada foi exercitado em aparelho nem contra um semeador de produção. +- A suíte inteira e `npm run demo` não foram rodados nesta branch. diff --git a/packages/core/lib/seeder.js b/packages/core/lib/seeder.js index e9d59bcd..275acef9 100644 --- a/packages/core/lib/seeder.js +++ b/packages/core/lib/seeder.js @@ -889,7 +889,9 @@ const ROOT_DENIALS_HARD = 2 * ROOT_CREATORS_MAX // still counts their records (below the cut, and block 0, leaves and key // blocks at any cut) and waits for them, but their join never picks a // group, fetches a root or supports one (a root already held stays by the -// retention rule, _groupSupported). +// retention rule, _groupSupported). Such a writer is listed by its newest +// on:true join for the group (the walk counts a writer only after one): +// readers check the page item's seq against an on:true join naming it. // writer -> { group, seq, left }. function liveGroupJoins (decls, walks = new Map()) { const allowed = new Set() @@ -920,22 +922,29 @@ function liveGroupJoins (decls, walks = new Map()) { const pair = d.group + ':' + writer if (!released.has(pair) && (d.on || !allowed.has(pair))) continue if (joined.has(d.group) && !groups.has(d.group)) continue - out.set(writer, { group: d.group, seq: d.seq, left: true }) + const onSeq = walks.get(d.group).onSeq + const seq = onSeq === undefined ? undefined : onSeq.get(writer) + if (seq === undefined) continue + out.set(writer, { group: d.group, seq, left: true }) } return out } // Steps one group-join or group-cut of a diary into its walk for that group // (`walks`, group -> walk state), each seq once: the scan reads a diary in -// seq order and never steps back. +// seq order and never steps back. The state also keeps `onSeq`, writer -> +// the seq of its newest on:true join for the group, for the writers the +// walk counts or released only (so no more than the walk's caps per group). function groupWalkStep (walks, group, e) { let s = walks.get(group) if (s === undefined) { s = slotWalkState() + s.onSeq = new Map() walks.set(group, s) } if (e.seq <= s.last) return slotWalkStep(s, e, group) + if (e.kind === 'join' && e.on === true && s.state.has(e.writer)) s.onSeq.set(e.writer, e.seq) } // One valid group-join or group-cut record at diary seq `i` folded into the @@ -2469,9 +2478,10 @@ class Seeder { // the map grows no faster than groupDecls; and // `groupWalks` the slot walk per group (group -> lib/group.js walk // state) over its group-join and group-cut records, which picks the - // writers that count (liveGroupJoins), with `groupEvents` those - // records per group in seq order, to step a walk again when a deleted - // one arrives after the scan passed it. + // writers that count and keeps the newest on:true join of each + // (groupWalkStep, liveGroupJoins), with `groupEvents` those records + // per group in seq order, to step a walk again when a deleted one + // arrives after the scan passed it. groupDecls: new Map(), groupBound: new Map(), groupWalks: new Map(), @@ -4286,8 +4296,20 @@ class Seeder { if (b === null || b.diary !== diary) continue if (!this._groupServed.has(k)) continue const live = entry.groupLive.get(k) - const bound = live !== undefined && live.group === b.group && !live.left - let seq = bound ? live.seq : b.seq + const listed = live !== undefined && live.group === b.group + const bound = listed && !live.left + // A left writer is listed by its newest on:true join too, so a binding + // stored with the seq of an off join takes it here. One the scan does + // not list (its diary named W in another group, the group is past the + // cap) still gets a row: the walk's newest on:true join of W, once the + // scan has read it. + let seq = b.seq + if (listed) seq = live.seq + else { + const s = entry.groupWalks.get(b.group) + const on = s === undefined || s.onSeq === undefined ? undefined : s.onSeq.get(k) + if (on !== undefined) seq = on + } if (k === b.group) { // A root's row must point at a join in its creator's own diary: the // binding may have been persisted with the seq of the member join diff --git a/packages/core/test/seeder-delete.test.js b/packages/core/test/seeder-delete.test.js index d179c1c0..cce2dc28 100644 --- a/packages/core/test/seeder-delete.test.js +++ b/packages/core/test/seeder-delete.test.js @@ -1480,6 +1480,27 @@ test('a deleted group-cut that arrives after the scan steps the slot walk at its t.alike(entry.groupLive.get(CUT_WRITERS[8]), { group: GROUP_KEY, seq: 10, left: false }, 'the ninth takes the slot it freed') }) +// A member joined a writer (seq 1), left (seq 2, the join off) and deleted +// the join (seq 3). The scan passed the join as a hole: when it arrives the +// walk counts the writer, which readers then check by that on join. +const LEFT_BLOCKS = [ + { type: 'member-cert', cert: { member: GROUP_DIARY } }, + { type: 'group-join', group: GROUP_KEY, writer: GROUP_WRITER, on: true, at: GROUP_AT }, + { type: 'group-join', group: GROUP_KEY, writer: GROUP_WRITER, on: false, at: GROUP_AT }, + { type: 'delete', seq: 1, at: GROUP_AT } +] + +test('a deleted on join that arrives after the scan lists its left writer by that join (#350)', async (t) => { + const held = new Set(LEFT_BLOCKS.keys()) + const { seeder, entry, reconciled } = groupFixture(held, LEFT_BLOCKS) + await seeder._pageArrived(GROUP_DIARY, entry, 2) + t.absent(entry.groupLive.has(GROUP_WRITER), 'an off join alone counts no writer') + + await seeder._pageArrived(GROUP_DIARY, entry, 1) + t.alike(entry.groupLive.get(GROUP_WRITER), { group: GROUP_KEY, seq: 1, left: true }, 'listed left by the late on join, never the off one') + t.alike(reconciled.at(-1), [GROUP_DIARY, [GROUP_WRITER]], 'the group cores are reconciled with it') +}) + test('a held group-join a tombstone targets never enters the deleted bookkeeping', async (t) => { const { seeder, entry } = groupFixture(new Set([0, 1, 2, 3, 4])) await learnGroupTombstones(seeder, entry) diff --git a/packages/core/test/seeder-groups-cuts.test.js b/packages/core/test/seeder-groups-cuts.test.js index 5e2e40ca..83e3b949 100644 --- a/packages/core/test/seeder-groups-cuts.test.js +++ b/packages/core/test/seeder-groups-cuts.test.js @@ -5,10 +5,12 @@ // or released writer is held whole, as a reader folds from a contiguous // copy (a reduced copy comes with the client nodes' sparse read). +const fs = require('node:fs') +const path = require('node:path') const test = require('brittle') const b4a = require('b4a') const { testnet, until } = require('./helpers/net') -const { liveGroupJoins, groupWalkStep } = require('../lib/seeder') +const { Seeder, liveGroupJoins, groupWalkStep } = require('../lib/seeder') const { groupJoinRecord, groupCutRecord, @@ -98,7 +100,7 @@ test('liveGroupJoins: a counted writer whose join is off stays, left; an uncount for (let i = 0; i < 9; i++) records.push(join(key(i))) records.push(join(key(1), false), join(key(8), false), cut(key(1), 2)) const out = kept(records) - t.alike(out.get(key(1)), { group: G, seq: 10, left: true }, 'frozen and left: kept for its history') + t.alike(out.get(key(1)), { group: G, seq: 2, left: true }, 'frozen and left: kept for its history, by its on join') t.absent(out.has(key(8)), 'never counted: not kept') t.alike(out.get(key(0)), { group: G, seq: 1, left: false }) @@ -106,10 +108,52 @@ test('liveGroupJoins: a counted writer whose join is off stays, left; an uncount // root key never through an off join. const H = 'bb'.repeat(32) const gone = kept([join(H, true, H), join(key(50), true, H), join(key(50), false, H), join(H, false, H)]) - t.alike(gone.get(key(50)), { group: H, seq: 3, left: true }) + t.alike(gone.get(key(50)), { group: H, seq: 2, left: true }) t.absent(gone.has(H), 'the root key is not kept through an off join') }) +test('liveGroupJoins: a left or released writer is listed by its newest on join for the group, never an off join (#350)', (t) => { + // Readers check the item's seq against an on:true join naming the writer. + const H = 'bb'.repeat(32) + const out = kept([ + join(key(0)), join(key(0)), join(key(0), false), + join(key(1)), cut(key(1), 0), join(key(1), false), + join(key(2), true, H), join(key(2)), join(key(2), false), + join(key(3)), join(key(3), false), join(key(3)), join(key(3), false) + ]) + t.alike(out.get(key(0)), { group: G, seq: 2, left: true }, 'joined twice, then left: the second join') + t.alike(out.get(key(1)), { group: G, seq: 4, left: true }, 'released, then left: its join') + t.alike(out.get(key(2)), { group: G, seq: 8, left: true }, 'an on join to another group is not it') + t.alike(out.get(key(3)), { group: G, seq: 12, left: true }, 'left, back and left again: the last on join') +}) + +test('a stored binding the scan no longer lists gets its on join too, never an off one (#350)', (t) => { + // An older seeder stored W in G with its off join (seq 2); the diary then + // named W in H, so the scan lists W there and not in G. + const D = key(90) + const H = 'bb'.repeat(32) + const W = key(0) + const { decls, walks } = diary([join(W), join(W, false), join(W, true, H)]) + const entry = { gated: true, dropped: false, groupDecls: decls, groupWalks: walks, groupBound: new Map(), groupRefused: new Map(), groupLive: liveGroupJoins(decls, walks) } + t.is(entry.groupLive.get(W).group, H, 'the scan lists W in H only') + const rows = [] + const seeder = Object.create(Seeder.prototype) + Object.assign(seeder, { + _closing: false, + _groups: new Map([[W, { diary: D, group: G, seq: 2 }]]), + _groupServed: new Map([[W, {}]]), + _groupIndex: { + addWriter: (group, k, d, seq) => rows.push({ group, key: k, diary: d, seq }), + setLeft: (k, left) => rows.push({ key: k, left }) + }, + _persist: async () => {}, + _isBlocked: () => true + }) + seeder._reconcileGroups(D, entry) + t.is(seeder._groups.get(W).seq, 1, 'the binding takes its on join in G') + t.alike(rows, [{ group: G, key: W, diary: D, seq: 1 }, { key: W, left: true }], 'and so does its row, left') +}) + test('liveGroupJoins: groups past MAX_GROUPS_PER_DIARY keep no writer, left or not (#350)', (t) => { const records = [] for (let g = 0; g <= MAX_GROUPS_PER_DIARY; g++) records.push(join(key(1000 + g), true, key(5000 + g))) @@ -308,6 +352,45 @@ test('a 9th writer after a freeze is admitted, a counted writer whose join is of t.is(events.filter((e) => e.event === 'fatal').length, 0) }) +test('a writer that left before its admission is listed by its on join, and a binding stored with the off join heals at the next start (#350)', async (t) => { + t.timeout(240000) + const { bootstrap } = await testnet(t) + const assoc = makeAssociation() + const { dataDir } = prepareSeederDir(t, assoc) + const first = await startSeeder(t, bootstrap, dataDir, { associationKey: assoc.hex }) + + // B's diary: its certificate (0) and the join of W (1); then B leaves + // online, before any seeder saw W: a leave in W (block 6) and the join + // turned off (2). + const { A, B, R, W } = await cutWorld(t, bootstrap, assoc) + await B.cores.w.append(b4a.from(JSON.stringify(groupLeave({ seen: null, cuts: [{ writer: W, seq: 6 }] })))) + await B.diary.append(groupJoinRecord({ group: R, writer: W, on: false })) + await admit(A, assoc) + await admit(B, assoc) + await admitted(first.events, W) + await settledFor(first.seeder, B) + await downloaded(first.seeder, W, 7) + const item = first.seeder._groupIndex.page(R).items.find((i) => i.key === W) + t.is(item.left, true, 'listed left') + t.is(item.seq, 1, 'by its on join, the block readers check') + t.is(readGroups(dataDir)[W].seq, 1, 'and stored with it') + await first.seeder.close() + + // A binding stored with the seq of the off join, as the build before + // this one wrote it, takes the on join at the next scan. + const file = path.join(dataDir, 'admitted.json') + const data = JSON.parse(fs.readFileSync(file, 'utf8')) + data.groups[W].seq = 2 + fs.writeFileSync(file, JSON.stringify(data)) + const second = await startSeeder(t, bootstrap, dataDir, { associationKey: assoc.hex }) + await settledFor(second.seeder, B) + await until(() => readGroups(dataDir)[W].seq === 1, { name: 'vínculo corrigido', timeoutMs: 10000 }).catch(() => {}) + t.alike(second.seeder._groupIndex.writer(W), { group: R, diary: B.key, seq: 1, left: true }, 'listed left by its on join again') + t.is(readGroups(dataDir)[W].seq, 1, 'and stored with it') + t.absent(second.events.some((e) => e.event === 'group-rejected' && e.key === W), 'never purged') + t.is(first.events.filter((e) => e.event === 'fatal').length + second.events.filter((e) => e.event === 'fatal').length, 0) +}) + test('a writer its diary released (cut 0) stays held whole, and a fresh reader reads its leave in order (#350)', async (t) => { t.timeout(150000) const { bootstrap } = await testnet(t) diff --git a/packages/core/test/sync-groups-7.test.js b/packages/core/test/sync-groups-7.test.js new file mode 100644 index 00000000..2ebdb567 --- /dev/null +++ b/packages/core/test/sync-groups-7.test.js @@ -0,0 +1,67 @@ +'use strict' + +// Member sync of a writer whose member left the group before a seeder +// admitted it (docs/protocol.md section 10, "Scan"): the seeder lists it +// left, by its newest on:true join, and a reader fetches it from that +// listing. +const test = require('brittle') +const { testnet, until } = require('./helpers/net') +const { generateAssociationKeyPair } = require('../lib/cert') +const member = require('../lib/member') +const store = require('../lib/store') +const { groupJoinHistory } = require('../lib/group') +const { person, exchange, startSeeder, syncOnce, stored, ownWriter, texts } = require('./helpers/sync-groups') + +// The diary seqs of ctx's joins of `writer` to `group`, by `on`. +async function joinSeqs (ctx, group, writer) { + const s = await store.openStore(ctx.dataDir) + try { + const joins = groupJoinHistory(await store.readAll(await store.openDiary(s)), group).filter((j) => j.writer === writer) + return { on: joins.filter((j) => j.on).map((j) => j.seq), off: joins.filter((j) => !j.on).map((j) => j.seq) } + } finally { + await s.close() + } +} + +test('a writer that left online is listed by its on join: a reader fetches it, no hint is disproved (#350)', async (t) => { + t.timeout(170000) + const { bootstrap } = await testnet(t) + const kp = generateAssociationKeyPair() + const seeder = await startSeeder(t, bootstrap, kp) + const a = await person(t, kp, 'Ana') + const b = await person(t, kp, 'Bia') + const { community } = await member.communityCreate(a, { name: 'Bairro', join: 'open' }) + const { group } = await member.groupCreate(a, { name: 'Horta', join: 'open', community }) + await member.groupPost(a, { group, text: 'primeiro' }) + await exchange(a, b) + await member.communityJoin(b, { community }) + await member.groupJoin(b, { group }) + await member.groupPost(b, { group, text: 'oi' }) + const wb = ownWriter(b, group) + // B leaves with the group folded: a leave in its writer and its diary's + // join turned off, all before any seeder saw its writer. + t.is((await member.groupLeave(b, { group })).state, 'left') + const seqs = await joinSeqs(b, group, wb) + t.is(seqs.on.length, 1) + t.is(seqs.off.length, 1, 'the leave turned the join off') + + const ra = await syncOnce(bootstrap, a) + t.ok(ra.result.ok, 'A pushes its diary and root: ' + ra.result.errors.join('; ')) + const rb = await syncOnce(bootstrap, b) + t.ok(rb.result.ok, 'B pushes its diary: ' + rb.result.errors.join('; ')) + await until(() => { + const e = seeder._groupServed.get(wb) + return e && e.headerOk && seeder._groupIndex.writer(wb) !== null + }, { name: 'escritor de B no semeador', timeoutMs: 30000 }) + const row = seeder._groupIndex.writer(wb) + t.is(row.left, true, 'listed left') + t.is(row.seq, seqs.on[0], 'by its on join, never the off one') + + const ra2 = await syncOnce(bootstrap, a) + t.ok(ra2.result.ok, ra2.result.errors.join('; ')) + const skips = ra2.events.filter((ev) => ev.event === 'group-skipped' && ev.key === wb).map((ev) => ev.reason) + t.alike(skips, [], 'the listing of B\'s writer is not disproved (no unbound hint charged to the seeder)') + t.ok(ra2.events.some((ev) => ev.event === 'group-downloaded' && ev.key === wb), 'A fetches B\'s writer') + t.ok(await stored(a, wb), 'and keeps it') + t.ok((await texts(a, group)).includes('oi'), 'B\'s post from before the leave is read') +}) diff --git a/packages/web-member/test/sync-groups-3.test.js b/packages/web-member/test/sync-groups-3.test.js new file mode 100644 index 00000000..53284da3 --- /dev/null +++ b/packages/web-member/test/sync-groups-3.test.js @@ -0,0 +1,55 @@ +// A writer whose member left the group before the seeder admitted it +// (docs/protocol.md section 10, "Scan"): the seeder lists it left, by its +// newest on:true join, and a browser node fetches it from that listing. +const test = require('brittle') +const { testnet, until } = require('./helpers/net') +const { generateAssociationKeyPair } = require('@varanda/core/lib/cert') +const store = require('../lib/node-store') +const ops = require('../lib/member-ops') +const { member, seederOverWs, indexed, once, named, held } = require('./helpers/sync-groups') + +// The diary seqs of m's joins of `writer` to `group`, by `on`. +async function joinSeqs (m, group, writer) { + const { entries } = await ops.logRead(m.ctx) + const joins = entries.filter((e) => e.record.type === 'group-join' && e.record.group === group && e.record.writer === writer) + return { on: joins.filter((e) => e.record.on).map((e) => e.seq), off: joins.filter((e) => !e.record.on).map((e) => e.seq) } +} + +test('a writer that left online is fetched from the seeder listing, no hint disproved (#350)', async (t) => { + t.timeout(170000) + const { bootstrap } = await testnet(t) + const assocKp = generateAssociationKeyPair() + const { seeder, url } = await seederOverWs(t, assocKp, bootstrap) + const a = await member(assocKp, 'Ana') + const b = await member(assocKp, 'Bia') + const c = await member(assocKp, 'Caio') + const { community } = await ops.communityCreate(a.ctx, { name: 'Bairro', join: 'open' }) + const { group } = await ops.groupCreate(a.ctx, { name: 'Horta', join: 'open', community }) + t.ok((await once(a, url, [])).ok, 'creator pushed') + await until(() => indexed(seeder, group, group), { name: 'root indexed' }) + await store.addGroupReplica(b.storage, group) + t.ok((await once(b, url, [])).ok, 'member fetched the roots') + t.is((await ops.communityJoin(b.ctx, { community })).state, 'member', 'joined the community') + t.is((await ops.groupJoin(b.ctx, { group })).state, 'member', 'joined the group') + await ops.groupPost(b.ctx, { group, text: 'oi' }) + const w = (await store.readGroupWriters(b.storage)).find((e) => e.group === group).key + // B leaves with the group folded, before any seeder saw its writer: a + // leave in the writer and the diary's join turned off. + t.is((await ops.groupLeave(b.ctx, { group })).state, 'left') + const seqs = await joinSeqs(b, group, w) + t.is(seqs.on.length, 1) + t.is(seqs.off.length, 1, 'the leave turned the join off') + t.ok((await once(b, url, [])).ok, 'member pushed its diary') + await until(() => indexed(seeder, group, w) && seeder._groupServed.get(w) && seeder._groupServed.get(w).headerOk, { name: 'writer indexed', timeoutMs: 30000 }) + const item = seeder.groupWriters({ group, after: null, limit: 64 }).items.find((it) => it.key === w) + t.is(seeder._groupIndex.writer(w).left, true, 'listed left') + t.is(item.seq, seqs.on[0], 'by its on join, never the off one') + + await store.addGroupReplica(c.storage, group) + const ev = [] + t.ok((await once(c, url, ev)).ok, 'the reader synced') + const skips = named(ev, 'group-skipped').filter((e) => e.key === w).map((e) => e.reason) + t.alike(skips, [], 'the listing of B\'s writer is not disproved (no unbound hint charged to the seeder)') + t.ok(await held(c, w), 'the reader holds B\'s writer') + t.ok((await ops.groupRead(c.ctx, { group })).items.some((p) => p.text === 'oi'), 'B\'s post from before the leave is read') +})