Skip to content

perf(agent-runtime): split sidecar bundle - #1284

Merged
vastsa merged 1 commit into
mainfrom
codex/perf-agent-runtime-bundle-size
Oct 1, 2026
Merged

vastsa merged 1 commit into
mainfrom
codex/perf-agent-runtime-bundle-size

Conversation

@vastsa

@vastsa vastsa commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Split the agent sidecar into hashed ESM chunks while keeping sidecar.js as the release entry.
  • Load the trusted-extension runner and native Pi session service only when those features are used.
  • Stage each bundle and replace the generated output only after esbuild succeeds, preventing stale chunks from shipping.

Validation

  • pnpm --filter @pi-desktop/agent-runtime typecheck
  • pnpm -C packages/agent-runtime exec vitest run --testTimeout=60000 (82 files, 1,155 tests)
  • node --test apps/desktop/test/agent-runtime-bundle-package.test.mjs (build and process smoke outside node_modules)
  • pnpm lint:biome
  • pnpm check:pr-base

The release entry was a single 7.8 MB file even though trusted
extensions and native Pi sessions are optional. Split the ESM output
and load those heavy modules only when their features are used.

Build into a staging directory and replace the generated bundle only
after esbuild succeeds, keeping stale hashed chunks out of releases
without discarding the previous bundle on build failure.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 13:26

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The lazy-loading and staged bundle changes preserve existing contracts and have focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Splits the agent sidecar into lazy-loaded ESM chunks while preserving its stable packaged entry point.

Changes:

  • Lazy-loads native session and trusted-extension implementations.
  • Adds staged bundle replacement with hashed chunks.
  • Expands lifecycle and packaged-bundle regression coverage.
File Description
packages/​agent-runtime/​src/​sidecar.ts Lazily loads the native Pi service.
packages/​agent-runtime/​src/​runtime.ts Lazily loads and deduplicates extension runner initialization.
packages/​agent-runtime/​src/​native-pi-session.ts Re-exports the extracted session prefix.
packages/​agent-runtime/​src/​native-pi-session-id.ts Defines the lightweight session prefix constant.
packages/​agent-runtime/​src/​extensions/​runtime-lifecycle.test.ts Tests concurrent lazy extension loading.
packages/​agent-runtime/​src/​extensions/​loader.ts Updates split-bundle documentation.
packages/​agent-runtime/​src/​extensions/​bundle.test.ts Tests split ESM extension loading.
packages/​agent-runtime/​scripts/​bundle.mjs Implements staged, hashed bundle generation.
packages/​agent-runtime/​package.json Routes bundling through the new script.
apps/​desktop/​test/​agent-runtime-bundle-package.test.mjs Verifies packaging, chunk replacement, and sidecar startup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vastsa
vastsa merged commit a339630 into main Oct 1, 2026
5 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 8fbeaec8 Deployed Oct 1, 2026 by vercel[bot]
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