Skip to content

fix(bay): 修复预热沙盒卡住与多容器误判 - #25

Draft
RhoninSeiei wants to merge 4 commits into
AstrBotDevs:mainfrom
RhoninSeiei:fix/warm-pool-runtime-recovery
Draft

fix(bay): 修复预热沙盒卡住与多容器误判#25
RhoninSeiei wants to merge 4 commits into
AstrBotDevs:mainfrom
RhoninSeiei:fix/warm-pool-runtime-recovery

Conversation

@RhoninSeiei

@RhoninSeiei RhoninSeiei commented Jul 15, 2026

Copy link
Copy Markdown

修改内容

  • 周期检查待处理和可用的预热沙盒,运行时缺失或多容器组不完整时重新加入预热队列。
  • 预热任务始终检查真实运行时状态,并恢复中断的会话启动。
  • 清理失败时保留会话元数据,供后续任务再次处理。
  • Kubernetes Pod 删除完成后再创建同名运行时。
  • 预热恢复完成后,通过 warm_state IS NULL 条件更新写回 available,避免并发调度留下永久待处理状态,同时保留已领取和已退役状态。

问题原因

预热队列只保存在进程内,任务失败或进程重启后可能长期停留在待处理状态。运行时探测曾把部分存在的多容器组视为健康,清理失败后又会丢失再次处理所需的信息。调度器重置状态与预热任务同时执行时,任务还可能读取旧的 ORM 对象并跳过可用状态写回。

验证

  • 预热池单元测试:38 passed
  • 生产组合分支单元测试:525 passed
  • Ruff:通过
  • v0.4.0 实际运行验证:失效运行时恢复后为 available=1pending=0
  • 双沙盒验证:冷启动首个 Shell 42.752 秒,百度页面标题正确,截图 28,866 字节,测试沙盒均已清理

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves multi-container runtime group health checks and cleanup handling, updates the Kubernetes driver to wait for pod deletion during destruction, and refactors the warm pool scheduler's reconciliation logic. Feedback on the scheduler changes highlights a potential issue where unconditionally requeuing all pending sandboxes could disrupt active, healthy warmup tasks; the reviewer suggests only requeuing sandboxes that have no active session or whose session has failed or stopped.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +167 to +169
pending_rows = [
(sandbox, session) for sandbox, session in warm_rows if sandbox.warm_state is None
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

无条件地重新排队所有待处理沙盒(即 sandbox.warm_state is None)会导致那些当前正在进行中且正常的预热沙盒(例如会话处于 STARTINGRUNNING 状态但尚未被标记为 AVAILABLE)也被重新排队。这可能会导致重复的预热任务、冗余的驱动程序/数据库查询以及潜在的并发竞争问题。

我们应该仅在待处理沙盒没有活动会话(即 session is None)或者其会话已失败或已停止时,才重新排队它们。

        pending_rows = [
            (sandbox, session)
            for sandbox, session in warm_rows
            if sandbox.warm_state is None
            and (
                session is None
                or session.observed_state in (SessionStatus.FAILED, SessionStatus.STOPPED)
            )
        ]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已修复。de8a09b 仅对无会话或 FAILED、STOPPED 会话的 pending 记录重新入队,并新增 STARTING、RUNNING 会话保持现状的参数化测试;相关 20 项测试通过。

from app.drivers.base import ContainerStatus
from app.models.sandbox import Sandbox, WarmState
from app.models.session import Session, SessionStatus
from app.models.session import Session

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

导入 SessionStatus 以便在过滤待处理沙盒以重新排队时检查会话状态。

Suggested change
from app.models.session import Session
from app.models.session import Session, SessionStatus

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已同步处理。de8a09b 恢复 SessionStatus 导入,并用于筛选允许重新入队的失败或停止会话。

@RhoninSeiei

Copy link
Copy Markdown
Author

补充处理了调度器与预热任务并发时的状态写回问题:调度器将数据库状态重置为 null 后,任务可能仍持有旧的 available 对象并跳过写回。现改为带 warm_state IS NULL 条件的数据库更新,同时保留 claimedretiring 状态。

v0.4.0 实际运行验证中,失效 Ship 自动恢复,下一轮调度统计为 available=1pending=0。双沙盒浏览器验证通过,百度页面标题与截图均正常,测试沙盒均已清理。

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