fix: make agent loopback base port env-configurable (#2752) (#2753)

_COOKBOOK_BASE was hardcoded to http://localhost:7000 with no env-var
override anywhere in the codebase. Tools that do an internal HTTP
loopback (app_api, trigger_research, cookbook state read/write) silently
fail with "All connection attempts failed" whenever the running uvicorn
isn't on port 7000 — which is most non-default deployments and any
side-by-side multi-instance setup. The misleading "Task triggered"
message from manage_tasks during a research request hides that the
underlying research never starts.

Resolution order, lowest to highest priority:
  1. Fallback http://127.0.0.1:7000 (preserves legacy default).
  2. APP_PORT — derive http://127.0.0.1:$APP_PORT (matches docker-compose
     which already reads APP_PORT).
  3. ODYSSEUS_INTERNAL_BASE — explicit override (e.g. behind a TLS proxy
     where loopback isn't 127.0.0.1).

127.0.0.1 instead of "localhost" avoids IPv6/DNS ambiguity for a
strictly-local call.

No API or schema change. Defaults preserved: existing setups on port
7000 are unaffected.

Caught by #2752.

Co-authored-by: pewdiepie-archdaemon <pewdiepie-archdaemon@users.noreply.github.com>
This commit is contained in:
PewDiePie
2026-06-08 01:47:47 +09:00
committed by GitHub
parent 55343e89fb
commit c9198baa2e
+15 -1
View File
@@ -2495,7 +2495,21 @@ async def do_manage_calendar(content: str, owner: Optional[str] = None) -> Dict:
# Cookbook routes loopback. The agent's tool calls run in-process but
# need to reach admin-gated cookbook routes; we ride the per-process
# internal token so require_admin lets us through. See core/middleware.py.
_COOKBOOK_BASE = "http://localhost:7000"
#
# Resolution order:
# 1. ODYSSEUS_INTERNAL_BASE — explicit override (e.g. behind a TLS proxy).
# 2. APP_PORT — derive http://127.0.0.1:$APP_PORT (matches docker-compose).
# 3. Fallback http://127.0.0.1:7000 — preserves legacy default.
#
# 127.0.0.1 (not "localhost") avoids IPv6/DNS ambiguity for a strictly-local
# call. Without this, tools that loop back (app_api, trigger_research,
# cookbook state read/write) fail with "All connection attempts failed"
# whenever the running uvicorn isn't on 7000 — which is most non-default
# deployments and any side-by-side multi-instance setup.
_COOKBOOK_BASE = os.environ.get(
"ODYSSEUS_INTERNAL_BASE",
f"http://127.0.0.1:{os.environ.get('APP_PORT', '7000')}",
)
def _internal_headers(owner: Optional[str] = None) -> Dict[str, str]: