Skip to content

feat(agents-server): refactor routing for tenant library mode#4307

Merged
icehaunter merged 1 commit into
mainfrom
codex/agents-server-routing-refactor-squashed
May 12, 2026
Merged

feat(agents-server): refactor routing for tenant library mode#4307
icehaunter merged 1 commit into
mainfrom
codex/agents-server-routing-refactor-squashed

Conversation

@icehaunter
Copy link
Copy Markdown
Contributor

Summary

  • Rebuilds agents-server from monolithic HTTP handling into a tenant-context-driven router architecture.
  • Makes the package usable as a library entrypoint through globalRouter.fetch(request, tenantContext), while keeping an OSS standalone wrapper for local/server use.
  • Treats the current Durable Streams subscription contract and routing adapter boundary as the source of truth for backend stream paths.

Work Done

  • Splits routing into focused modules for global, OSS, internal control-plane, entities, entity types, cron, Durable Streams proxying, and stream append handling.
  • Introduces explicit TenantContext, tenant-aware runtime host wiring, per-tenant runtime/registry/stream clients, and tenant-scoped database schema updates.
  • Adds DurableStreamsRoutingAdapter plus the OSS path-prefixed single-tenant adapter for mapping public/runtime stream names to backend DS paths.
  • Reworks Durable Streams subscription proxying around /v1/stream-meta/subscriptions/*, including path mapping, webhook URL rewriting, callback storage, claim/ack/release forwarding, and response mapping.
  • Moves OSS bootstrap concerns into server.ts and keeps routing code library-safe for external hosts that own tenancy and authentication.
  • Updates wake forwarding and callback forwarding to enrich runtime wake payloads, preserve DS callback state, map ack streams, mark entities idle on completion, and notify entity bridges.
  • Adds supporting runtime, scheduler, projector, UI, desktop, docs, and tests needed for the refactored server architecture.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 73.72061% with 570 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.50%. Comparing base (c38e519) to head (8e8f2b1).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/agents-server/src/entity-projector.ts 60.44% 142 Missing ⚠️
packages/agents-server/src/utils/server-utils.ts 39.79% 59 Missing ⚠️
...kages/agents-server/src/routing/internal-router.ts 81.11% 44 Missing ⚠️
packages/agents-server/src/runtime.ts 76.24% 43 Missing ⚠️
...ackages/agents-server/src/manifest-side-effects.ts 49.38% 40 Missing and 1 partial ⚠️
...s/agents-server/src/routing/entity-types-router.ts 41.66% 35 Missing ⚠️
packages/agents-server/src/scheduler.ts 54.54% 35 Missing ⚠️
packages/agents-server/src/host.ts 73.50% 31 Missing ⚠️
...gents-server/src/routing/durable-streams-router.ts 83.05% 20 Missing ⚠️
...kages/agents-server/src/routing/entities-router.ts 85.58% 16 Missing ⚠️
... and 17 more

❗ There is a different number of reports uploaded between BASE (c38e519) and HEAD (8e8f2b1). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (c38e519) HEAD (8e8f2b1)
unit-tests 11 10
typescript 11 10
packages/agents-runtime 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4307      +/-   ##
==========================================
- Coverage   58.84%   49.50%   -9.34%     
==========================================
  Files         251      230      -21     
  Lines       24468    16524    -7944     
  Branches     6374     4869    -1505     
==========================================
- Hits        14397     8181    -6216     
+ Misses      10064     8334    -1730     
- Partials        7        9       +2     
Flag Coverage Δ
packages/agents 67.80% <100.00%> (ø)
packages/agents-mcp 77.19% <ø> (ø)
packages/agents-runtime ?
packages/agents-server 74.30% <73.91%> (+5.03%) ⬆️
packages/agents-server-ui 5.31% <0.00%> (ø)
packages/electric-ax 38.04% <ø> (ø)
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 94.32% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 49.50% <73.72%> (-9.34%) ⬇️
unit-tests 49.50% <73.72%> (-9.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@icehaunter icehaunter force-pushed the codex/agents-server-routing-refactor-squashed branch 2 times, most recently from 7943cfc to 2d05944 Compare May 12, 2026 13:33
@netlify
Copy link
Copy Markdown

netlify Bot commented May 12, 2026

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit bd8d8a8
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/6a032ed0567caf0008dbea63
😎 Deploy Preview https://deploy-preview-4307--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@icehaunter icehaunter force-pushed the codex/agents-server-routing-refactor-squashed branch from 2d05944 to bd8d8a8 Compare May 12, 2026 13:44
Copy link
Copy Markdown
Contributor

@samwillis samwillis left a comment

Choose a reason for hiding this comment

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

Merge when green

@icehaunter icehaunter force-pushed the codex/agents-server-routing-refactor-squashed branch from bd8d8a8 to f012030 Compare May 12, 2026 14:00
@icehaunter icehaunter force-pushed the codex/agents-server-routing-refactor-squashed branch from f012030 to 8e8f2b1 Compare May 12, 2026 14:02
@icehaunter icehaunter merged commit 08e85a0 into main May 12, 2026
31 of 32 checks passed
@icehaunter icehaunter deleted the codex/agents-server-routing-refactor-squashed branch May 12, 2026 14:04
icehaunter added a commit that referenced this pull request May 13, 2026
## Summary
- Ports the pull-wake runner work onto the tenant-aware agents-server
routing refactor.
- Uses the current Durable Streams `v1/stream-meta/subscriptions/*`
pull-wake API instead of restoring donor `/consumers` minting or
monolithic server routing.
- Keeps the routing-refactor branch as the source of truth for package
organization, tenancy, and Durable Streams path mapping.
- Adds follow-up fixes for Electron logging, desktop multi-instance dev
startup, env override handling, and pull-wake/dev-auth test coverage.

## Work Done
- Adds tenant-scoped pull-wake control-plane schema for runner
registration, dispatch policy state, wake notifications, claims,
offsets, and related public fields.
- Extends server/runtime types with authenticated users, dispatch
policies, runner rows, wake rows, claim rows, and public entity/type
dispatch fields.
- Adds focused `/_electric/runners` routes for registration, listing,
heartbeat offset persistence, enable/disable, and claim handling with
authenticated owner checks.
- Implements dispatch-policy parsing and effective policy resolution for
spawns, parent inheritance, and entity-type defaults.
- Links entity main streams into Durable Streams runner/webhook
subscriptions after spawn/fork and unlinks them on kill, using the
routing adapter for all backend stream paths.
- Extends `StreamClient` and the Durable Streams router to map
subscription `wake_stream`, patterns, explicit streams, claim responses,
ack requests, release requests, and response stream paths through the
adapter.
- Ports the runtime pull-wake runner loop for compact DS wake events,
server-side claim enrichment, claim headers, claim-scoped write tokens,
runner heartbeats, and done/ack transport.
- Hardens callback-forward behavior for pull and webhook claims,
including local claim responses, DS ack forwarding, entity running/idle
state, stale conflict handling, and write-token lifecycle cleanup.
- Ports the remaining UI/CLI integration needed for local asserted
identity, auth-aware fetches, runner-backed local sessions, new session
spawning, entity observe paths, sidebar session display, and the compose
smoke stack.
- Adds `ELECTRIC_DESKTOP_USER_DATA_DIR` and env-selected desktop server
startup for multi-desktop local testing.
- Makes the agents-server `start` script respect externally supplied dev
env vars.
- Adds tests for dev asserted auth, dispatch policy schema validation,
entrypoint env parsing, and a mocked Horton pull-wake e2e.

## Verification
- `pnpm -C packages/agents-runtime build`
- `pnpm --filter @electric-ax/agents-server typecheck`
- `pnpm --filter @electric-ax/agents-desktop typecheck`
- `cd packages/agents-server && pnpm exec vitest run
test/dev-asserted-auth.test.ts test/dispatch-policy-schema.test.ts
test/entrypoint.test.ts test/horton-pull-wake-e2e.test.ts
--reporter=dot`

## Stack
- Stacked on #4307 (`feat(agents-server): refactor routing for tenant
library mode`).

---------

Co-authored-by: Kyle Mathews <mathews.kyle@gmail.com>
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