Skip to content

feat(dev): run agentex locally without Docker #353

Open
aringuyen3 wants to merge 3 commits into
mainfrom
aringuyen/run-local-no-docker
Open

feat(dev): run agentex locally without Docker #353
aringuyen3 wants to merge 3 commits into
mainfrom
aringuyen/run-local-no-docker

Conversation

@aringuyen3

@aringuyen3 aringuyen3 commented Jul 9, 2026

Copy link
Copy Markdown

What

Adds a docker-free mode that runs the full agentex backend as host processes with embedded datastores — a lighter alternative to the Docker Compose stack, closer to a one-command langgraph dev-style workflow.

./dev.sh no-docker                    # whole stack, no Docker
./dev.sh no-docker --lean             # Postgres + Redis + API + MongoDB only (no Temporal/OTel)
./dev.sh no-docker --no-temporal      # skip Temporal + the worker
./dev.sh no-docker --mongo-uri <uri>  # use an external MongoDB instead of a local mongod

The bare ./dev.sh (Docker) is unchanged and now also accepts an explicit ./dev.sh docker alias. The docker-free mode is also available as make dev-no-docker and python -m scripts.dev_nodocker.

Why

Standing up a local environment previously required the full Docker stack. This lets a developer run the backend with a single command and no Docker daemon:

  • Postgres via bundled pgserver (unix socket) and Redis via bundled redislite
  • a Temporal dev server + Web UI and the agentex worker
  • a local mongod — always started; the stack requires it (the Temporal worker builds Mongo-backed repositories at boot)
  • an optional OpenTelemetry collector

It runs migrations, supervises uvicorn + the worker, and tears everything down cleanly on Ctrl-C / SIGTERM. --ephemeral uses a throwaway data dir; --mongo-uri points at an existing MongoDB instead of launching a local mongod.

App-side change

Safe no-op wherever the backend runs in Docker / staging / prod (the env var it keys on is unset there):

ACP host rewrite for docker-free mode. Agents register their ACP URL at host.docker.internal (the SDK default, so a Docker backend can reach an agent on the host), which a host-process backend can't resolve. The runner sets AGENTEX_ACP_HOST_OVERRIDE=127.0.0.1 and the backend rewrites only that sentinel host to the override when dialing agents — in the ACP request path, the agent-API-key proxy path, and the Temporal healthcheck. When the env var is unset, the stored URL is used verbatim. Default-scaffolded agents work without manifest edits.

Also

  • Fix a frontend dev-server process leak in dev.sh (kill the whole make → npm → next tree and sweep orphans; report status by listening port).
  • Correct the MongoDB (brew trust first) and OpenTelemetry (release binary; not in Homebrew) install commands.
  • Add a dev-no-docker uv dependency group (pgserver, redislite, greenlet) pulled only for docker-free mode.
  • Document docker-free mode in README.md and CLAUDE.md.

Contract note

The runner is a package (scripts/dev_nodocker/), so the direct invocation is python -m scripts.dev_nodocker (not python scripts/dev_nodocker.py). ./dev.sh no-docker and make dev-no-docker are unchanged for callers.

Testing

Manually exercised on macOS (Docker stopped):

  • Full stack and --lean — the API passes /healthz within ~1s and /readyz reports Postgres, Redis, and MongoDB all healthy; the Temporal worker stays up; teardown frees all ports with no orphaned processes.
  • Fail-fast path: full mode with mongod absent aborts with an actionable install message (or point at an external instance with --mongo-uri).
  • Booted end-to-end via python -m scripts.dev_nodocker; agents scaffolded by agentex init connect without manifest edits (ACP host rewrite).

Platform support: macOS and Linux only. Not supported on native Windows — the embedded Redis (redislite) ships no Windows server build; run it under WSL2, where redislite/pgserver/mongod behave as on Linux (WSL2 path not yet verified).

Greptile Summary

This PR adds a docker-free local development mode (./dev.sh no-docker / make dev-no-docker / python -m scripts.dev_nodocker) that runs the full agentex backend — Postgres (via pgserver), Redis (via redislite), Temporal, MongoDB, and an optional OTel collector — as host processes with no Docker daemon required. A companion app-side change rewrites agents' registered host.docker.internal ACP URLs to 127.0.0.1 via a new AGENTEX_ACP_HOST_OVERRIDE env var, applied in the ACP request path, the API-key proxy path, and the Temporal health-check activity.

  • New scripts/dev_nodocker/ package: pure-config config.py, side-effectful services.py (provision/teardown each datastore), supervise.py (spawn/stream/health-check), and runner.py (orchestration + signal handling); all hooked into dev.sh and make.
  • dev.sh improvements: adds no-docker and docker subcommands, fixes frontend process-tree leak on stop/restart (kill_tree + sweep_stray_frontends), and records the active mode in .dev-logs/mode so stop/status/restart know which path to use.
  • Production ACP path: src/utils/acp_url.py adds resolve_acp_url() wired into agents_acp_use_case._resolve_acp_url, agent_api_keys_use_case proxy path, and healthcheck_activities.check_status_activity; it is a no-op when the env var is unset, so Docker / staging / prod are unaffected.

Confidence Score: 4/5

Safe to merge — production code changes are confined to the ACP URL rewrite (a no-op when the env var is unset) and the deployment-URL fallback logic; the docker-free runner is dev-only.

The production-path changes are minimal and guarded by an env var that is unset in Docker/staging/prod. The dev runner is well-structured and fail-fast for required services. Two issues from earlier review rounds (runner crash returning exit code 0, empty-string deployment URL bypass) remain open; neither affects Docker or production paths but would affect developers using the new no-docker mode.

agentex/scripts/dev_nodocker/runner.py — the non-zero exit code on crash path should be verified before this becomes part of CI scripts.

Important Files Changed

Filename Overview
agentex/scripts/dev_nodocker/runner.py Orchestrates startup, supervision, and teardown of all local services; returns exit code 0 unconditionally even when a managed process crashes (previously flagged).
agentex/scripts/dev_nodocker/services.py Provisions embedded Postgres, Redis, Temporal, MongoDB, and OTel; fail-fast on required services, best-effort on optional ones; teardown handles SIGKILL for Redis after graceful shutdown.
agentex/scripts/dev_nodocker/supervise.py Subprocess plumbing — spawn with merged stdout/stderr streaming, TCP port probing with process-alive guard, migrations runner, and graceful terminate with SIGKILL fallback.
agentex/scripts/dev_nodocker/config.py Pure, side-effect-free config: argparse definition, DevNoDockerConfig dataclass, env-var builder. Well-designed and unit-testable.
agentex/src/utils/acp_url.py New utility that rewrites host.docker.internal ACP URLs to a configurable host override; cleanly no-ops when the env var is unset, so it is safe for Docker/staging/prod paths.
agentex/src/domain/use_cases/agents_acp_use_case.py _resolve_acp_url now uses truthiness check (not is None) for the deployment URL fallback — empty-string handling issue previously flagged; resolve_acp_url wired in correctly.
agentex/src/domain/use_cases/agent_api_keys_use_case.py Proxy path now wraps agent.acp_url with resolve_acp_url; minimal, correct change that is a no-op in production.
agentex/src/temporal/activities/healthcheck_activities.py Healthcheck activity now resolves ACP URL before dialing, ensuring docker-free mode rewrites host.docker.internal correctly for Temporal-scheduled checks.
dev.sh Adds no-docker and docker subcommands, process-tree kill fix for frontend, OTel binary installer with partial checksum verification (unverified install when checksum fetch fails — previously flagged), and mode-file tracking for stop/restart.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant devsh as dev.sh no-docker
    participant runner as runner.py
    participant services as services.py
    participant supervise as supervise.py
    participant api as API (uvicorn)
    participant agent as Agent process

    devsh->>runner: asyncio.run(run(cfg))
    runner->>services: provision_postgres(cfg)
    services-->>runner: pg_server, database_url
    runner->>services: provision_redis(cfg)
    services-->>runner: redis_server, redis_url
    runner->>services: provision_mongo(cfg)
    services->>supervise: wait_for_port(proc, host, port)
    services-->>runner: mongo_proc, mongo_uri
    runner->>services: provision_temporal(cfg)
    services-->>runner: temporal_env, temporal_address
    runner->>supervise: run_migrations(cfg, env)
    supervise-->>runner: done
    runner->>supervise: spawn api + worker
    runner->>supervise: wait_for_health(api_port)
    supervise-->>runner: True / False

    alt Signal or process crash
        runner->>supervise: terminate worker + api
        runner->>services: temporal.shutdown + teardown_redis + pg.cleanup
    end

    Note over api,agent: ACP URL rewrite (all modes)
    api->>api: resolve_acp_url(raw_url)
    Note right of api: Rewrites host.docker.internal to 127.0.0.1 only when AGENTEX_ACP_HOST_OVERRIDE is set. No-op in Docker and prod.
    api->>agent: HTTP dial at resolved URL
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant devsh as dev.sh no-docker
    participant runner as runner.py
    participant services as services.py
    participant supervise as supervise.py
    participant api as API (uvicorn)
    participant agent as Agent process

    devsh->>runner: asyncio.run(run(cfg))
    runner->>services: provision_postgres(cfg)
    services-->>runner: pg_server, database_url
    runner->>services: provision_redis(cfg)
    services-->>runner: redis_server, redis_url
    runner->>services: provision_mongo(cfg)
    services->>supervise: wait_for_port(proc, host, port)
    services-->>runner: mongo_proc, mongo_uri
    runner->>services: provision_temporal(cfg)
    services-->>runner: temporal_env, temporal_address
    runner->>supervise: run_migrations(cfg, env)
    supervise-->>runner: done
    runner->>supervise: spawn api + worker
    runner->>supervise: wait_for_health(api_port)
    supervise-->>runner: True / False

    alt Signal or process crash
        runner->>supervise: terminate worker + api
        runner->>services: temporal.shutdown + teardown_redis + pg.cleanup
    end

    Note over api,agent: ACP URL rewrite (all modes)
    api->>api: resolve_acp_url(raw_url)
    Note right of api: Rewrites host.docker.internal to 127.0.0.1 only when AGENTEX_ACP_HOST_OVERRIDE is set. No-op in Docker and prod.
    api->>agent: HTTP dial at resolved URL
Loading

Reviews (5): Last reviewed commit: "fix comments" | Re-trigger Greptile

@aringuyen3
aringuyen3 requested a review from a team as a code owner July 9, 2026 14:48
Comment thread agentex/src/domain/use_cases/agents_acp_use_case.py Outdated
Stand up the full backend as host processes with embedded datastores — no
Docker daemon required — as a lighter alternative to the container stack.

`./dev.sh local` (also `make dev-local` / `python -m scripts.dev_local`) provisions:
- Postgres via bundled pgserver (unix socket) and Redis via bundled redislite
- a Temporal dev server + UI and the agentex worker (--no-temporal to skip)
- a local mongod, required for the full stack (--no-mongo / --lean to skip)
- an optional OpenTelemetry collector (--no-otel to skip)
then runs migrations, supervises uvicorn + the worker, and tears everything down
cleanly on SIGINT/SIGTERM. --lean is a minimal Postgres+Redis+API stack; --ephemeral
uses a throwaway data dir. The runner is a small scripts/dev_local package
(config / services / supervise / runner) so the pure config/env layer stays testable.

App-side changes to make the no-Docker path robust (all no-ops when Mongo is
configured, as it always is in Docker/prod):
- The Temporal worker no longer crashes when MongoDB is unavailable — the Mongo CRUD
  adapter tolerates an unset database and errors only on real use, so the worker
  degrades like the API instead of taking down the stack.
- Skip the Mongo connection entirely when MONGODB_URI is unset, removing a ~20s
  startup hang against the implicit localhost:27017 default.
- In local mode the backend rewrites agents' host.docker.internal ACP host to loopback
  (AGENTEX_ACP_HOST_OVERRIDE), so default-scaffolded agents work without manifest edits.

Also fix a frontend dev-server process leak in dev.sh (kill the whole make→npm→next
tree and sweep orphans; report status by listening port), correct the MongoDB and
OpenTelemetry install commands, and document local mode in README and CLAUDE.md.
@aringuyen3
aringuyen3 force-pushed the aringuyen/run-local-no-docker branch from 356b3eb to aa8bb61 Compare July 13, 2026 16:34
raw = acp_url_override

# Prefer the production deployment's URL when there's no explicit override.
if raw is None and agent.production_deployment_id:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@smoreinis can you take a look here just make sure it doesn't conflict with the preview workflow?

"""
# In docker-free local mode, rewrite host.docker.internal -> the host-reachable
# override so the healthcheck matches how the request path dials the agent.
acp_url = resolve_acp_url(acp_url)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just making sure, no other places we need to do conversion right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, only running this mode

if acp_url_override:
return acp_url_override
"""Resolve the ACP URL for an agent, optionally overriding with a specific URL.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did we lose the override?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

hi, so ./dev.sh no-docker will pass _ACP_HOST_OVERRIDE_ENV variable, so the function resolve_acp_url will resolve this. Besides this, the logic of this function is kept the same

Returns the URL unchanged when the override env var is unset or the URL does
not use the Docker sentinel host, so it is safe to call on every ACP dial.
"""
override = os.environ.get(_ACP_HOST_OVERRIDE_ENV)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this where the override moved?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, here we override the environment variable _ACP_HOST_OVERRIDE_ENV. This environment is set and passed from config.py file

Comment thread agentex/Makefile
# Development Server
#

dev: install-dev ## Start development server with Docker Compose

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these are both technically local maybe rename to something more meaningful?

Comment thread CLAUDE.md

> **MongoDB is required for the full local stack** and is always started — the Temporal
> worker builds Mongo-backed repositories at startup, so a missing/unreachable Mongo
> makes the runner fail fast (with an install message) rather than crash the worker.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ty for adding here

@danielmillerp danielmillerp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lots of small questions! also as far as testing on PC, not super sure. A lot of our clients do use PCs and I know there are Scaliens who have PCs. What problems do you anticipate?

@levilentz levilentz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall this is rad.

One UX suggestion: in addition dev.sh, I think this would be really nice to have in the agentex CLI. I.E. you can run a single agent inline. therefore to start running a single agent you can start quick rather than having both the agentex backend and cli running. then this setup would be suitable for someone testing a multiagent flow.

Not sure if that is possible given the abstraction and integration, but wanted to throw it out there as a north star.

@danielmillerp

Copy link
Copy Markdown
Collaborator

Overall this is rad.

One UX suggestion: in addition dev.sh, I think this would be really nice to have in the agentex CLI. I.E. you can run a single agent inline. therefore to start running a single agent you can start quick rather than having both the agentex backend and cli running. then this setup would be suitable for someone testing a multiagent flow.

Not sure if that is possible given the abstraction and integration, but wanted to throw it out there as a north star.

+1 to that!

@aringuyen3

Copy link
Copy Markdown
Author

lots of small questions! also as far as testing on PC, not super sure. A lot of our clients do use PCs and I know there are Scaliens who have PCs. What problems do you anticipate?

@danielmillerp So Im testing this on Windows (via AWS Workspaces) but the embedded Redis uses (the redislite package has no native Windows build (Redis ships no supported Windows server) so the dependency required to run locally without Docker won't even install on native Windows.

Comment on lines +119 to +126
await asyncio.wait([stop_task, *waiters], return_when=asyncio.FIRST_COMPLETED)
if not stop.is_set():
dead = [name for name, p in procs if p.returncode is not None]
logger.error(
"A managed process exited unexpectedly: %s. Shutting down.",
", ".join(dead) or "?",
)
return 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Unexpected process crash returns exit code 0

When the API or worker dies before a signal is received, run() logs the crash but falls through to return 0, so main() calls raise SystemExit(0). Any caller that checks $? — including make dev-no-docker and direct python -m scripts.dev_nodocker invocations — sees success even when the dev stack crashed. Returning a non-zero code on the crash path lets CI and scripts reliably detect the failure.

Prompt To Fix With AI
This is a comment left during a code review.
Path: agentex/scripts/dev_nodocker/runner.py
Line: 119-126

Comment:
**Unexpected process crash returns exit code 0**

When the API or worker dies before a signal is received, `run()` logs the crash but falls through to `return 0`, so `main()` calls `raise SystemExit(0)`. Any caller that checks `$?` — including `make dev-no-docker` and direct `python -m scripts.dev_nodocker` invocations — sees success even when the dev stack crashed. Returning a non-zero code on the crash path lets CI and scripts reliably detect the failure.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Cursor Fix in Claude Code Fix in Codex

@aringuyen3 aringuyen3 closed this Jul 17, 2026
@aringuyen3 aringuyen3 reopened this Jul 17, 2026
@aringuyen3

Copy link
Copy Markdown
Author

Some findings from testing local dev on Windows:

  • I'm testing running locally on native Windows, but the embedded Redis uses the redislite package, which has no native Windows build (Redis ships no supported Windows server). So the dependency required to run locally won't even install on native Windows.
  • Workarounds today: run dev locally with Docker, or use the Docker-free local mode inside WSL2.
  • Open question for FDE / customer environments: can they install WSL2 in their env? I wouldn't assume it's always available.
  • Worth noting: I use AWS Workspace, which doesn't support WSL2 — so even the WSL2 path isn't universal internally.

@NiteshDhanpal had a clear view on how to scope this. His take: don't treat Windows-native local mode as a hard requirement for now (given the redislite/Redis limitation), and use a support matrix instead:

  • Mac/Linux → Docker-free local mode
  • Windows with WSL2 allowed → Docker-free local mode inside WSL2
  • Windows without WSL2 / locked-down envs → Docker-based local dev

His main concern is a reliable fallback so customers aren't blocked when local setup is painful or impossible, and he thinks a cloud/dev-environment fallback is the most reliable option for that.

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.

3 participants