Repository navigation
fix(core): 按 WorkflowRun 所有者登记模型尝试 - #93
Conversation
model_request_attempts (0035) required an IssueRun: run_id was NOT NULL with foreign keys to issue_runs and to run_model_bindings' run_id. 0040 made a WorkflowRun the owner of its frozen bindings, and liveModelBinding maps that owner into runId for the runtime gates, so BeginModelAttempt wrote a workflow run id into run_id. The foreign key failed inside the gateway's begin step, which answers 503 model_metrics_unavailable before contacting the provider; every WorkflowRun model request failed this way. Migration 0044 gives the ledger 0040's discriminator shape: workflow_run_id is added, run_id becomes nullable, exactly one owner is required, and the run and binding references are split per owner, each tenant-scoped. BeginModelAttempt writes the column the binding actually owns. Statistics reads stay IssueRun-only, as decided: WorkflowRun rows carry a NULL run_id and cannot enter them. Existing rows all carry run_id, so nothing is backfilled. Tests cover the real PostgreSQL grant/binding/execution chain ending in a WorkflowRun attempt and its finalization, the fresh and 0043-upgrade migration paths, and the final table shape used by the statistics test. Refs ora-space/circus#273 Co-Authored-By: Claude Code <noreply@anthropic.com>
|
@Zpc001 麻烦有空 review 一下这个修复(对应 circus#263,运行 #273)。要点:
配套 ADR:ora-space/specs#140。 |
wanglongan587
left a comment
There was a problem hiding this comment.
Review 结论:Approve
审阅版本:cloud e6f1c7ac86c934a4f116a223f0b8e13720a360f9(base ceb39bc780588a98fef0d639b5c7319ba63b882b)。CI check(run 39247755340)通过;日志确认 TestWorkflowModelAttemptRegistersUnderWorkflowRun、TestMigration0044ModelAttemptWorkflowRunAppliesFreshAndUpgrades、TestMigration0035ModelAttemptsFreshAndUpgradeWithoutBackfill 均实际执行并通过。
已核对
- 根因与形状:
0044_model_attempt_workflow_run.sql复用0040的 owner 判别:run_id/workflow_run_id恰一非空;运行外键分别指向issue_runs/workflow_runs的(id,tenant_id),绑定外键指向run_model_bindings的(id,run_id)/(id,workflow_run_id);并补齐workflow_run_tenant_identity与model_binding_workflow_run_identity。存量行都有run_id,不回填,与 0035 的约束历史一致。 - 写入侧:
internal/core/model_attempts.go:29-34用绑定的原始workflow_run_id决定写哪一列,而不是liveModelBinding投影后的runId(internal/core/model_grants.go:40-41的投影只服务运行时门禁);IssueRun 路径仍写run_id。 - 读取边界:
internal/core/session_model_statistics.go:32,87的statistics/model-calls仍按tenant_id + run_id过滤;WorkflowRun 行run_id为 NULL,不会混入,符合 #262「首期只登记、读取另行安排」。 - 迁移编号:main 最新为
0043,本 PR 用0044,符合memory/rules/migration-numbering.md;fresh / 0043 升级 / 重复迁移都有真实 PostgreSQL 断言。 - 交付物:改动只有迁移、实现、测试和迁移 README,没有开发过程记录。
非阻塞说明
- #262 的落地要求包含「WorkflowRun 绑定能成功登记并发送上游」。本 PR 的直接测试覆盖到登记与收尾,未直接覆盖 gateway 转发;转发路径本 PR 未改,IssueRun 的贯通测试仍绿。合并后 #70 重跑真实成功路径是最终证据,建议在运行总结里写明这个证据边界。
model_attempt_workflow_run_order当前没有读取方,与 IssueRun 索引保持对称可以接受;读取开放时再评估是否需要 partial index。internal/core/README*的「模型请求统计」仍只提到0035;不是错误,若要完整可补一句0044的登记范围(可选)。
建议合并顺序:先合并本 PR,再按 specs#140 的最终提交合并 ADR 同步(该 PR 需先补核心用例证据)。
|
@EricWvi cloud#93 已由 @wanglongan587 approve(审阅提交 specs#140 已按 review 补齐核心用例证据与读取承接 issue(circus#285),等 cloud#93 合并后把代码链接固定到合并提交,再请 @wanglongan587 复审。 |
缺陷
WorkflowRun 的每次模型请求都在 model-gateway 的登记步骤被拒绝,供应商从未被调用。
model_request_attempts(0035)把run_id定义为非空,并同时外键到issue_runs(id,tenant_id)与run_model_bindings(id,run_id);0040之后 WorkflowRun 的冻结绑定以workflow_run_id归属,liveModelBinding又把它的所有者投影为runId,BeginModelAttempt便把这个 workflow run id 写进了只认 IssueRun 的run_id,两条外键都失败。网关的登记步骤失败一律返回503 model_metrics_unavailable,且按已批准的不变量不发送上游。改动
0044_model_attempt_workflow_run.sql,让台账采用0040的判别形状:run_id改为可空,新增workflow_run_id,model_attempt_owner_exclusive要求恰有其一;(run_id,tenant_id) → issue_runs(id,tenant_id)与(workflow_run_id,tenant_id) → workflow_runs(id,tenant_id);(binding_id,run_id) → run_model_bindings(id,run_id)与(binding_id,workflow_run_id) → run_model_bindings(id,workflow_run_id),并补上后者所需的两个唯一约束;run_id,不回填。BeginModelAttempt按绑定的原始workflow_run_id写入对应列;IssueRun 路径不变。run_id为空的登记行不会进入按run_id过滤的statistics/model-calls,读取侧无需改动(依据 circus#262;读取形状与授权由 circus#285 承接)。测试
TestWorkflowModelAttemptRegistersUnderWorkflowRun:真实 PostgreSQL 上驱动 WorkflowRun 的 grant、binding 与 execution 链,登记成功并断言run_id为空、workflow_run_id正确,再用FinishModelAttempt收尾。TestMigration0044ModelAttemptWorkflowRunAppliesFreshAndUpgrades:全新库与停在0043的升级库达到同一形状,重复迁移无变化。TestMigration0035ModelAttemptsFreshAndUpgradeWithoutBackfill:按最终形状断言所有者外键与两个所有者索引。本地
task format、task lint(0 issues)、task test(REQUIRE_POSTGRES=1,真实 PostgreSQL,全包通过)均为绿。ADR 状态
specs/decisions/cloud/model-access/20261016-recorded-http-attempt-statistics.md维持approved:本 PR 补齐其 WorkflowRun 登记范围,ADR 正文由 ora-space/specs#140 同步;统计读取仍不开放(由 circus#285 承接),因此不转为implemented。真实 WorkflowRun 到上游的端到端验证随合并后的 #70 验收补充。Refs ora-space/circus#273
🤖 Generated with Claude Code