Skip to content

Commit 265c04d

Browse files
matt2eclaude
andcommitted
fix(communities): log why known-communities sync stopped or skipped an intent
A stopped sync left no trace on the device: a 403, a 404 or an unreadable list halted it silently, and a refused intent was parked without a word. The routes need a server capability (BUZZ_USER_CAPABILITY), so a user without it is refused on every sign-in with nothing to show for it. sync.ts now writes one console warning per refusal naming the route (or the add/remove and its address), the reason (the named refusal or the HTTP status) and the consequence: stops until the next sign-in, or skips the intent until it is replaced or the next sign-in. Nothing else changes; the owner still reports nothing to the app. Tests: the halting table and the parked-add table each assert exactly one warning with the expected route, reason and consequence. docs/communities.md describes the warning. Validation on this tree: `vitest run src/bundled/builderlab/known-communities` 2 files, 64 tests passed; `tsc --noEmit` clean; `biome check --error-on-warnings` clean on the touched files. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 6ce6706 commit 265c04d

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

‎docs/communities.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ sides no longer share) stops until then, and a session the service has ended
184184
signs the plugin out. A service that answers any of the routes with 404 has no
185185
known-communities routes yet, or not all of them: sync stops until the next
186186
sign-in. The owner reports nothing to the app, so a halted or parked sync is
187-
not shown anywhere yet. A listed address this device could never save is left
188-
out and counted in a console warning, so one bad row cannot stop the account's
189-
sync.
187+
not shown anywhere yet; each refusal is named once in a console warning (the
188+
route, the address and the reason), since an account without the routes'
189+
server capability is refused on every sign-in and would otherwise leave no
190+
trace on the device. A listed address this device could never save is left
191+
out and counted the same way, so one bad row cannot stop the account's sync.
190192
Signing out or disabling the plugin abandons the request in flight and leaves
191193
the queue intact.
192194

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ it.each([
262262
requests: 2,
263263
},
264264
])("halts until the next sign-in when $name", async ({ arrange, requests }) => {
265+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
265266
const h = await fixture({
266267
signedIn: false,
267268
snapshot: { sync: queued(primary) },
@@ -274,8 +275,12 @@ it.each([
274275
h.client.remove.mock.calls.length;
275276
await until(() => expect(calls()).toBe(requests));
276277
await vi.advanceTimersByTimeAsync(0);
277-
// Halted, not failed: no retry is scheduled.
278+
// Halted, not failed: no retry is scheduled, and the device says why.
278279
expect(vi.getTimerCount()).toBe(0);
280+
expect(warn).toHaveBeenCalledTimes(1);
281+
expect(warn.mock.calls[0]?.[0]).toMatch(
282+
/^Builderlab (list|add wss:\/\/primary\.example) answered (forbidden|invalid_response|HTTP 40[45]); .* stops until the next sign-in\.$/,
283+
);
279284
window.dispatchEvent(new Event("online"));
280285
h.enqueue(secondary);
281286
await vi.advanceTimersByTimeAsync(120_000);
@@ -446,6 +451,7 @@ it.each([
446451
])(
447452
"parks an add the service answers $kind, keeps sending others, and sends the intent that replaces it",
448453
async (refusal) => {
454+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
449455
const h = await fixture({
450456
snapshot: { sync: queued(primary, secondary) },
451457
arrange: (client) =>
@@ -457,6 +463,12 @@ it.each([
457463
expect(h.outbox()).toEqual([{ url: primary, removed: false }]),
458464
);
459465
expect(h.client.add).toHaveBeenCalledTimes(2);
466+
expect(warn).toHaveBeenCalledTimes(1);
467+
expect(warn.mock.calls[0]?.[0]).toBe(
468+
`Builderlab add ${primary} answered ${
469+
refusal.kind === "rejected" ? "HTTP 415" : refusal.kind
470+
}; known-communities sync skips it until it is replaced or the next sign-in.`,
471+
);
460472
// Triggers and time pass it over, and the same intent queued again is
461473
// the same request: still parked.
462474
window.dispatchEvent(new Event("online"));

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "../../../features/communities/known-communities";
66
import type { KnownCommunities } from "../../../features/communities/service";
77
import type { OAuthSession } from "../oauth/session";
8-
import type { KnownCommunitiesClient, UpdateResult } from "./client";
8+
import type { KnownCommunitiesClient, Refusal, UpdateResult } from "./client";
99

1010
const backoff = (failures: number) => Math.min(60_000, 1000 * 2 ** failures);
1111
/** The service has no such route: not yet deployed, or only partly. */
@@ -14,6 +14,13 @@ const missing = (result: UpdateResult) =>
1414
/** An intent's identity for parking: the newer intent that replaces a parked
1515
* one is a different request and goes out. */
1616
const key = (op: PendingOp) => `${op.removed ? "-" : "+"}${op.url}`;
17+
/** The owner reports nothing to the app, so a refusal is at least logged. */
18+
const warn = (what: string, result: Refusal, then: string) =>
19+
console.warn(
20+
`Builderlab ${what} ${
21+
result.kind === "rejected" ? `HTTP ${result.status}` : result.kind
22+
}; known-communities sync ${then}.`,
23+
);
1724

1825
/** Drains the known-community outbox to the account service and reconciles
1926
* its list, for one plugin lifetime. It runs only while signed in: each
@@ -68,6 +75,7 @@ export function startKnownCommunitiesSync({
6875
if (!listed) {
6976
const list = await client.list(signal);
7077
if (list.kind !== "listed") {
78+
warn("list answered", list, "stops until the next sign-in");
7179
halted = true;
7280
return;
7381
}
@@ -99,10 +107,20 @@ export function startKnownCommunitiesSync({
99107
await knownCommunities.apply(
100108
acknowledge(knownCommunities.snapshot().sync, op),
101109
);
102-
else if (result.kind === "forbidden" || missing(result)) {
103-
halted = true;
104-
return;
105-
} else parked.add(key(op));
110+
else {
111+
const what = `${op.removed ? "remove" : "add"} ${op.url} answered`;
112+
if (result.kind === "forbidden" || missing(result)) {
113+
warn(what, result, "stops until the next sign-in");
114+
halted = true;
115+
return;
116+
}
117+
warn(
118+
what,
119+
result,
120+
"skips it until it is replaced or the next sign-in",
121+
);
122+
parked.add(key(op));
123+
}
106124
}
107125
failures = 0;
108126
// A parked intent that was replaced or withdrawn no longer counts, so

0 commit comments

Comments
 (0)