Skip to content

fix(cockpit): mid-round log seeding — ops stderr tail rides the snapshot - #219

Merged
steponeerror merged 1 commit into
masterfrom
feature/cockpit-log-tail
Oct 26, 2026
Merged

steponeerror merged 1 commit into
masterfrom
feature/cockpit-log-tail

Conversation

@steponeerror

Copy link
Copy Markdown
Owner

问题

驾驶舱(运营 tab)轮次进行中打开页面时,点「展开全量日志」没有任何可见变化。

根因:task_log SSE 事件是 fire-and-forget——后端 UpdateManager.ops_log 只 _emit 不留存,快照(SSE 初始事件与 /api/tasks)只带 tasks+batch。轮中开页的用户丢掉订阅前的全部 stage 行,日志面只剩 1 行,展开与收起视觉相同。

修复(三层)

  1. 后端日志尾(backend/ipdb/_tasks.py):每 ops task 一条 _OPS_LOG_KEEP=200 deque 尾(与前端 LOG_KEEP_LINES 同窗)。start_ops_round 建、下一轮 start 清扫、终态后仍随快照出(轮后开页也能播上一轮尾)。snapshot() 增 logs 面 {task_id: [lines]},经 TasksSnapshotOut extra="allow" 透传。未知 task_id 照发事件不建尾(恢复轮替身不破)。
  2. 前端播种(frontend/src/tasks/TaskProvider.tsx):seedLogs 接 SSE snapshot 事件与 resync fetch 两口;合并律=尾更长才替换——同 task 的 append-only 流上,更短的旧快照(fetch/SSE 竞态)不得缩水已收行。
  3. 驾驶舱 UX(frontend/src/pages/OpsCockpit.tsx):展开钮带行数计数(单行时也有可见差);新一轮起跑上升沿复位展开态(全新日志面不跨轮携带)。

验证

  • backend:test_ops_rounds + test_tasks + test_tasks_pruning 90 passed(新 3 例:尾随快照出+终态留+下轮清扫 / 205 行窗 200 / 未知 tid 只发不建)
  • frontend:vitest 全量 437/437(新 3 例:快照播种+播种后追加 / 更短旧快照不缩水 / 计数+新轮复位)+ tsc + build 绿

单写者直修(伞收口判例),非 SDD 派发。

task_log was fire-and-forget: a page opened mid-round saw only
post-subscribe lines, so 展開全量日誌 clicked with no visible change.

- backend: _OPS_LOG_KEEP=200 tail per ops task in UpdateManager
  (created at start_ops_round, swept next round, survives terminal
  state); snapshot() gains a logs face {task_id: [lines]}; unknown
  task_id still emits without a tail
- frontend: TaskProvider.seedLogs on snapshot event + resync fetch,
  replace-only-if-longer (stale snapshot never shrinks received lines)
- cockpit: expand button carries the line count; new round's rising
  edge resets the expanded state

Gates: backend 90/0 (ops_rounds+tasks+pruning, 3 new), frontend
vitest 437/437 (3 new) + tsc + build
@steponeerror
steponeerror marked this pull request as ready for review October 26, 2026 07:50
@steponeerror
steponeerror merged commit d6afb25 into master Oct 26, 2026
3 checks passed
@steponeerror
steponeerror deleted the feature/cockpit-log-tail branch October 26, 2026 07:51
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