Repository navigation
fix(console): ask /auth/me/permissions in the organization/list wave when the session names the active organization - #29302
Conversation
…when the session names the active organization Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…ave; changeset Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…zation; launcher read pinned behind the gate Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…anization; the provider takes that request once The prop-flip moved the request only from after organization/list to after the shell's discovery round trip, which leaves in the same wave. The request now starts beside ProtectedRoute and the provider takes it. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…replay of either end Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…-wave test Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…ble mocks The three App tests that mock ../AppContent now name ConsolePermissionsRequest, which App.tsx renders beside the /home + /apps protected route. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…pContent mocks Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
…-y1aiyw Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
|
domain:ui#2 · zhuangjianguo · session_01QsR2jRFuJz9QBZqPVHYVhJ Contract reviewServed-tier: Face: the ① Derived judgments
② Semver level
③ Boundary flagsThe dev raised the Clause-② reading on the built Implemented-by: VERDICT: PASS |
|
domain:ui#2 · zhuangjianguo · session_01QsR2jRFuJz9QBZqPVHYVhJ 维护者速读
席位意见: 方案在第一版(翻转 席位核对 — ACCEPT ·
|
Requested by Steedos · project thread
Fixes #29114
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
/auth/me/permissions不再排在organization/list之后才发,而是在会话答复里已带活动组织时立刻发出,与组织列表同一波;组织闸门、/me/apps与页面本身照旧等组织选定。@object-ui/permissions为此新增一个"先发请求、Provider 只取一次"的接口。/organizations。回滚即 revert 本 PR。ui/packages/permissions/src/MePermissionsProvider.tsx的 held request(取用、释放、StrictMode 重放);②ui/apps/console/src/AppContent.tsx的ConsolePermissionsRequest与requestKey;③ui/apps/console/src/App.tsx布局路由里新增的一个兄弟元素。pnpm --dir ui exec vitest run apps/console/src/__tests__/App.permissionsWave-29114.test.tsx packages/permissions/src/__tests__/MePermissionsProvider.heldRequest-29114.test.tsx,预期 13 个测试全绿(权限请求在组织列表与 discovery 都未答复时已发出,且全程只有一次)。What changes
/auth/me/permissionsnow leaves in the same wave asorganization/listwhen theget-sessionanswer already names the active organization. The server answers that endpoint for the session's active organization (resolveAuthzContextreadssession.activeOrganizationId, never a header), so the id in the session answer settles which answer comes back.Why it was late. The Console's one permissions provider (
ConsolePermissionsScope, mounted byApp.tsxon the pathless/home+/appslayout route) renders underProtectedRoute, whoseConnectedShellrenders nothing until the adapter's/discoveryanswers, and whoseRequireOrganizationrenders nothing untilorganization/listanswers. Both leave when the session answer lands, so the permissions request left one wave late, and everything after it (meta/*,/me/apps, the page) one wave later. Moving only the organization gate is not enough: measured, the request then waits on/discoveryinstead, which is in the same wave (see Acceptance notes).@object-ui/permissions(public additions,Clause-②: yes (widening)):startMePermissionsRequest({ endpoint, fetcher, key })asks now and holds the request with the endpoint and the identity (key) it was asked for. It must be public because the caller is the Console's route, which mounts long before the provider; nothing inside the package can see the session answer.MePermissionsProviderProps.requestKey?: string(optional). When a held request matches the provider's endpoint and key, the provider uses it as its first attempt instead of asking again; it is gone once that provider has its answer. A take for any other endpoint or key drops it. WithoutrequestKeythe provider behaves exactly as before. It must be public because the provider is the package's public component and the key is the only way a caller can say which question the held answer is for.releaseMePermissionsRequest(endpoint, key)says the caller no longer needs the answer (the route was left, or the session names another organization). The request is dropped on the next task unless asked for again by then. It must be public so the caller that started the request can end it; without it a request nobody took would stay held and could later be read as a stale answer.StartMePermissionsRequestOptionsis the options type of the first function.Console (
ui/apps/console/src/AppContent.tsx,App.tsx):ConsolePermissionsRequest(renders nothing) asks for the answer the moment the session names the active organization, keyeduser.id:activeOrganizationId, and releases it on unmount or key change.App.tsxrenders it besideProtectedRoutein the/home+/appslayout route element (the one line inApp.tsx).ConsolePermissionsScopepasses the same key asrequestKey, so its provider takes that request. Its position, the organization gate above it,/me/appsand every page are unchanged./organizations, and the provider asks after the gate, as before.Tests
New
ui/apps/console/src/__tests__/App.permissionsWave-29114.test.tsx(4 tests), the realApproute tree, realProtectedRoute, realRequireOrganization, realConsolePermissionsScope,MePermissionsProviderandLauncherAppsProvider; the auth state is a store moved the wayAuthProvidermoves it, andConnectedShellis reduced to its one effect on this order (nothing renders below it until the test says the adapter connected). Cases: the session names the organization, so the request leaves whileorganization/listanddiscoveryare both unanswered, the page and/me/appsstill wait for the list, and in the end there is one permissions request and no duplicate URL; an app route, with the list answering before the shell; control: a session naming no organization asks nothing until the pipeline chose one; control: a session with no active organization is redirected to/organizationswith zero permissions requests.New
ui/packages/permissions/src/__tests__/MePermissionsProvider.heldRequest-29114.test.tsx(9 tests): same endpoint and key, the held request is the answer and the provider asks nothing; starting twice asks once; used once (a second provider asks for itself); another key asks and drops the held request; no key asks as before; a released request is not taken; a replayed starter asks once; a StrictMode provider uses the held request and asks nothing; a transient failure of the held request is retried by the provider.Five existing console tests that replace
../AppContentwith a mock (App.agentChatLink-10640,App.docsPortalLazy,App.nativeShellMode-29039,i18nAfterSignIn-12034,internalFormShell) name the newConsolePermissionsRequestexport as() => null, one line each; without it vitest refuses the missing mock export.Ablations (each through
scripts/ablation-replace.mjs, mutation landed by anchor count and blob hash, restored byte-identical to HEAD, underos-verify-lock):<ConsolePermissionsRequest />removed from the layout route: 2 red (both early-request cases), the two controls stay green.const held = null): 5 red (2 app, 3 provider).Acceptance notes
Measurement, production build (
vite buildof the Console at origin/main 87d6bae and at this branch, each served byvite previewproxying toexamples/app-crmunderobjectstack dev --seed-admin --fresh; Chromium; three full-page opens of/homeeach; resource timing; the session namesactiveOrganizationId):organization/liststartOn the Vite dev server (StrictMode doubles effects on both legs): origin/main +147 / +295 / +200 ms with two permissions requests per open; this branch −17 / −22 / −25 ms with one.
The first design was measured and dropped. Owning the organization gate in
ConsolePermissionsScope(requireOrganization={false}on the route) only moved the request from afterorganization/listto after/discovery(+51 / +66 / +60 ms on the dev server,discovery10547→10558 then permissions 10602 besidemeta/app10610). The surface amendment on the card records the switch.Known cost: a session whose active organization the organization list does not confirm (a stale session) sends one permissions request nobody reads, then redirects to
/organizationsas before.The early request carries the same
X-Tenant-IDas the other requests of that wave (organization/list,get-active-member): whateverActiveOrganizationStorageholds before the list answers. The framework scopes the answer from the session, not the header.Lint:
react-refresh/only-export-componentsnow warns twice onMePermissionsProvider.tsx(the two new non-component exports); warnings only, the file already exported non-component types.AppContent.tsxcarries the same two warnings it had on main.ui/packages/permissions/src/index.ts(three export lines) is outside the claim's named file list; the exports are what the amendment declares.Verification
Head
d783ff15(main merged after #29140 and again before opening; both merges clean, no parallel change to the touched files).node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 34 commands, all exit 0 ate37c383b(the same 12 paths as the head);--ranreconciles 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN.apps/console+packages/permissionsvitest (297 files) ate37c383b: green after the five mock stubs (2908 tests). At the head: the App route-table tests,i18nAfterSignIn-12034,internalFormShell,pages/settingsand the permissions package, 58 files / 482 tests green.ui/scripts/vitest: 169 files green.pnpm --dir ui run check:spec-symbols: 0.node scripts/check-sdui-manifest.mjs: 0.pnpm --filter @object-ui/console run type-checkandpnpm --filter @object-ui/permissions run type-check: 0. eslint on every touched file: 0 errors, 4 warnings (see Acceptance notes).pnpm build(117 tasks) green after the first main merge.Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses. (eslint on every touched file: 0 errors; the repo-wide run is CI's)main, one pull request.packages/spectouched: not touched.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko
Generated by Claude Code