Skip to content

Commit d99b746

Browse files
fix(plugin-sharing): warn once per boot when a hierarchy scope falls back to owner-only (#35780)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao6bxiPKCvVuzoFTExumbxoz)_ Fixes #35172 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:运维人员在不经命令行启动的运行时里,第一次有人用到上下级可见范围而企业版组件没装时,日志里会出现一条警告,说明这些范围只按本人记录生效;终端用户无感。 - 为什么做:属于权限可见性排查这条线,替自托管运行时的运维人员解决「为什么每个人只看得到自己的记录」查不到原因的问题。 - 出错会怎样:最坏是这条警告不出现或多出现几次,访问结果本身不变;可以直接撤回。 - 要你做什么:无 ## What changes `SharingService.resolveOwnerScopeIds` (plugin-sharing) fails closed to owner-only when a hierarchy scope (`own_and_reports`, `unit`, `unit_and_below`) is asked for and no `hierarchy-scope-resolver` service is registered. That branch used to log nothing, so only `os serve` (the CLI line added by #35168) ever said so. - The first time that fallback is taken, the service logs one `warn` (`HIERARCHY_RESOLVER_ABSENT_NOTICE`), with meta `{ capability: 'hierarchy-security', provider, scope }`. The provider is read from `PLATFORM_CAPABILITY_PROVIDERS['hierarchy-security'].package`, so it is the same `@objectstack/security-enterprise` string `os validate` / `os verify` / `os serve` print. The prefix and level match the no-org warning just below it (`[sharing] hierarchy scope NOT widened: ...`, `warn`). Per AGENTS.md "Degradation log levels", this is a functional degradation, so `warn` is the right level. - **Once per boot.** The latch is a boolean on the service instance. The plugin builds exactly one `SharingService`, in its `kernel:ready` hook (`sharing-plugin.ts`), so one instance means one boot. The callers (read filter, write gates, share management, middleware) run per request. The condition belongs to the composition, not to a caller or an object, so a finer key would only repeat the line. The latch is claimed before the log, inside a `try`, so a throwing logger cannot fail a gate or throw once per request. - **Only when the fallback is taken.** `own`, `org` and an unset scope return before the resolver lookup, so an app that never uses a hierarchy scope logs nothing. A registered resolver also logs nothing. - **The CLI stops claiming silence for this token** (patch round 1, claim amendment 7033136082). `enterpriseAbsenceConsequence` (`packages/cli/src/utils/capability-preflight.ts`) used to end every enterprise-token sentence with "and no log line says so". A new table, `ENTERPRISE_ABSENCE_RUNTIME_NOTICE`, maps a token to the opening words of the warning its runtime logs. For `hierarchy-security`, the sentence now says the runtime logs one warning (`[sharing] hierarchy scope NOT widened ...`) the first time it falls back. Any token without a row keeps the old clause. I made it a separate table, not a clause folded into `ENTERPRISE_ABSENCE_CONSEQUENCE`, for two reasons. First, the consequence is what the metadata does and the notice is what the runtime says, and a token can have either without the other. Second, the exported table's type stays unchanged. - **Logging only.** The latch records no verdict: the resolver is still looked up on every call, and the returned ids are unchanged (`[me]`). `check:startup-registry-verdict` is green on this tree. ## Tests New top-level `describe` in `src/sharing-service.test.ts` (the shared harness file). It has six cases: - the notice names the capability, the registry provider and the owner-only consequence; - a resolver-less hierarchy scope warns once across two calls (`unit_and_below`, then `own_and_reports`) plus a public `canManageShares` gate, and every call answers `['bob']`; - a fresh instance, standing for a new boot, warns again; - CONTROL: `undefined` / `own` / `org` produce no `warn` at all; - CONTROL: a registered resolver produces no notice and returns its own ids; - a throwing logger leaves the answer intact and is called only once. The plugin-side notice pin also asserts the prefix the CLI quotes. `packages/cli/test/capability-preflight.test.ts` gains three pins: - every runtime-notice row keys an enterprise-edition registry token; - `hierarchy-security` no longer contains "no log line says so" and names the `[sharing] hierarchy scope NOT widened` prefix; - CONTROL: a generic token still says "no log line says so". ## Acceptance notes - The round-1 finding (the CLI sentence claiming "no log line says so") is fixed in this PR under the claim amendment. - Round 2 (claim amendment 7035179372, head `9c805c664c`), comment only: the comment on the unmounted-known-tokens block in `packages/cli/src/commands/serve.ts` no longer says the owner-only fallback happens "without a word". It now says the runtime logs it once at the first fallback, and that `os serve` says it at start-up, before any request. Readings on that file: eslint `--no-inline-config` exit 0; check:doc-authoring, check:issue-citations, check:nul-bytes, check:closed-ceremony-text and check-drift-comment all exit 0. ## Verification Two-minute check: `pnpm --filter @objectstack/plugin-sharing exec vitest run --maxWorkers=2 src/sharing-service.test.ts -t "said once per boot"` should show 6 passed. Files to read first: `packages/plugins/plugin-sharing/src/sharing-service.ts`. The risk hunk is the `if (!resolver)` branch in `resolveOwnerScopeIds`. Round-1 readings are on head `e26a7e36bb`. Round-0 readings, on `4ae41bb446`, are kept below. Two-minute check (CLI): `pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 test/capability-preflight.test.ts` should show 50 passed. <details><summary>Round 1 (e26a7e3): affected test files, CLI ablation, derived gates</summary> ``` narrowed build (core/types/lint/plugin-sharing closures) + both files, under os-verify-lock: test/capability-preflight.test.ts Tests 50 passed (50) src/sharing-service.test.ts Tests 174 passed (174) os-verify-lock: VERDICT command-exit 0 ablation: ENTERPRISE_ABSENCE_RUNTIME_NOTICE hierarchy-security row deleted ablation-replace: ok mutation landed: anchor 1 -> 0, blob deafdf7 -> a609ab686a4c x hierarchy-security no longer claims silence: it names the warning the runtime logs Tests 1 failed | 49 passed (50) ablation-replace: blob after restore deafdf7 ablation-replace: blob at HEAD deafdf7 Run reconciliation — 71 derived, 69 run, 2 NOT-MEASURED, 0 UNRUN. ``` NOT MEASURED: `check:dual-build-cjs-loads` and `check:i18n`. Reason: both exit 3 PREREQUISITE NOT MET, for want of a repo-wide build; CI runs both. Declared narrowing: the full CLI `unit` tier and `pnpm --filter @objectstack/cli typecheck` were not run locally. The verify lock was queued for about 75 minutes behind dogfood runs, so the build was narrowed to the closures the two touched test files import. CI `Test Core` and `TypeScript Type Check` run the full set. </details> Round 0 (`4ae41bb446`): <details><summary>Package test + typecheck (under os-verify-lock)</summary> ``` Test Files 75 passed (75) Tests 1601 passed (1601) > tsc --noEmit && tsc --noEmit -p tsconfig.scripts.json && pnpm check:test-typecheck os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation: latch removed, the once-pin goes red; restored by blob hash</summary> ``` ablation-replace: ok mutation landed: anchor 1 -> 0, blob 865061d -> a7557d5d43f7 x a hierarchy scope with no resolver warns ONCE across two calls, and still answers owner-only x a throwing logger neither fails the gate nor throws again Tests 2 failed | 4 passed | 168 skipped (174) ablation-replace: blob after restore 865061d ablation-replace: blob at HEAD 865061d ``` </details> <details><summary>Derived gates (dispatch-gates --commands, reconciled with --ran)</summary> ``` Run reconciliation — 67 derived, 65 run, 2 NOT-MEASURED, 0 UNRUN. dispatch-gates --ran: 67 derived famil(ies) accounted for — 65 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3). ``` NOT MEASURED: `check:dual-build-cjs-loads` and `check:i18n`. Reason: both exit 3, PREREQUISITE NOT MET, because they need a repo-wide build (58+ packages without `dist/`). CI runs both. As a direct substitute, the rebuilt `plugin-sharing` `dist/index.js` (CJS) and `dist/index.mjs` (ESM) both load and export `SharingService`. Also run, beyond the derivation: `check:startup-registry-verdict` exit 0 and `check:durability-log-level` exit 0. </details> Not run locally: the full `test:repo` project (CI `Test Core`), dogfood (no `!` and no narrowing arm), and `pnpm lint` (CI-owned). --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_ <!-- signed: repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 401eb44 commit d99b746

6 files changed

Lines changed: 221 additions & 9 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-sharing': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
fix(plugin-sharing): a hierarchy scope that falls back to owner-only for want of a resolver now says so once per boot
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
When a permission set grants a hierarchy scope (`own_and_reports`, `unit`, `unit_and_below`) and no `hierarchy-scope-resolver` service is registered (the `hierarchy-security` capability, provided by `@objectstack/security-enterprise`), the sharing layer fails closed to owner-only. It used to do so without a word, so a runtime booted without the CLI gave an operator nothing to explain why every user saw only their own records.
12+
13+
- The first time the fallback is taken, the sharing service logs one `warn` naming the capability, its provider and the owner-only consequence. It is logged once per service instance, which is once per boot, never once per request.
14+
- Nothing is logged for an app that never asks for a hierarchy scope, or when a resolver is registered.
15+
- The answer does not change: the scope still resolves to the caller alone.
16+
- `os validate`, `os verify` and `os serve` no longer end the `hierarchy-security` advisory with "and no log line says so": for that token they now say the runtime logs one warning, opening `[sharing] hierarchy scope NOT widened`, the first time it falls back. Other enterprise tokens keep their wording.

‎packages/cli/src/commands/serve.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5475,7 +5475,9 @@ export default class Serve extends Command {
54755475
// only from the app's own `plugins[]`, a cloud-only tier from a cloud
54765476
// runtime. The loop below stays quiet for those (they are known
54775477
// vocabulary, not typos), and the sharing layer then fails closed to
5478-
// owner-only without a word. Say it once at start-up, in the sentence
5478+
// owner-only; the runtime logs that once, at the first fallback, which
5479+
// may be long after boot. So say it here too, once at start-up and
5480+
// before any request, in the sentence
54795481
// `os validate` and `os verify` print for the same token, and only when
54805482
// nothing in `plugins[]` provides it. A warning, never a refusal: the
54815483
// boot is unchanged.

‎packages/cli/src/utils/capability-preflight.ts‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,48 @@ export function renderCapabilityMessage(c: DeclaredCapabilityClassification): st
9292
export const ENTERPRISE_ABSENCE_CONSEQUENCE: Readonly<Record<string, string>> = Object.freeze({
9393
// The sharing layer fails CLOSED without the `hierarchy-scope-resolver`
9494
// service (`SharingService.resolveOwnerScopeIds`, ADR-0057): a hierarchy
95-
// scope never widens, and nothing logs it.
95+
// scope never widens. What the runtime logs about it is
96+
// {@link ENTERPRISE_ABSENCE_RUNTIME_NOTICE}'s row.
9697
'hierarchy-security':
9798
"the hierarchy scopes (`own_and_reports`, `unit`, `unit_and_below`) behave as owner-only",
9899
});
99100

101+
/**
102+
* The warning the RUNTIME itself logs when an `enterprise` token's fallback is
103+
* taken, for the tokens whose runtime says so; the value is that warning's
104+
* opening words, as the operator will find them in the server log. A token
105+
* with no row here ends its sentence "and no log line says so", which is true
106+
* only while its runtime stays silent — so a runtime that starts logging adds
107+
* its row here in the same change, or the CLI goes on claiming a silence the
108+
* server log contradicts.
109+
*
110+
* A separate table rather than a clause folded into
111+
* {@link ENTERPRISE_ABSENCE_CONSEQUENCE}: the consequence is what the METADATA
112+
* does, the notice is what the RUNTIME says, and a token can have either one
113+
* without the other. Every key is pinned to an enterprise-edition registry row
114+
* in `capability-preflight.test.ts`.
115+
*/
116+
export const ENTERPRISE_ABSENCE_RUNTIME_NOTICE: Readonly<Record<string, string>> = Object.freeze({
117+
// `SharingService.resolveOwnerScopeIds` (plugin-sharing) logs this once per
118+
// boot, at `warn`, the first time a hierarchy scope falls back to owner-only.
119+
'hierarchy-security': '[sharing] hierarchy scope NOT widened',
120+
});
121+
100122
/**
101123
* The consequence sentence for an `enterprise` token with no provider wired in.
102-
* It names the edition that enforces the token and what the open edition does
103-
* instead, and nothing else: no product pitch, one fact an author can act on.
124+
* It names the edition that enforces the token, what the open edition does
125+
* instead, and whether the runtime says so — nothing else: no product pitch,
126+
* one fact an author can act on.
104127
*/
105128
export function enterpriseAbsenceConsequence(token: string): string {
106-
const shape = Object.prototype.hasOwnProperty.call(ENTERPRISE_ABSENCE_CONSEQUENCE, token)
129+
const has = (table: Readonly<Record<string, string>>) => Object.prototype.hasOwnProperty.call(table, token);
130+
const shape = has(ENTERPRISE_ABSENCE_CONSEQUENCE)
107131
? ENTERPRISE_ABSENCE_CONSEQUENCE[token]
108132
: `nothing provides "${token}", and the metadata that relies on it is not enforced`;
109-
return `Only the enterprise edition enforces it: without a wired provider, as on the open edition, ${shape}, and no log line says so.`;
133+
const said = has(ENTERPRISE_ABSENCE_RUNTIME_NOTICE)
134+
? `and the runtime logs one warning ("${ENTERPRISE_ABSENCE_RUNTIME_NOTICE[token]} …") the first time it falls back`
135+
: 'and no log line says so';
136+
return `Only the enterprise edition enforces it: without a wired provider, as on the open edition, ${shape}, ${said}.`;
110137
}
111138

112139
/** {@link renderCapabilityMessage} without the package prefix. */

‎packages/cli/test/capability-preflight.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { describe, expect, it } from 'vitest';
22
import {
33
ENTERPRISE_ABSENCE_CONSEQUENCE,
4+
ENTERPRISE_ABSENCE_RUNTIME_NOTICE,
5+
enterpriseAbsenceConsequence,
46
judgeDeclaredCapabilities,
57
preflightDeclaredCapabilities,
68
preflightProviderWiring,
@@ -384,6 +386,26 @@ describe('the enterprise consequence sentence', () => {
384386
}
385387
});
386388

389+
it('every runtime-notice row keys an enterprise-edition registry token', () => {
390+
for (const token of Object.keys(ENTERPRISE_ABSENCE_RUNTIME_NOTICE)) {
391+
expect(PLATFORM_CAPABILITY_PROVIDERS[token]?.edition, token).toBe('enterprise');
392+
}
393+
});
394+
395+
it('hierarchy-security no longer claims silence: it names the warning the runtime logs', () => {
396+
const m = enterpriseAbsenceConsequence('hierarchy-security');
397+
expect(m).not.toContain('no log line says so');
398+
// The prefix plugin-sharing's HIERARCHY_RESOLVER_ABSENT_NOTICE opens with.
399+
expect(m).toContain('[sharing] hierarchy scope NOT widened');
400+
});
401+
402+
it('CONTROL: a token whose runtime logs nothing still says so', () => {
403+
const m = enterpriseAbsenceConsequence('fixture-enterprise-token');
404+
expect(Object.prototype.hasOwnProperty.call(ENTERPRISE_ABSENCE_RUNTIME_NOTICE, 'fixture-enterprise-token')).toBe(false);
405+
expect(m).toContain('no log line says so');
406+
expect(m).not.toContain('[sharing]');
407+
});
408+
387409
it('hierarchy-security names the owner-only fallback, absent and unwired alike', async () => {
388410
const absent = renderCapabilityMessage(classifyRequiredCapability('hierarchy-security', () => false));
389411
const [unwired] = await preflightProviderWiring({

‎packages/plugins/plugin-sharing/src/sharing-service.test.ts‎

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import { describe, it, expect, beforeEach, vi } from 'vitest';
44
import { assertEngineDeleteDispatch } from '@objectstack/objectql';
5-
import { SharingService, type SharingServiceOptions } from './sharing-service.js';
5+
import {
6+
SharingService,
7+
HIERARCHY_RESOLVER_ABSENT_NOTICE,
8+
type SharingServiceOptions,
9+
} from './sharing-service.js';
610
import { buildSharingMiddleware } from './sharing-plugin.js';
711
import { bootRequestContext } from './exec-context-seam.testkit.js';
812
import { SysRecordShare } from './objects/sys-record-share.object.js';
@@ -2367,3 +2371,90 @@ describe('[#14484] grant stamps organization_id on both halves of the upsert', (
23672371
expect(engine._tables.sys_record_share[0].organization_id).toBe(ORG_CALLER);
23682372
});
23692373
});
2374+
2375+
describe('[ADR-0057] a missing hierarchy-scope resolver is said once per boot', () => {
2376+
const MANAGER_PROBE = {
2377+
hasWriteBypass: async () => false,
2378+
resolveWriteScope: async () => 'unit_and_below' as const,
2379+
};
2380+
const notices = (warn: ReturnType<typeof vi.fn>) =>
2381+
warn.mock.calls.filter((c) => c[0] === HIERARCHY_RESOLVER_ABSENT_NOTICE);
2382+
2383+
let engine: ReturnType<typeof makeFakeEngine>;
2384+
beforeEach(() => {
2385+
engine = makeFakeEngine({ account: ACCOUNT_SCHEMA, sys_record_share: {} });
2386+
engine._tables.account = [{ id: 'a1', name: 'Acme', owner_id: 'alice' }];
2387+
});
2388+
2389+
it('the notice names the capability, its registry provider and the owner-only consequence', () => {
2390+
expect(HIERARCHY_RESOLVER_ABSENT_NOTICE).toContain('"hierarchy-security"');
2391+
expect(HIERARCHY_RESOLVER_ABSENT_NOTICE).toContain('@objectstack/security-enterprise');
2392+
expect(HIERARCHY_RESOLVER_ABSENT_NOTICE).toContain('owner-only');
2393+
// `os validate` / `os verify` / `os serve` quote these opening words
2394+
// (`ENTERPRISE_ABSENCE_RUNTIME_NOTICE` in the CLI's capability-preflight).
2395+
expect(HIERARCHY_RESOLVER_ABSENT_NOTICE.startsWith('[sharing] hierarchy scope NOT widened')).toBe(true);
2396+
});
2397+
2398+
it('a hierarchy scope with no resolver warns ONCE across two calls, and still answers owner-only', async () => {
2399+
const warn = vi.fn();
2400+
const svc = new SharingService({ engine, securityService: () => MANAGER_PROBE, logger: { warn } });
2401+
const bob = await bootRequestContext({ userId: 'bob', activeOrganizationId: 'org_a' });
2402+
const resolve = (s: any) => (svc as any).resolveOwnerScopeIds(bob, s);
2403+
2404+
expect(await resolve('unit_and_below')).toEqual(['bob']);
2405+
expect(await resolve('own_and_reports')).toEqual(['bob']);
2406+
// Through a public gate too: the verdict is the owner-only one.
2407+
expect(await svc.canManageShares('account', 'a1', bob)).toBe(false);
2408+
2409+
expect(notices(warn)).toHaveLength(1);
2410+
expect(notices(warn)[0][1]).toMatchObject({
2411+
capability: 'hierarchy-security',
2412+
provider: '@objectstack/security-enterprise',
2413+
scope: 'unit_and_below',
2414+
});
2415+
});
2416+
2417+
it('a fresh service instance (a new boot) says it again', async () => {
2418+
const warn = vi.fn();
2419+
const bob = await bootRequestContext({ userId: 'bob', activeOrganizationId: 'org_a' });
2420+
for (let boot = 0; boot < 2; boot++) {
2421+
const svc = new SharingService({ engine, logger: { warn } });
2422+
expect(await (svc as any).resolveOwnerScopeIds(bob, 'unit')).toEqual(['bob']);
2423+
}
2424+
expect(notices(warn)).toHaveLength(2);
2425+
});
2426+
2427+
it('CONTROL: non-hierarchy scopes take no fallback and log nothing', async () => {
2428+
const warn = vi.fn();
2429+
const svc = new SharingService({ engine, logger: { warn } });
2430+
const bob = await bootRequestContext({ userId: 'bob', activeOrganizationId: 'org_a' });
2431+
for (const scope of [undefined, 'own', 'org'] as const) {
2432+
expect(await (svc as any).resolveOwnerScopeIds(bob, scope)).toEqual(['bob']);
2433+
}
2434+
expect(await svc.canManageShares('account', 'a1', { userId: 'alice' })).toBe(true);
2435+
expect(warn).not.toHaveBeenCalled();
2436+
});
2437+
2438+
it('CONTROL: a registered resolver takes no fallback and logs nothing', async () => {
2439+
const warn = vi.fn();
2440+
const svc = new SharingService({
2441+
engine,
2442+
securityService: () => MANAGER_PROBE,
2443+
hierarchyResolver: () => ({ resolveOwnerIds: async () => ['bob', 'alice'] }),
2444+
tenancy: () => ({ posture: 'single' }),
2445+
logger: { warn },
2446+
});
2447+
const bob = await bootRequestContext({ userId: 'bob', activeOrganizationId: 'org_a' });
2448+
expect(await (svc as any).resolveOwnerScopeIds(bob, 'unit_and_below')).toEqual(['bob', 'alice']);
2449+
expect(notices(warn)).toHaveLength(0);
2450+
});
2451+
2452+
it('a throwing logger neither fails the gate nor throws again', async () => {
2453+
const warn = vi.fn(() => { throw new Error('sink down'); });
2454+
const svc = new SharingService({ engine, logger: { warn } });
2455+
const bob = await bootRequestContext({ userId: 'bob', activeOrganizationId: 'org_a' });
2456+
expect(await (svc as any).resolveOwnerScopeIds(bob, 'unit')).toEqual(['bob']);
2457+
expect(await (svc as any).resolveOwnerScopeIds(bob, 'unit')).toEqual(['bob']);
2458+
expect(warn).toHaveBeenCalledTimes(1);
2459+
});
2460+
});

‎packages/plugins/plugin-sharing/src/sharing-service.ts‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
// since commit aa4b90d9a (the full-envelope ruling: no per-site subset contracts). Annotating the
2727
// implementations with a narrower shape is what forced this file to cast its
2828
// way out of its own contract to read fields the caller had already supplied.
29-
import type { ExecutionContext } from '@objectstack/spec/kernel';
29+
import { PLATFORM_CAPABILITY_PROVIDERS, type ExecutionContext } from '@objectstack/spec/kernel';
3030
// [commit 3f64fe6c6] The engine's own answer to "which column is this object walled
3131
// by?" — the twin of `SqlDriver.computeTenantField`, so the organization a grant
3232
// is stamped from is read off the SAME column the wall scopes the record by.
@@ -443,6 +443,30 @@ export const PHANTOM_ANCHOR_WRITE_DENY_NOTICE =
443443
'injected anchor, not a remote column, so ownership can never match; ' +
444444
'declare the real remote owner column or change the sharing model';
445445

446+
/**
447+
* [ADR-0057] The provider of the `hierarchy-security` capability, read from the
448+
* capability registry so this line names the SAME package `os validate`,
449+
* `os verify` and `os serve` name for the token.
450+
*/
451+
const HIERARCHY_SECURITY_PROVIDER =
452+
PLATFORM_CAPABILITY_PROVIDERS['hierarchy-security'].package;
453+
454+
/**
455+
* [ADR-0057] Logged ONCE per service instance (one per boot), the first time a
456+
* hierarchy scope (`own_and_reports` / `unit` / `unit_and_below`) is asked for
457+
* while no `hierarchy-scope-resolver` service is registered — the moment
458+
* {@link SharingService.resolveOwnerScopeIds} falls back to owner-only. A
459+
* functional degradation (the scope is narrower, nothing is lost), hence WARN.
460+
* The CLI says the same at `os serve` start; this is the line a runtime booted
461+
* without the CLI prints.
462+
*/
463+
export const HIERARCHY_RESOLVER_ABSENT_NOTICE =
464+
'[sharing] hierarchy scope NOT widened: capability "hierarchy-security" has no provider — ' +
465+
`no hierarchy-scope-resolver service is registered (${HIERARCHY_SECURITY_PROVIDER} provides it), ` +
466+
'so the hierarchy scopes (`own_and_reports`, `unit`, `unit_and_below`) behave as owner-only. ' +
467+
`Install ${HIERARCHY_SECURITY_PROVIDER} and add its plugin to \`plugins[]\` to widen them. ` +
468+
'Logged once per boot.';
469+
446470
/**
447471
* [#27662] The second silent cause of the same refusal: a federated object
448472
* whose owner column is NOT the phantom anchor — the author mapped a remote
@@ -682,6 +706,20 @@ export class SharingService implements ISharingService {
682706
*/
683707
private readonly phantomAnchorNotified = new Set<string>();
684708

709+
/**
710+
* [ADR-0057] Has {@link HIERARCHY_RESOLVER_ABSENT_NOTICE} been logged?
711+
*
712+
* One boolean per service instance. The plugin builds ONE service at
713+
* `kernel:ready`, so this is once per boot, while the fallback it reports
714+
* runs on every read, write and share-management gate. The condition is a
715+
* property of the composition, not of the caller or the object, so no key
716+
* finer than the instance adds anything but repeats. Set only when the
717+
* fallback is TAKEN: an app that never asks for a hierarchy scope logs
718+
* nothing. It records no verdict — the resolver is still looked up on every
719+
* call, so the returned ids never depend on it.
720+
*/
721+
private hierarchyResolverAbsenceNoted = false;
722+
685723
constructor(options: SharingServiceOptions) {
686724
this.engine = options.engine;
687725
this.hierarchyResolver = options.hierarchyResolver;
@@ -2474,7 +2512,23 @@ export class SharingService implements ISharingService {
24742512
const me = String(context.userId);
24752513
if (!scope || scope === 'own' || scope === 'org') return [me];
24762514
const resolver = this.hierarchyResolver?.();
2477-
if (!resolver) return [me];
2515+
if (!resolver) {
2516+
if (!this.hierarchyResolverAbsenceNoted) {
2517+
// Latch BEFORE the log, so a throwing logger cannot turn one line
2518+
// into one throw per request (#6783's ordering).
2519+
this.hierarchyResolverAbsenceNoted = true;
2520+
try {
2521+
this.logger?.warn?.(HIERARCHY_RESOLVER_ABSENT_NOTICE, {
2522+
capability: 'hierarchy-security',
2523+
provider: HIERARCHY_SECURITY_PROVIDER,
2524+
scope,
2525+
});
2526+
} catch {
2527+
/* a diagnostic must never fail, or change, an access verdict */
2528+
}
2529+
}
2530+
return [me];
2531+
}
24782532

24792533
const organizationId = activeOrganizationId(context);
24802534
if (organizationId === null && this.organizationScopeRequired()) {

0 commit comments

Comments
 (0)