Repository navigation
feat(spec,runtime): an AI route's req.user carries impersonatedBy and the admitting credential kind - #34736
Conversation
… the admitting credential kind The AI domain hands every AI route handler the session's impersonating administrator (ExecutionContext.impersonatedBy, as is) and which credential admitted the caller (session | api_key | oauth, the one reading the membership gate and the api-action forward take; a session token in an Authorization: Bearer header is session). The spec declares the route's user type, AIRouteUser, and the vocabulary, AIRouteCredentialKind; the runtime's AdmittingCredentialKind now names the spec's type. The pending 33808 changeset's FROM line no longer lists a bearer token among refused credentials: a bearer-carried session is the person's session. Claude-Session: https://claude.ai/code/session_01ADHkmSPLX3Q1ZVi4YC8GKg Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 47 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 178 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 5e71cbaf1859306068f82511b6868c81208e19cc && git checkout 5e71cbaf1859306068f82511b6868c81208e19cc
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e4a16d05e84d62895a6e3f8d77ab093f7417dba0 16f04a5fbdb3e6c84472dd5d6f00c04a429a2949 && git checkout -B drift-repro e4a16d05e84d62895a6e3f8d77ab093f7417dba0 && git merge --no-ff 16f04a5fbdb3e6c84472dd5d6f00c04a429a2949
node scripts/docs-audit/affected-docs.mjs --json e4a16d05e84d62895a6e3f8d77ab093f7417dba0
|
…er test Claude-Session: https://claude.ai/code/session_01ADHkmSPLX3Q1ZVi4YC8GKg Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp Final head for review: |
|
repo:objectstack#3 · os-support-ai · session_01WGufzi8zDwpH6wX7ZPUcHR 席位核对L1 first review (full) · ACCEPT (one nit) · Head-sha: There is no earlier L1 or contract-review record on any head. Inputs:
Scope reading. This is not security behaviour. No authorization decision moves. Nit
Checklist
Owed, for the seat: a contract review at CONTRACT_REVIEW_TIER. It is owed for the two new public exports of |
|
repo:objectstack#3 · os-support-ai · session_01WGufzgh1zkZzDXL36ckWAG Contract reviewServed-tier: First contract review of PR #34736 (card #34184). Read: the card body and all seven comments (seat analysis 6931424442, ruling 6942875153, claim 6943289412, dev report 6944692301, hand-off 6948356800, takeover 6949051710), the PR body, the eight-file list, the net diff against ① Derived judgments
② Semver levelClause-②: yes — matches the tree: the diff widens the published surface by two exports and narrows nothing. The takeover claim's
Check Changeset (red, two runs: 133952505706, 133958977656). Two questions:
③ Boundary flags
④ Design judgmentNo must-fix, no should-fix.
Check-runs on the head: 56 success, 13 skipped, 2 failure (both Nits (none affects correctness or what a consumer may rely on; each is left as an accepted deviation or a follow-up card, since a fix on this face moves the head):
Implemented-by: VERDICT: PASS |
…ing #34736) Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX
|
repo:objectstack#3 · os-support-ai · session_01WGufzfr1xZSFZzCR8HnqXX Landing · PR #34736 (card #34184) · head
|
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 44100385301 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
|
repo:objectstack#3 · os-support-ai · session_01WGufzfr1xZSFZzCR8HnqXX Queue ejection read · PR #34736 · queue run 44100385301 (triage 6951123107) · head Signature:
If the same signature ejects it again, it stops here and goes to the next seat to diagnose again. |
Requested by Steve · project thread
Fixes #34184
Clause-②: yes
Metadata-protocol: none
维护者速读
req.user多了两项:impersonatedBy(管理员模拟登录时是哪位管理员)和credential(凭什么凭据进来:session/api_key/oauth);spec 新增这个路由用户类型AIRouteUser和词表AIRouteCredentialKind。session),Q2 A(impersonatedBy原样交给门判断)。/actions和 MCPrun_action的ctx.user不动。回滚即 revert 本 PR。另改了尚未发版的 33808 changeset 一句措辞(不再把 Bearer 令牌列为被拒凭据)。packages/runtime/src/domains/ai.ts(组装req.user的一段)、packages/spec/src/contracts/ai-service.ts(AIRouteUser的两项说明)、.changeset/33808-ai-door-confirmation-in-app.md(改的那一句)。pnpm --filter @objectstack/runtime exec vitest run src/domains/ai-request-user-credential.test.ts,预期 9 个用例全过(cookie 会话、模拟会话、API Key、Bearer 会话各一例等)。What changes
@objectstack/spec/contracts(contracts/ai-service.ts) declares the AI-route caller:AIRouteCredentialKind = 'session' | 'api_key' | 'oauth'.sessionis a signed-in session whichever carrier brought its token (cookie orAuthorization: Bearer), per ruling 6942875153 Q1 A.AIRouteUser extends EvalUser: the actor envelope's keys (id,userId,name,displayName,positions,permissions,systemPermissions) plus two route facts,impersonatedBy?(carried as is, a fact the door judges and never the authorization subject, per Q2 A) andcredential?(absent when the request recorded none; the contract tells a door to read anything but'session', absence included, as not that session).@objectstack/runtime:domains/ai.tsbuildsreq.useras anAIRouteUser: the existingactorUserFromExecutionContextenvelope, plusimpersonatedByfromec.impersonatedBy(trimmed; blank adds no key) andcredentialfromadmittingCredentialKind(context), the one reading the environment-membership gate and the api-action forward already take. Both keys are absent, neverundefined, when there is nothing to say.security/admitting-credential.ts:AdmittingCredentialKindnow names the spec'sAIRouteCredentialKind, so the gate and the route spell the credential one way..changeset/33808-ai-door-confirmation-in-app.md(pending, not yet released) — DELIBERATE CORRECTION of one FROM/TO line. Before: "with an API key or bearer token TO the person's signed-in session to the app." After: "with an API key, an OAuth token or another service credential TO the person's signed-in session to the app, whether its session token rides in the cookie or in anAuthorization: Bearerheader." The seat's execution note under ruling 6942875153 asked for this: under Q1 A a bearer-carried session is the person's session, so listing "bearer token" among refused credentials contradicted the ruling.Check Changesetmay read the edit of another card's changeset; this paragraph is its declaration..changeset/34184-ai-route-user-credential.md(@objectstack/specpatch,@objectstack/runtimepatch;Metadata-protocol: nonetakes patch).No existing test was changed.
Tests
New
packages/runtime/src/domains/ai-request-user-credential.test.ts, 9 cases:HttpDispatcher.dispatch()(the real identity step,resolveAuthzContext): session cookie →session, noimpersonatedBykey; impersonated session →session+impersonatedBy= the admin,idstays the user; API key (x-api-key) →api_key; API key beside an impersonated session cookie →api_key, noimpersonatedBy; session token inAuthorization: Bearer→session; impersonated session token in a bearer header →session+impersonatedBy. The fake auth service plays better-auth's bearer plugin (one session read per token, whichever carrier).handleAIRequest: an agent principal carryingoauthScopes→oauth; an authenticated context with no admission → nocredentialkey; a blankimpersonatedBy→ no key.Ablation (one-shot, not kept)
node scripts/ablation-replace.mjs --file packages/runtime/src/domains/ai.ts --anchor ANCHOR (the two spread lines) --delete -- bash scripts/pm/os-verify-lock.sh -c "pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/ai-request-user-credential.test.ts"Tests 8 failed | 1 passed (9): every case pinning a key goes red; the one that stays green is the "no admission ⇒ no credential key" control, which an absent key satisfies by design.git diff HEADempty.Acceptance notes
AIRouteUserre-declares the actor envelope's key set that runtime'sActorUser(security/actor-user.ts) also declares; the runtime assignmentuser: AIRouteUser = { ...actor, … }makes the compiler refuse anActorUserthat loses a key the spec requires, but a key added toActorUseralone would not be caught. Not filed: no reproducible defect today.in-app-pending-action-decided-by-person,.changeset/34189-pending-action-decide-session.md, theIAIService.rejectPendingActiondocblock) read as OAuth/service tokens under Q1 A and were left as is; the contract prose inAI_ACTION_CONFIRMATION_CAPABILITYalready says "a delegated or OAuth token"..changeset/*.mdwhen the maintainer releases: if it ships before this PR lands, the 33808 sentence goes out as it was and the correction becomes a docs-only amend of the released entry.Verification
Head
30f7347df0(the second commit adds one module-topimport '@objectstack/metadata'to the new test, whichcheck:test-source-aliasasked for; nothing else changed since924dbf5b91).pnpm --filter @objectstack/runtime exec vitest run src/domains/ai-request-user-credential.test.ts src/domains/ai-request-user-capability-channel.test.ts src/domains/ai-anonymous-deny-ordering.test.ts src/action-ctx-user-shape.test.ts src/domains/api-action-forward.test.tson30f7347df0:Test Files 5 passed (5),Tests 145 passed (145).pnpm --filter @objectstack/runtime typecheck && pnpm --filter @objectstack/spec typecheckunder the verify lock:VERDICT command-exit 0.pnpm --filter @objectstack/spec check:generated→All 14 generated artifacts are up to date(aftergen:api-surfaceandgen:export-origins, the two it named stale).dispatch-gates --commandsderived 92; all 92 ran with exit codes recorded;dispatch-gates --ran→92 derived, 92 run, 0 NOT-MEASURED. 91 exit 0. The one red ischeck-empty-changeset.mjs --base origin/main, by design: it refuses the edit of the pending33808note, which this PR declares above as a DELIBERATE CORRECTION.check:dual-build-cjs-loadsanswered exit 3 (no dists) on the first pass and exit 0 after a fullpnpm build; it and six test-family gates were re-run on30f7347df0.30f7347df0:Check Changesetis red for the same reason (Reject an empty-frontmatter changeset added by this PR:.changeset/33808-ai-door-confirmation-in-app.md exists on the merge base and was not added by this PR), the confirming record being the seat's, per that gate's own text. Every other completed check is green or skipped by its filter; Test Core, Test UI and Type Check · workspace were still running when this was written.!in the title, no(narrowing)arm).