Skip to content

perf(team-reports): keep collection off the Gateway event loop - #159101

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-team-reports-fetch-runs-main-thread-bursts-20260919
Sep 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-team-reports-fetch-runs-main-thread-bursts-20260919

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large Team Reports collection runs parse source responses and aggregate activity on the Gateway event loop, causing heap churn and pauses while reports are generated.

User Impact

Report collection runs in a worker, with bounded batches staged in SQLite. Report counts, attribution, JSON, and Markdown stay unchanged. Boot catch-up reuses accepted closed days when retrying a partially failed run; explicit manual generation still refreshes the requested day.

There is no new configuration, durable schema migration, or retention change. Existing databases reopen unchanged. Scratch activity belongs to the existing store connection and disappears on close. Week/month reports already used stored days on this base; this preserves that behavior.

Why This Change Was Made

Uses the existing public WorkerTaskPool / serveWorkerTasks contract from openclaw/plugin-sdk/process-runtime and openclaw/plugin-sdk/worker-task-server, documented in worker task admission. The host retains the SQLite broker and LLM capability; it forwards bounded requests and drains admitted callbacks before closing storage. No new SDK surface or alternate inline production execution path is added.

Collectors upsert at most 100 events per batch. Aggregation decodes payloads in bounded queries, caps retained evidence while counting, and reads daily rollups under one SQLite snapshot. Compact sort identities still scale with event count to preserve the existing JavaScript collation; full source bodies no longer accumulate for the period. Production growth is about 500 lines, above the lane's 150-line guideline because this includes the complete worker lifecycle/host bridge and store cutover.

Evidence

Synthetic fixture: 2,000 issues, 1,000 commits, 1,500 Discord messages, 93 repositories, 12 channels, and 692 threads. Real collectors, generation, SQLite backend, and production worker run with fixture HTTP responses; summaries are disabled. Measurements include instrumentation and worker startup.

Main-isolate measurement Before Final worker run
Sampled peak heap delta 95.68 MiB 52.12 MiB
Longest synchronous callback 54.67 ms 19.01 ms
Longest event-loop turn 69.49 ms 19.04 ms
Fixture elapsed time 299.83 ms 949.15 ms

An earlier same-lease worker run measured 52.02 MiB / 5.54 ms synchronous / 6.40 ms event-loop turn. Both worker runs meet the <100 MiB / <50 ms targets. Worker startup and IPC increase this zero-latency fixture's elapsed time; the intended improvement is Gateway responsiveness. Running the new streaming collector directly measured 80.91 MiB and 16.72 ms synchronous, with aggregation still in the SQLite worker.

Daily and monthly report JSON and Markdown SHA-256 values match the baseline exactly in all runs. This fixture measures main-isolate heap, not total process RSS, and does not reproduce the full production multi-GB burst. No live API run, deployment, restart, or Gateway instrumentation was performed.

All heavy proof used blacksmith-testbox, profile openclaw-check:

Lease Commands and results
tbx_01m3fbd407ym1nb3j74jhpdtqb Baseline benchmark and first worker benchmark passed. Initial invocation found missing dependencies; pnpm install --frozen-lockfile passed. Two plugin-suite attempts stopped at checksum-sync timeout before tests ran.
tbx_01m3fct9bg88ccbkctzmjp2zah Verified source HEAD and changed-file hashes; installed dependencies. node scripts/run-vitest.mjs extensions/team-reports --maxWorkers=1: 271 tests / 17 files passed, 50.77 s wrapper wall time. Changed checks identified missing safety comments, subsequently fixed. Reuse eventually hit the same sync timeout.
tbx_01m3fdmypdkpy63hfq39mt1cj1 node scripts/check-changed.mjs --base HEAD found a flattened LLM request union, then lint issues; all were fixed. Production/test typechecks, metadata, dependency and dead-export guards passed. Reuse hit a checksum-sync timeout.
tbx_01m3ferha8qptqsht2zpfqbzmr Focused plugin lint passed. Package-manifest/runtime-dependency contracts: 528 tests passed in 2.02 s. All 270 existing plugin tests passed; one new lifecycle fixture failed because Vitest did not expose the spied original, then its corrected native-worker test passed (5.13 s wrapper wall). check-plugin-npm-runtime-builds.mts --package extensions/team-reports built all four runtime entries. Final worker/direct benchmarks passed with matching output hashes. node scripts/check-changed.mjs --base HEAD passed, including production/test types, all extension lint, metadata, dependency/dead-export/sidecar/cycle guards.
tbx_01m3fhcfk5h41ftdx2b2rgcxty CI repair: pnpm deadcode:full and node --import ./scripts/tsx.mjs scripts/check-deadcode-unused-files.mts passed; both unused-file scans reported zero entries.

Changed-test costs on the final lease, measured with /usr/bin/time pnpm test <file> --maxWorkers=1 --reporter=dot: aggregate 1.84 s; scheduler 26.40 s; store 9.86 s; GitHub source 1.75 s; Discord source 1.62 s; worker lifecycle 5.64 s. All passed. Scheduler/store wall time includes worker compilation/import and real SQLite lifecycle coverage; the new worker test itself took about 0.15 s.

The new lifecycle test exercises real worker exit and retained host callback settlement. Added coverage also protects batch backpressure, cross-batch upserts/comment deduplication, exact Unicode comment identity, and boot catch-up after partial failure. The benchmark is standalone test support, adding no per-PR timed benchmark. Existing test coverage remains intact. All leases are stopped at handoff.

Reproduce the benchmark with:

node --expose-gc --import ./scripts/tsx.mjs extensions/team-reports/src/report-run.benchmark.test-support.ts --worker

Independent Codex autoreview: no actionable P0–P2 findings. The first GitHub CI run passed its four selected test jobs (55, 90, 103, and 110 seconds) and completed type checks, but the dependency lane found the standalone benchmark absent from the unused-file entrypoint graph. The benchmark's real command is now documented and registered in the test-aware Knip configuration, with no ignore or baseline relaxation. The exact failed scans pass on the repair lease above. Final CI succeeded on acb327afa77d4208a35d1c9e971b8188e5f9ca85, including openclaw/ci-gate. The selected node jobs completed in 57–109 seconds.

Stream source activity through bounded SQLite batches, preserve report outputs, and reuse accepted closed days during boot retries.
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation plugin: team-reports size: XL labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 3:15 PM ET / 19:15 UTC.

ClawSweeper review

What this changes

Moves Team Reports collection and aggregation into workers, stages activity in bounded SQLite batches, and lets boot catch-up reuse accepted closed daily reports.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

Current main still runs Team Reports collection on the Gateway event loop, so this PR remains useful. One introduced catch-up check can silently reuse a daily report after its source settings change and should be repaired before merge.

Priority: P2
Reviewed head: acb327afa77d4208a35d1c9e971b8188e5f9ca85

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The production-path fixture and focused validation provide useful evidence, but the catch-up compatibility defect blocks merge.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its reported Testbox fixture exercises the production worker, collectors, and SQLite backend and observes lower main-isolate heap and event-loop delay with matching report hashes; it does not cover changed-settings restart or live Gateway load. The durable report schema is unchanged.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its reported Testbox fixture exercises the production worker, collectors, and SQLite backend and observes lower main-isolate heap and event-loop delay with matching report hashes; it does not cover changed-settings restart or live Gateway load. The durable report schema is unchanged.
Evidence reviewed 7 items Introduced catch-up condition: The new reuse branch checks a closed report, healthy stored sources, and GitHub organization names, but does not compare whether Discord is now enabled or whether its channels and other collection settings changed.
Settings affect report content: The plugin configuration independently defines Discord enablement, guild, channels, excerpts, GitHub filters, and people; an unchanged organization list does not establish an unchanged collection scope.
Restart test covers only unchanged settings: The added partial-failure restart test reopens the store with the same setup configuration and asserts that yesterday is skipped; it does not exercise changed source settings.
Findings 1 actionable finding [P1] Recollect closed days when source settings change
Security None None.

How this fits together

The Team Reports plugin collects GitHub and optional Discord activity, combines it with a roster, and stores daily and summary reports in its SQLite database. The Gateway serves those reports through plugin routes and commands.

flowchart LR
  A[GitHub and Discord] --> B[Collection worker]
  B --> C[Bounded activity batches]
  C --> D[SQLite store worker]
  D --> E[Daily and period reports]
  E --> F[Gateway report views]
  G[Catch-up settings] --> B
Loading

Before merge

  • Recollect closed days when source settings change (P1) - The introduced catch-up branch compares only GitHub organizations. If a prior partially failed run saved a healthy GitHub-only day and the operator enables Discord before restart, catch-up skips that day and can finish successfully without its Discord activity; changing channels or filters has the same stale-report risk. Require matching source settings or recollect when their provenance is unavailable.
  • Resolve merge risk (P1) - After a partially failed run, restarting with Discord newly enabled or with different channels can leave yesterday's old counts and excerpts in place while catch-up records success.
  • Complete next step (P2) - Make catch-up recollect when the stored day's source settings are changed or unverified, and prove that restart case before merge.

Findings

  • [P1] Recollect closed days when source settings change — extensions/team-reports/src/run.ts:84-90
Agent review details

Security

None.

PR surface

Source +495, Tests +678, Docs +24, Config +1, Other +4. Total +1202 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 15 629 134 +495
Tests 10 739 61 +678
Docs 2 27 3 +24
Config 1 2 1 +1
Generated 0 0 0 0
Other 1 4 0 +4
Total 29 1401 199 +1202

Review metrics

Metric Value Why it matters
Main-isolate fixture peak 95.68 → 52.12 MiB reported The controlled production-path fixture supports the responsiveness goal, though it does not measure a deployed Gateway.
Code growth production +495 net lines; tests and test support +678 net lines The PR body attributes production growth to the worker lifecycle, host bridge, and store cutover.

Merge-risk options

Maintainer options:

  1. Verify scope before reuse (recommended)
    Recollect an accepted day whenever the source settings that produced it cannot be proven to match the current configuration, and cover a changed-settings restart.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Repair boot catch-up so an accepted closed day is not reused under changed or unverified GitHub and Discord collection settings; add a focused restart regression, preserve manual refresh and the worker cutover, and leave CHANGELOG.md untouched.

Technical review

Best possible solution:

Keep collection and aggregation in workers, and reuse a stored day during catch-up only when its source settings can be verified against the current settings; otherwise recollect it.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: save a healthy GitHub-only closed day during a partially failed run, enable Discord, then restart into boot catch-up. The new condition skips that day because only GitHub organizations are compared; this scenario was not executed in this read-only review.

Is this the best way to solve the issue?

Yes for the worker cutover, subject to the catch-up repair. The existing Plugin SDK worker pool and SQLite store owner fit this performance change; stored-day reuse needs a complete scope check.

Full review comments:

  • [P1] Recollect closed days when source settings change — extensions/team-reports/src/run.ts:84-90
    The introduced catch-up branch compares only GitHub organizations. If a prior partially failed run saved a healthy GitHub-only day and the operator enables Discord before restart, catch-up skips that day and can finish successfully without its Discord activity; changing channels or filters has the same stale-report risk. Require matching source settings or recollect when their provenance is unavailable.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cafb3a4d1ca2.

Labels

Label changes:

  • add P2: This is a bounded plugin responsiveness improvement with one settings-sensitive catch-up regression.
  • add merge-risk: 🚨 compatibility: The new reuse condition can silently retain a report generated under different source settings after restart.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its reported Testbox fixture exercises the production worker, collectors, and SQLite backend and observes lower main-isolate heap and event-loop delay with matching report hashes; it does not cover changed-settings restart or live Gateway load. The durable report schema is unchanged.

Label justifications:

  • P2: This is a bounded plugin responsiveness improvement with one settings-sensitive catch-up regression.
  • merge-risk: 🚨 compatibility: The new reuse condition can silently retain a report generated under different source settings after restart.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its reported Testbox fixture exercises the production worker, collectors, and SQLite backend and observes lower main-isolate heap and event-loop delay with matching report hashes; it does not cover changed-settings restart or live Gateway load. The durable report schema is unchanged.

Evidence

Acceptance criteria:

  • [P1] pnpm test extensions/team-reports/src/scheduler.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --base HEAD.

What I checked:

  • Introduced catch-up condition: The new reuse branch checks a closed report, healthy stored sources, and GitHub organization names, but does not compare whether Discord is now enabled or whether its channels and other collection settings changed. (extensions/team-reports/src/run.ts:84, acb327afa77d)
  • Settings affect report content: The plugin configuration independently defines Discord enablement, guild, channels, excerpts, GitHub filters, and people; an unchanged organization list does not establish an unchanged collection scope. (extensions/team-reports/src/config.ts:29, acb327afa77d)
  • Restart test covers only unchanged settings: The added partial-failure restart test reopens the store with the same setup configuration and asserts that yesterday is skipped; it does not exercise changed source settings. (extensions/team-reports/src/scheduler.test.ts:241, acb327afa77d)
  • Current main still needs the worker change: Current main's report generator calls collectors and daily aggregation directly, and its plugin entry has no Team Reports runner. (extensions/team-reports/src/run.ts:1, cafb3a4d1ca2)
  • Production worker boundary: The new runner uses the existing Plugin SDK worker pool and forwards store and model requests to the service host; the store backend creates connection-owned temporary activity storage. (extensions/team-reports/src/run-worker.ts:18, acb327afa77d)
  • Reported behavior proof: The PR body reports a Testbox fixture using the production collector, worker, and SQLite backend: main-isolate peak heap fell from 95.68 to 52.12 MiB and the longest event-loop turn from 69.49 to 19.04 ms, with matching daily and monthly output hashes. The author explicitly states that no live API or Gateway deployment was exercised. (extensions/team-reports/src/report-run.benchmark.test-support.ts:91, acb327afa77d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prove that boot catch-up recollects a closed day when Discord is enabled or its channels change after the earlier report.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 9dc8955 into main Sep 26, 2026
130 of 132 checks passed
@steipete
steipete deleted the steipete/perf-micro-team-reports-fetch-runs-main-thread-bursts-20260919 branch September 26, 2026 19:32
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…law#159101)

* perf(team-reports): move report collection off the gateway thread

Stream source activity through bounded SQLite batches, preserve report outputs, and reuse accepted closed days during boot retries.

* chore(team-reports): register the fixture benchmark entrypoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: team-reports rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant