Skip to content

Commit c5a1d37

Browse files
matt2eclaude
andcommitted
fix(communities): keep parked reasons per intent and recompute the sync error after a pass
Address kalvinnchau's P3 on PR #644 (note f4521998). The sync owner kept one `error` string for halts, parked refusals and transient failures, and cleared it only when nothing was parked. With an add parked on limit_reached and a network failure on another upload in the same pass, the retry that then went through left "Couldn't reach Builderlab." in the rail, hiding the quota refusal that was still the only outstanding problem; and once a transient failure overwrote a parked reason, that reason could not come back for the sign-in. - sync.ts: `parked` is a Map from intent key to its refusal reason, so the park branch records the reason with the intent instead of writing `error`. After a pass goes through and parked intents that were replaced or withdrawn are pruned, `error` is recomputed from what remains parked (the first surviving reason, or none), so a transient failure is cleared unconditionally. Halts still set `error` through `refuse()`, and the catch path still reports the transient failure until the next pass. Tests: the note's sequence (A parked on limit_reached, B throws, B's retry accepted) ends on `{ phase: "error", pending: 1, error: limit_reached }`, and with A and B parked for different reasons, withdrawing B reports A's reason. Both fail on the previous sync.ts and pass on this tree. docs/communities.md says the hint names a still-parked refusal once a retry goes through, and lists the new coverage. Validation on this tree: `vitest run src/bundled/builderlab src/features/communities` 30 files, 433 tests passed; `tsc --noEmit` clean; `biome check --error-on-warnings` clean on the touched directory. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 8f14c98 commit c5a1d37

3 files changed

Lines changed: 73 additions & 11 deletions

File tree

‎docs/communities.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ is not silently dropped. Beside **Add a community**, a quiet indicator reads
209209
owner is reporting; without the Builderlab plugin, a configured service, the
210210
native app or a service with the routes there is no sync to promise, so
211211
nothing is shown. Its hint names the reason: signing in, a refusal, or the
212-
retry under way. The indicator and the
212+
retry under way. Once a retry goes through, it names a refusal still parked
213+
rather than the failure that is over. The indicator and the
213214
hints promise nothing about how long a refusal lasts.
214215

215216
## Session lifetime
@@ -367,8 +368,9 @@ no repeated report, parked and halting refusals including rejections named by
367368
status, an unreadable list (through the real client, keeping every membership)
368369
and the quiet 404 on the list or an upload for a service without the routes,
369370
addresses the list left out, a parked add replaced by the removal that then
370-
goes out and re-sent on the next sign-in, both lost-acknowledgement orders
371-
against a set service, an abandoned upload on sign-out that keeps the queue, a
371+
goes out and re-sent on the next sign-in, a parked refusal reported again
372+
after a failed upload beside it or another parked intent clears, both
373+
lost-acknowledgement orders against a set service, an abandoned upload on sign-out that keeps the queue, a
372374
session ended
373375
by the service and disposal. `index.test.tsx` runs the real plugin wiring
374376
through to the list request under the signed-in credential, and that an

‎src/bundled/builderlab/known-communities/sync.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,66 @@ it("sends a parked intent again on the next sign-in", async () => {
570570
h.dispose();
571571
});
572572

573+
it("reports a parked intent's refusal again once a failed upload beside it goes through", async () => {
574+
const full = "Builderlab can’t save more communities for this account.";
575+
const h = await fixture({
576+
snapshot: { sync: queued(primary, secondary) },
577+
arrange: (client) =>
578+
client.add
579+
.mockResolvedValueOnce({ kind: "limit_reached" })
580+
.mockRejectedValueOnce(reachError()),
581+
});
582+
await until(() =>
583+
expect(h.status).toHaveBeenLastCalledWith({
584+
phase: "error",
585+
pending: 2,
586+
error: "Couldn’t reach Builderlab.",
587+
}),
588+
);
589+
// The retry sends only the failed upload; the parked one is what remains.
590+
await vi.advanceTimersByTimeAsync(1000);
591+
await until(() =>
592+
expect(h.status).toHaveBeenLastCalledWith({
593+
phase: "error",
594+
pending: 1,
595+
error: full,
596+
}),
597+
);
598+
expect(h.sent()).toEqual([
599+
{ url: primary, removed: false },
600+
{ url: secondary, removed: false },
601+
{ url: secondary, removed: false },
602+
]);
603+
h.dispose();
604+
});
605+
606+
it("reports the refusal of the intent still parked once another parked intent is withdrawn", async () => {
607+
const h = await fixture({
608+
snapshot: { sync: queued(primary, secondary) },
609+
arrange: (client) =>
610+
client.add.mockImplementation(async (url) =>
611+
url === primary
612+
? { kind: "invalid_request" }
613+
: { kind: "limit_reached" },
614+
),
615+
});
616+
await until(() =>
617+
expect(h.status).toHaveBeenLastCalledWith(
618+
expect.objectContaining({ phase: "error", pending: 2 }),
619+
),
620+
);
621+
h.enqueue(secondary, true);
622+
await until(() => expect(h.client.remove).toHaveBeenCalledTimes(1));
623+
await until(() =>
624+
expect(h.status).toHaveBeenLastCalledWith({
625+
phase: "error",
626+
pending: 1,
627+
error: "Builderlab refused one of your community addresses.",
628+
}),
629+
);
630+
h.dispose();
631+
});
632+
573633
it.each([
574634
{ name: "join, lost acknowledgement, leave", first: false },
575635
{ name: "leave, lost acknowledgement, rejoin", first: true },

‎src/bundled/builderlab/known-communities/sync.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export function startKnownCommunitiesSync({
7272
let unavailable = false;
7373
let error: string | undefined;
7474
let reported: SyncStatus | undefined;
75-
// Refused intents wait for the next sign-in, counted as pending meanwhile.
76-
const parked = new Set<string>();
75+
// Refused intents wait for the next sign-in, counted as pending meanwhile,
76+
// each with the reason it was refused.
77+
const parked = new Map<string, string>();
7778
let outbox = knownCommunities.snapshot().sync.outbox;
7879
let ready = knownCommunities.snapshot().status === "ready";
7980

@@ -151,17 +152,16 @@ export function startKnownCommunitiesSync({
151152
);
152153
else if (result.kind === "forbidden" || missing(result))
153154
return refuse(result);
154-
else {
155-
parked.add(key(op));
156-
error = reason(result);
157-
}
155+
else parked.set(key(op), reason(result));
158156
}
159157
failures = 0;
160158
// A parked intent that was replaced or withdrawn no longer counts.
161159
const pending = knownCommunities.pending().map(key);
162-
for (const entry of parked)
160+
for (const entry of parked.keys())
163161
if (!pending.includes(entry)) parked.delete(entry);
164-
if (parked.size === 0) error = undefined;
162+
// The pass went through, so an earlier failure is over: what remains
163+
// wrong is only what is still parked.
164+
error = parked.values().next().value;
165165
} catch (reason) {
166166
if (
167167
signal.aborted ||

0 commit comments

Comments
 (0)