Skip to content

cold-start: lazy-load agent runner heavy dependencies#43

Merged
x0ba merged 1 commit into
stagingfrom
cold-start/lazy-agent-runner
May 28, 2026
Merged

cold-start: lazy-load agent runner heavy dependencies#43
x0ba merged 1 commit into
stagingfrom
cold-start/lazy-agent-runner

Conversation

@x0ba
Copy link
Copy Markdown
Owner

@x0ba x0ba commented May 28, 2026

Stack Context

This stack reduces Vercel cold-start time by shrinking the shared SvelteKit server boot path and isolating heavy agent/GitHub dependencies.

Why?

The agent runner statically imported Playwright, Browserbase, and tool-agent provider SDKs at module load. Dashboard routes that only read run snapshots were paying that cost. Heavy modules now load only when the matching run mode starts.

Test plan

  • Start a tool-agent run and confirm it completes
  • Start a browser run and confirm Browserbase session creation still works

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flightlog Ready Ready Preview, Comment May 28, 2026 4:53pm

Copy link
Copy Markdown
Owner Author

x0ba commented May 28, 2026

@x0ba x0ba changed the title Lazy-load browser and tool-agent modules in the agent runner. cold-start: lazy-load agent runner heavy dependencies May 28, 2026
@x0ba x0ba marked this pull request as ready for review May 28, 2026 07:56
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

This PR lazy-loads four heavy module dependencies (./tool-agent, ./browser, ./openai, $lib/server/openai-transport) using dynamic import() so that dashboard routes and other SvelteKit server paths that never start an agent run no longer pay the cold-start cost of loading Playwright, Browserbase, and provider SDKs at module initialisation.

  • The runToolAgent import is moved inside the existing tool_agent try/catch (line 155), so any import failure is caught and surfaced via failRun.
  • The three browser-path imports (lines 179–181) are placed outside the browser try block (line 234), meaning a module-load failure there bypasses failRun and leaves the run stuck in the database without cleanup.

Confidence Score: 4/5

The change is safe for the tool-agent path, but the browser path has an unguarded window where a dynamic import failure leaves a run permanently stuck in the database.

The runToolAgent dynamic import is correctly placed inside its try/catch so errors are handled gracefully. The three browser-path imports (lines 179–181) are outside the browser try block: if any throw, failRun is never called, the run record stays in a bad state, and the rejection propagates to the void-discarded promise with no cleanup. This is a real gap introduced by the refactor, not a pre-existing condition.

src/lib/server/agent-runner/service.ts — specifically the three browser dynamic imports at lines 179–181 that fall outside the browser try/catch block.

Important Files Changed

Filename Overview
src/lib/server/agent-runner/service.ts Converts four static imports to dynamic imports for cold-start savings; tool-agent import is correctly guarded inside try/catch, but the three browser-path imports land outside the browser try block, leaving runs in a broken state if any import fails.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[runAgent called] --> B{runMode === tool_agent?}
    B -- Yes --> C["try { ... }"]
    C --> D["await import('./tool-agent') ✅ inside try/catch"]
    D --> E[runToolAgent]
    E --> F[return]
    C -- catch --> G[failRun]
    B -- No / browser --> H["await import('openai-transport') ⚠️ outside try"]
    H --> I["await import('./browser') ⚠️ outside try"]
    I --> J["await import('./openai') ⚠️ outside try"]
    J --> K[credential checks]
    K --> L["try { ... }"]
    L --> M[createBrowserSession → agent loop]
    L -- catch --> N[failRun]
    H -- throws --> O["❌ no failRun, run stuck in DB"]
Loading

Fix All in Cursor Fix All in Codex

Reviews (2): Last reviewed commit: "Lazy-load browser and tool-agent modules..." | Re-trigger Greptile

Comment thread src/lib/server/agent-runner/service.ts
Copy link
Copy Markdown
Owner Author

x0ba commented May 28, 2026

Merge activity

  • May 28, 4:49 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 28, 4:53 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 28, 4:53 PM UTC: @x0ba merged this pull request with Graphite.

@x0ba x0ba changed the base branch from cold-start/split-regression-executor to graphite-base/43 May 28, 2026 16:50
@x0ba x0ba changed the base branch from graphite-base/43 to staging May 28, 2026 16:51
Playwright, Browserbase, and provider SDKs are imported only when the corresponding run mode starts.
@x0ba x0ba force-pushed the cold-start/lazy-agent-runner branch from bff4529 to 2b31168 Compare May 28, 2026 16:52
@x0ba x0ba merged commit d5f39a9 into staging May 28, 2026
3 of 5 checks passed
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.

1 participant