fix(rectification): product-domain open wrapper runs as invoker; V10 turn append in history test and replay harness; rename segment migrations (BUG-1131)

- open_agentic_rectification_case_v2 (12 args) becomes SECURITY INVOKER: the
  immutable-skill ACL reconciliation leaves EXECUTE on the 11-arg open only to
  service_role, so the definer wrapper hit 42501 on every homepage/new open.
- The pending-opening read moves to owner function
  agentic_rectification_opening_pending_v1, granted to service_role only.
- History test and persisted replay harness append turns through the V10
  request-idempotent overload; the V9 overload is revoked from service_role.
- Opening test fixture adds the required birth_time_source.
- Segment migrations renamed to 20261001* so they sort after staging's
  20260930* migrations on both fresh and existing databases.
- Stale Windows replay replaced with the production-path replay (M1/M2 equal
  to accepted research, implementation_identity included).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
This commit is contained in:
Jesse_Chen
2026-10-01 08:04:05 +08:00
co-authored by Claude Opus 5.5
parent 66f087b588
commit 73605c3b8e
8 changed files with 79203 additions and 79152 deletions
+16
View File
@@ -15165,3 +15165,19 @@
- 防复发:首页首屏只放空白首页用得到的东西;只有少数人或少数时刻用得到的模块(引导、老资料兼容、研究数据)按需加载,并在「一定会用到」的那一刻之前(揭幕前)预加载。别把整个研究 JSON 导入客户端模块。
- 相关记录:BUG-1127、BUG-1128
- 修复版本:分支 `codex/home-first-load-20260930`(`b743b16b`、`e2c3791f`)
- 修复版本:—
## BUG-1131 | 盘型口径的 12 参数开案包装以属主身份调用 11 参数开案,首页 / 新建开案 42501
- 状态:investigating(修复已落 `codex/rectification-varga-resolution-fix-20261001`;真库定向通过,全量真库与部署后 smoke 待补)
- 首次发现 / 最近更新:2026-09-30 / 2026-10-01
- 影响面:`frontend/supabase/migrations/20261001020000_rectification_segment_checks.sql` 的 `open_agentic_rectification_case_v2(…, p_product_domain text)`;`frontend/src/lib/rectification-agentic/v9/case-service.ts::openRectificationCase` 对 `intent !== "session"`(首页、新建)一律走该 12 参数版本。
- 用户现象(若部署):从首页或「新建」发起生时校正全部失败,接口报 `permission denied for function open_agentic_rectification_case_v2`(42501);按会话打开历史 Case 不受影响。
- 触发条件:任何首页 / 新建开案。
- 根因:12 参数包装是 `security definer`,以属主 `schema_owner` 身份调用既有 11 参数 `open_agentic_rectification_case_v2`;而 `20260814010000_immutable_skill_registry.sql` 的 ACL 对账块把 11 参数函数的 EXECUTE 从除 `service_role` 外所有角色(含属主)收回。改成 `security invoker` 后又暴露第二层:运行角色对 `agentic_rectification_cases` / `turns` 没有直接读表权限,包装里「是否待开场」的 `exists(...)` 被拒(`permission denied for table agentic_rectification_cases`)。
- 修复:包装改为 `security invoker`(调用方 service_role 本就可执行 11 参数开案与 `initialize_agentic_rectification_domain_v1`);「是否待开场」判断移入新的属主函数 `agentic_rectification_opening_pending_v1(uuid,uuid)`,只授权 service_role。未给属主或任何非 service_role 角色补 EXECUTE,未改 08-14 迁移。两条新迁移尚未部署到任何环境,原文件修改。
- 验证:本机无 Docker,Claude 用独立 PostgreSQL 17.9 + `docker`/`psql` 本地替身跑 `frontend/tests/database-segment-opening.test.ts`:修复前 1/0/1(42501,与执行方 DinD 现场一致);修复后 1/1/0。测试新增断言:新属主函数 authenticated 不可执行;12 参数包装 `prosecdef = false`。
- 同轮修正的测试缺陷:该测试第二段「真实扫描」开案的出生快照缺 `birth_time_source`,被 11 参数开案的 `agentic_rectification_profile_incomplete` 校验拒绝——此段此前一直被 42501 挡住从未执行。原值:快照无 `birth_time_source`;新值:`birth_time_source: "family_exact"`(与同文件第一段一致);原因:满足原开案资料完整性约束,不放宽约束。
- 防复发:新增 SECURITY DEFINER 函数若调用其他 RPC,必须确认被调函数 ACL 仅 service_role 时属主不可调;优先 `security invoker` 包装 + 属主只读小函数。真库 `database-segment-opening.test.ts` 锁定 `prosecdef` 与 ACL。
- 相关记录:BUG-1115、BUG-1116、BUG-1117、BUG-621。
- 复发自:无(新迁移引入,未部署)
- 修复版本:`codex/rectification-varga-resolution-fix-20261001`(未合入、未部署)。
File diff suppressed because it is too large Load Diff