From b27e761b3e8716a6653518d32f5fe7d4c546c9ce Mon Sep 17 00:00:00 2001 From: Abir Abbas Date: Wed, 8 Jul 2026 10:38:32 -0400 Subject: [PATCH] fix: honor the PORT injected by `af run` instead of hardcoding 8004 pr-af called `app.run(port=8004)` with a hardcoded port. The SDK treats an explicit port as the highest-priority override, so it ignored the PORT env var the AgentField runner injects when it allocates a free port. Result: `af run pr-af` bound 8004 while the CLI polled its assigned port, and the readiness check timed out ('agent node did not become ready within 10s'). Read PORT with an 8004 fallback (same pattern sec-af/cloudsecurity-af use), so `af run` works out of the box while standalone `python -m pr_af.app` still defaults to 8004. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/pr_af/app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pr_af/app.py b/src/pr_af/app.py index 0a3daad..fd5547b 100644 --- a/src/pr_af/app.py +++ b/src/pr_af/app.py @@ -378,7 +378,12 @@ async def health() -> dict[str, str]: def main() -> None: - app.run(port=8004, host="0.0.0.0") + # Honor the PORT injected by the AgentField CLI/runner (`af run` allocates a + # free port and passes it via PORT); fall back to 8004 when launched + # standalone. Previously this was hardcoded to 8004, which the SDK treats as + # an explicit override — so `af run pr-af` bound 8004 while the CLI polled its + # assigned port, and the readiness check timed out. + app.run(port=int(os.getenv("PORT", "8004")), host="0.0.0.0") if __name__ == "__main__":