Skip to content

Commit 07ad232

Browse files
committed
fix: route async codex audit jobs through nginx
1 parent 652abe7 commit 07ad232

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

scripts/deploy_codex_audit_service.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,17 @@ text = re.sub(
176176
177177
route_template = """
178178
{indent}# CodexAuditBridge route start
179-
{indent}location /v1/codex-audit {{
179+
{indent}location = /v1/codex-audit {{
180+
{indent} proxy_pass http://127.0.0.1:{port};
181+
{indent} proxy_http_version 1.1;
182+
{indent} proxy_set_header Host $host;
183+
{indent} proxy_set_header X-Real-IP $remote_addr;
184+
{indent} proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
185+
{indent} proxy_set_header X-Forwarded-Proto https;
186+
{indent} proxy_read_timeout 3600s;
187+
{indent} proxy_send_timeout 3600s;
188+
{indent}}}
189+
{indent}location ^~ /v1/codex-audit/ {{
180190
{indent} proxy_pass http://127.0.0.1:{port};
181191
{indent} proxy_http_version 1.1;
182192
{indent} proxy_set_header Host $host;
@@ -289,9 +299,28 @@ import re
289299
import sys
290300
291301
text = Path(sys.argv[1]).read_text(encoding="utf-8")
292-
for block in re.findall(r"server\s*\{.*?\n\}", text, flags=re.S):
302+
303+
304+
def server_blocks(source: str):
305+
for match in re.finditer(r"\bserver\s*\{", source):
306+
open_brace = source.find("{", match.start())
307+
depth = 0
308+
for index in range(open_brace, len(source)):
309+
char = source[index]
310+
if char == "{":
311+
depth += 1
312+
elif char == "}":
313+
depth -= 1
314+
if depth == 0:
315+
yield source[match.start() : index + 1]
316+
break
317+
318+
319+
for block in server_blocks(text):
293320
if not re.search(r"\blisten\s+443\b", block):
294321
continue
322+
if "# CodexAuditBridge route start" not in block:
323+
continue
295324
match = re.search(r"\bserver_name\s+([^;\s]+)", block)
296325
if match and match.group(1) not in {"_", "localhost"}:
297326
print(match.group(1))

tests/test_run_monthly_codex_audit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,11 @@ def test_vps_ops_workflow_runs_only_manual_self_hosted_ops(self) -> None:
484484
def test_vps_deploy_adds_nginx_audit_route_without_router_service(self) -> None:
485485
deploy_script = Path("scripts/deploy_codex_audit_service.sh").read_text(encoding="utf-8")
486486

487-
self.assertIn("location /v1/codex-audit", deploy_script)
487+
self.assertIn("location = /v1/codex-audit", deploy_script)
488+
self.assertIn("location ^~ /v1/codex-audit/", deploy_script)
488489
self.assertIn("CODEX_AUDIT_SERVICE_JOB_DIR", deploy_script)
489490
self.assertIn("proxy_pass http://127.0.0.1:{port}", deploy_script)
491+
self.assertIn('"# CodexAuditBridge route start" not in block', deploy_script)
490492
self.assertIn("audit service did not become healthy", deploy_script)
491493
self.assertIn("nginx config test failed; restoring previous config", deploy_script)
492494
self.assertNotIn("CODEX_SERVICE_ROUTER", deploy_script)

0 commit comments

Comments
 (0)