shells feed: an idle refresh opens no task files

AF
1m ago
+448-107

On 6 Dec the live daemon ran at 46-480% CPU in the app live-shells feed (shells/v1). Two causes, both fixed here:

  • Expired tasks were reopened on every collection. Registries keep finished tasks for 24 h, but the feed shows 30 min. Each collection sampled every registry task (opening its output files and reading its layout), then dropped the expired ones from the cache, so the next collection reopened them. Expired tasks are now skipped before any file work.
  • The feed woke twice a second. poll_task woke the feed on every 500 ms watchdog pass for every indexed task, changed or not. The watchdog now stamps each task's output once per pass and wakes the feed only when something changed. The collector keys watched tasks on that in-memory revision. Other tasks keep path lstat stamps, so output appended to an ended task still shows.

One idle collection with 200 retained and 200 expired tasks (debug build, build server): before 183.9 ms, 400 artifact opens and 2,800 store opens; after 27.3 ms, 0 and 0. The new test fails on the old code with exactly those counts.

Not changed: the per-collection operator_shell_rows query and the 1 s tick while database-only rows are retained. Both are per collection, not per task.


Summary by cubic

Fixes the live shells feed (shells/v1) CPU spike by removing per-collection file opens and unnecessary wake-ups.

  • Expired tasks are now filtered before any file work, so finished tasks outside the 30-minute feed window never get reopened. Saved rows that expire after being loaded are also dropped before sampling.
  • The watchdog stamps each task's output once per pass and wakes the feed only when output changes, instead of every 500 ms.
  • Unchanged watched tasks reuse cached snapshots without stat; direct appends to ended tasks still show through file stamps.
  • One idle collection with 200 retained and 200 expired tasks dropped from 183.9 ms with 400 artifact opens and 2,800 persistence opens to 27.3 ms with 0 and 0.

Not changed: the per-collection operator_shell_rows query and the 1 s tick while database-only rows are retained. Both are per collection, not per task.

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge, with a non-blocking gap in refreshing late output from retired tasks.

Findings

  1. P2 Late output stays hidden ▶

Summary

Reduces file work and wake-ups in the shells/v1 feed.

  • The shells feed skips expired tasks before opening their files.
  • The shells feed refreshes watched output only when it changes.
  • Task polling now lives in a separate registry file.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[Watchdog stamps indexed task] --> B{Output changed?}
  B -->|Yes| C[Wake feed and sample rows]
  B -->|No| D[No feed wake]
  E[One-second timer] --> F{Any persisted reader?}
  F -->|Yes| C
  F -->|No, facts unchanged| G[Skip task sampling]
  H[Append to retired task] --> I[File stamps change]
  I --> J[Detected only when rows are sampled]

Reviews (2) · Last reviewed commit: "shells feed: skip saved rows that expire..." · Reviewed by Greptile