Skip to content

INTR-652 - Reduce startup latency cpu time and memory use in sidecars - #223

Merged
FarinM merged 3 commits into
mainfrom
intr-652-reduce-startup-latency-cpu-time-and-memory-use-in-sidecars
Oct 12, 2026
Merged

FarinM merged 3 commits into
mainfrom
intr-652-reduce-startup-latency-cpu-time-and-memory-use-in-sidecars

Conversation

@FarinM

@FarinM FarinM commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

After #216 narrowed the probe and workflow children, the parent sidecar still loaded framework code it never executes. Imports for small helpers pulled in Hub database services, broad type/schema barrels, and the agent execution runtime. The supervisor also imported the aggregate control channel, which constructs every control-message validator and the combined union at import time. ArkType compiles validators as those schemas are constructed, so each sidecar paid initialization and memory costs for unused dependencies before connecting to the Hub.

This narrows the sidecar's startup graph and removes a redundant event validation pass:

  • Use @intx/hub-sessions/substrate for repository access. Move workflowSourceAssetMountPath into @intx/types/workflow-sources and replace parseAgentId with the existing deriveWorkflowRunId. Deployment code calls the shared helpers directly; the injection fields and duplicate test and benchmark helpers are removed.
  • Import byte, ID, credential, grant, and adapter configuration helpers through focused entry points. Tool factory checks use @intx/agent/authoring; workflow inspection uses the definition/projection entries. inlineBodyRef lives in a leaf module so the probe does not load body rewriting code through the projection entry.
  • Import the individual IPC sender, receiver, and payload modules from the supervisor, recycling code, and pack client. The supervisor uses the existing per-kind validation path without constructing the combined control-payload union. Shared payload schemas and the message header remain eager.
  • Validate inference events once at the IPC receiver with parseInferenceEvent and forward the canonical InferenceEvent result directly. EventPayload remains a type alias; its redundant validator export is removed.
  • Extend the boot-graph tests to cover the sidecar. Positive assertions check that the walk reaches deployment wiring and the repository substrate; exclusions check for Hub services, database dependencies, unused runtime/schema barrels, and the aggregate control channel. The child and probe checks remain in the renamed process-boot-graph.test.ts.
Measurement Before After
Startup to WebSocket hello 724 ms 497 ms
CPU time after hello 846 ms 569 ms
RSS after hello 410.0 MiB 243.5 MiB

Measurements are medians of 12 alternating runs in fresh processes per variant on macOS arm64 with Bun 1.4.3, comparing the branch's base (f9c940190) with c9aaca55f. Each run uses an empty data directory and a local WebSocket stub. Startup is measured from process spawn to the first hello; CPU time and RSS are sampled just afterward. These cover startup with no deployments, not workflow throughput or memory under sustained load, and do not quantify the saving from removing the second event validation pass.

Removed exports have no remaining in-repository callers. Run ID validation still uses parseRunAddress; invalid-address diagnostics now use deriveWorkflowRunId's JSON-escaped formatting.

Validation: make all passed with 10,137 tests passing and two live Google API tests skipped. The first commit also passed the focused 301-test suite independently, including its guard against database imports in the sidecar.

Sidecars need repository access and shared address helpers without
loading the Hub database layer during startup.
Broad imports loaded unused execution code and eagerly constructed
the complete control-payload union. Import the individual channel
modules so the supervisor uses the existing per-kind validation path.
The receiver already authenticates and validates each event. Return
the canonical event type so forwarding does not parse it a second
time.
@linear

linear Bot commented Oct 12, 2026

Copy link
Copy Markdown

INTR-652

@alexanderguy alexanderguy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@FarinM
FarinM merged commit cd02c31 into main Oct 12, 2026
6 checks passed
@FarinM
FarinM deleted the intr-652-reduce-startup-latency-cpu-time-and-memory-use-in-sidecars branch October 12, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants