Skip to content

Commit 0a383d6

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-c9oqlr
2 parents 6903a73 + 90cea47 commit 0a383d6

14 files changed

Lines changed: 1101 additions & 244 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
refactor(objectql): `ScopedContext`'s two bodies that hand the instance on move into its facet
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- The bodies of `ScopedContext#transaction` and of its symbol-keyed grants seeding step (the one a hook's `runAs: 'user'` api awaits) move out of `engine.ts` into `engine-scoped-context.ts`. Each method stays on the class as a one-call stub with its signature and docblock. Where a body handed the context itself on (`return this`, `callback(this, …)`), it reads the same instance through its host's `facade` entry.
11+
- No behaviour changes and nothing to do on upgrade. The built declaration files keep every member and every docblock; the source maps move.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql): a by-id delete the driver answers as removing nothing leaves no recycle-bin entry
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The recycle bin writes its entry before the record's row is removed, so a bin that cannot take the entry refuses the delete before anything goes. When the driver then answers that it removed nothing (`false`, or a count of `0`: the row was already gone, filtered out, or lost a race), the entry used to stay, naming a record that is still live. Admins saw it in the recycle-bin list, and a restore of it was refused `409 RESTORE_UNIQUE_VALUE_TAKEN`, until the retention sweep reaped it. The engine now removes that entry in the same unit of work, inside the delete's transaction when one covers the bin, so the recycle-bin list no longer shows such entries. A delete the driver confirms still writes exactly one entry, its `recycleBinEntryId` answer is unchanged, and the snapshot, restore and purge are untouched. If the entry cannot be removed, the engine logs it once at `error` and the delete's answer stays the same.

‎.claude/skills/pm-dispatch/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报
162162
| `domain:spec` | `packages/spec` 整包:schema 形状、`contracts/**`、退役行为半边、strictness 台账;describe/JSDoc/墓碑散文/错误 guidance 与 alias 表;`packages/spec/scripts/**`、`packages/spec/docs/**` 及按锚定规则的例外归本域的工具链(域边界枚举与席内分派见 `references/lanes/spec.md`) |
163163
| `domain:ui` | `ui/**` 全部代码:`@object-ui/*` 库与 `ui/apps/*`、`ui/packages/types` 与 schema 语料、`ui/scripts` 与门禁工具、文档随所记录的面走;`packages/console`(dist 由 `pnpm console:build` 生成 ⛔ 不手改);协议恒归 `domain:spec`,受管面归 `domain:skills`;详见 `references/lanes/ui.md` |
164164
| `domain:cloud` | 涉 cloud 即整卡归 cloud PM(`repo:cloud` 席,同挂 `repo:cloud`):读或改 cloud 代码、生产方、事实或带 cloud 半边;本仓车道 ⛔ 不认领;cloud PM 跟到关卡,余下纯本仓活由它写明 cloud 事实后另立卡;判据见 `references/cross-repo-coordination.md` |
165-
| `security` · `review`(车道,无 `domain:*` 标签) | 本仓安全公告(无文件面;修复落在归属包;私有仓卡归该仓车道,cloud 即上行);席位 `security#N` 与职责见 `references/lanes/security.md`;永不公开的规则只住 `references/security-findings.md`。复核席 `review#N` 见 `references/lanes/review.md` |
165+
| `security` · `review` · `eval`(车道,无 `domain:*` 标签) | 本仓安全公告(私有仓卡归该仓车道,cloud 即上行);席位 `security#N` 见 `references/lanes/security.md`;永不公开的规则只住 `references/security-findings.md`。复核席、AI 评测席各见 `references/lanes/review.md`、`references/lanes/eval.md` |
166166
| (无固定归属,按落点分诊) | `packages/apps/*`、`examples/*`(归它演练的子系统,测试基建见 devx 行)、`docs/audits/**` |
167167

168168
- 表未覆盖的包首次分诊时归类并走 PR 更新本表;新增或退役 `domain:*` 必须同批改本表。
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 车道章程:AI 评测席(eval)
2+
见 seat-lifecycle.md;本文是本车道岗位说明,现值状态恒在座位贴,⛔ 不迁入本文。
3+
4+
## 座位与唤醒
5+
6+
- 席位 `eval#N`,首席 `eval#1`;签名、座位贴、信箱同他席;无 `domain:*` 标签、无 `pm:queue`。
7+
- 节奏由维护者在 Routines 设定;⛔ 本席不自建、不改频率。
8+
- 建议节奏:每周一轮场景卡;每次发版一轮问数基线。
9+
10+
## 评测范围
11+
12+
- ① 场景卡(cloud 场景库专题建成的场景库):Claude Code 经 MCP 跑搭建与运行两半,确定性打分。
13+
- ② 产品内问数基线:cloud `packages/service-ai-studio/src/evals/run-ask-accuracy-cli.ts`。
14+
- 它对本地 objectos-ee 运行,按正确、有引用、无泄露三项评分。
15+
- ③ 托管聊天评测集的 13 个场景:仓库密钥配齐后纳入。
16+
- ④ AI 写数据五道关卡:建成后纳入例行。
17+
18+
## 成本规则
19+
20+
- 默认走 Claude Code 订阅,守维护者成本原则:目前阶段尽量不用云端 token,API 更贵。
21+
- ②③ 必须调 API,只在维护者批准的预算内运行;每轮记模型与花费,三周读数进座位贴。
22+
- 模型与频次:低成本或与托管默认一致;每次发版跑一次,不做每晚回归。
23+
- 题次:首次每题 1 次(30 轮);正式基线每题 5 次(150 轮)。
24+
25+
## 产出
26+
27+
- 每轮一份评分卡,附与上一轮的趋势对比。
28+
- 产品缺陷按立卡门交对应车道;评分误判交跑分器维护者。
29+
30+
## 边界
31+
32+
- ⛔ 不派 `os-dev`、不改产品代码、不开 PR。
33+
- 技能文本归 `domain:skills`;本席见文本问题以 `finding` 报。
34+
- 安全发现(含任何泄露)只照 `../security-findings.md`;评分卡里的泄露只写有泄露,⛔ 不写内容。
35+
- ⛔ 不对外发布准确率数字;对外口径由维护者决定。
36+
37+
## 地盘
38+
39+
- 本仓:`docs/qa/scenarios/**`、`packages/qa/`、`packages/cli/src/lint/` 下的跑分器文件。
40+
- cloud:`packages/service-ai-studio/src/evals/` 的运行与题库维护;代码修改仍走对应车道。
41+
42+
## 交接
43+
44+
- cloud 场景库专题建完场景库、运行器与跑分器后,例行运行移交本席,该专题关闭。
45+
- cloud 首个问数基线由本席在本地执行;托管聊天评测集与五道关卡就绪即纳入例行。

‎.claude/skills/pm-dispatch/references/project-forms.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- 项目指令只有一行:`pm-dispatch <席位> [<席位>…]`,如 `pm-dispatch 总监`、`pm-dispatch ui skills`。
1414
- 首词恒为技能目录名 `pm-dispatch`;⛔ 不用 `fleet`,它已是 bot 与中继的名字。
1515
- 席位词 = 中文名或车道文件名:总监 = `lanes/director.md`,分诊 = `triage.md`,复核 = `review.md`。
16-
- 其余席位词同 `lanes/<lane>.md` 文件名:ui、skills、devx、server、spec、hotcrm、mobile、qa。
16+
- 其余席位词同 `lanes/<lane>.md` 文件名:ui、skills、devx、server、spec、hotcrm、mobile、qa、eval。
1717
- 一车道多席:协调者取 🟢 行写本账号的那一席;无则取空席;再无则问维护者一次。
1818
- 其余一切住本文:⛔ 不往项目里贴模板;⛔ 不在账号层复制技能。
1919

‎packages/objectql/src/engine-scoped-context.ts‎

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
/**
44
* [#30052 codemod] The "Scoped execution context: repositories, elevation,
55
* transactions" section: the bodies of `ScopedContext`'s methods `object`,
6-
* `sudo`, `withRunAs`, `releaseJoinedHandle`, `txDriver`, `beginTransaction`,
7-
* `commitTransaction`, `rollbackTransaction`, `serveFormulaField` moved out of
8-
* `engine.ts` whole by `scripts/codemod-split-engine.mjs` (its second pass).
6+
* `sudo`, `withRunAs`, `[SEED_USER_GRANTS]`, `transaction`,
7+
* `releaseJoinedHandle`, `txDriver`, `beginTransaction`, `commitTransaction`,
8+
* `rollbackTransaction`, `serveFormulaField` moved out of `engine.ts` whole by
9+
* `scripts/codemod-split-engine.mjs` (its second pass).
910
* The bodies of `derive` and `[APP_AUTHORED_HOOK_API]` moved by hand
1011
* (#30975): each writes the private `appAuthored` of the instance it builds,
1112
* which the codemod refuses to move (`foreign-private`), so each writes it
@@ -37,7 +38,11 @@
3738
import { driverSupportsTransactions } from '@objectstack/spec/data';
3839
import type { IScopedContext } from '@objectstack/spec/contracts';
3940
import type { ExecutionContext } from '@objectstack/spec/kernel';
40-
import { appAutomationElevationOf, markAppAutomationElevation } from '@objectstack/core';
41+
import { appAutomationElevationOf, markAppAutomationElevation, resolveUserAuthzGrants } from '@objectstack/core';
42+
import type { EngineTransactionInfo, EngineTransactionOptions } from '@objectstack/core';
43+
import { rolledBackRefusal } from './summary-errors.js';
44+
import { TransactionUnsupportedError } from './transaction-errors.js';
45+
import { redactPropagatedDriverFault } from '@objectstack/types';
4146
import { UnscopedHookApi } from './hook-run-as.js';
4247
import { refuseAppAuthoredPermanentDelete } from './recycle-bin/app-authored-delete.js';
4348
import type { HookRunAs, HookRunAsRef } from './hook-run-as.js';
@@ -57,6 +62,8 @@ export interface ScopedContextHost {
5762
derive: ScopedContext['derive'];
5863
readonly engine: ScopedContext['engine'];
5964
readonly executionContext: ScopedContext['executionContext'];
65+
/** The instance itself: a moved body reads `this.facade` where the method read a bare `this` (#30020). */
66+
readonly facade: ScopedContext;
6067
readonly joinedHandles: ScopedContext['joinedHandles'];
6168
releaseJoinedHandle: ScopedContext['releaseJoinedHandle'];
6269
txDriver: ScopedContext['txDriver'];
@@ -121,6 +128,111 @@ export class ScopedContextFacet {
121128
return this.derive({ ...this.executionContext, isSystem: false });
122129
}
123130

131+
/** The body of `ScopedContext#[SEED_USER_GRANTS]`; the method's docblock there is its contract. */
132+
static async seedUserGrants(this: Pick<ScopedContextHost, 'derive' | 'engine' | 'executionContext' | 'facade'>): Promise<ScopedContext> {
133+
const ctx = this.executionContext;
134+
if (!ctx.userId) return this.facade;
135+
const needsGrants = !Array.isArray(ctx.permissions);
136+
const needsPeers = !Array.isArray(ctx.org_user_ids);
137+
const needsEmail = !ctx.email;
138+
if (!needsGrants && !needsPeers && !needsEmail) return this.facade;
139+
const grants = await resolveUserAuthzGrants(
140+
this.engine,
141+
ctx.userId,
142+
ctx.tenantId ? { tenantId: ctx.tenantId } : {},
143+
);
144+
return this.derive({
145+
...ctx,
146+
...(needsGrants ? { positions: grants.positions, permissions: grants.permissions } : {}),
147+
...(needsPeers ? { org_user_ids: grants.org_user_ids } : {}),
148+
...(needsEmail && grants.email ? { email: grants.email } : {}),
149+
});
150+
}
151+
152+
/** The body of `ScopedContext#transaction`; the method's docblock there is its contract. */
153+
static async transaction(this: Pick<ScopedContextHost, 'derive' | 'engine' | 'executionContext' | 'facade'>, callback: (trxCtx: ScopedContext, info: EngineTransactionInfo) => Promise<any>, opts?: EngineTransactionOptions): Promise<any> {
154+
const engine = this.engine as any;
155+
// The engine's ambient transaction store (ADR-0034), reached the `as any`
156+
// way this whole class reaches engine internals, for the D2 join below. A
157+
// transaction this call opens is published by the engine's own helper.
158+
const txStore = engine?.txStore as
159+
| { getStore(): { transaction: unknown } | undefined }
160+
| undefined;
161+
162+
// ADR-0067 D2 — JOIN an already-open ambient transaction instead of opening
163+
// a nested driver one (#6168). Same first move, same reasons and the same
164+
// shape as `ObjectQL.transaction`: a nested begin would take a second
165+
// connection AND would not be covered by the outer rollback, so the outer
166+
// caller would stop owning the one-and-only commit/rollback.
167+
//
168+
// BEFORE the driver/`require` handling on purpose, mirroring the engine:
169+
// when there is an ambient transaction there IS a transaction, so
170+
// `require: true` is satisfied by joining it and the degrade is not
171+
// reachable.
172+
const ambient = txStore?.getStore();
173+
if (ambient?.transaction) {
174+
// The handle is threaded EXPLICITLY into the child context, not left to
175+
// the ambient store, for the same reason the engine surface threads it:
176+
// `buildDriverOptions` prefers the explicit handle, and it survives async
177+
// boundaries the store does not. It is identity-equal to the store's
178+
// handle, so `transactionCoversDriverFor` still attributes it to the
179+
// OUTER owner and the #5351 same-origin gate judges it unchanged.
180+
const joinedCtx = this.derive({ ...this.executionContext, transaction: ambient.transaction });
181+
// JOINED, not owned: the outer caller decides commit vs rollback (#5696).
182+
return callback(joinedCtx, { owned: false });
183+
}
184+
185+
// Find the default driver for transaction support
186+
const driver = engine.defaultDriver
187+
? engine.drivers?.get(engine.defaultDriver)
188+
: undefined;
189+
190+
// [#18063] Declaration, not bare method presence — see the engine surface's
191+
// gate; one predicate serves both so they cannot answer differently.
192+
if (!driverSupportsTransactions(driver)) {
193+
const datasource = engine.defaultDriver ?? driver?.name;
194+
if (opts?.require === true) {
195+
// Same fail-closed refusal as the engine surface (#5696 point 1).
196+
throw new TransactionUnsupportedError(datasource ?? '<no default datasource>');
197+
}
198+
// No transaction support — execute directly. Declared (ADR-0119 D1), but
199+
// said out loud since #4619: the caller asked for atomicity and the
200+
// callback is about to run without any.
201+
engine.warnTransactionUnsupported?.(datasource, driver?.supports?.transactionsUnsupported === true);
202+
return callback(this.facade, { owned: false });
203+
}
204+
205+
const trx = await driver.beginTransaction();
206+
const trxCtx = this.derive({ ...this.executionContext, transaction: trx });
207+
// Publish this transaction into the engine's ambient store so internal
208+
// queries during writes reuse its connection (ADR-0034) — and so a nested
209+
// `transaction()` on either surface can JOIN it. The store entry also
210+
// carries WHICH driver owns the transaction (#4619) so the write path can
211+
// report a write routed off it. [#22855] Through the engine's ONE unit
212+
// helper, `runOpenedUnit`, the one `ObjectQL.transaction` runs its callback
213+
// in, reached the same `as any` way as `txStore` itself. It closes the unit
214+
// when the callback settles, so work the callback started and did not await
215+
// (an `async: true` hook) no longer keeps the finished handle, neither the
216+
// ambient one nor the `trxCtx` one threaded above.
217+
const runIn = <R>(fn: () => Promise<R>): Promise<R> =>
218+
typeof engine.runOpenedUnit === 'function' ? engine.runOpenedUnit(trx, driver, fn) : fn();
219+
220+
try {
221+
// Reached only with no ambient transaction to join, so this call really
222+
// did open one and the callback owns the outcome (#5696 / #6168).
223+
const result = await runIn(() => callback(trxCtx, { owned: true }));
224+
if (driver.commit) await driver.commit(trx);
225+
else if (driver.commitTransaction) await driver.commitTransaction(trx);
226+
return result;
227+
} catch (error) {
228+
if (driver.rollback) await driver.rollback(trx);
229+
else if (driver.rollbackTransaction) await driver.rollbackTransaction(trx);
230+
// [#21274] The engine surface's twin (`ObjectQL.transaction`), the
231+
// stale-roll-up conversion included.
232+
throw redactPropagatedDriverFault(rolledBackRefusal(error));
233+
}
234+
}
235+
124236
/**
125237
* Was `handle` JOINED by this context rather than opened by it? Consumes the
126238
* record, so the trio's terminal call is also what forgets the handle.

0 commit comments

Comments
 (0)