Repository navigation
Conversation
The soc-dashboard page polls /api/task-center and /api/activity every 1-3 seconds while open. Each poll re-parsed every workflow definition on disk (up to 163KB each) and re-scanned all plugin manifests, pinning one core at 100%+ in the serve process. Session runners share that process and were starved (agent turns stalled on the same event loop). Add module-level caches invalidated by file mtime_ns: - _WORKFLOW_ROOTS constant (was rebuilt per call, Path.home() hit 3x per poll) - _MANIFEST_MAP_CACHE (keyed by workflow roots dir mtimes fingerprint) - _NODE_COUNT_CACHE (keyed by workflow.json mtime_ns, per workflow) Cache writes are copy-then-replace (GIL-atomic), so no locks are needed. API responses are byte-identical; edited definitions refresh on the next request. Measured in production (soc-dashboard left open): serve CPU 104% -> 16-18%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SOC dashboard polls
/api/task-centerand/api/activityevery 1-3 secondswhile open. Each poll re-parsed every workflow definition on disk (up to
163KB each) and re-scanned all plugin manifests, pinning one core at 100%+ in
the serve process. Session runners (agents) share that process and were
starved — agent turns stalled mid-stream with the UI stuck on "generating".
Root cause (py-spy, 108 samples in production)
100% of hot samples landed in the polling handler chain:
_workflow_manifest_name_map()— rebuilt the whole manifest map per request(
Path.home()×3,read_text+json.loadsper plugin manifest)_workflow_node_count(workflow_id)— re-read and re-parsed eachworkflow.json(up to 163KB) for every workflow row, every pollPath.home()/Path.resolve()/_load_partsappearing throughout the stackFix
Module-level caches invalidated by file
mtime_ns(copy-then-replace, GIL-atomic,no locks):
_WORKFLOW_ROOTSconstant — roots built once_MANIFEST_MAP_CACHE— keyed by a fingerprint of the workflow roots dir mtimes_NODE_COUNT_CACHE— keyed by eachworkflow.json'smtime_nsDefinitions edited on disk refresh automatically on the next request; no TTL,
no stale window.
Verification (production, v2026.11.09)
/api/task-centerresponseReproduction
top -p $(pgrep -f "flocks serve")→ CPU ~100%py-spy record --pid <pid> -d 12→ all samples in_task_center_workflow_rows