Skip to content

refactor(monitor): delegate dispatch to shared QPK runner - #605

Merged
Pigbibi merged 1 commit into
mainfrom
refactor/lb-monitor-dedupe-20261024
Oct 23, 2026
Merged

Pigbibi merged 1 commit into
mainfrom
refactor/lb-monitor-dedupe-20261024

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

改动

把 application/monitor_dispatcher.py 从 ~270 行重复实现缩成薄门面,全部实现复用 QPK pin 350dd38ece0952beef096893a7dcf8ae3871609a 中的 quant_platform_kit.common.platform_runner.monitor。

  • 保留的公开 API(显式导入 + __all__,无 import *):MONITOR_TARGET_ENV_NAMES、DEFAULT_LOOKBACK_MINUTES、DEFAULT_TIMEOUT_SECONDS、DEFAULT_MAX_WORKERS、MonitorWindow、MONITOR_WINDOWS、load_monitor_targets、dispatch_due_monitors
  • main.py 与 tests/test_monitor_dispatcher.py 的导入路径和调用不变
  • 未改 QPK pin、pyproject.toml、uv.lock、CI 或部署 workflow
  • diff:1 file changed, 25 insertions(+), 266 deletions(-)

行为等价依据

本地模块与 QPK 版本逐函数相同,唯一差异是 _fetch_id_token:

  • 本地:id_token.fetch_id_token(Request(), audience)
  • QPK:get_deployment_context().fetch_id_token(audience)

QPK 默认 QSL_CLOUD_PROVIDER=gcp,其 GcpDeploymentContext.fetch_id_token 执行的正是同样的 id_token.fetch_id_token(Request(), audience)。LB 仓库与部署配置均未设置 QSL_CLOUD_PROVIDER,因此运行时行为等价。

已确认无其他代码依赖该模块的私有函数(_fetch_id_token、_send_dispatch、_iter_due_dispatches 等)。tests/test_request_handling.py 对 main 模块命名空间的 monkeypatch 仍作用在导入后的同一对象上。

验证

检查 结果
基线(origin/main 32eee32)uv run pytest -q tests 2161 passed, 3 skipped, 176 subtests passed
改后 uv run pytest -q tests 2161 passed, 3 skipped, 176 subtests passed
uv run pytest -q tests/test_monitor_dispatcher.py 2 passed
uv run ruff check . All checks passed

无新增失败,失败/跳过项与基线一致。

风险

  • 运行时行为由 QPK pin 决定:若后续升级 QPK 引入 monitor 模块变更,会影响本路径;本次不升级 pin。
  • token 获取从直接调用 google.oauth2.id_token 改为经 get_deployment_context();在当前默认 provider 下等价,若未来主动设置非 gcp 的 QSL_CLOUD_PROVIDER,行为会随之切换到对应 provider 实现。

不合并、不部署,等待评审。

🤖 Generated with Claude Code

Replace the duplicated ~270-line dispatcher with a thin compatibility
facade over quant_platform_kit.common.platform_runner.monitor at the
pinned QPK revision 350dd38. Public names and the
application.monitor_dispatcher import path stay unchanged; main.py and
tests need no changes.

Behavior equivalence: the local module was function-for-function
identical to QPK except _fetch_id_token. QPK defaults QSL_CLOUD_PROVIDER
to gcp, whose GcpDeploymentContext.fetch_id_token performs the same
id_token.fetch_id_token(Request(), audience) call, and neither the LB
repo nor its deploy config sets QSL_CLOUD_PROVIDER. No QPK pin, CI, or
deployment workflow changes are included.

Verification:
- baseline on origin/main 32eee32: 2161 passed, 3 skipped, 176 subtests
- after: 2161 passed, 3 skipped, 176 subtests
- uv run pytest -q tests/test_monitor_dispatcher.py: 2 passed
- uv run ruff check .: all checks passed

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Pigbibi
Pigbibi merged commit ec89707 into main Oct 23, 2026
1 check passed
@Pigbibi
Pigbibi deleted the refactor/lb-monitor-dedupe-20261024 branch October 23, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant