Open
[P3][契约] 插件代理端点未落地:GET /api/plugins/agent/installed 恒 404、POST /api/plugins/agent/report-missing 恒 405,runtime 侧插件缺失上报链路整体失效 #4081
吕军涛Add on  26 minutes ago
吕军涛
吕军涛Collaborators
26 minutes ago Create

现象(生产 Loki 最近 1 小时实测:2026-11-24 00:00–01:00 CST)

worker/运行时侧已经在调用插件代理的两个端点,但 mgmt 侧两个都不可用(一个路由不存在、一个方法不被允许):

GET  /api/plugins/agent/installed        → 404  22 bytes   (upstream=127.0.0.1:8081)
POST /api/plugins/agent/report-missing   → 405  31 bytes   (upstream=127.0.0.1:8081)
  • 1 小时 nginx 侧 3 次 installed + 2 次 report-missing,来自 3 台不同 runtime 主机(114.116.255.67、119.3.162.95、113.44.129.140),客户端均为 python-httpx/0.28.1。
  • mgmt 应用日志同步记录 POST /api/plugins/agent/report-missing status=405 duration=3-5ms(4 条 = 2 次请求被重复记录,均在 master-002)。
114.116.255.67 - - [24/Nov/2026:00:44:22 +0800] "GET /api/plugins/agent/installed HTTP/1.1" 404 22 "-" "python-httpx/0.28.1" upstream=127.0.0.1:8081
114.116.255.67 - - [24/Nov/2026:00:44:33 +0800] "POST /api/plugins/agent/report-missing HTTP/1.1" 405 31 "-" "python-httpx/0.28.1" upstream=127.0.0.1:8081
113.44.129.140 - - [24/Nov/2026:00:23:49 +0800] "GET /api/plugins/agent/installed HTTP/1.1" 404 22 "-" "python-httpx/0.28.1" upstream=127.0.0.1:8081

关键点:先 GET installed 拿不到清单(404)→ 判定「插件缺失」→ POST report-missing 上报又被 405 拒掉。两侧同时断,插件缺失既查不到、也报不上,插件市场的「缺失发现→回补」闭环完全静默。

归因(推断,需主控侧确认)

  • 404 说明 installed 路由未注册在 mgmt;405 说明 report-missing 路由存在但只注册了其它方法(与 #3743 /api/faro/collect 恒 405 同一类:路由/方法注册与客户端契约不一致)。
  • 客户端已随 worker 发布(python-httpx 而非浏览器),属版本/契约漂移:worker 端先落地了插件代理调用,mgmt 侧端点缺席或路径/方法改动未同步。建议核对 mgmt 路由声明与 worker 侧 client 常量表(plugins/agent/*)。

建议

  1. 主控侧给出权威路径与允许方法,并在 mgmt 落地:GET /api/plugins/agent/installed(返回本机已物化插件清单)、POST /api/plugins/agent/report-missing(登记缺失插件,落表 + 可观测指标)。
  2. 两侧做契约对齐:worker 侧 client 常量表与 mgmt OpenAPI 由同一份 schema 生成,CI 增加「worker 调用的每个端点必须在 mgmt 路由表中存在且方法匹配」的断言(本次 404+405 均可被该断言拦下)。
  3. 过渡期:mgmt 对未实现端点返回 501 + error_code=NOT_IMPLEMENTED(而非 404/405 裸包),worker 侧遇到 404/405 不再重试、按「平台不支持插件代理」降级并上报一次,避免每台 runtime 反复静默失败。
  4. 对 report-missing 增加计数指标(plugin_missing_report_total),缺端点时应能直接告警而不是靠翻 nginx 日志。

证据

  • {service_name="nginx-gateway"} |= "plugins/agent" → 1h 5 条(3×404 installed + 2×405 report-missing),3 台 runtime 主机。
  • {service_name="grape-mgmt"} |= "report-missing" → 1h 3 条 WARNING(405)。
  • 同族参照:#3743(/api/faro/collect 恒 405,P2,coding)。
likedislike
grape_bot
grape_botCollaborators
23 minutes ago Comments:

[VOD Agent] 已结构化收敛需求(不改动原 Issue 正文,仅作为审视结论供后续 spec/实现参考):

目标

在 mgmt 主控侧落地插件代理两个端点(GET /api/plugins/agent/installed、POST /api/plugins/agent/report-missing),恢复 runtime 侧插件缺失上报链路,使插件市场「缺失发现→回补」闭环可用。

现状

  • worker/runtime 侧已随版本上线插件代理调用(客户端 python-httpx/0.28.1),mgmt 侧两端点均不可用:
    • GET /api/plugins/agent/installed → 恒 404(路由未注册)
    • POST /api/plugins/agent/report-missing → 恒 405(路由存在但方法不被允许)
  • 生产 Loki 1 小时实测:5 次失败(3×404 + 2×405),来自 3 台不同 runtime 主机,mgmt 应用日志同步记录 405 WARNING。
  • 两侧同时断:插件缺失既查不到清单、也报不上缺失,链路完全静默失效。
  • [degraded] 项目知识基线为降级生成(codegraph 不可用),以上归因以报告人 Loki/nginx/mgmt 日志证据与同族 Issue #3743(/api/faro/collect 恒 405)为依据:属路由/方法注册与客户端契约漂移(worker 先落地调用、mgmt 端点缺席或未同步),推断需主控侧代码确认。

期望行为

  1. mgmt 落地两个端点:GET /api/plugins/agent/installed 返回本机已物化插件清单;POST /api/plugins/agent/report-missing 登记缺失插件(落表 + 可观测指标)。
  2. 契约对齐:worker 侧 client 常量表与 mgmt OpenAPI 由同一份 schema 生成;CI 增加「worker 调用的每个端点必须在 mgmt 路由表中存在且方法匹配」断言。
  3. 过渡期:mgmt 对未实现端点返回 501 + error_code=NOT_IMPLEMENTED;worker 遇 404/405 不再重试,按「平台不支持插件代理」降级并仅上报一次。
  4. report-missing 增加计数指标 plugin_missing_report_total,缺端点时可直接告警。

验收标准

优先级

P3(按原 Issue 标注)


来源:Issue #4081
auto-submitted by VOD Agent

likedislike
grape_bot
grape_botCollaborators
17 minutes ago Comments:

[issue agent] 📋 Spec Document

结论先行:代码侧两端点已落地,生产 404/405 是「运行版本滞后」而非「路由未注册」

按目标分支 arch-weekly-11-ljt(与 main 逐项核对,结论一致)核验:

  • src/domains/mgmt/routes/plugins_agent.py(97 行)已实现两端点:
    • POST /api/plugins/agent/report-missing(operation_id=plugins_agent_report_missing,L50-78):缺插件报告 → build_missing_plugin_report/build_install_request/submit_install_request,入统一确认队列(source=agent_report),队列不可用时降级回 degraded_comment 文本,恒 200 不阻塞任务;
    • GET /api/plugins/agent/installed(operation_id=plugins_agent_installed,L81-97):invalidate_plugin_cache() 后读最新物化状态,返回 {repo_key, plugins, count}。
  • 路由已注册:src/api/main.py:643-646 from src.domains.mgmt.routes.plugins_agent import router + app.include_router(plugins_agent_router)。
  • 契约已登记:contracts/required_operations.json:734-750 含两条 operationId + method + path;src/api/openapi.py 的 contract_integrity() 在登记操作缺失/方法漂移时抛 ContractDegradedError,tests/contracts/test_contract_required_operations_2081.py 全量参数化回归——即「端点必须存在且方法匹配」已有 CI/渲染层断言。

生产 404/405 的精确归因(可复核)

upstream=127.0.0.1:8081 说明响应来自 mgmt 进程本身,但两侧响应体长度把原因钉死了:

  • 404 22 bytes = {"detail":"Not Found"}(22 字符);405 31 bytes = {"detail":"Method Not Allowed"}(31 字符)。
  • src/api/spa.py:428 有全局 @app.get("/{path:path}") SPA catch-all:未注册的 GET 落进 SPA 兜底 → 由兜底返回 404;同一路径没有 POST 处理器 → Starlette 直接 405。这正是「GET 404 + POST 405」成对出现的唯一自洽解释,也说明原推断「report-missing 路由存在但只注册了其它方法」不成立(当前代码里没有任何 /api/plugins/agent/* 的 GET 变体)。
  • 综上:8081 上运行的 mgmt 构建早于 plugins_agent 路由合入,属发布版本漂移;不是代码缺失。

剩余真实缺口(本单可执行范围)

  1. plugin_missing_report_total 计数指标不存在(plugin_negotiation.py 仅 logger.debug),缺端点/降级只能翻 nginx 日志;deploy/alerts.yml 10 条规则里无插件代理相关告警。
  2. 过渡期语义未落地:未实现端点仍是裸 404/405,无 501 + error_code=NOT_IMPLEMENTED;调用侧(runtime 侧 python-httpx/0.28.1 插件代理客户端)遇 404/405 无「一次性降级、不重试」约定。
  3. 部署侧无能力位:调用方无法在发起前得知本实例是否支持插件代理,只能靠试错拿到 404/405。

Spec: Issue #4081 — 插件代理端点契约补齐与缺失上报可观测化

Generated by Issue Agent | Developability: ready(按上述证据收敛范围) | 2026-11-24

Objective

  • 让插件市场「缺失发现 → 回补」闭环在生产可观测、可告警、可降级:mgmt 缺端点这类发布漂移不再静默。
  • 用户:runtime 侧执行中的 Agent(缺插件时)与平台值班(排障/告警)。
  • 成功标准:插件代理端点不可用或缺失上报发生时,5 分钟内可在指标/告警侧看到;调用侧不再对 404/405 反复重试。

Scope

In Scope

  1. 缺失上报计数:POST /api/plugins/agent/report-missing 递增 plugin_missing_report_total(沿用现有指标出口与命名规范,若仓库要求 grape_ 前缀则为 grape_plugin_missing_report_total),标签至少 result="submitted|degraded",可选 repo_key/agent_type。
  2. 告警规则:deploy/alerts.yml 增两条——①降级占比/降级次数(result="degraded" 持续 >0);②插件代理端点不可用(基于 grape_http_requests_total{path=~"/api/plugins/agent/.*",status=~"404|405"} 或等价 route-missing 计数),规则名建议 GrapePluginAgentEndpointMissing。
  3. 能力位:在只读健康/版本出口(src/api/health_endpoints.py 或 /api/version)暴露插件代理两端点是否已注册(复用 load_required_operations() + contract_integrity() 的 missing 明细),使调用侧可先查后调、确定性降级。
  4. 过渡期错误语义:未实现端点返回 501 + error_code=NOT_IMPLEMENTED(src/api/errors.py: api_error(501, ..., "NOT_IMPLEMENTED")),不再裸 404/405;仅对「路径已知但服务端未实现」的插件代理端点生效,不改全局 404 语义。
  5. 调用侧降级约定(跨仓):runtime 插件代理客户端遇 404/405/501 记一次结构化 WARNING 并降级为「平台不支持插件代理」,同一任务内不重试、只上报一次;若客户端不在本仓,本仓交付 3、4 两项契约并由 coding 在该单内注明跨仓跟进项。

Out of Scope

  • 不改 report-missing 的入队/降级业务逻辑(已实现,恒 200 语义保持)。
  • 不改 SPA catch-all 路由与全局 404 语义。
  • 不做插件市场前端改动。
  • 生产 mgmt 实例的版本核对与发布(部署动作)由 sre 执行,不在 coding 范围。

Technical Approach

方案:以「契约登记 + 渲染层强校验 + 指标/告警 + 能力位」四件套,把「端点是否可用」从运行期试错前移到发布期可验证、运行期可观测。

  1. 计数接入:在 report_missing 返回前按 submit["submitted"] 结果递增(submitted/degraded 两分支),与 grape_repo_dispatch_busy_total 同一注册点。
  2. 告警:沿用 deploy/alerts.yml 既有 for/labels/annotations 结构,severity 取 warning(P3)。
  3. 能力位:GET /api/version(或 /health)增 plugin_agent: {installed: bool, report_missing: bool, missing_operations: [...]},数据源为 contract_integrity(custom_openapi(app)) 的 missing_operations。
  4. 501 语义:在 plugins_agent 路由内对「能力未就绪」分支返回 501(非全局兜底),并补 tests/mgmt 用例断言 status=501、error_code=NOT_IMPLEMENTED。

关键设计决策

决策 选项 选择 理由
404/405 是否改为 501 全局 catch-all 改造 / 路由内局部改造 路由内局部 全局改造会波及鉴权/前端兜底与既有 404 断言
调用侧如何判断能力 试错 404 / 健康位前置查询 健康位 一次 HTTP 即可确定性降级,避免每任务试错
指标命名 plugin_missing_report_total / grape_ 前缀 随仓库现有规范 与 grape_http_requests_total、grape_repo_dispatch_busy_total 对齐 alert 表达式

Affected Modules

模块 改动类型 说明
src/domains/mgmt/routes/plugins_agent.py 修改 计数递增 + 未实现分支 501
指标注册点(与 grape_repo_dispatch_busy_total 同处) 修改 新增 counter
src/api/health_endpoints.py / src/api/code_version.py 修改 能力位暴露
deploy/alerts.yml 修改 两条告警规则
tests/mgmt、tests/contracts 新增/修改 501 语义、指标递增、能力位契约用例

依赖关系

contracts/required_operations.json(已含两操作)→ contract_integrity() → 能力位出口 → 调用侧降级;report_missing → 指标 → 告警。

Acceptance Criteria

Risks & Mitigations

Risk Impact Mitigation
指标注册点与 /metrics 出口分离导致落地后仍查不到 Med 落地后必须实证 /metrics 出现该 counter(AC 第 2 条)
调用侧客户端不在本仓,降级语义无法同单闭环 Med 本仓先交付契约(501+能力位),跨仓跟进项在任务内显式登记
生产 8081 仍是旧构建,代码全绿但线上仍 404/405 High sre 核对构建版本(含 plugins_agent.py 的 commit)并发布;能力位可用于发布后验收
新增告警误报 Low for: 10m + 仅对插件代理路径前缀生效

Open Questions

  • 无(生产构建版本核对属 sre 动作,已在评论中标出)
likedislike
grape_botgrape_botCollaborators
17 minutes ago Modify description of issue
grape_botgrape_botCollaborators
17 minutes ago Assign grape_bot as responsible person
grape_botgrape_botCollaborators
17 minutes ago Added label: api-contractbugobservabilityP3spec-readytriaged
grape_botgrape_botCollaborators
17 minutes ago Associated milestone: arch-weekly-11
grape_bot
grape_botCollaborators
17 minutes ago Comments:

[issue agent] 分诊与流转已完成(Spec 见上一条评论)。

  • 评级:ready(需求完整、技术可行、依赖就绪、范围已按证据收敛)
  • 标签:P3 / api-contract / observability / bug / spec-ready / triaged
  • 里程碑:arch-weekly-11(due 2026-12-06)
  • 负责人:@grape_bot(机器人接管)
  • A2A:已交办 coding(event seq=100124),目标分支 arch-weekly-11-ljt

需 sre 同步执行的一环:生产 mgmt 8081 的构建版本核对——当前实例未包含 plugins_agent 路由(src/domains/mgmt/routes/plugins_agent.py + src/api/main.py:643-646 已在 main/arch-weekly-11-ljt 存在),发布含该路由的构建后线上 404/405 即消失;可用本次 Spec 交付的能力位做发布后验收。

likedislike
grape_bot
grape_botCollaborators
16 minutes ago Comments:

[issue agent] A2A 交办结果记录:handoff 已发出(event seq=100124 → coding),但下游 coding 任务执行失败,非需求/Spec 问题。

  • 失败原因(任务 t_576375c7d81b 回执):credential_not_configured —— 该仓库在该 runtime 上无可用凭据(无 bot、亦无归属者/会话用户凭据),建树取 token 失败,无法 clone/fetch。属平台凭据配置缺失,重试不会改变结果。
  • 需人工介入:在仓库/runtime 侧配置可用凭据后重新交办 coding(Spec 与实现范围已就绪,可直接复用评论 203201073 的 Spec,无需重新分析)。
  • 未变更项:评级 ready、Spec、标签、里程碑、负责人均按原结论保留;A2A 不重复发起,避免双跑。
likedislike