fix(worker): 独立 worker 启动加载 DB 设置——修复拆分部署下事件丢失与身份注入消失 - #512
Merged
Conversation
worker_main 此前只跑 pydantic 默认值,与 API 的 DB 生效设置分叉。生产 SESSION_EVENT_CHUNK_STORAGE_ENABLED=true 时:API 写 chunk、worker 走 legacy 内联,事件被 chunk 视图的 merge 覆写蒸发——刷新即丢整段对话历史 (2026-09-09 生产 P0,18:30Z 起全部会话 event_count=2);SANDBOX_PLATFORM 同理回落默认,本地 daemon 身份段(#499)不再注入;token 统计同步失真。 修复:_amain 启动先 initialize_settings()(DB > env > 默认,对齐 API lifespan)再 validate_distributed_runtime_settings,失败快速退出由 CrashLoopBackOff 显性暴露,绝不带默认值吞事件。staging 复现验证: chunk=on + worker 拆分下事件完整落库(复现样本 event_count=2 → 修复后全量)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
独立 worker 进程(#507 拆分部署)此前不加载 DB 设置,只跑 pydantic 默认值,与 API 的生效设置(DB > env > 默认)分叉——2026-09-09 生产 P0 的根因。
事故链(生产 18:30Z 起全部会话受影响)
SESSION_EVENT_CHUNK_STORAGE_ENABLED=true:API 写 chunk 存储$pushevent_count=2(user:message + 零值 token:usage),刷新即丢整段历史;同一根因还导致SANDBOX_PLATFORM回落默认 → 本地 daemon 身份段(fix(prompt): 本地 daemon 会话注入「沙箱=用户本机」身份段 #499)不再注入staging 此前测不出的原因:staging DB 没开 chunk 开关(两边都 false,路径一致)。开启后 5 分钟内稳定复现(
event_count=2)。Fix
worker_main._amain启动第一步initialize_settings()+validate_distributed_runtime_settings(settings),对齐 API lifespan(src/api/main.py:443);失败快速退出,由 k8s CrashLoopBackOff 显性暴露——绝不带默认值继续吞事件。Testing
test_amain_loads_db_settings_before_any_service(顺序契约)、test_amain_settings_init_failure_stops_startup(失败即停)——修复前 RED、修复后 GREENtests/infra/task/+tests/infra/session/+tests/kernel/config/+tests/client/共 920 passed