Skip to content

fix: 修复任务生命周期与调度就绪,优化执行和构建开销 - #3069

Merged
whyour merged 5 commits into
developfrom
codex/execution-readiness-optimization
Sep 12, 2026
Merged

whyour merged 5 commits into
developfrom
codex/execution-readiness-optimization

Conversation

@whyour

@whyour whyour commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

任务停止与退出回调竞争时,旧执行可能覆盖新执行的状态;HTTP 健康检查成功也可能早于调度定义恢复。本 PR 修复这些生命周期与就绪问题,并改进执行开销、日志处理、数据库初始化和镜像构建一致性。

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Other

What is the current behavior?

  • 停止后立即重跑仍可能被旧手动执行认领;恢复时的旧快照可能覆盖并发成功的任务配置变更。
  • HTTP 可用不代表 CronClient 通道和调度定义就绪;服务层包装错误还会将调度不可用的 503 变成 500。
  • 日志收尾、实例退出和子进程清理存在竞争;启动同步、Shell 辅助进程与默认 APM 增加开销。
  • 镜像源码、静态产物与依赖可能来自不同构建状态;artifact actions 使用已弃用的 Node.js 20 action runtime。

Issue Number: N/A

What is the new behavior?

  • 统一子进程观察与日志收尾。停止按快照 PID 精确终止,确认退出后只更新对应实例,保留后来启动的实例及脚本退出码。手动执行使用持久化 queued_token 区分每次排队;旧执行在等待并发名额、启动认领和最终清理时均不能接管新一代执行。配置更新及回滚不重写排队标识。
  • 在实际 CronClient 通道上探测 scheduler;恢复时完整替换调度集合,清除已删除或禁用的任务,空数据库也会清空调度器。恢复成功后才标记就绪,失败有界重试,旧代际不能误标就绪。
  • HTTP 与 gRPC 中的任务创建、更新、删除、启停,以及恢复快照,共用跨进程配置锁。锁覆盖数据库读写、调度注册和回滚,避免旧快照覆盖并发成功的修改。锁竞争有界等待并返回 503,仅在操作期间维护锁,无新增空闲轮询。
  • 调度通道不可用时使 readiness 失效并返回 503,创建、更新和启用回滚保留该状态与原始错误,不自动重放业务写请求。
  • 日志打开与目录创建限制在配置根目录,拒绝目录穿越及越界/悬空符号链接;保留中文多级目录和并发尾行写入。
  • 显式、幂等的 schema 迁移保留旧数据,本次新增可空的排队标识列。缓存 Node 路径,减少 Shell 环境、时间和 API 解析开销;保留 PM2,默认关闭主进程/worker 高级 APM,唯一 HTTP worker 直接监听。
  • CI 验证后再构建,镜像使用同一 workflow 的静态产物、固定源码提交及锁文件。递归校验全部静态产物,检测修改、缺失、额外残留及符号链接;包含隐藏产物并检测未跟踪构建输入。
  • upload-artifact 升级到 v6、download-artifact 升级到 v7,均原生使用 Node.js 24;项目测试运行时仍为 Node.js 20。

Validation

  • 本地 Node.js 20 完整回归:153 项,150 通过、0 失败、3 项 macOS 平台跳过;后端 TypeScript 构建通过。
  • GitHub Linux 回归及构建通过,CodeQL 全部通过;artifact 上传成功,regression 检查的 annotations 为空,已无 Node.js 20 action 弃用警告。
  • 真实子进程覆盖晚启动、停止后重排、并发名额等待、SIGTERM-resistant 进程退出;两个独立 OS 进程验证配置锁互斥。
  • 回归覆盖恢复与五类配置变更并发、恢复等待已开始的注册、三类操作回滚后的 503、回滚不复活旧排队标识、旧数据库迁移及备份恢复。
  • 累计回归还覆盖日志边界、完整产物校验、Shell 缓存、调度集合恢复及 readiness HTTP 503。
  • 性能对比数据来自前面的 benchmark 候选镜像,不能视为后续 CR 修复后重新测量的结果。

Does this PR introduce a breaking change?

  • Yes
  • No

自定义 Docker 构建需要先生成 static/ 与构建信息,并提供匹配的源码提交和锁文件;不再从独立静态仓库拉取浮动产物。

调度未就绪或配置锁等待超时时,健康接口/相关任务变更可能返回 503。高级 APM 可通过 QL_PRIMARY_APM=true、QL_WORKER_APM=true 恢复;自定义多 HTTP worker 部署使用 QL_HTTP_SHARED_LISTEN=true 恢复共享监听。

@vercel

vercel Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
qinglong Ready Ready Preview Sep 12, 2026 4:29pm UTC
qinglong-back Ready Ready Preview Sep 12, 2026 4:29pm UTC

Comment thread back/shared/logStreamManager.ts Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Lifecycle races, incomplete scheduler reconciliation, and build provenance gaps can still produce incorrect state or artifacts.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Improves task lifecycle correctness, scheduler readiness, runtime overhead, and reproducible container builds.

Changes:

  • Unifies process/log cleanup and adds scheduler recovery safeguards.
  • Adds schema migration and shell/runtime optimizations.
  • Strengthens CI, build provenance, and regression coverage.
File summaries
File Description
test/back/worker-apm.test.cjs Tests worker APM policy.
test/back/task-time.test.cjs Tests timestamp optimization.
test/back/subscription-cleanup.test.cjs Tests subscription cleanup failures.
test/back/stop-race.test.cjs Tests stop/completion races.
test/back/shell-api-parsing.test.cjs Tests shell API parsing.
test/back/schema-migrations.test.cjs Tests migration safety.
test/back/scheduler-readiness.test.cjs Tests readiness recovery.
test/back/primary-apm.test.cjs Tests primary APM defaults.
test/back/node-path-lock.test.cjs Tests cache locking.
test/back/node-path-cache.test.cjs Tests Node path caching.
test/back/manual-execution.test.cjs Tests manual task lifecycle.
test/back/http-exclusive-listen.test.cjs Tests HTTP listener policy.
test/back/execution-lifecycle.test.cjs Tests process and log lifecycle.
test/back/env-name-parsing.test.cjs Tests environment parsing.
test/back/build-provenance.test.cjs Tests build provenance.
shell/task.sh Reduces timestamp subprocesses.
shell/share.sh Optimizes parsing and timing.
shell/otask.sh Uses cached Node path discovery.
shell/node_path_cache.sh Implements locked path cache.
shell/api.sh Consolidates token/response parsing.
scripts/write-build-info.cjs Generates build metadata.
scripts/benchmark-execution.cjs Adds execution benchmark.
package.json Adds test/build scripts.
ecosystem.config.js Configures container APM defaults.
docker/verify-build.cjs Verifies image build inputs.
docker/Dockerfile.debian310 Uses pinned Debian build inputs.
docker/Dockerfile.debian Uses pinned Debian build inputs.
docker/Dockerfile.310 Uses pinned Alpine build inputs.
docker/Dockerfile Uses pinned Alpine build inputs.
back/shared/schemaMigrations.ts Adds explicit schema migrations.
back/shared/schedulerReadiness.ts Implements scheduler readiness state.
back/shared/runCron.ts Uses unified process observation.
back/shared/logStreamManager.ts Serializes writes and closure.
back/shared/childProcess.ts Centralizes child lifecycle handling.
back/services/subscription.ts Hardens subscription cleanup.
back/services/schedule.ts Unifies scheduled process lifecycle.
back/services/http.ts Adds exclusive listener mode.
back/services/health.ts Checks scheduler readiness.
back/services/cron.ts Revises stop/manual execution handling.
back/schedule/health.ts Adds scheduler-local probe.
back/schedule/client.ts Adds probes and RPC deadlines.
back/loaders/initData.ts Configures scheduler recovery.
back/loaders/db.ts Runs explicit migrations.
back/app.ts Coordinates worker recovery and APM.
back/api/system.ts Ensures response cleanup.
back/api/health.ts Returns readiness-aware status codes.
back/api/cron.ts Gates scheduler-dependent mutations.
.github/workflows/validate.yml Adds validation workflow.
.github/workflows/build-docker-image.yml Builds images from same-run artifacts.
.dockerignore Reduces Docker build context.
Review details

Suppressed comments (1)

back/schedule/client.ts:69

  • The delete path has the same pre-RPC gap: a waitForReady timeout bypasses the callback that invalidates readiness, leaving health stale and returning 500 rather than 503. Invalidate and classify this rejection before propagating it.
    await this.waitForReady(2000);
  • Files reviewed: 50/50 changed files
  • Comments generated: 6
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docker/verify-build.cjs Outdated
Comment thread scripts/write-build-info.cjs Outdated
Comment thread back/loaders/initData.ts
Comment thread back/schedule/client.ts
Comment thread back/services/cron.ts
Comment thread back/services/cron.ts Outdated
@whyour
whyour merged commit a94e665 into develop Sep 12, 2026
8 checks passed
@whyour
whyour deleted the codex/execution-readiness-optimization branch September 12, 2026 16:32

This branch was successfully deployed

2 active deployments
Preview – qinglong — 04b297f5 Deployed Sep 12, 2026 by vercel[bot]
Preview – qinglong-back — 04b297f5 Deployed Sep 12, 2026 by vercel[bot]
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.

3 participants