Skip to content

perf(front): cache activity monitor data per org and parallelize job lookups - #1389

Open
loadez wants to merge 3 commits into
mainfrom
ws/front-activity-fanout
Open

loadez wants to merge 3 commits into
mainfrom
ws/front-activity-fanout

Conversation

@loadez

@loadez loadez commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Speeds up the Activity Monitor (/activity, /activity/data) and /agents for organizations with many running pipelines. Org-wide activity data is cached for 5 seconds per organization with one shared in-flight fetch, so open tabs polling the same organization no longer each repeat the full fan-out. Project visibility is still filtered per user on every request.

Job lookups now start per pipeline page while paging, and the job, project, user and debug joins use map lookups instead of list scans. When loading fails, /activity/data returns a 503 JSON error (the page keeps its last data) and the page renders empty activity instead of a 500. The response shape is unchanged.

Tested: new tests for the cache (per-user filtering, shared fetch, errors not cached), per-page job lookups, and equivalence of the joins with the previous implementation; front test suite, mix credo --all and mix format --check-formatted pass.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T11:49:49.933698Z 6415f18 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6415f1869a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


fetch_accessable_projects =
Async.run(fn -> list_projects(org_id, user_id, tracing_headers) end)
case Async.await(task, timeout: @org_activity_timeout) do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cancel descendant fetches when the org timeout fires

When an organization fetch exceeds 90 seconds—which is possible with the sequential, 30-second-per-page pipeline/debug pagination—this await shuts down only the fetch_org_activity/2 wrapper. The organization, project, pipeline, debug, and per-page job tasks it created with Task.Supervisor.async_nolink continue running independently; because the timeout result is not cached, the next browser poll starts another full fetch while those tasks are still active. Cancel all descendant tasks when the bound expires so a slow backend cannot accumulate overlapping RPC work.

Useful? React with 👍 / 👎.

Comment on lines +234 to +237
start_jobs = fn
[] -> nil
pipelines -> start_jobs_fetch(tracing_headers, org_id, ppl_ids_of(pipelines))
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cancel page job tasks when pipeline pagination fails

If a later Plumber page fails after one or more successful pages, those earlier calls have already started Zebra job tasks here, but list_pipeline_pages/3 returns only the error and discards the partial pages containing their task handles. Consequently list_pipelines_and_jobs/2 exits without awaiting or shutting down those tasks; since the failed result is not cached, repeated polls during a pagination outage can accumulate redundant job-list RPCs. Retain and cancel the started tasks on the pagination error path.

Useful? React with 👍 / 👎.

@loadez
loadez force-pushed the ws/front-activity-fanout branch 2 times, most recently from e9a6f87 to 9d6e111 Compare November 10, 2026 11:32
…lookups

- Cache org-wide activity data for 5s per org with a single shared
  in-flight fetch; project visibility is still filtered per user.
- Start the job lookup for each pipeline page while paging instead of
  after all pages, sending only that page's pipeline ids.
- Replace list scans in the job, project, user and debug joins with
  map and set lookups; count hidden items without building them.
- Return 503 JSON from /activity/data and render empty activity on
  page load when loading fails, instead of a 500.
…ancel abandoned lookups

- Cache only the pipeline, block job and job fields the activity page and
  the agent stats read. Every cache read copies the entry, so the raw
  pipelines and jobs cost far more memory and time than the page needs.
- The per-page job lookups of one load share a single budget of 10 zebra
  pages, the same limit as the previous single lookup.
- Every task of an org fetch runs under a supervisor owned by that fetch
  and stopped when it ends, so an organization or project failure, a failed
  pipeline page or the fetch cap no longer leaves plumber and zebra lookups
  running in the background. The organization and projects are awaited
  before the first pipeline page is requested.
- Start the users lookup right after paging, while the job lookups run.
- The fetch cap can be set with :activity_monitor_fetch_timeout_ms.
- The job lookups of one load share a budget of 5,000 jobs, the same as
  the previous single lookup. Each lookup always gets its first page, so
  no pipeline page is left without jobs; later pages are fetched only
  while the load is under the budget, and an overshoot from lookups
  running in parallel is trimmed from the later pages.
- ACTIVITY_MONITOR_FETCH_TIMEOUT_MS sets the fetch cap; a value that is
  not a positive integer falls back to the default.
- Stopping a fetch's task supervisor that is already gone is not an
  error.
- Tests clear the feature cache they fill, and the cancellation tests
  let in-flight mock requests settle before asserting silence.
@loadez
loadez force-pushed the ws/front-activity-fanout branch from d1a0212 to ad813e3 Compare December 4, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants