================================================================
test166 — evidence-only task diagnostics and REST fallback (#166)
================================================================

Date: 2026-08-10
Base: 936a41107d2e314fb932b4a40541959a0a7055c4 (origin/main)
Source commit: 8d290a8e91a747ca350091a8181c2cf9c9f54104
Branch: feat/166-task-diagnostics

Docker image:
  tag: anet-test166:dev
  image id: sha256:42fd92e9bf0aa9dfaabaa519348a123005d5df356f47cb702c365cdfedbe8da8
  embedded TEST166_SOURCE_COMMIT:
    8d290a8e91a747ca350091a8181c2cf9c9f54104

Final result:
  10 pass / 0 fail / 22 expect() calls
  4 witnessed-red mutations, each rc=1
  RESULT: PASS

Scope
-----

- Adds an evidence-only diagnostic to the already network-scoped single-task
  REST response (`GET /api/tasks/:id` and its existing singular alias).
- Adds Chinese and English MCP-first / REST-fallback documentation.
- Does not change task creation, delivery, retry, reply, or lifecycle state.
- Does not add a Dashboard surface and does not change any agent runtime.

Diagnostic contract
-------------------

The top-level `diagnostic` object has schema_version=1, a finite `code`, an
`action_hint`, and these evidence facts only:

- task status;
- target session existence/status;
- the exact target alias's live SSE connection count in the task network;
- authoritative runtime_submitted_at / consumed_at presence.

Precedence is terminal > consumed > submitted > missing registration >
offline > no live SSE > lifecycle-only progress > delivered/waiting.

The API deliberately does not claim that an external model session has or
lacks MCP tools. The Hub cannot observe that capability. It also does not
turn a correlation into a root-cause assertion.

Real-wire coverage
------------------

The HTTP suite boots the real Hub with a private SQLite DB, creates two real
users/networks, registers the same alias in both, and opens real SSE streams.
It proves:

1. Network B's same-alias SSE connection is not counted for network A.
2. Network B cannot read network A's task (404 task_not_found).
3. A same-network SSE connection is reported without claiming runtime
   submission or consumption.
4. Authoritative runtime timestamps outrank current connectivity.
5. Offline and missing target sessions remain distinct.

Witnessed-red mutations
-----------------------

Each mutator requires exactly one production anchor and a byte change before
the test is run. Removing any of the following turns the named behavior red:

1. terminal-precedence — rc=1
2. runtime-consumed-precedence — rc=1
3. no-sse-gate — rc=1
4. cross-network-sse — rc=1

The fourth mutation intentionally sums every same-alias SSE connection across
networks; the real two-network HTTP test rejects that leakage.

Documentation behavior
----------------------

Both language variants now document:

- MCP-first delegation and explicit REST fallback;
- canonical task_id plus compatibility message_id;
- parent_task_id only when an authoritative current task id exists;
- omission means no automatic upstream reply chaining;
- Authorization header use, not a query token;
- diagnostic evidence limits, including that MCP mounting is unobservable.

Residual issue scope
--------------------

This candidate closes the REST diagnostic and fallback-documentation portion
of #166. It does not pretend that the Hub can inspect an arbitrary external
Codex/Claude tool panel at startup. A future runtime-owned bootstrap check may
warn when its own known MCP configuration is absent, but that is outside this
server-only evidence contract.

Verdict: PASS. Candidate remains unmerged and undeployed pending independent
review.
================================================================
