feat(advisor): P1 outlets — findings push to SSE + MCP scheduler_advisor_findings

The advisor's findings previously lived only in its JSONL decision log on
its own host. P1 adds two observe-only outlets so diagnoses reach humans
and other agents live:

apiserver side:
- backend/broker.go: EventAdvisorFinding ("advisor.finding") event type +
  AdvisorFinding struct + Event.AdvisorFindings field.
- controllers/events.go: ReportFindings — POST /xce/v1/advisor/findings
  (generated_at/scenario/findings), publishes one broker event. Broadcast
  only: the decision log remains the store of record.
- router/routers.go: route behind RequirePermission("advisor:report").
- middleware/whitelist.go: admit /xce/v1/advisor/findings in the POST URL
  whitelist (the URL middleware 403s before the router's RBAC otherwise —
  same shape as bug-1489).
- config/rbac.yaml: advisor_agent role (advisor:report + the six *:view
  grants the snapshot needs) and advisor:report in the permission
  whitelist. mcp_readonly stays strictly *:view. New
  TestRBACYAML_AdvisorAgentRole_PinsReportSurface pins the role surface.

advisor side:
- internal/push: Pusher — best-effort POST of each round's findings, one
  retry, nil/unconfigured/empty findings are no-ops; failures log and
  never affect the observe loop.
- internal/agent: SetPusher wired after the decision-log append (the log
  is authoritative; push is a fan-out).
- internal/config + cmd: push default-on to the same XCE_API_URL with the
  same XCE_API_KEY (the key's role needs advisor:report); ADVISOR_PUSH=
  off|false|0 disables.

mcp-server side:
- internal/advisor.go: lenient JSONL reader for the advisor's decision
  log (ADVISOR_LOG env), tail-bounded, corrupt lines skipped.
- scheduler_advisor_findings tool: recent records with parsed findings;
  friendly errors when the log is missing/unconfigured. Passive reader —
  never talks to the advisor process.

Cluster verification (t1/t2/t3): redeployed apiserver closure, deployed
rbac.yaml, issued advisor_agent key. Forced-PEND job → pend_stall fired
on the real LLM (glm-5-3-flash, 19.4s, degraded=false) → 2 findings, all
evidence verbatim in the snapshot, unverified=false → SSE broadcast
captured on /xce/v1/events → MCP tool returned both records. Second PEND
job joining the stalled set fired a new decision within one round
(change-triggered semantics). Verification jobs killed; sanity job
submitted→ran→DONE; all daemons and 3 hosts healthy.

Design doc: architecture diagram gains the push branch; roadmap P1
marked done (CLI outlet not built).

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
lei.chen 2026-10-19 10:06:32 +00:00
parent 3e3b6d7947
commit 1691e49a05
17 changed files with 677 additions and 9 deletions

View file

@ -21,7 +21,7 @@
apiserver REST ──────▶│ snapshot: 紧凑集群状态(字段白名单+top-N 截断) │
(schedulerclient) └──────────────┬───────────────────────────────┘
▼
SSE /xce/v1/events ─▶ detect: 确定性触发器(阈值→冷却→去重)
SSE /xce/v1/events ─▶ detect: 确定性触发器(去重;变化即触发)
(事件只提前扫描) │ 命中
▼
provider.Evaluate(Scenario, State, Runbook)
@ -31,13 +31,22 @@
▼
幻觉防火墙 VerifyEvidence
│
▼
declog: JSONL 决策日志(全上下文)
┌─────────────┼──────────────────┐
▼ ▼ ▼
declog JSONL push(P1) (未来:CLI 直出)
决策日志 ─▶ POST /xce/v1/advisor/findings
(存档/审计) └─ apiserver broker ─▶ SSE advisor.finding 事件
```
- 代码位置:`src/frontend/advisor/`,独立 Go module(`replace schedulerclient`),
`CGO_ENABLED=0`,不进 meson(与 mcp-server 一致,`go build` 直出)。
- 部署:t1 上以 `XCE_API_KEY`(mcp_readonly 角色)运行 `advisor run`。
- 部署:t1 上以 `XCE_API_KEY`(advisor_agent 角色)运行 `advisor run`。
- 出口(P1):决策日志是存档底账;push 是尽力而为的广播(失败只记日志,
永不影响观察循环),目标 = 同一 apiserver 的
`POST /xce/v1/advisor/findings`(`advisor:report` 权限),服务端原样
转成 SSE `advisor.finding` 事件分发给订阅者。`ADVISOR_PUSH=off` 关闭。
MCP 侧 `scheduler_advisor_findings` 工具直接读决策日志 JSONL
(`ADVISOR_LOG`),是被动读者、不经过 advisor 进程。
## 3. Provider 契约
@ -108,7 +117,7 @@ tokens / findings / raw / state(+digest) / degraded`。JSONL、按大小轮转
| 阶段 | 内容 |
|---|---|
| P1 | propose 档:findings 推送(SSE/MCP 工具/CLI);runbook 上提 schedulerclient;评估 echo vs LLM 的对照数据 |
| P1 ✅ | propose 档:findings 推送(SSE 广播 + MCP 工具,已实现;CLI 直出未做);评估 echo vs LLM 的对照数据 |
| P2 | act 档(仅当引入带校准置信度的 provider——见附录 A):allowlist + 爆炸半径上限 + 审计 |
| — | 自洽性伪置信度(k 次采样一致率)作为 act 档的非 Jev 替代——5 倍成本,只在关键判断用 |