Skip to content

feat(work): record structured task stop reasons - #2580

Merged
hidb4ai merged 8 commits into
oceanbase:masterfrom
beatenevo:codex/issue-2544-structured-stop-reason
Nov 12, 2026
Merged

hidb4ai merged 8 commits into
oceanbase:masterfrom
beatenevo:codex/issue-2544-structured-stop-reason

Conversation

@beatenevo

@beatenevo beatenevo commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Closes #2544. Tracking: #2542.

Rationale for this change

A deliberately interrupted attempt can already use blocked or cancelled, but its reason can only be recorded as prose. Add a typed, optional stop_reason so a caller can recover the recorded judgement from the outcome Source without parsing its summary.

What changes are included in this PR?

  • Add TaskStopReason with a closed kind (safety, authorization, capability, missing_evidence, scope), a nonblank trimmed condition, basis, and at most 31 exact citations.
  • Accept a reason only on blocked and cancelled. Require evidence for verified; reject evidence for declared. Resolve supplied citations through the existing same-scope evidence validation before writing.
  • Carry the optional field through OpenAPI, generated Python HTTP models, server mapping, and the existing Python client request model.
  • Expose the optional nullable field in OpenClaw's powercontext_task_outcome and Pi's pc_task_outcome, with bounded reason schemas and guidance on status, evidence, and authority. Forward the complete reason to the Server without duplicating its domain validators.
  • Preserve Source serialization bytes and content digests when no reason is supplied, including existing blocked records. No stored-record migration or inferred reasons.
  • Document the behavior in English and Chinese and cover validation, SQLite persistence/reopen/readback, HTTP rejection, and continuity projection.
  • Regenerate Desktop contract manifests/types and qualify all twelve Desktop operations using the exact Server wheel from 0b434770, preserving every historical qualification record.

TaskOutcomeStatus and WorkContinuityEventStatus are textually unchanged against ed8902b2. WorkContinuityEvent and builtin/work/continuity.py are unchanged. The OpenAPI TaskOutcome.required list and additionalProperties: false are unchanged.

Are there any user-facing changes?

HTTP, MCP tool schemas derived from the public contract, Python client requests, and the OpenClaw/Pi outcome tools can carry the optional reason. The exact outcome Source remains the supported read path. The record preserves a judgement; it does not establish that stopping was correct, grant permission, approval, or retry budget, or guarantee that another agent will honour it.

Non-blocking capability boundaries:

  • Enumeration: retrieval requires a known source_id via get_source, or caller-side scanning. continuity() does not expose the reason, and ListSourcesRequest has no kind/status filter. Server-side discovery of previous stops by class is not delivered here; it remains the read-surface question in [Tracking] repeated-trial work-continuity gaps — research registry (case: three-session stereotaxic task) #2542 finding G.
  • Recurrence and aggregates: the reason itself is excluded from recurrence failure evidence and avoided derivation. Existing observation/check rules still apply: a verified observation with exact evidence under a blocked outcome can still qualify as failure evidence, and qualifying check results retain their existing behavior. This PR does not exempt the entire outcome from recurrence processing. Continuity parses the new field but emits only the existing status and counts the record as an outcome, without a success/failure classification. Experience incubation can inspect the captured Source content; this PR adds no reason-based policy, ledger item, statistics counter, or retry path.

How was this change tested?

Acceptance item Result Evidence
blocked / cancelled recording and readback PASS SQLite file persistence/reopen tests and Python client → ASGI HTTP → SQLite → Source readback
Wrong-status rejection PASS All four disallowed statuses rejected by runtime validation and HTTP before persistence
Evidence rules PASS Both invalid basis/evidence combinations rejected; missing and cross-scope citations rejected before recording
Existing payload compatibility PASS Every existing status accepted without a reason; exact Source bytes and content digests preserved
Continuity projection PASS New records project with their original status and no invalid records
Status enums and required fields PASS Both enum definitions compared textually with ed8902b2; OpenAPI required list and closed-object rule unchanged
Reason excluded from failure evidence PASS Focused recurrence test; existing observation/check eligibility remains in force
OpenClaw / Pi schemas and forwarding PASS Five kinds, optional/null compatibility, malformed field rejection, exact citation forwarding; Pi native argument validation; both plugin suites and type checks
Python API generation and drift PASS make api-generate; scripts/generate_api.py --check; scripts/generate_js_operations.py --check
Complete contract gate PASS (62 tests) make contract-test, including Desktop identity and qualified business profile checks
Desktop product protocol qualification PASS All four real SQLite HTTP/TLS modes with bundled profile sqlite-task-stop-reason-0b434770-v1; native profile-coverage test, generator check, and typecheck
OceanBase / SeekDB acceptance NOT_RUN Validation uses SQLite; no external backend acceptance claim

Commands and results:

.venv/bin/python -m pytest tests/builtin/test_task_stop_reason.py tests/builtin/runtime/test_task_stop_reason.py tests/builtin/runtime/test_work_continuity.py tests/builtin/artifacts/experience/test_recurrence.py tests/builtin/runtime/test_recurrence_ledger.py tests/e2e/test_runtime_server.py -q --tb=short
95 passed, 3 skipped (external database cases)

.venv/bin/python -m pytest tests/test_api_contract.py tests/test_js_operations.py tests/test_mcp.py -q --tb=short
70 passed

pnpm --dir integrations/openclaw/plugins/memory-powercontext test
103 passed; plugin build passed
pnpm --dir integrations/openclaw/plugins/memory-powercontext run typecheck
Passed

pnpm --dir integrations/pi/plugins/powercontext test
164 passed
pnpm --dir integrations/pi/plugins/powercontext run typecheck
Passed

.venv/bin/ruff check --no-fix
.venv/bin/ruff format --check
.venv/bin/ty check
uv lock --check
uv run prek run -a
All passed

The new host-tool tests validate the published schemas and requests against stubbed HTTP responses; Pi also uses its native argument validator. They do not establish a live host → real Server → persistence workflow for the new field.

Desktop qualification uses the ordinary native product ConnectionManager against the exact built Server wheel in anonymous loopback, static Bearer, HTTPS with explicit CA/base path, and enforced Provider modes. All four modes passed. The new record binds the Server commit, normalized OpenAPI digest, wheel digest, and twelve-operation set; source verification confirms all 738 packaged runtime files match 0b434770 byte for byte. desktop/VALIDATION.md records the native probe identity and environment. This verifies local SQLite protocol compatibility, not installed UI, native credential persistence, other operating systems, external databases, or release readiness.

pnpm --dir desktop generate
pnpm --dir desktop generate:check
pnpm --dir desktop run typecheck
cargo build --locked --manifest-path desktop/src-tauri/Cargo.toml --example server_probe
.venv/bin/python desktop/tests/real_server.py --product-qualification sqlite-task-stop-reason-0b434770-v1
cargo test --locked --manifest-path desktop/src-tauri/Cargo.toml --test session bundled_product_qualification_covers_every_desktop_operation
make contract-test
62 passed

AI usage statement

OpenAI Codex (GPT-6) assisted with implementation, tests, bilingual documentation, and local validation. Review and acceptance remain with the maintainers.

Comment thread openapi/powercontext.yaml
maxItems: 32
items:
$ref: "#/components/schemas/HandoffCitation"
TaskStopReasonKind:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] 新增 OpenAPI schema 后 Desktop 契约身份失效,contract-test 在这个 head 上是红的

openapi/powercontext.yaml 新增了 TaskStopReason/TaskStopReasonKind,并给 TaskOutcome 加了 stop_reason,文件摘要随之从 de74d806343998ba… 变为 34cc6572321296c6…(sha256(openapi 字节,CRLF→LF))。本 PR 没有改 desktop/ui/src/generated/operations.ts 与 desktop/src-tauri/src/transport/operations.json,两者仍写 de74d806343998ba…。

后果(实测,非推断):

  • exact head 镜像内 pytest tests/test_desktop_contract.py tests/builtin/test_task_stop_reason.py tests/builtin/runtime/test_task_stop_reason.py → 2 failed, 22 passed,两处失败都是 Stale Desktop contract identity ... run 'pnpm --dir desktop generate'。
  • CI job 129775659065(CI preflight):make contract-test → 2 failed, 65 passed,make: *** [Makefile:168: contract-test] Error 1,退出码 2。
  • 该 head 的 check-run 目前是 1 success / 3 failure / 34 skipped:preflight 失败后其余 suite 全部 skip,因此 stop_reason 的写入、回读与续跑在所有 CI 套件上都没有验收证据。我能给出的行为证据只有本地 sqlite(tests/builtin/*/test_task_stop_reason.py、tests/e2e/test_runtime_server.py -k stop_reason,24 项通过,其中 4 个非 blocked/cancelled 状态返回 422 且 GET 该 source 为 404,即未落盘)。

建议的处理顺序:

  1. 先 pnpm --dir desktop generate,把两个 manifest 的 contractSha256 更新为 head 摘要。这步是机械的,能立刻消掉这两个失败。
  2. 再补一个 contractSha256 等于新摘要的 desktop/src-tauri/src/connections/compatibility.json profile,否则 test_bundled_desktop_contract_has_a_qualified_business_profile 会接替变红。这才是正文 HOLD 指的是 macOS 资格记录(可参考 fix(api): declare 409 for artifact replacement #2553 的 sqlite-artifact-conflict-8dc98e49-v1 + desktop/VALIDATION.md 条目做法)。

在 1、2 完成前 preflight 保持红,这个 PR 无法进入合并判定。正文把它记录为"等维护者指示"不改变门禁状态,也不产生验收证据。

补充核对(通过,无需处理):TaskOutcomeStatus 与 WorkClaimBasis 两个枚举与 merge-base 69b2d7e2 逐字一致;stop_reason 没有进入 avoided 推导(builtin/artifacts/experience/recurrence.py::avoided_refs 只读 observations 与 checks),与文档表述一致;builtin/runtime/application.py::_outcome_evidence 把 stop_reason.evidence 纳入引用可用性校验,verified 的 citation 确实会被验证,declared 带 evidence 会被 pydantic 校验拒绝。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已在 head 61f8213c 复核,这个问题不再成立:

  • openapi/powercontext.yaml 归一化(CRLF→LF)后 SHA-256 = e1ff2e3ad1d6a09a9288c4c66e111a54c4979026e29806ff70543988b8e29220;
  • desktop/src-tauri/src/transport/operations.json 的 contractSha256 同为 e1ff2e3a…;
  • desktop/src-tauri/src/connections/compatibility.json 新增条目 sqlite-task-stop-reason-4cb70619-v1 的 contractSha256 也是 e1ff2e3a…。

三处一致,说明本 head 的契约身份已登记并自洽,之前「新 schema 未登记导致 contract-test 红」的前提消失。

仍待确认:commits/61f8213c/check-runs 只返回 7 个 check run(另有 1 项 tests (3.11, unit) in_progress,其余 desktop 相关 job 尚未产生),因此 desktop 契约 job 在这条提交上的最终结论无法判定,本次不据此给出合并结论。

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed c786e47606d65484ea06b8eb343e248539b0d229. I found no new correctness blocker in the stop-reason implementation. The Desktop contract identity/qualification mismatch reported earlier is fixed at this head.

Merge readiness is still blocked by CI:

  • OpenDAL package fails on pydantic-discarded-extra-argument at integrations/opendal/src/powercontext_connector_opendal/source.py:160. The same diagnostic occurs on base cc752d8a; it is outside this PR's changes.
  • OceanBase harness acceptance has replay evidence showing ImportError: cannot import name 'text_block' from 'acp' before workload execution. SQLite harness acceptance is also red. These failures do not establish a defect in stop-reason persistence, but the CI gate still needs to pass before merging.

There are no new database tables, migrations, HTTP paths, or operation IDs. However, TaskStopReason, TaskStopReasonKind, and TaskOutcome.stop_reason extend the public SDK/HTTP/MCP/tool contracts, so this review remains COMMENT under the requested no-new-public-interfaces approval condition.

@hireview001 hireview001 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.

  • Resolve merge conflicts with the target branch.
  • CI failed: CI result (failure).
  • CI failed: dsh-package (failure).
  • CI failed: Main (failure). Failed steps: dsh-package / Test built plugin in the real DSH runtime; CI result / Require successful selected checks.

@beatenevo
beatenevo requested a review from knqiufan as a code owner November 11, 2026 09:21

@hireview001 hireview001 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.

  • Resolve merge conflicts with the target branch.

@AlexStocks AlexStocks added the 1.5.2 v1.5.2 release tracking label Nov 12, 2026

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@hidb4ai
hidb4ai merged commit 230efe1 into oceanbase:master Nov 12, 2026
70 checks passed
jackie-cqz added a commit to jackie-cqz/powercontext that referenced this pull request Nov 13, 2026
Resolve the conflict with the standalone seekdb maintenance identity (oceanbase#2585)
and the 30 other commits that landed since the previous merge, including the
processing status projection (oceanbase#2568) and the structured task stop reasons
(oceanbase#2580).

- `release/upgrade-support.json`: keep the rationale sentence added upstream
  for the seekdb maintenance identity, append the sentence about this branch's
  code-organization changes, and recompute the persistence digest after
  formatting. The generated table and index DDL for all 76 tables is
  identical to master on the SQLite and MySQL dialects.

Follow the moves and removals into code that arrived with the merge:

- `tests/builtin/runtime/test_context_reuse.py` imports access control from
  `powercontext.builtin.authz`.
- The `scheduler_path` argument is dropped from the new calls in
  `test_artifact_merge_experience.py` and `test_dashboard.py`.
- The startup-deadline test in `test_real_experience_skill_harness.py` stops
  passing a scheduler database path to `_start_server` and
  `_start_configured_server`, which no longer take one. It passed the path
  positionally, so a search for the `scheduler_path=` keyword could not find it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.5.2 v1.5.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(work): record a structured stop reason so a deliberate refusal is retrievable

4 participants