Skip to content

fix(core): 按 WorkflowRun 所有者登记模型尝试 - #93

Merged
EricWvi merged 1 commit into
ora-space:mainfrom
Kyber5323:fix/263-model-attempt-workflow-run
Oct 19, 2026
Merged

EricWvi merged 1 commit into
ora-space:mainfrom
Kyber5323:fix/263-model-attempt-workflow-run

Conversation

@Kyber5323

@Kyber5323 Kyber5323 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

缺陷

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),并补上后者所需的两个唯一约束;
    • 新增 WorkflowRun 所有者的有序索引,IssueRun 索引不变。存量行都带 run_id,不回填。
  • BeginModelAttempt 按绑定的原始 workflow_run_id 写入对应列;IssueRun 路径不变。
  • 统计读取不开放 WorkflowRun: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

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>
@Kyber5323

Copy link
Copy Markdown
Contributor Author

@Zpc001 麻烦有空 review 一下这个修复(对应 circus#263,运行 #273)。要点:

  • 新增 0044_model_attempt_workflow_run.sql:model_request_attempts 改为 run_id / workflow_run_id 恰有其一,与 0040 的绑定判别一致;运行与绑定外键按所有者拆分。
  • BeginModelAttempt 按绑定的原始所有者写对应列;统计读取仍只开放 IssueRun,WorkflowRun 行不会混入。
  • 测试覆盖真实 PostgreSQL 上的 WorkflowRun 登记与收尾、0044 全新与 0043 升级路径;CI check 已通过。

配套 ADR:ora-space/specs#140。

@wanglongan587 wanglongan587 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,没有开发过程记录。

非阻塞说明

  1. #262 的落地要求包含「WorkflowRun 绑定能成功登记并发送上游」。本 PR 的直接测试覆盖到登记与收尾,未直接覆盖 gateway 转发;转发路径本 PR 未改,IssueRun 的贯通测试仍绿。合并后 #70 重跑真实成功路径是最终证据,建议在运行总结里写明这个证据边界。
  2. model_attempt_workflow_run_order 当前没有读取方,与 IssueRun 索引保持对称可以接受;读取开放时再评估是否需要 partial index。
  3. internal/core/README* 的「模型请求统计」仍只提到 0035;不是错误,若要完整可补一句 0044 的登记范围(可选)。

建议合并顺序:先合并本 PR,再按 specs#140 的最终提交合并 ADR 同步(该 PR 需先补核心用例证据)。

@Kyber5323

Copy link
Copy Markdown
Contributor Author

@EricWvi cloud#93 已由 @wanglongan587 approve(审阅提交 e6f1c7a),CI check 通过,状态 MERGEABLE / CLEAN。按 review 结论,cloud#93 先合;合并后我在 #70 重跑真实成功路径,并在运行总结里注明登记测试与网关转发证据的边界。

specs#140 已按 review 补齐核心用例证据与读取承接 issue(circus#285),等 cloud#93 合并后把代码链接固定到合并提交,再请 @wanglongan587 复审。

@EricWvi
EricWvi merged commit 090bded into ora-space:main Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants