Skip to content

[APPS-2792] Add: in-process local execution for backend functions - #479

Draft
tyffical wants to merge 1 commit into
masterfrom
tiffany.trinh/apps-2792-in-process-execution
Draft

[APPS-2792] Add: in-process local execution for backend functions#479
tyffical wants to merge 1 commit into
masterfrom
tiffany.trinh/apps-2792-in-process-execution

Conversation

@tyffical

@tyffical tyffical commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Motivation

Changes

What changed File
Added executeScriptLocally, which runs a bundled backend function via a dynamic import() of a content-addressed data: URL, directly inside this process — no forked child. local-execution.ts
Ported the $.Actions Proxy (nested-property-path walk → {fqn, inputs}) from the closed fork-based prototype as a direct in-process function call instead of an IPC round trip. local-execution.ts
The $ context passed to the customer's module exposes only backendFunctionArgs and Actions — verified by test — so a real auth token can later live in a module-private closure the customer's code has no way to reach. local-execution.ts
Added tests covering the happy path, changed-code correctness (no stale-cache bug), $.Actions call resolution and validation, sync/async error propagation, timeout behavior, and the no-token-exposure invariant. local-execution.test.ts

QA Instructions

yarn install
yarn test:unit packages/plugins/apps/src/vite/local-execution.test.ts
# Expected: Test Suites: 1 passed / Tests: 9 passed ✅ VERIFIED
yarn test:unit packages/plugins/apps
# Expected: Test Suites: 23 passed / Tests: 294 passed ✅ VERIFIED
yarn workspace @dd/apps-plugin run typecheck
# Expected: no output, clean exit ✅ VERIFIED
npx eslint packages/plugins/apps/src/vite/local-execution.ts packages/plugins/apps/src/vite/local-execution.test.ts --quiet
# Expected: no output, clean exit ✅ VERIFIED

No manual local or staging QA for this PR specifically: this module isn't wired into createDevServerMiddleware yet, so there's no npm run dev request path that reaches executeScriptLocally() — nothing a human can click through yet, matching the same situation the original fork-based prototype (#461) was in. The tests above exercise a real, unmocked dynamic import() of real generated code end-to-end, not a mocked substitute. Real local + staging manual QA becomes possible once this is wired into the dev server (follow-up PR).

Blast Radius

  • No behavior change yet: this module is net-new and not called from anywhere in the existing dev server. Zero effect on any currently-shipping behavior.
  • Risk: low. New, isolated file; existing test suite (294 tests) passes unchanged.

Out of Scope / Follow-ups

Item Status Next step
Wiring into the real dev server (handleExecuteAction) Not started Follow-up PR, stacked on this one
Real auth token / closure-scoping for real $.Actions execution Blocked Needs the single-action execution endpoint (Action Platform team) to exist first — executeActionRemotely stays a stub until then
Hardening (concurrent-execution behavior, broader error-edge-case coverage) Not started Tracked as a separate milestone in the kickoff doc

Documentation

Executes a bundled backend function via a dynamic import() of a
content-addressed data: URL, directly inside the Vite dev server's own
process -- no forked child process. The dev server is already the
isolation boundary from production, so a crash or hang here only
affects the developer's own dev server; process-level isolation is
deliberately not added preemptively.

$.Actions calls resolve through a Proxy (ported from the render.ts
$.Actions logic) that invokes a local, in-process function directly --
no IPC needed, since there's no separate process to cross. The remote
call itself is still a stub pending the single-action execution
endpoint.

The $ context passed to the customer's module exposes only
backendFunctionArgs and Actions -- verified by test -- so that once a
real auth token is wired in for real action execution, it can live in
a module-private closure the customer's dynamically-imported code has
no way to reach.
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