Files
OpenOPC/docs/company-metadata-ownership.md
T
LZH-YS1998 76c530a9e5 test: repair full suite — hang fix, stale-test updates, patch hygiene, timeout backstop
Suite went from 27 failures plus one permanent hang (never finished) to
1846 passed / 0 failed in ~85s, including under FORCE_COLOR.

- office_shutdown_lifecycle: construct WSHandler via the real __init__
  (helper) instead of hand-copied __new__ stubs that drift from the
  constructor (#11 added _runtime_status_sync_task and the stubs hung);
  the formerly-hanging wait now has a 5s wait_for.
- import-time patch hygiene: company_recruiter / company_reorg /
  engine_session_defaults replaced module-level permanent
  tempfile.TemporaryDirectory monkeypatching with paired
  setUpModule/tearDownModule, fixing order-dependent sqlite failures in
  transcript_pagination during full runs.
- stale tests updated to current product semantics: resume stubs use
  status="done" (failed is deliberately non-resumable), fix4 asserts the
  native review contract through build_company_work_item_contract,
  delivery fixture carries user_visible/feedback_scope=final, ownership
  doc names progress_log, session compression calls
  maybe_compact_session(force=True) explicitly, hard delete removes the
  work item row, parallel-isolation asserts delegate rebind and stubs
  _get_project_delegate, role update goes through OrgService on an
  editable custom org (plus read-only rejection case), collab_rpc patches
  the single os.name decision point instead of poisoning pathlib, codex
  no-pty builds inside the patch, identity-guard false positives reworded.
- cli_board actions rewritten against the real OfficeServiceFactory seam
  with a tempdir OPC_HOME (old direct-engine stubs were never consulted
  and the tests wrote into the real OPC home).
- cli_app assertions strip ANSI via _plain_output so a color-forcing
  shell (FORCE_COLOR) cannot break plain-text expectations.
- deleted never-runnable test_org_concurrency (pytest.mark.asyncio
  without the plugin, stdlib-only assertions) and three dead skipped
  filesystem-handoff tests.
- pyproject: dev extra (pytest, pytest-timeout) and a 300s per-test
  timeout backstop so a wedged test fails instead of stalling the suite.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 22:14:47 +08:00

27 lines
2.4 KiB
Markdown

# Company Mode Metadata Ownership
Company Mode keeps two different records with different responsibilities:
- `DelegationWorkItem` owns business, collaboration, board, review, report, and user-visible progress facts.
- Runtime `Task` owns execution envelopes, sessions, external-agent state, locks, runtime audit, stdout/result records, and replay.
The executable owner matrix lives in `opc/layer2_organization/metadata_ownership.py`. Treat this document as the human-readable summary; the code is the contract used by tests and runtime diagnostics.
## Owner Groups
| Owner | Examples | Rule |
|---|---|---|
| `work_item` | `work_kind`, `current_turn_mode`, dependency/waiting ids, handoff/context preview, prompt contracts, `progress_log`, role and employee context, review/report metadata, verification fields, delivery package, self-evolution fields | Scheduling, board projection, collaboration, review/report, and user-visible progress reads should use `DelegationWorkItem.metadata`. |
| `runtime_task` | `runtime_v2`, `runtime_verification*`, `member_session_state`, `external_resume_*`, `working_memory`, `interrupted_recovery`, `last_stop_reason`, `peer_wait`, comms reactivation audit, `runtime_control_state`, runtime session team/seat ids | Execution infrastructure should store these only on runtime `Task.metadata`. They must not become WorkItem business facts. |
| `execution_copy` | `mode`, `execution_mode`, `runtime_model`, `company_profile`, organization/runtime topology, delegation ids, seat/role routing, execution-agent selection, workspace/comms roots, parent session id | Runtime `Task` may carry these as immutable routing and UI envelope copies. They are not the authoritative business facts. |
WorkItem-to-runtime-Task linkage is not metadata. It is owned by the `work_item_runtime_links` table. UI payloads may expose this relation as `runtime_task_id` or `execution_turn_id`.
## Migration And Diagnostics
- New Company Mode writes WorkItem-owned fields to `DelegationWorkItem.metadata`.
- Runtime Task metadata is stripped of WorkItem-owned fields that are not allowed execution copies.
- `migrate_work_item_owned_metadata_from_linked_tasks` can dry-run or backfill missing WorkItem-owned values from linked legacy Tasks.
- Conflicts are not silently repaired. WorkItem wins, and diagnostics report `metadata_ownership_conflict`.
- Runtime invariants are validated by `opc/layer2_organization/work_item_runtime_invariants.py` and related tests.