Skip to content

Commit 3570b81

Browse files
fix(console): a session answered "not shown" sends no first-run checklist reads on later opens (#37184)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8JtfL3chjK7xVPpJ6UJRz9z)_ Fixes #37182 Clause-②: no Metadata-protocol: none ## 维护者速读 - 做了什么:看不到「开始使用」清单的会话(普通成员;控制面上的普通组织所有者),第一次被服务端答成「不显示」后,本机记住这个答案(按组织、用户、权限集合,24 小时);之后打开控制台不再多发 `GET /api/settings`。 - 管理员不受影响:每次照旧读取并显示清单。权限变了、换人或换组织、过期、读取失败,都会重新读。 - 结果:cloud 控制面计费页的预热打开回到 25 次请求;下一轮 cloud 抄版本把预算从 26 改回 25。 - 要你做的:无。 ## What changes - `firstRunChecklistLogic.ts`: a device record of the server's "not shown" answer, `os:first-run-checklist-not-shown:<orgId>:<userId>`, holding the capability list it was read for and when (`notShownRecordKey`, `wasAnsweredNotShown`, `markAnsweredNotShown`, `NOT_SHOWN_RECORD_TTL_MS` = one day). It fails toward reading again: unreadable storage, a record that does not parse, a different capability set, an expired record, or one dated in the future all read. - `firstRunChecklistState.tsx`: the provider checks the record before scheduling its reads and asks nothing while it stands; when `readChecklistSettings` answers `null` (the server's answer that this session may not write `localization`), it writes the record. A read that throws writes nothing. An administrator's path is untouched. ## Why Since #36791 the provider is mounted above every app route and, after the first paint, sends `GET /api/settings` for every session whose `systemPermissions` is non-empty. For a session never shown the checklist that request buys nothing, on every console open. The cloud pin round cloud#4982 (PR cloud#4983) measured it as the 26th call of the control plane's `page/pricing` warm open, budget 25. Why a remembered answer and not a capability check before the request: the session that red the budget, an ordinary organization owner on the control plane, holds `setup.write`; that plane re-registers `localization` with `writePermission: manage_platform_settings` (cloud `control-plane-settings.ts`). Which permission a deployment's manifest asks is known only once the list answers, and naming one in the console would be a second copy of the manifest's declaration that drifts on the next deployment that changes it. The first open on a device still pays the one read; every later open within the day does not. ## Verification - `pnpm exec vitest run apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx` (from `ui/`): 119 passed. - New provider pins (`a session answered "not shown" asks nothing again on this device`): a member reads once then never; an owner holding `setup.write` where `localization` asks `manage_platform_settings` reads once across three opens; an administrator reads and is shown it on every open; a member made administrator reads again at once; a failed list read records nothing; another user in the same browser reads for themself. New logic pins cover the key, capability-set match, the one-day bound, a future-dated record, unreadable storage and unparseable records. - Ablation: with `firstRunChecklistState.tsx` reverted to `main`, the member and control-plane-owner pins fail (2 failed, 88 passed in that file); the other four pass on both, as preservation pins. - `eslint` on the four touched files: 0 errors (2 pre-existing `react-refresh/only-export-components` warnings on `firstRunChecklistState.tsx`). - Not run locally: the cloud `console-boots` budget. The next cloud pin round reads it and moves `page/pricing` `maxCalls` back to 25, with the reading recorded on cloud#2914. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbZaRxCTLgg8LsLBuFb --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 893eac8 commit 3570b81

5 files changed

Lines changed: 255 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/console': patch
3+
---
4+
5+
fix(console): a session the server answered "not shown" sends no first-run checklist reads on its next console opens
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Since the first-run checklist's reads moved above every app route, every session holding any capability sent `GET /api/settings` after the first paint on every console open, only to learn it may not write `localization` and is never shown the checklist: a plain member, and an ordinary organization owner on the cloud control plane (it holds `setup.write`, but that plane's `localization` manifest asks `manage_platform_settings`). The provider now remembers that answer on the device, per organization, user and capability set, for one day, and asks nothing while it stands. An administrator's reads are unchanged; a changed capability set, another user or organization, an expired record, or a failed read reads again.

‎ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,88 @@ describe('only an administrator sees it', () => {
352352
});
353353
});
354354

355+
describe('a session answered "not shown" asks nothing again on this device (objectstack#37182)', () => {
356+
const listCalls = () => calls('GET', '/api/settings');
357+
358+
/** Opens the console again, as a new tab of the same browser does: the provider remounts, the device storage stays. */
359+
async function reopen(systemPermissions: string[]) {
360+
cleanup();
361+
renderChecklist(systemPermissions);
362+
await settle();
363+
}
364+
365+
it('a member: the list is read on the first open and not on the next', async () => {
366+
renderChecklist(MEMBER);
367+
await settle();
368+
expect(listCalls()).toHaveLength(1);
369+
await reopen(MEMBER);
370+
expect(listCalls()).toHaveLength(1);
371+
expect(fetchMock).toHaveBeenCalledTimes(1);
372+
expect(screen.queryByTestId('first-run-checklist')).toBeNull();
373+
});
374+
375+
it('an owner who holds setup.write where localization asks more (the cloud control plane): one read, then none', async () => {
376+
const OWNER = ['manage_org_users', 'setup.access', 'setup.write'];
377+
const routed = fetchMock.getMockImplementation()!;
378+
fetchMock.mockImplementation(async (url: string, init?: RequestInit) =>
379+
url === '/api/settings' && (init?.method ?? 'GET') === 'GET'
380+
? ok({ manifests: [{ ...LOCALIZATION_MANIFEST, writePermission: 'manage_platform_settings' }, MAIL_MANIFEST] })
381+
: routed(url, init),
382+
);
383+
renderChecklist(OWNER);
384+
await settle();
385+
expect(listCalls()).toHaveLength(1);
386+
expect(calls('GET', '/api/settings/localization')).toHaveLength(0);
387+
await reopen(OWNER);
388+
await reopen(OWNER);
389+
expect(fetchMock).toHaveBeenCalledTimes(1);
390+
expect(screen.queryByTestId('first-run-checklist')).toBeNull();
391+
});
392+
393+
it('an administrator reads on every open, and is shown the checklist each time', async () => {
394+
renderChecklist(ADMIN);
395+
expect(await screen.findByTestId('first-run-checklist')).toBeTruthy();
396+
await reopen(ADMIN);
397+
expect(await screen.findByTestId('first-run-checklist')).toBeTruthy();
398+
expect(listCalls()).toHaveLength(2);
399+
expect(calls('GET', '/api/settings/localization')).toHaveLength(2);
400+
});
401+
402+
it('a changed capability set reads again: a member made an administrator is shown it at once', async () => {
403+
renderChecklist(MEMBER);
404+
await settle();
405+
await reopen(ADMIN);
406+
expect(listCalls()).toHaveLength(2);
407+
expect(await screen.findByTestId('first-run-checklist')).toBeTruthy();
408+
});
409+
410+
it('a list read that fails is no answer: the next open reads again', async () => {
411+
const routed = fetchMock.getMockImplementation()!;
412+
fetchMock.mockImplementation(async (url: string, init?: RequestInit) =>
413+
url === '/api/settings'
414+
? ({ ok: false, status: 503, statusText: 'Service Unavailable', headers: new Headers(), json: async () => ({}) } as unknown as Response)
415+
: routed(url, init),
416+
);
417+
renderChecklist(MEMBER);
418+
await settle();
419+
fetchMock.mockImplementation(routed);
420+
await reopen(MEMBER);
421+
expect(listCalls()).toHaveLength(2);
422+
});
423+
424+
it('another user in the same browser reads for themself', async () => {
425+
renderChecklist(MEMBER);
426+
await settle();
427+
AUTH.user = { id: 'u_other' };
428+
try {
429+
await reopen(MEMBER);
430+
} finally {
431+
AUTH.user = { id: 'u_admin' };
432+
}
433+
expect(listCalls()).toHaveLength(2);
434+
});
435+
});
436+
355437
describe('one required row, the basics; every other platform row optional (objectstack#36739)', () => {
356438
it('a fresh workspace: the basics first and required, then mail and invite, optional, each with its way in', async () => {
357439
renderChecklist(ADMIN);

‎ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import {
2525
organizationBasics,
2626
markDismissed,
2727
wasDismissed,
28+
NOT_SHOWN_RECORD_TTL_MS,
29+
markAnsweredNotShown,
30+
notShownRecordKey,
31+
wasAnsweredNotShown,
2832
type ChecklistStorage,
2933
} from '../firstRunChecklistLogic';
3034
import type { ResolvedSettingValue, SettingsManifest, Specifier } from '../types';
@@ -236,6 +240,62 @@ describe('hiding the checklist is a per-device record, per workspace and user',
236240
});
237241
});
238242

243+
describe('"not shown" is a per-device answer, per workspace, user and capability set, for a day (objectstack#37182)', () => {
244+
function memory(): ChecklistStorage & { data: Map<string, string> } {
245+
const data = new Map<string, string>();
246+
return { data, getItem: (k) => data.get(k) ?? null, setItem: (k, v) => void data.set(k, v) };
247+
}
248+
const HELD = 'setup.access\nsetup.write';
249+
const T0 = Date.UTC(2026, 10, 25, 2, 0, 0);
250+
251+
it('keys the record on both ids, apart from the dismiss record, and reads it back for the same capability set', () => {
252+
const storage = memory();
253+
const key = notShownRecordKey('org_1', 'u_owner');
254+
expect(key).toBe('os:first-run-checklist-not-shown:org_1:u_owner');
255+
expect(key).not.toBe(dismissRecordKey('org_1', 'u_owner'));
256+
expect(wasAnsweredNotShown(storage, key, HELD, T0)).toBe(false);
257+
expect(markAnsweredNotShown(storage, key, HELD, T0)).toBe(true);
258+
expect(wasAnsweredNotShown(storage, key, HELD, T0 + 1000)).toBe(true);
259+
expect(wasAnsweredNotShown(storage, notShownRecordKey('org_2', 'u_owner'), HELD, T0 + 1000)).toBe(false);
260+
});
261+
262+
it('a changed capability set reads again', () => {
263+
const storage = memory();
264+
const key = notShownRecordKey('org_1', 'u_owner');
265+
markAnsweredNotShown(storage, key, HELD, T0);
266+
expect(wasAnsweredNotShown(storage, key, `${HELD}\nmanage_platform_settings`, T0 + 1000)).toBe(false);
267+
expect(wasAnsweredNotShown(storage, key, 'setup.access', T0 + 1000)).toBe(false);
268+
});
269+
270+
it('stands for a day, then reads again; a record dated in the future reads again', () => {
271+
const storage = memory();
272+
const key = notShownRecordKey('org_1', 'u_owner');
273+
markAnsweredNotShown(storage, key, HELD, T0);
274+
expect(wasAnsweredNotShown(storage, key, HELD, T0 + NOT_SHOWN_RECORD_TTL_MS - 1)).toBe(true);
275+
expect(wasAnsweredNotShown(storage, key, HELD, T0 + NOT_SHOWN_RECORD_TTL_MS)).toBe(false);
276+
expect(wasAnsweredNotShown(storage, key, HELD, T0 - 1)).toBe(false);
277+
});
278+
279+
it('storage that cannot be read, or a record that does not parse, reads again', () => {
280+
const broken: ChecklistStorage = {
281+
getItem: () => {
282+
throw new Error('denied');
283+
},
284+
setItem: () => {
285+
throw new Error('denied');
286+
},
287+
};
288+
expect(wasAnsweredNotShown(broken, 'k', HELD, T0)).toBe(false);
289+
expect(wasAnsweredNotShown(undefined, 'k', HELD, T0)).toBe(false);
290+
expect(markAnsweredNotShown(broken, 'k', HELD, T0)).toBe(false);
291+
const storage = memory();
292+
for (const raw of ['not json', 'null', '2026-11-25T00:00:00.000Z', JSON.stringify({ held: HELD }), JSON.stringify({ held: HELD, at: 'x' })]) {
293+
storage.data.set('k', raw);
294+
expect(wasAnsweredNotShown(storage, 'k', HELD, T0)).toBe(false);
295+
}
296+
});
297+
});
298+
239299
describe('completion: the basics are required; mail, invite and both AI rows are optional (objectstack#32643, objectstack#36739)', () => {
240300
it('only the basics done, every optional row not: complete, and the progress counts every row', () => {
241301
const rows = [

‎ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,88 @@ export function markDismissed(storage: ChecklistStorage | undefined, key: string
252252
}
253253
}
254254

255+
/**
256+
* Where "the server answered that this session is not shown the checklist"
257+
* lives, per workspace and per user: `os:first-run-checklist-not-shown:<orgId>:<userId>`
258+
* (objectstack#37182).
259+
*
260+
* The checklist's provider is mounted above every app route, and the only way
261+
* it learns that a session may not write `localization` is to ask: the first
262+
* request of `readChecklistSettings` lists the settings manifests. For a
263+
* session that is never shown the checklist that request bought nothing, on
264+
* every console open: a plain member, and an ordinary organization owner on the
265+
* cloud's control plane, which holds `setup.write` but whose `localization`
266+
* manifest asks `manage_platform_settings`. No capability check before the
267+
* request can tell that second session apart: the permission a deployment's
268+
* manifest asks is known only once the list answers, and naming one in the
269+
* console would be a second copy of the manifest's declaration.
270+
*
271+
* So the answer is remembered on the device, beside the dismiss record and for
272+
* the same reason (the narrowest scope the client can see that holds every tab
273+
* of one sign-in), with what it was read for:
274+
*
275+
* - the capability set it was read for: any change to it (a grant, a
276+
* revocation) is a different session as far as the checklist goes, and it
277+
* reads again;
278+
* - when it was read: after {@link NOT_SHOWN_RECORD_TTL_MS} it reads again, so
279+
* a deployment that starts showing the checklist to this session (a
280+
* manifest's `writePermission` changed by an upgrade) is followed within a
281+
* day.
282+
*
283+
* Only a server's ANSWER is remembered: a read that failed, and an
284+
* administrator's checklist, are not, so the administrator's reads are exactly
285+
* what they were. The record fails toward reading again: storage that cannot
286+
* be read, a record that does not parse, or one dated in the future, all read.
287+
*/
288+
export const NOT_SHOWN_RECORD_PREFIX = 'os:first-run-checklist-not-shown';
289+
290+
/** How long a "not shown" answer stands before the provider asks again: one day. */
291+
export const NOT_SHOWN_RECORD_TTL_MS = 24 * 60 * 60 * 1000;
292+
293+
export function notShownRecordKey(orgId: string, userId: string): string {
294+
return `${NOT_SHOWN_RECORD_PREFIX}:${orgId}:${userId}`;
295+
}
296+
297+
/**
298+
* Did the server answer, within the last {@link NOT_SHOWN_RECORD_TTL_MS}, that
299+
* this user in this workspace, holding exactly `held` (the capability list,
300+
* newline-joined), is not shown the checklist?
301+
*/
302+
export function wasAnsweredNotShown(
303+
storage: ChecklistStorage | undefined,
304+
key: string,
305+
held: string,
306+
now: number = Date.now(),
307+
): boolean {
308+
if (!storage) return false;
309+
try {
310+
const raw = storage.getItem(key);
311+
if (raw === null) return false;
312+
const record = JSON.parse(raw) as { held?: unknown; at?: unknown } | null;
313+
if (!record || record.held !== held || typeof record.at !== 'number') return false;
314+
const age = now - record.at;
315+
return age >= 0 && age < NOT_SHOWN_RECORD_TTL_MS;
316+
} catch {
317+
return false;
318+
}
319+
}
320+
321+
/** Record that the server answered "not shown" for `held`. Returns `false` when it could not be written. */
322+
export function markAnsweredNotShown(
323+
storage: ChecklistStorage | undefined,
324+
key: string,
325+
held: string,
326+
now: number = Date.now(),
327+
): boolean {
328+
if (!storage) return false;
329+
try {
330+
storage.setItem(key, JSON.stringify({ held, at: now }));
331+
return true;
332+
} catch {
333+
return false;
334+
}
335+
}
336+
255337
/**
256338
* The browser's own zone, or `undefined` when it reports none.
257339
*

‎ui/apps/console/src/pages/settings/firstRunChecklistState.tsx‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
* answers `null` and nothing further is asked;
1717
* - after the console's first paint (`whenBootPainted`), so the reads never go
1818
* out beside the page's own first reads;
19+
* - not at all for a session the server already answered "not shown" on this
20+
* device, for this organization, user and capability set, within the last
21+
* day (`wasAnsweredNotShown`, objectstack#37182): the list request that
22+
* finds that out would otherwise go out on every console open;
1923
* - each answer is stored with the identity it was read for (organization,
2024
* user, capability set), so an answer read for another one is never drawn.
2125
*
@@ -45,10 +49,13 @@ import {
4549
dismissRecordKey,
4650
hasInvitedColleagues,
4751
LOCALIZATION_NAMESPACE,
52+
markAnsweredNotShown,
4853
markDismissed,
54+
notShownRecordKey,
4955
organizationBasics,
5056
readBrowserAnswers,
5157
readChecklistSettings,
58+
wasAnsweredNotShown,
5259
wasDismissed,
5360
type BrowserAnswers,
5461
type ChecklistCompletion,
@@ -205,14 +212,25 @@ export function FirstRunChecklistProvider({ children }: { children: ReactNode })
205212
}, [getAuthConfig]);
206213

207214
useEffect(() => {
208-
if (!identity || !orgId || heldKey === null) return;
215+
if (!identity || !orgId || !userId || heldKey === null) return;
209216
const held = heldKey === '' ? [] : heldKey.split('\n');
210217

218+
// The server already answered "not shown" for exactly this session: ask
219+
// nothing (objectstack#37182).
220+
const notShownKey = notShownRecordKey(orgId, userId);
221+
if (wasAnsweredNotShown(deviceStorage(), notShownKey, heldKey)) return;
222+
211223
let cancelled = false;
212224
whenBootPainted()
213-
.then(() => (cancelled ? null : readChecklistSettings(held)))
225+
.then(() => (cancelled ? undefined : readChecklistSettings(held)))
214226
.then((found) => {
215-
if (cancelled || !found) return;
227+
if (cancelled || found === undefined) return;
228+
if (!found) {
229+
// An answer, not a failure (a failed read throws past this): keep it
230+
// so the next open does not ask again.
231+
markAnsweredNotShown(deviceStorage(), notShownKey, heldKey);
232+
return;
233+
}
216234
setLoaded({ identity, settings: found });
217235
// Only an administrator's checklist asks who else is here.
218236
Promise.all([getMembers(orgId), listInvitations(orgId)])

0 commit comments

Comments
 (0)