Skip to content

Commit da4510a

Browse files
songoowloopx-agent
andauthored
fix(benchmark): bind provider admission to each native invocation (#7777)
Give each opted-in heartbeat invocation its own immutable Goal/Turn owner and gateway route. Recheck current authority after waits, bound POST dispatch, preserve default transport behavior, and cover stale connections, real backpressure, and checkpoint resumes. Signed-off-by: song <liusongstep@gmail.com> Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Co-authored-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 85b0975 commit da4510a

15 files changed

Lines changed: 1560 additions & 32 deletions

‎benchmark/edgebench/run.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def main(argv=None):
123123
help="Opt-in short heartbeat context with same-invocation full captures")
124124
parser.add_argument("--context-delivery", choices=("off", "on"), default="off",
125125
help="Experimental native Codex benchmark heartbeat reuse only; off by default")
126+
parser.add_argument("--provider-request-admission", action="store_true",
127+
help="Opt-in canonical admission before each heartbeat custom Responses request")
126128
parser.add_argument("--native-goal-continue", action="store_true",
127129
help="Opt-in: when a native Goal declares completion with budget left, start "
128130
"continuation Goals until the budget edge (native-goal worker only)")
@@ -197,6 +199,13 @@ def main(argv=None):
197199
parser.error("--turn-envelope requires a heartbeat worker")
198200
if args.context_delivery != "off" and not args.worker.startswith("heartbeat-"):
199201
parser.error("--context-delivery requires a heartbeat worker")
202+
if args.provider_request_admission:
203+
if not args.worker.startswith("heartbeat-"):
204+
parser.error("--provider-request-admission requires a heartbeat worker")
205+
if not (api_base_url or "").strip() or not (api_key or "").strip():
206+
parser.error("--provider-request-admission requires OPENAI_BASE_URL and OPENAI_API_KEY")
207+
if (os.environ.get("CODEX_WIRE_API") or "responses") != "responses":
208+
parser.error("--provider-request-admission requires CODEX_WIRE_API=responses")
200209
if args.native_goal_continue and args.worker != "native-goal":
201210
parser.error("--native-goal-continue requires --worker native-goal")
202211
if (args.replan_after_turns is not None or args.replan_after_todos is not None
@@ -345,6 +354,7 @@ def main(argv=None):
345354
task_entry=args.task_entry,
346355
turn_envelope=args.turn_envelope,
347356
context_delivery=args.context_delivery,
357+
**({"provider_request_admission": True} if args.provider_request_admission else {}),
348358
native_goal_continue=args.native_goal_continue,
349359
replan_after_turns=args.replan_after_turns,
350360
replan_after_todos=args.replan_after_todos,
@@ -412,6 +422,7 @@ def main(argv=None):
412422
"sforge_source": active_source_receipt(),
413423
**turn_envelope_receipt(explicit=args.turn_envelope),
414424
**({"context_delivery": "on"} if args.context_delivery != "off" else {}),
425+
**({"provider_request_admission": "on"} if args.provider_request_admission else {}),
415426
**({"native_goal_continue": True} if args.native_goal_continue else {}),
416427
"task_sha256": hashlib.sha256(task_file.read_bytes()).hexdigest(),
417428
"feedback": args.feedback, "internet": task.internet,

‎benchmark/runtime/RUNTIME.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,48 @@ approval in its envelope; publishing and production actions keep their gates.
417417
Staging uses Harbor upload/exec methods, without Docker-label container discovery.
418418
Backend-specific networking stays in the benchmark's native launcher.
419419

420+
### Opt-in provider request admission
421+
422+
Set `provider_request_admission: true` in the Harbor heartbeat agent's `kwargs`,
423+
or pass `--provider-request-admission` to an EdgeBench heartbeat worker, to check
424+
the existing canonical admission before each model-provider request. This is a
425+
separate boolean opt-in from context delivery and turn envelopes. It requires a
426+
custom `OPENAI_BASE_URL`, `OPENAI_API_KEY` and the `responses` wire API; login-file
427+
routes and other execution modes reject activation before execution. The worker
428+
receives `LOOPX_PROVIDER_REQUEST_ADMISSION=on`, and enabled run/profile receipts
429+
record `provider_request_admission: "on"`. Omission keeps the existing environment
430+
and receipt shape. Disable it by omitting the option on a new trial.
431+
432+
Each native invocation gets its own listener and random request path, bound once
433+
to that invocation. A successor never rebinds the earlier listener to a new
434+
process or admission identity. The request check reuses the existing Stop, quota
435+
and canonical admission owners; it does not grant additional work or invent a
436+
second quota counter. Inbound parsing, upstream connection setup and waiting for
437+
the response do not hold the Goal/registry lock. The admitted POST dispatch has
438+
an absolute two-second deadline, shortened by a smaller remaining phase budget.
439+
An uncertain or partially sent request remains unknown and is not retried by
440+
this transport.
441+
442+
Per-invocation receipts distinguish requests started, bytes fully sent, pending
443+
responses and unknown partial sends. `sent` does not certify provider acceptance
444+
or completion; a response still pending when the worker exits remains visible
445+
as pending. Request observations contain identities and transport outcomes,
446+
without request/response bodies, query strings or credentials. Their file writes
447+
run outside the invocation state lock and the canonical admission scope.
448+
449+
The isolated Codex home and checkpoint configuration retain the existing
450+
provider route. Only the native process command receives a temporary route
451+
override for its invocation. SForge may already have selected a host credential
452+
gateway, including an HTTP route; admission forwards to that same effective
453+
route read back from the trial, with its existing credential contract. A loopback
454+
listener alone is not a credential or OS isolation boundary. The caller still
455+
owns provider access, credential isolation and the worker's process/filesystem
456+
boundary. This option changes request admission, not provider identity, scoring
457+
or benchmark qualification.
458+
For HTTPS upstreams, an explicit proxy uses HTTP CONNECT; unsupported proxy
459+
layouts refuse activation before launch. A slow upload can reach the bounded
460+
send deadline and remain unknown even when the upstream has received some bytes.
461+
420462
## Results, timeout and recovery
421463

422464
### Live session observation

‎benchmark/runtime/checkpoint_wake.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def _write_input(self, process, body, command, deadline, timeout, *, phase_limit
210210
stream.close() # No buffered writes: all input used the raw pipe.
211211

212212
def run(self, execution, body, wake, session_wake, stdout, stderr, timeout, *, phase_limited=False):
213-
from .worker import child_process, heartbeat_launch_check, native_command
213+
from .worker import native_child_process, native_command
214214
from .sessions import BenchmarkSessionWake
215215

216216
deadline = time.monotonic() + timeout if timeout is not None else float("inf")
@@ -223,10 +223,10 @@ def run(self, execution, body, wake, session_wake, stdout, stderr, timeout, *, p
223223
raise subprocess.TimeoutExpired("checkpoint source wake", timeout)
224224
command = native_command(launch_env, execution, "execute", wake, session_wake)
225225
continuation = None
226-
with child_process(command, env=launch_env, stdout=stdout, stderr=stderr,
227-
goal_admission=session_wake.admission if session_wake is not None else None,
228-
check_current_launch=heartbeat_launch_check(
229-
launch_env, session_wake, original_quota=original_quota)) as process:
226+
with native_child_process(command, env=launch_env, stdout=stdout, stderr=stderr,
227+
session_wake=session_wake, receipt=self.receipt, wake=wake,
228+
timeout=remaining if timeout is not None else None,
229+
original_quota=original_quota) as process:
230230
self.receipt["host_invoked"] = True
231231
self._write_input(process, body, command, deadline, timeout,
232232
phase_limited=phase_limited)

‎benchmark/runtime/harbor.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(
7575
planning_timeout_sec=None,
7676
turn_envelope=False,
7777
context_delivery="off",
78+
provider_request_admission=False,
7879
native_goal_continue=False,
7980
task_objective=None,
8081
execution_observation=None,
@@ -101,6 +102,11 @@ def __init__(
101102
turn_envelope,
102103
context_delivery,
103104
)
105+
if type(provider_request_admission) is not bool:
106+
raise ValueError("provider_request_admission must be a boolean opt-in")
107+
if provider_request_admission and self.execution.mode != "heartbeat":
108+
raise ValueError("provider_request_admission requires heartbeat execution")
109+
self.provider_request_admission = provider_request_admission
104110
if planning_timeout_sec is not None:
105111
raise ValueError(
106112
"Remove planning_timeout_sec; planning shares scheduler_timeout_sec with execution"
@@ -173,6 +179,13 @@ def __init__(
173179
raise ValueError("Task objective must be a non-empty string")
174180
self.task_objective = task_objective
175181
super().__init__(*args, **kwargs)
182+
if self.provider_request_admission:
183+
if not (self._get_env("OPENAI_BASE_URL") or "").strip() or not (
184+
self._get_env("OPENAI_API_KEY") or ""
185+
).strip():
186+
raise ValueError("provider_request_admission requires a custom provider URL and API key")
187+
if (self._get_env("CODEX_WIRE_API") or "responses") != "responses":
188+
raise ValueError("provider_request_admission requires the Responses wire API")
176189

177190
def _turn_envelope_receipt(self) -> dict:
178191
return {**turn_envelope_receipt(explicit=self.execution.turn_envelope),
@@ -369,6 +382,7 @@ async def install(self, environment: BaseEnvironment) -> None:
369382
if self.execution_observation is not None else {}),
370383
**self._turn_envelope_receipt(),
371384
**self._planning_receipt(),
385+
**({"provider_request_admission": "on"} if self.provider_request_admission else {}),
372386
"home_scope": "trial",
373387
"loopx_usage_ping_enabled": False,
374388
"login_shell_node_path": _BASH_ENV,
@@ -621,6 +635,7 @@ def _worker_env(self, *, cwd: str) -> dict[str, str]:
621635
if self.checkpoint_request_path is not None else {}),
622636
**({"LOOPX_TURN_ENVELOPE": "1"} if self.execution.turn_envelope else {}),
623637
**({"LOOPX_CONTEXT_DELIVERY": "on"} if self.execution.context_delivery != "off" else {}),
638+
**({"LOOPX_PROVIDER_REQUEST_ADMISSION": "on"} if self.provider_request_admission else {}),
624639
**({"LOOPX_NATIVE_GOAL_CONTINUE": "1"} if self.native_goal_continue else {}),
625640
"LOOPX_ITERATION_CONTEXT": self.execution.context,
626641
"LOOPX_CODEX_SANDBOX": self.execution.sandbox,
@@ -750,6 +765,7 @@ def token_delta(key: str) -> int | None:
750765
"task_entry": self.execution.task_entry,
751766
**self._turn_envelope_receipt(),
752767
**self._planning_receipt(),
768+
**({"provider_request_admission": "on"} if self.provider_request_admission else {}),
753769
"home_scope": "trial",
754770
**self._replan_receipt(),
755771
"benchmark_phase": self._phase_number,

0 commit comments

Comments
 (0)