myxce/src/frontend/apiserver/middleware
lei.chen 1691e49a05 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>
2026-10-19 10:06:32 +00:00
..
cors.go Merge Go frontend (apiserver + xcecli) into meson build 2026-04-14 11:23:18 +08:00
cors_test.go Merge Go frontend (apiserver + xcecli) into meson build 2026-04-14 11:23:18 +08:00
load_test.go test(apiserver): run TestLoadJobs only when a live server is given 2026-10-02 09:37:43 +00:00
rate_limit.go Merge Go frontend (apiserver + xcecli) into meson build 2026-04-14 11:23:18 +08:00
README Merge Go frontend (apiserver + xcecli) into meson build 2026-04-14 11:23:18 +08:00
startserver.go fix: spurious errors/warnings from a pc13v HA deploy (bug-1872..1877) 2026-09-28 04:35:19 +00:00
startserver_test.go fix: spurious errors/warnings from a pc13v HA deploy (bug-1872..1877) 2026-09-28 04:35:19 +00:00
test_rate_limit.bat Merge Go frontend (apiserver + xcecli) into meson build 2026-04-14 11:23:18 +08:00
validatehandler.go merge: sync Rongsong's scheduler-framework (c5b172c7..3442a57d, 781 commits) 2026-10-14 05:17:03 +00:00
validatehandler_test.go merge: sync Rongsong's scheduler-framework (c5b172c7..3442a57d, 781 commits) 2026-10-14 05:17:03 +00:00
whitelist.go feat(advisor): P1 outlets — findings push to SSE + MCP scheduler_advisor_findings 2026-10-19 10:06:32 +00:00
whitelist_test.go feat(advisor): P1 outlets — findings push to SSE + MCP scheduler_advisor_findings 2026-10-19 10:06:32 +00:00

go test -v load_test.go