Skip to content

thirdshift console uses 50-74% of a core while idle #1153

Closed

Description

@JacobStephens2

thirdshift console (0.14.3) burns 50-74% of one core on stephens.page with no Console tabs open. Over 33h46m of uptime the thirdshift-console.service process (PID 3393557) accumulated 7h38m of CPU time, a steady ~22% of a core averaged over its life on a 4-core host.

Evidence

  • pidstat 5s samples at 2026-10-23 13:13-13:20 UTC: 51%, 74%, 60% CPU. Roughly 60% of that is system time (e.g. 35.6% sys vs 24.4% usr), split across tokio-rt-worker threads.

  • 4 established connections to 127.0.0.1:8711 from the Apache proxy for console.stephens.page. After I closed every Console tab in Chrome, CPU did not drop and 2 of the 4 connections were replaced by new ones, so the load does not track open browser tabs.

  • Restarting does not clear it. After sudo systemctl restart thirdshift-console at 13:19 UTC, the new process (PID 2591794) sampled 64.5% CPU (26.9% usr, 37.6% sys) over its first 10s and had used 28s of CPU in 47s of uptime, with 3 proxy connections open. The spin starts at launch rather than building up over the process's life, which should make it easy to reproduce.

  • thirdshift console log shows only sign-in, code-sent and password-set entries, nothing that accounts for the activity.

  • /proc/<pid>/io over 5s after the restart: 87 MB rchar across 54,342 read syscalls (about 17 MB/s and 11k reads/s, all from page cache, read_bytes 0) and 5.3 MB wchar (about 1 MB/s out to the proxy connections). That is where the system time goes.

  • 300 samples of /proc/<pid>/fd mostly caught the process holding directories under ~/.thirdshift/logs/*/*/commands/* open, led by JacobStephens2/thirdshift/commands/pickup (445 MB) and JacobStephens2/keeplore/commands/architect (725 MB). The whole store is 6.4 GB across 5,366 files.

Likely causes (at 380e63a)

Every one of these is a fixed-interval poll rather than a reaction to a change:

  • src/console/live.rs:13-29 - observe() re-renders the whole Inbox page every 1s and diffs the HTML, whether or not anyone is viewing. This explains the spin starting at launch.
  • src/console/live.rs:40-58 - each live connection runs still_allowed() on a blocking thread every 250ms.
  • src/console/logs.rs:220-222 - each open log reader re-reads its log every 250ms.
  • src/console.rs:322-335 - the shutdown watcher reloads the accounts file every 250ms.

A one-off thirdshift status takes 0.10s (0.04 usr, 0.03 sys), so a 1Hz render alone should cost about 10% of a core, not 60%. Either render_page does far more than the CLI (likely walking the log store) or the per-connection loops make up the rest. Profile before changing code, and confirm the fix against the same measurements.

Scope

  • Fix all four polling loops above, not only the Inbox observer.
  • Switching to change-driven updates (filesystem notifications such as the notify crate, or signals from the code that writes Command logs and account state) is in scope and preferred over tuning intervals. Keep a slow fallback poll only if notifications can be missed.
  • Bounding the log store itself is out of scope and tracked in Command log store grows without bound (6.4 GB on stephens.page) #1155. The fix here has to hold at the current 6.4 GB.

Expected

An idle Console with no viewers should sit near 0% CPU, and CPU with viewers connected should scale with actual state changes, not with time.

Workaround

None short of sudo systemctl stop thirdshift-console, which takes the Console offline. Restarting does not help (see above). Stopping or restarting the service does not affect running thirdshift Runs, since they live outside the service's cgroup.

Acceptance criteria

  • Root cause identified with a profile or syscall/IO measurement, recorded in the PR
  • With no viewers connected, thirdshift console averages under 1% of one core over 60s on stephens.page (6.4 GB log store)
  • With 3 viewers connected (Inbox open, one log reader open) and no Runs changing state, it averages under 5% of one core over 60s
  • With no viewers and no state changes, rchar grows by under 1 MB per minute
  • Inbox and log readers still update within about 2s of a change, and a removed account still loses its sessions without a request
  • Tests cover the change-driven update path

Activity

  1. added
    bug
    needs-triage
    on Oct 23, 2026
  2. JacobStephens2 commented on Oct 23, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Triage findings: reproduced on a second host, likely cause found

    Reproduced with zero viewers

    This is the thirdshift host (Caddy in front, not stephens.page), running thirdshift-console.service on 0.14.3, PID 4139545, up 2d14h.

    • Lifetime CPU is 19.2h (38,694s usr + 30,269s sys), about 30% of a core averaged over its uptime. System time is 44% of the total, matching the split in the report.
    • pidstat 5s samples at 2026-10-23 13:20 UTC: 49.6%, 46.8%, 39.4%, about 55/45 usr/sys. Most of it is on two tokio-rt-worker threads, each around 16%.
    • No established TCP connections to 127.0.0.1:8711 at all (ss -tn state established '( sport = :8711 or dport = :8711 )' is empty). The load doesn't depend on viewers.
    • No child processes were seen over 2s of sampling, so the cost is in-process.
    • From /proc/4139545/io: lifetime rchar is 2.4 TB, about 10.7 MB/s on average, from about 2,100 read syscalls/s. A live 5s sample showed about 4 MB/s and 1,100 reads/s.

    Likely cause: the Inbox observer re-renders every second, and each render re-reads the logs

    src/console/live.rs observe() starts a task when the server starts. That task calls render_inbox("thirdshift status") every 1s, whether or not anyone is subscribed. It diffs the HTML to decide whether to bump the watch revision. render_inbox → render_page → status::inbox(&config) (src/console.rs:482) rebuilds the whole Inbox from disk each time.

    To measure what one render costs, I traced the equivalent CLI, thirdshift status:

    • About 0.09s CPU per run (10 runs: 0.49s usr + 0.44s sys), split about evenly between usr and sys.
    • About 10.5 MB read across about 900 file opens, 1,567 read and 206 getdents64 calls.
    • The biggest reads are whole files: logs/<owner>/<repo>/activity.log (500 KB for thirdshift, 290 KB for chart35, 220 KB for muxboard and so on) and complete commands/{issue,pickup}/*.log files of 200–300 KB each.
    • ~/.thirdshift/logs holds 3,460 files, 4.4 GB. Per-tick cost grows as Runs pile up, which fits both hosts getting worse over time.

    The reads are served from page cache, which explains the high system-time share (kernel copy work). On an 8 GB host it also keeps several GB of logs hot in cache.

    Smaller periodic work

    • Shutdown watcher, src/console.rs:323-338: every 250ms it stats the executable (restart::Executable::changed). When sign-in is enabled it also calls spawn_blocking(Accounts::load), which reloads config.toml, takes console-accounts.lock and parses console-accounts.json. That's 4 times a second with no viewers.
    • Per SSE viewer, src/console/live.rs:40-56: each open /events stream runs spawn_blocking(still_allowed) every 250ms. This doesn't apply to the idle case above, but it is a fixed per-viewer cost that doesn't depend on state changes (acceptance criterion 3).

    Gap I couldn't close

    At 1 Hz, one CLI-equivalent render accounts for about 10% of a core. The observed 40–50% is higher than that. ptrace and perf on the service process were denied, so I couldn't profile it directly. Things to check: whether the Console's render reads more than the CLI path (template plus hidden sections), and how much the 4 Hz Accounts::load loop costs. A profile (perf record -p <pid> as root, or strace -c -f -p <pid> as root) would settle it.

    Suggested fix direction

    1. Make the observer change-driven instead of a re-render poll: watch ~/.thirdshift/logs with inotify/notify, or check cheap mtimes/sizes first and only re-render on a change. At minimum, skip rendering when changes.receiver_count() shows no subscribers.
    2. Have status::inbox stop reading whole activity.log and command logs on every call: tail or seek to what it needs, or cache parsed state keyed by (path, len, mtime).
    3. Slow down the 250ms account and executable checks (1–5s is plenty for revocation and self-update), or make them change-driven by watching the mtime of console-accounts.json and config.toml.
    4. Add a regression test or bench: an idle Console with N synthetic Runs does a bounded amount of reading per minute.

    Recommendation

    Category bug (already applied). State ready-for-agent: the cause is located and the acceptance criteria are measurable (pidstat / /proc/<pid>/io on an idle service). Left at needs-triage until the maintainer confirms.

  3. added
    ready-for-agent
    and removed
    needs-triage
    on Oct 23, 2026
  4. JacobStephens2 commented on Oct 23, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI from local measurements, before stopping the service.

    A third host, with a root syscall profile

    thirdshift-console.service 0.14.3, behind Apache (httpd), up 1d19h56m. This host has 8 cores and 15 GB of RAM. Its log store is much smaller: 166 MB across 498 files (vs 6.4 GB on stephens.page). Measured 2026-10-23 13:33–13:36 UTC.

    CPU and IO

    • Lifetime CPU is 4h21m (10,264s usr + 5,431s sys), about 10% of a core averaged over its uptime.
    • 60s from /proc/<pid>/stat, sampled every 10s: 20%, 18%, 21%, 20%, 18%, 17% of one core. That's 18.7% overall, 69/31 usr/sys.
    • The same 60s from /proc/<pid>/io: rchar grew 133 MB (2.2 MB/s) over 84,482 read calls (about 1,400/s). read_bytes stayed at 0, so all of it came from page cache. wchar grew 14.8 MB.
    • Lifetime rchar is 228 GB.
    • 9 proxy connections to 127.0.0.1:8711 were open, and the per-thread CPU is spread evenly across the 4 tokio-rt-worker threads.

    So the cost holds even with a small store. It scales with the number of Command records in a directory, not the store's byte size.

    strace -c -f, 20s, as root

    syscall calls per second
    stat 45,220 (9,516 ENOENT) 2,261
    getdents64 35,126 1,756
    read 22,770 1,139
    open 15,251 763
    mmap / munmap 12,686 each 634
    close / fcntl 14,900 each 745
    fstat 11,255 563
    mkdir (all EEXIST) 187 9
    flock 187 9
    fsync / renameat 26 each 1.3

    Most of the wall time is in futex and epoll_pwait, which is idle waiting. The work is directory listing and opening small files.

    What it opens: 6,836 open/stat calls in 10s

    count / 10s path
    2,740 logs/<org>/<repo>/commands/pickup/*.json (276 files in the dir)
    1,090 that commands/pickup directory itself
    657 <repo>/commands/issue/*.json (126 files)
    623 <repo>/commands/architect/*.json (31 files)
    275 / 198 <repo>/commands/{pickup,issue}/*.log
    224 / 100 the issue / architect directories
    117 JacobStephens2/thirdshift/commands/issue/*.json
    106 config.toml
    91 / 91 console-accounts.json / console-accounts.lock

    The commands/pickup directory is listed about 109 times a second, and its Command records are opened about 274 times a second. That is far more often than the 1 Hz Inbox observer alone would cause. It points to the per-connection 250ms loops (still_allowed, log readers) or to listing being repeated inside a single render, for example once per Command or per Run instead of once per directory. The 300-sample /proc/<pid>/fd capture agrees: the directory most often held open was <repo>/commands/pickup.

    Writes nobody asked for

    • console-accounts.json is rewritten about every 2s (temp file + fsync + renameat into ~/.thirdshift/console-accounts.json), while the page is only being watched (9 proxy connections, no sign-ins in the measurement window). Something in the session or still-allowed path seems to persist on read. That also makes the 250ms watchers' reload of that file self-inflicted churn.
    • mkdir("~/.thirdshift") runs about 8 times a second, always with EEXIST, which suggests the directory is created on every config or account load.

    These are worth adding to the fix scope. An idle Console should write nothing.

  5. JacobStephens2 commented on Oct 23, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI from local measurements, after stopping the service.

    Same host, after sudo systemctl stop thirdshift-console.service

    Stopped at 2026-10-23 13:39 UTC, using the workaround from the issue body.

    • The unit is inactive (main process exit status 15, SIGTERM). No thirdshift console process is left, and nothing is listening on 127.0.0.1:8711. Requests through the proxy now fail, as expected.
    • The unit's final CPUUsageNSec is 15,775s, or 4h23m of CPU across its 1d20h life, about 10% of a core on average. Between the first reading at 13:32:46 and the stop it used another 80s, about 21% of a core over those 6½ minutes. That window includes strace overhead.
    • No other thirdshift process was running at the time of the stop, so no Run was affected.
    • Host-wide CPU over the next 60s didn't settle the question. The host was 42% busy across 8 cores, almost all of it from an unrelated rustc build, so the drop from the Console (about 0.2 core of 8, roughly 2.5% of the host) is within that noise. The before figures in the previous comment were measured on the Console process alone, and they're the ones to compare a fix against.

    To check the fix on this host, restart the fixed binary with the same 9-ish proxy connections, then repeat the 60s /proc/<pid>/stat and /proc/<pid>/io samples and the strace -c -f profile. The aim is under 1% of a core, rchar under 1 MB/min, and no renameat into console-accounts.json while idle.

  6. JacobStephens2 commented on Oct 23, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Code findings at 380e63a, plus a fourth host

    These are the causes the earlier comments left open. Each one points to code.

    Why console-accounts.json is rewritten every ~2s

    On every signed-in request, the auth middleware calls Accounts::load()?.session(&selected, true) (src/console/auth.rs:107). With touch set, session() updates the session's last-use time and calls save(): a temp file, fsync, then a rename over console-accounts.json (src/console/accounts.rs:198-213, 241-247). So every page fetch writes to disk. Sessions last 30 days, so the last-use time only needs persisting when it is more than about a minute old.

    Where the mkdir EEXIST calls and config.toml reads come from

    Accounts::open runs fs::create_dir_all(root) on every load (accounts.rs:97). Accounts::load also runs UserConfig::load() each time. Accounts are loaded:

    • by the shutdown watcher, 4 times a second (console.rs:323-335)
    • by still_allowed() in every Inbox stream, 4 times a second (live.rs:42)
    • by every log reader, 4 times a second (logs.rs:201)
    • on every request (auth.rs:107)

    That fits the 106 reads of config.toml per 10s in the root profile.

    Every render reads the whole store, not just the Inbox window

    Snapshot::load_with_silence (src/logs/reading.rs:43-100) lists and parses every *.command.json and *.child.json in every repo. inbox_days is only applied afterwards, in snapshot.inbox(false, config.inbox_days) (src/logs/status/inbox.rs:201-202). The cost of each render therefore grows with the total number of records, which #1155 is what lets grow. A fix that holds without #1155 needs either a parse cache keyed on (path, mtime, len) or loading only the records the Inbox window needs. Making the observer change-driven alone isn't enough, because each change still costs a full-store parse.

    The browser multiplies each change

    Every commands event makes each subscriber in a tab refetch /: the page refresh (assets/console.js:136) and the notifications check (assets/notifications.js:35). Each fetch is a full server render plus an accounts save (see above). If the event stream errors, assets/changes.js also falls back to refetching every 5s. With viewers connected, one state change therefore costs several full renders per tab. Keep this in mind when measuring acceptance criterion 3.

    A small correction on threads

    The Console builds a new_current_thread runtime (console.rs:308). The busy tokio-runtime-worker threads in the measurements are therefore the spawn_blocking pool. The time goes into the blocking closures (rendering and account loads), not the async scheduler.

    Fourth host: orchestration.etadventures.com

    thirdshift-console.service 0.14.3, up 23h, no established connections to 127.0.0.1:8711. The log store is 56 MB with 94 .json files, on 8 cores.

    • Lifetime CPU is 52m45s, about 3.8% of a core.
    • 20s sample on 2026-10-23: 4% of one core, rchar about 37 MB/min.
    • Lifetime rchar is 51.7 GB.

    This is the same bug at a smaller size. It agrees with the third host that the cost scales with the number of records, not the store's byte size.

    Still open

    Nobody has yet attributed the "commands/pickup listed about 109 times a second" figure. The per-viewer 250ms loops, the per-request account loads and the browser's extra refetches together look like enough to explain it, but that is unmeasured. The strace profile on the fixed build should confirm it.

  7. added
    in-progress
    and removed
    ready-for-agent
    on Oct 23, 2026
  8. removed
    in-progress
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions