Skip to content

fix(console): ask /auth/me/permissions in the organization/list wave when the session names the active organization - #29302

Merged
objectstack-fleet[bot] merged 12 commits into
mainfrom
claude/project-thread-y1aiyw
Nov 2, 2026
Merged

objectstack-fleet[bot] merged 12 commits into
mainfrom
claude/project-thread-y1aiyw

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread

Fixes #29114

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 改了什么:打开 Console 首页或任一应用时,/auth/me/permissions 不再排在 organization/list 之后才发,而是在会话答复里已带活动组织时立刻发出,与组织列表同一波;组织闸门、/me/apps 与页面本身照旧等组织选定。@object-ui/permissions 为此新增一个"先发请求、Provider 只取一次"的接口。
  • 为什么改:权限答复决定导航和按钮能不能画出来,以前它白等一整波(组织列表,以及元数据外壳的 discovery),之后的整层请求也跟着晚一波;服务端本来就按会话里的活动组织作答,没有必要等。
  • 风险与回滚:低。请求总数不变(实测两边都是 20/19/19 个 API 请求、0 个重复 URL);会话没有活动组织时走原来的顺序;先发的请求只被同一用户+同一组织的 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/permissions now leaves in the same wave as organization/list when the get-session answer already names the active organization. The server answers that endpoint for the session's active organization (resolveAuthzContext reads session.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 by App.tsx on the pathless /home + /apps layout route) renders under ProtectedRoute, whose ConnectedShell renders nothing until the adapter's /discovery answers, and whose RequireOrganization renders nothing until organization/list answers. 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 /discovery instead, 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. Without requestKey the 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.
  • StartMePermissionsRequestOptions is the options type of the first function.
  • Both ends survive a React StrictMode replay: a replayed starter (start, release, start) asks once, and a provider whose effect is torn down before it used the answer leaves it held for its replay. Not a cache: the answer is used for the moment it was asked in.

Console (ui/apps/console/src/AppContent.tsx, App.tsx):

  • ConsolePermissionsRequest (renders nothing) asks for the answer the moment the session names the active organization, keyed user.id:activeOrganizationId, and releases it on unmount or key change. App.tsx renders it beside ProtectedRoute in the /home + /apps layout route element (the one line in App.tsx).
  • ConsolePermissionsScope passes the same key as requestKey, so its provider takes that request. Its position, the organization gate above it, /me/apps and every page are unchanged.
  • A session that names no organization asks nothing early: the organization pipeline may still activate one (the single-membership repair) or redirect to /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 real App route tree, real ProtectedRoute, real RequireOrganization, real ConsolePermissionsScope, MePermissionsProvider and LauncherAppsProvider; the auth state is a store moved the way AuthProvider moves it, and ConnectedShell is 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 while organization/list and discovery are both unanswered, the page and /me/apps still 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 /organizations with 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 ../AppContent with a mock (App.agentChatLink-10640, App.docsPortalLazy, App.nativeShellMode-29039, i18nAfterSignIn-12034, internalFormShell) name the new ConsolePermissionsRequest export 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, under os-verify-lock):

  • <ConsolePermissionsRequest /> removed from the layout route: 2 red (both early-request cases), the two controls stay green.
  • the provider ignores the held request (const held = null): 5 red (2 app, 3 provider).

Acceptance notes

  • Measurement, production build (vite build of the Console at origin/main 87d6bae and at this branch, each served by vite preview proxying to examples/app-crm under objectstack dev --seed-admin --fresh; Chromium; three full-page opens of /home each; resource timing; the session names activeOrganizationId):

    leg perm start − organization/list start API requests duplicate URLs
    origin/main +87 / +66 / +58 ms (after the list answered) 20 / 19 / 19 0
    this branch −8 / −11 / −12 ms 20 / 19 / 19 0

    On 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 after organization/list to after /discovery (+51 / +66 / +60 ms on the dev server, discovery 10547→10558 then permissions 10602 beside meta/app 10610). 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 /organizations as before.

  • The early request carries the same X-Tenant-ID as the other requests of that wave (organization/list, get-active-member): whatever ActiveOrganizationStorage holds before the list answers. The framework scopes the answer from the session, not the header.

  • Lint: react-refresh/only-export-components now warns twice on MePermissionsProvider.tsx (the two new non-component exports); warnings only, the file already exported non-component types. AppContent.tsx carries 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 at e37c383b (the same 12 paths as the head); --ran reconciles 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN.
  • Full apps/console + packages/permissions vitest (297 files) at e37c383b: green after the five mock stubs (2908 tests). At the head: the App route-table tests, i18nAfterSignIn-12034, internalFormShell, pages/settings and 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-check and pnpm --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

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (not touched)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes. (eslint on every touched file: 0 errors; the repo-wide run is CI's)
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QsR2jS5xnxYaE4MkTEF5ko


Generated by Claude Code

claude added 12 commits November 2, 2026 08:49
…when the session names the active organization

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
…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
…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
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 2, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#2 · zhuangjianguo · session_01QsR2jRFuJz9QBZqPVHYVhJ

Contract review

Served-tier: TIER_DEFAULT
Head-sha: d783ff158a655c4582fb5576f6e558b29442722f
Local-runs: none

Face: the Clause-②: yes (widening) declaration only (claim amendment 6573912180). The diff touches no packages/spec/src/**, no governed path and declares no narrowing. Read: the PR's 12-file diff at this head, card #29114 with its triage comment and claim amendments 6573543242 / 6573912180 / 6575999313, the os-dev report 6575961170, and the head's check-runs.

① Derived judgments

  • @object-ui/permissions (published; src/index.ts is its entry) gains three exports: startMePermissionsRequest(options): void, releaseMePermissionsRequest(endpoint?, key?): void and type StartMePermissionsRequestOptions { endpoint?; fetcher?; key }. Additive only; nothing removed or renamed. Each has a caller that needs it public: the Console route asks before the provider mounts (start), and must drop a request nobody took when the route is left or the organization changes (release). Correct as a widening.
  • MePermissionsProviderProps gains the optional requestKey?: string. Optional, so every existing <MePermissionsProvider> still type-checks; absent ⇒ takeHeldRequest returns null before touching the held slot, so the provider asks exactly as before. Correct; the "absent = old behaviour" claim holds by reading.
  • Behaviour of the held request (module-level, one slot): keyed on endpoint + userId:organizationId, the pair the server answers /auth/me/permissions for; taken once by the first live provider with that endpoint and key and settled after its first attempt; a take for another endpoint/key drops it; a released request is dropped on the next task only if no caller asked again, so a StrictMode mount/unmount/mount neither asks twice nor drops a live request; each taker reads a clone() of the original response, so a torn-down reader cannot consume the body a replay needs. A failed held attempt counts as attempt 0 and the provider's existing retry loop asks again. Not a cache: no answer outlives the question it was asked for. Correct for the card's acceptance (request in the organization/list wave, request count unchanged: 20/19/19 both legs, 0 duplicate URLs).
  • @object-ui/console: ConsolePermissionsRequest (renders null) beside ProtectedRoute in the /home + /apps layout route; ConsolePermissionsScope passes requestKey. A session with no active organization asks nothing early. The console's exports are its app module, not a published accept set the claim widens.

② Semver level

patch for @object-ui/permissions and @object-ui/console in .changeset/29114-permissions-organization-list-wave.md, with Clause-②: yes (widening) and Metadata-protocol: none copied verbatim. AGENTS.md (changeset levels): a non-protocol change, widening or breaking, ships patch; none takes patch. Consistent.

③ Boundary flags

The dev raised the Clause-② reading on the built .d.ts before pr_create (answered by amendment 6573912180) and five mechanical test-mock stubs outside the surface (accepted after the fact, amendment 6575999313). No open_questions. The module-level slot is process-global; a second Console-like host using requestKey with the same endpoint shares it, which is the documented take-once semantics, not a leak. PR author is objectstack-fleet[bot] (relay write).

Implemented-by: claude/project-thread-y1aiyw
Reviewed-by: session_01QsR2jRFuJz9QBZqPVHYVhJ

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#2 · zhuangjianguo · session_01QsR2jRFuJz9QBZqPVHYVhJ

维护者速读

  • 改了什么:打开 Console 首页或任一应用时,/auth/me/permissions 在会话已带活动组织时立刻发出,与 organization/list 同一波,不再晚一整波;组织闸门、/me/apps 与页面照旧等组织选定。@object-ui/permissions 新增「先发请求、Provider 只取一次」的两个函数、一个类型和一个可选属性 requestKey。
  • 为什么改:权限答复决定导航和按钮能否画出,以前白等组织列表和 discovery 一整个来回,后面整层请求也跟着晚一波。
  • 风险与回滚:低。请求总数不变(实测 20/19/19,0 个重复 URL);没有活动组织的会话走原顺序;先发的请求只给同一用户+同一组织的 Provider 取用一次,不是缓存。陈旧会话会多一个没人读的请求。回滚即 revert 本 PR。
  • 先看:ui/packages/permissions/src/MePermissionsProvider.tsx 的 held request,然后 ui/apps/console/src/AppContent.tsx 的 ConsolePermissionsRequest。
  • 两分钟验证:pnpm --dir ui exec vitest run apps/console/src/__tests__/App.permissionsWave-29114.test.tsx packages/permissions/src/__tests__/MePermissionsProvider.heldRequest-29114.test.tsx,预期全绿。
  • 需要你做的:无,席位验收后进合并队列。

席位意见: 方案在第一版(翻转 requireOrganization)实测无效后改为「提前发、只取一次」,实测把权限请求从组织列表之后 +58~+87 ms 提到之前 −8~−12 ms,请求数不变。公开面只增不减,按 Clause-②: yes (widening) 走默认档复核,已 PASS(6576263592)。

席位核对 — ACCEPT · domain:ui#2 · head d783ff15 · 2026-11-02T11:43Z

  • 形态: draft PR on main, Fixes #29114 on its own line and no other card number beside a closing keyword. 12 files, +696/−16, Tier S (not governed; under 3000 lines). All inside claim 6572873226 as amended by 6573543242 (held request, one App.tsx sibling), 6573912180 (Clause-② widening) and 6575999313 (five test-mock stubs).
  • 前提实测: on a prod build of origin/main with app-crm --fresh, three /home opens put the permissions request +87/+66/+58 ms after organization/list started; this head puts it −8/−11/−12 ms before, with 20/19/19 API requests on both legs and 0 duplicate URLs. The first design (a requireOrganization flip) was measured to gain nothing because of /discovery, and was reverted before this head.
  • 门禁 check-runs (pinned to head d783ff158a655c4582fb5576f6e558b29442722f): 44 success, 11 skipped, 0 failed, 0 pending, including Lint & Repo Gates, TypeScript Type Check, Type Check UI, Lint UI, Check Changeset and Test UI. Dev local gates: 34/34 derived families exit 0, --ran 0 NOT-MEASURED; build 117/117. Ablations: no starter reds 2, a provider ignoring the held request reds 5.
  • 接受的偏差: five existing console tests gained a one-line ConsolePermissionsRequest mock stub before the amendment that covers them (6575999313); mechanical, no assertion changes. A stale session organization costs one unread request before the redirect (declared in the PR).
  • 范围外去向: none reported. No Skills-docs: line is owed.
  • 落地条款: contract review TIER_DEFAULT PASS on this head (6576263592) covers the Clause-②: yes (widening) declaration; patch is the AGENTS.md level for a non-protocol widening. mergeable_state is clean. Land by pr_ready + automerge_enable.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 11:44
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 2, 2026 11:44
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 5901871 Nov 2, 2026
56 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-y1aiyw branch November 2, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant