Changesets · Branches · Tags · Compare
| Changeset | df0616f1e05bac28f415edd1d33e00f7df22388cced328308141706901dc4546 |
|---|---|
| Author | WaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-08-31 01:09 +08:00 |
| Committer | GitHub <noreply@github.com> · 2026-08-31 01:09 +08:00 |
| Parents | ae59bab5e01a |
3 files changed
modified crates/utopia-server/src/api/ontology_routes.rs +1 −1
| @@ -1398,7 +1398,7 @@ | ||
| 1398 | 1398 | Path(kb_id): Path<Uuid>, |
| 1399 | 1399 | ) -> ApiResult<Json<serde_json::Value>> { |
| 1400 | 1400 | require_kb(&state, &user, kb_id, Role::Editor).await?; |
| 1401 | - let outcome = crate::type_resolution::resolve(&state, kb_id, Some(user.id)).await?; | |
| 1401 | + let outcome = crate::type_resolution::resolve(&state, kb_id).await?; | |
| 1402 | 1402 | let _ = utopia_store::audit::record( |
| 1403 | 1403 | &state.pool, |
| 1404 | 1404 | Some(kb_id), |
modified crates/utopia-server/src/type_resolution.rs +22 −8
| @@ -382,13 +382,27 @@ | ||
| 382 | 382 | pub crosses_axis: bool, |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | -/// 跑一遍类型消解:检索候选 → 裁决 → 三档处置。 | |
| 386 | -pub async fn resolve( | |
| 387 | - state: &AppState, | |
| 388 | - kb_id: Uuid, | |
| 389 | - // 落库那一步记在谁头上。这条路是人在界面上按的,所以有人 | |
| 390 | - actor: Option<Uuid>, | |
| 391 | -) -> AppResult<ResolutionOutcome> { | |
| 385 | +/// 跑一轮类型消解并落库。 | |
| 386 | +/// | |
| 387 | +/// **落库时不带 actor,尽管是人点的运行。** `retype_entities` 的 actor 参数 | |
| 388 | +/// 现在有两重身份:账本里记"谁改的",而 0051 之后它还决定 `type_source`—— | |
| 389 | +/// 有 actor 就是 `human`,而 `human` 意味着**引擎从此不再碰这个实体**。 | |
| 390 | +/// | |
| 391 | +/// 这两个问题不是一回事: | |
| 392 | +/// | |
| 393 | +/// | | 谁发起 | 谁判定这个实体是什么 | | |
| 394 | +/// |---|---|---| | |
| 395 | +/// | 手工改实体类型 | 人 | 人 | | |
| 396 | +/// | 认可类对 + 点名实体 | 人 | 人 | | |
| 397 | +/// | **跑一轮消解** | 人点了运行 | **引擎** | | |
| 398 | +/// | |
| 399 | +/// 第三行传了 user 就等于宣称"这个类是人判的",于是**跑过一次消解的实体 | |
| 400 | +/// 从此永远不再被消解**。实测:一个没有任何人工 PATCH 记录(`entity.retyped` | |
| 401 | +/// 审计 0 条)的库,跑完消解后每个实体都成了 `type_source = human`, | |
| 402 | +/// 下一次预览返回空列表。 | |
| 403 | +/// | |
| 404 | +/// 谁点的运行记在 `ontology.types_resolved` 审计里,带批次 id,查得到。 | |
| 405 | +pub async fn resolve(state: &AppState, kb_id: Uuid) -> AppResult<ResolutionOutcome> { | |
| 392 | 406 | let items = preview(state, kb_id).await?; |
| 393 | 407 | let items: Vec<_> = items |
| 394 | 408 | .into_iter() |
| @@ -524,7 +538,7 @@ | ||
| 524 | 538 | (None, 0) |
| 525 | 539 | } else { |
| 526 | 540 | let (b, n) = |
| 527 | - utopia_store::resolution::retype_entities(&state.pool, kb_id, &picks, actor).await?; | |
| 541 | + utopia_store::resolution::retype_entities(&state.pool, kb_id, &picks, None).await?; | |
| 528 | 542 | (Some(b), n) |
| 529 | 543 | }; |
| 530 | 544 | Ok(ResolutionOutcome { |
modified crates/utopia-store/tests/human_type_decisions.rs +55 −0
| @@ -310,3 +310,58 @@ | ||
| 310 | 310 | .await?; |
| 311 | 311 | run |
| 312 | 312 | } |
| 313 | + | |
| 314 | +/// **引擎改过的实体,下一轮还要捞得回来。** | |
| 315 | +/// | |
| 316 | +/// 这一条守的是一个真出过的事故:类型消解落库时把「点运行的那个人」当成了 | |
| 317 | +/// `retype_entities` 的 actor,而 0051 之后有 actor 就写 `type_source = 'human'`。 | |
| 318 | +/// 于是**跑过一次消解的实体从此永远不再被消解**——一个没有任何人工 PATCH 记录 | |
| 319 | +/// 的库,跑完一轮之后预览返回空列表,而且没有任何报错。 | |
| 320 | +/// | |
| 321 | +/// 「谁点的运行」与「谁判定这个实体是什么」是两件事。前者记在 | |
| 322 | +/// `ontology.types_resolved` 审计里,后者才该决定 `type_source`。 | |
| 323 | +#[tokio::test] | |
| 324 | +async fn an_engine_retype_does_not_lock_the_entity_out_of_the_next_round() -> anyhow::Result<()> { | |
| 325 | + let Ok(url) = std::env::var("UTOPIA_DATABASE_URL") else { | |
| 326 | + eprintln!("跳过:未设 UTOPIA_DATABASE_URL"); | |
| 327 | + return Ok(()); | |
| 328 | + }; | |
| 329 | + let pool = PgPool::connect(&url).await?; | |
| 330 | + let f = seed(&pool).await?; | |
| 331 | + | |
| 332 | + let run = async { | |
| 333 | + let e = entity(&pool, &f, "Initech", Some(f.org_type), "extracted").await?; | |
| 334 | + // 留一个 specific_type:让它在「取材条件」上始终够格,这样落选与否 | |
| 335 | + // 只取决于 type_source——否则改成叶子类之后它本来就该落选,测不出东西 | |
| 336 | + sqlx::query("UPDATE entities SET specific_type = 'startup company' WHERE id = $1") | |
| 337 | + .bind(e) | |
| 338 | + .execute(&pool) | |
| 339 | + .await?; | |
| 340 | + // 引擎自动裁决:没有人为这一条背书 | |
| 341 | + utopia_store::resolution::retype_entities(&pool, f.kb, &[(e, f.sub_type)], None).await?; | |
| 342 | + | |
| 343 | + assert_eq!( | |
| 344 | + source_of(&pool, e).await?, | |
| 345 | + "inferred", | |
| 346 | + "引擎裁决不是人的背书" | |
| 347 | + ); | |
| 348 | + | |
| 349 | + let picked = utopia_store::resolution::entities_for_type_resolution(&pool, f.kb, 100) | |
| 350 | + .await? | |
| 351 | + .into_iter() | |
| 352 | + .map(|c| c.id) | |
| 353 | + .collect::<std::collections::HashSet<_>>(); | |
| 354 | + assert!( | |
| 355 | + picked.contains(&e), | |
| 356 | + "引擎改过一次不该把实体锁死——本体还会长大,它还得能被重判" | |
| 357 | + ); | |
| 358 | + Ok::<_, anyhow::Error>(()) | |
| 359 | + } | |
| 360 | + .await; | |
| 361 | + | |
| 362 | + sqlx::query("DELETE FROM knowledge_bases WHERE id = $1") | |
| 363 | + .bind(f.kb) | |
| 364 | + .execute(&pool) | |
| 365 | + .await?; | |
| 366 | + run | |
| 367 | +} |