Skip to content

feat(rest): 请求→环境解析统一到 kernel-resolver 缝 — ADR-0076 D11 步骤④ (#2462) - #3487

Merged
os-zhuang merged 1 commit into
mainfrom
feat/d11-step4-env-resolution
Jul 25, 2026
Merged

feat(rest): 请求→环境解析统一到 kernel-resolver 缝 — ADR-0076 D11 步骤④ (#2462)#3487
os-zhuang merged 1 commit into
mainfrom
feat/d11-step4-env-resolution

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

动机(#2462 D11 步骤④)

REST 服务器一直维护着自己的 hostname/X-Environment-Id → environment 平行解析链,且同一条链在 resolveRequestEnvironmentIdresolveI18nServicecomputeExecCtx 里手抄了三份;而 HTTP dispatcher 早已把同一个问题交给 host 注入的 ADR-0006 kernel-resolver 缝(cloud 的 CloudKernelResolver,6 级解析链)。后果:同一个 unscoped 请求打在 dispatcher 面和 REST 面上可能归属不同的 environment(REST 链缺 session 级兜底,也不认 resolver 的 control-plane skip 语义)。

改动

  • 新增 RestRequestEnvResolver 缝(rest 包本地结构类型,照 RestKernelManager 模式避免 runtime↔rest 包环)。
  • RestApiPlugin 把 host 的 kernel-resolver 服务适配进该缝:装配 context{request}resolveKernel,回读 context.environmentIddefaultKernel 绑定 host kernel 服务面(resolver 的 session/default-project 级从它解析 auth/objectql/default-project)。cloud 侧零改动——kernel-resolverenv-registry 本就注册在同一 host kernel(objectos-stack.ts)。
  • resolveRequestEnvironmentId 成为唯一入口:explicit id → 注入 resolver(正常返回即终局,含 undefined=有意 unscoped;仅抛错才降级)→ 旧内建链(hostname → header)→ 单环境 default。三份手抄内联链收敛为一处调用。
  • envRegistry 链原样保留:OSS 单环境部署(无 resolver 服务)行为零变化,也是 resolver 异常时的降级路径。

行为差异(仅 cloud/多租户部署,需 review 把关)

resolver 在场时 unscoped REST 路由从 3 级链变为与 dispatcher 完全一致的 6 级链:

  1. 新增 session 兜底:hostname 未绑定且无 header 时,登录用户经 session.activeEnvironmentId / org default 解析——dispatcher 面早已如此,REST 面补齐(消除双面归属分歧)。
  2. skip 前缀语义:resolver 对 control-plane 路径返回 undefined 为终局,REST 不再二猜。REST 消费点均为数据面路由(REST 自己的 /discovery 直用 boot 时控制面 protocol,不做 env 解析),实际不受影响。
  3. hostname 缓存:cloud EnvironmentDriverRegistry 自带 TTL 缓存,REST 侧 30s 缓存仅在降级链中仍生效——双缓存的正式退役留给 D11 步骤③。

验证

  • 新增 rest-env-resolution.test.ts:9 条缝契约测试(explicit 短路 / resolver 优先 / undefined 终局 / 抛错降级 / 旧链原样 / header+default 兜底 / getOrCreate 路由 / plugin 装配含 facade 透传 / 无 resolver 正常服务)。
  • rest 包全量 348 测试绿;@objectstack/http-conformance 跨适配器 41 断言绿(两适配器 socket 级行为一致);--force 重建 rest 及 11 个下游包含 DTS 全绿。

Closes 部分 #2462(D11 步骤④)。步骤③(按域拆 dispatcher/rest-server)随后单独 PR。

🤖 Generated with Claude Code

…er seam — ADR-0076 D11 step ④ (#2462)
The REST server ran its own parallel hostname/X-Environment-Id chain
(hand-copied inline in resolveRequestEnvironmentId, resolveI18nService
and computeExecCtx) while the HTTP dispatcher resolves the same question
through the host-injected ADR-0006 kernel-resolver seam — the same
unscoped request could be attributed to different environments depending
on which HTTP surface served it.
- New RestRequestEnvResolver seam; RestApiPlugin adapts the host's
`kernel-resolver` service into it (cloud registers that service next
to `env-registry` already — zero cloud-side change).
- resolveRequestEnvironmentId is now THE single entry point; the two
inline copies collapse into it.
- Resolver verdicts are final (undefined = deliberately unscoped); only
a throw degrades to the legacy chain. Legacy chain unchanged for OSS
single-environment boots.
Verified: 9 new seam-contract tests, rest 348 tests green,
http-conformance 41 cross-adapter assertions green, DTS build of the
11-package dependent closure green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercelBot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
specReadyReadyPreview, CommentJul 25, 2026 3:15am

Request Review

@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation tests tooling size/m labels Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/rest.

8 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/api/error-catalog.mdx(via @objectstack/rest)
  • content/docs/api/error-handling-server.mdx(via @objectstack/rest)
  • content/docs/api/index.mdx(via @objectstack/rest)
  • content/docs/plugins/index.mdx(via @objectstack/rest)
  • content/docs/plugins/packages.mdx(via @objectstack/rest)
  • content/docs/protocol/kernel/i18n-standard.mdx(via packages/rest)
  • content/docs/releases/implementation-status.mdx(via @objectstack/rest)
  • content/docs/releases/v12.mdx(via @objectstack/rest)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationsize/mteststooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@os-zhuang