Repository navigation
feat(gateway): fixed mode for the env clock, each agent tool call costs set task time, 60 s by default (FD-7183) - #1003
Open
sarah-chitty-1 wants to merge 9 commits into
Open
sarah-chitty-1 wants to merge 9 commits into
sarah-chitty-1 wants to merge 9 commits into
Conversation
…s clock_mode (FD-7183) A task whose clock is frozen lived through none of the agent's work: a turn took no task time, and a trigger due mid-turn waited for the next one. In work mode the clock stays at rate 0 and the gateway moves it on by a fixed 60 virtual seconds (WORK_SECONDS_PER_CALL, not configurable) for each answered tool call the agent makes, so thinking and model latency cost nothing and every model sees the same world for the same work. - sync_env_clock and set_env_clock_rate take clock_mode: "work" (unset keeps today's behaviour). It arms or sets rate 0 and turns work mode on (clock/v1 work); a nonzero rate with it is an error, and a gateway whose card lacks work is refused before the clock is touched. - The gateway charges calls on the MCP path and the step API's /step paths (not a post-turn hook's), after their barriers, through Clock.advance_by, then holds the answer until the time triggers the charge made due have landed (TriggerEngine.settle_due). Each charge is a work_clock_charge event. - Only the agent is charged: roles whose calls provoke triggers, less executors (TriggerEngine.agent_roles). Setup, verifier, user sim, contacts, trigger tool actions and hooks never are. get_time and stay_quiet are free. - set_time, set_rate and clear leave work mode, so set_env_clock_rate 0 after the agent stops it. - always_on gets no setting: it reads the mode from /clock/state and reports each turn's work in agent_turn_end, the judge's per-wake line and counts["work_clock"], and refuses an agent whose role work mode doesn't charge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s for all runnable world work (FD-7183) Review fixes for cf8c06b. Who is charged: the role guess is gone (TriggerEngine.agent_roles). A call with no AgentEnv-Role header resolved to "default", which the guess charged, so collect_artifacts, a verifier and run_code scripts moved the clock; an agent on its own role with no matching watch_roles was never charged. Now prompt_agent opens a work window (PUT /clock/work/window) naming its agent's role around its conversation, and always_on one around each turn, nudges included; a call is charged only while a window naming its role is open. Late calls of the agent's role outside a window are logged as work_clock_outside_window. Both steps refuse more than one env in work mode. always_on's roles check is removed. The hold: a charged call's answer now waits for all world work runnable now (every trigger fire at work, due deferred calls, and what they set going), not only the triggers that one charge made due; a fire waiting on later task time is excluded. Barrier wait and hold share one budget. Virtual stamps no longer depend on executor latency. Lifecycle: set_time leaves work mode before registering get_time; /clock/work and /clock/work/window are control routes; a post-turn hook's /step call is free only with the control token; get_time/stay_quiet are free only as the gateway's own tools; _change_clock wakes watchers and followers, and a charge is recorded, even when what follows the advance raises. Reporting: work_clock_charge is logged before the hold with tool_call_event_id, and work_clock_hold in a finally (shielded), so a cancelled call leaves a trace. always_on reads each turn's work from its window's close, after freezing, within attempts=2/timeout=10; logs work_mode_off once; the judge line adds the nudge turn's work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…an infra error (FD-7183) A window left open would charge calls made after the agent (a verifier's or collect_artifacts' header-less reads, for an agent on the default role) and move the world on under the grading. So a close that still fails after its retry now fails closed with WorkWindowError, an AgentTurnInfraError, which a retry_config can redo: - prompt_agent raises it once the agent's work is done; when the agent itself raised, its error stays the one raised, the close failure logged and added as a note on it. - always_on ends the run with it at the turn's end (two tries, 10 s each); a run being cancelled stays cancelled, the failure logged. - A window that can't be opened (other than work mode found off, a 409) fails the same way before the agent starts. Also adds the tests the mutation run asked for: a deferred call due later doesn't hold a call; a barrier's own longer timeout is the call's budget; a call answered after its window closed counts in a retried close; a second cancel doesn't drop the hold's record; the window goes on the deployment in work mode only; a 409 on open runs the agent with no window; work mode ended between always_on turns is found at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mode charges a fixed 60 s per answered tool call, so its public surface now says so, with no "work" alias (nothing is released yet): - clock_mode: "fixed"; the clock/v1 card method "fixed"; the route /clock/fixed (windows at /clock/fixed/window); the "fixed" block in /clock/state and in the mode's and windows' answers - trace events fixed_clock_charge, fixed_clock_hold, fixed_clock_skipped, fixed_clock_outside_window and fixed_mode_off; the run record's counts["fixed_clock"] and settings["clock"]["fixed"] - work_clock.py -> fixed_clock.py (FixedClock, FixedModeOff, parse_fixed_body), CLOCK_FIXED_MODE, CLOCK_FIXED_PATH, FIXED_SECONDS_PER_CALL, start_fixed, require_fixed, fixed_mode_envs; error messages, docstrings and AGENTS.md The agent's work window keeps its name (open_work_window, close_work_window, the work_window event, WorkWindowError), as does each turn's "work" field, since they describe the agent working, not the mode. No behaviour change; a test now shows "work" is refused as a clock_mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…window, and window failures go ungraded (FD-7183) Three P1s from review on PR 1003: - State checks escaped the hold: at_work() now counts a state trigger whose check is under way (evaluating, its task kept as eval_task), so _settle_world waits for the check and then for the fire it starts, within the same budget, however slow the check. - A charge decided before the call's barrier wait was applied after it even if fixed mode had ended meanwhile. The call now carries a ticket (the clock's generation, fixed mode's session, the role's windows by the serial they were opened with), re-checked in the same step as the advance: set_rate, set_time, clear, turning it off, or the window closing (even reopened by the same id) skips the charge as fixed_clock_skipped. - A WorkWindowError (a window that couldn't be opened or closed) is now recorded as agent_turn_infra_error with error_code agent_env.work_window_failed before always_on's finish() saves the record, so ended_on_infra_failure is true and verifiers leave the run ungraded. prompt_agent's saved response gets error_type infra_error and the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ngraded, not scored 0 (FD-7183) Review on PR 1003: prompt_agent saves its response as infra_error when its work window can't be closed, but the verifiers' skip check only knew always_on records, so the gateway's failure scored 0 against the agent. ended_on_infra_failure now also takes the prompt response and recognizes one saved with error_code agent_env.work_window_failed (clock_mode.work_window_failed). The response check and the judge (rubrics_verifier's _not_graded_reason, and always_on_agent_verifier's) leave such a run ungraded. Any other infra_error a prompt_agent turn ended on still scores 0 with a prompt_error row, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…windows left open (FD-7183) Two bugs an independent review found in fixed mode. A role-less agent's CLI calls were never charged. prompt_agent and always_on opened the window for `agent.role or "default"`, but deploy_agent sets AGENT_ENV_ROLE only for an agent with a role, so the generated MCP CLI sends its own default, `cli`, which no window named: nothing was charged and nothing logged. The window now names both `default` and `cli` for such an agent (clock_mode.agent_window_roles, used by both steps). The CLI's default role is unchanged, so no task outside fixed mode changes. No harness-side caller (verifier, collect_artifacts, user sim, contacts, triggers, post-turn hooks) sends role `cli`; only the generated CLI does. A window whose open or close failed was never cleaned up, and could go on charging later callers, a retry's or a later step's verifiers included: - After a failed open, the step now sends a close for that window id before raising (a 404 is fine), since the gateway may have opened it and only its answer was lost. - A window that may still be open (its close failed twice, or the close after a failed open failed too) is recorded in context.metadata["work_windows_left_open"], and the next step to open a window on that env closes it first, failing closed with WorkWindowError (before the agent starts) if that close fails. - Before opening, the step also closes any window the gateway shows open under its own step id. A step never runs beside itself, so such a window is an earlier attempt's: this covers a retry whose rollback undid the failed attempt's record (undo_steps drops everything the span wrote), and a worker that died with its context. - always_on's cancelled-turn path now records the run as an infrastructure failure (error_code agent_env.work_window_failed), as its other close-failure path does; the run stays cancelled. Why not have the gateway close an overlapping window on open: two windows naming the same role can be open at once on purpose. Task steps with no dependency between them run concurrently, so two prompt_agent steps whose agents share a role (two role-less agents, say) each hold a window naming it, and the gateway is built for that (per-window serials in Ticket, test_two_windows_each_count_their_own_roles). Replacing on open would close the first step's window when the second opens, and once the second closed, the first agent's later calls would go uncharged. always_on nudges don't overlap (each turn's window closes before the next opens), and WindowConflict only concerns re-opening the same id. Left open: a retry whose span starts after the clock step but before the failed step, with header-less tool calls in between, still runs those under the earlier attempt's window until the step itself re-runs and closes it (a span that re-runs the clock step ends every window anyway). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Make the per-call charge a parameter instead of a constant Rather than hard-coding
Tasks get 60 s without writing anything, and a task that needs finer or coarser steps can say so. |
Greptile P2: the two close calls repeated attempts=2, timeout=10 inline. They now share WINDOW_CLOSE_ATTEMPTS and WINDOW_CLOSE_TIMEOUT_SECONDS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s the default (FD-7183) Fixed mode moved the frozen clock on by a constant FIXED_SECONDS_PER_CALL (60 s) for each charged tool call. The charge is now a parameter, as the review asked. Gateway: - PUT /clock/fixed requires seconds_per_tool_call to turn the mode on, and answers 400 without it. The value must be a finite number above 0 and at most FIXED_MAX_SECONDS_PER_CALL (86400, a day). Booleans, NaN, infinity, 0, negatives and non-numbers are refused. Turning the mode off takes no charge, and a request that sends one is refused too. - FixedClock stores the charge and cost() charges it. The state's fixed block reports it as seconds_per_call, which is null while the mode is off. - The clock/v1 card's fixed request schema marks seconds_per_tool_call as required when on is true (if/then), and forbids it when on is false. - One validator, constants.fixed_seconds_per_call_error, is used by the gateway and by the steps. Steps: - sync_env_clock and set_env_clock_rate take fixed_time_increment_on_tool_call_seconds. Left unset it means FIXED_SECONDS_PER_CALL (60). It is checked at load the way the gateway checks it, and accepted only with clock_mode "fixed". - to_dict writes it only when set, so existing step JSON is unchanged. - The step sends it to the gateway (start_fixed) and records it in clock_configurations beside clock_mode. Docs and docstrings no longer say the charge is a fixed 60 s. They now say it defaults to 60 s and a task may set it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
@earakely-scale Done in 4749a02, as you described:
|
| FIXED_MAX_SECONDS_PER_CALL, never a boolean. The gateway's /clock/fixed checks it, and the clock steps at load.""" | ||
| if isinstance(value, bool) or not isinstance(value, (int, float)): | ||
| return f"must be a number of seconds, got {value!r}" | ||
| if not math.isfinite(value) or value <= 0: |
There was a problem hiding this comment.
Oversized integers cause server errors
fixed_seconds_per_call_error calls math.isfinite(value) before checking the upper bound. A JSON integer such as 10**400 raises OverflowError here. Since /clock/fixed catches only ClockError, the caller gets a server error instead of the promised 400.
Call math.isfinite only for floats, as _parse_rate already does, so oversized integers reach the maximum check.
Suggested change
| if not math.isfinite(value) or value <= 0: | |
| if (isinstance(value, float) and not math.isfinite(value)) or value <= 0: |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/env/gateway/constants.py
Line: 119
Comment:
**Oversized integers cause server errors**
`fixed_seconds_per_call_error` calls `math.isfinite(value)` before checking the upper bound. A JSON integer such as `10**400` raises `OverflowError` here. Since `/clock/fixed` catches only `ClockError`, the caller gets a server error instead of the promised 400.
Call `math.isfinite` only for floats, as `_parse_rate` already does, so oversized integers reach the maximum check.
```suggestion
if (isinstance(value, float) and not math.isfinite(value)) or value <= 0:
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
FD-7183. Today an always_on world clock either runs on wall time during the agent's turns, so provider latency costs in-world time, or it is frozen, so the agent's work costs no time at all. This PR adds a third clock mode, fixed: the clock is frozen, and each tool call the agent makes costs a set amount of in-world time, 60 s by default. The same work costs the same in-world time on every model and provider.
A task picks it the way it picks frozen today:
"clock_mode": "fixed"on itssync_env_clockstep, or onset_env_clock_rate. Fixed mode means a rate of 0, and a nonzero rate with it is an error. The charge defaults to 60 s; a task can set its own withfixed_time_increment_on_tool_call_secondson the same step (a number above 0, at most a day, and only with fixed mode). The gateway takes it asseconds_per_tool_callwhen the mode turns on. Tasks withoutclock_modebehave exactly as before, and their step JSON is unchanged byte for byte.How it works
fixed_clock_outside_window.get_timeandstay_quietcost nothing when gateway-native.WorkWindowError, an infra error, rather than letting verifier calls be charged. A window left open is closed before the next agent starts: one a failed step recorded, or one the gateway still shows under the same step id from an earlier attempt. If it still can't be closed, the agent doesn't start. prompt_agent and always_on refuse more than one env in fixed mode, since their clocks would drift apart.defaultand ascli, the role the generated MCP CLI sends without one.PUT /clock/fixedturns the mode on (withseconds_per_tool_call) or off, andPUT /clock/fixed/windowopens or closes windows. Both are control routes./clock/stategains afixedblock, and the clock/v1 card lists thefixedmethod.fixed_clock_chargetrace event: time before and after, held fires and hold seconds. Gateway-native and/stepcalls also carrytool_call_event_id; MCP calls proxied to a backing server don't yet./steppost-turn-hook exemption now needs the control token./clock/stateand records:agent_turn_end;counts["fixed_clock"]in the summary.Known limits
defaultwith header-less harness callers while its window is open. The gateway can't tell them apart. Outside the window those callers are never charged.clock_mode. Tasks should adopt it only after workers run this version.timeout_seconds, a client's tool timeout). A charged call can wait up to 30 s for a slow contact reply, so a slow contact model can still bring a turn to its limit sooner. Task time is not affected.What every task sees
Tasks without
clock_modebehave as before. A few additions show up for every task:/clock/statehas afixedblock (on: falsewhen unused), and the clock/v1 card lists thefixedmethods.output_tokenson eachagent_turn_endandnudgewhen the agent reports usage.set_env_clock_raterecordsdeploy_step_idwheneverenv_step_idis set.How it was tested
Tests were written first:
All of them pass now.
The 6 failures (
computer_exec_test×4,test_mcp_cli_builder×2) fail the same way on the base commit, because of macOSbase64output. The timing-sensitive tests passed 5 runs in a row under load. Ruff is clean.4749a02 makes the charge a per-task setting with a 60 s default, as review asked. A further independent review found two gaps, fixed in 586df8b with 10 tests that failed first: a role-less agent's CLI calls went uncharged, and a window whose open or close failed was never cleaned up.
Four independent reviewers covered the gateway lifecycle, charging paths, task steps and test adequacy. Their findings are fixed in 5d61fab and b6ebd40. 970152f renames the mode from "work" to "fixed" with no behaviour change.
A mutation run of 72 mutants killed 69. The 3 survivors are equivalent or harmless:
🤖 Generated with Claude Code
Confidence Score: 5/5

The PR appears safe to merge, with a non-blocking error-response issue for oversized charge values.Findings
Fix with agent prompt
Summary
Adds fixed clock mode, with a task-selected charge per agent tool call and a 60-second default.
Diagram
sequenceDiagram participant Step participant Agent participant Gateway participant World Step->>Gateway: Open work window Agent->>Gateway: Call tool Gateway->>World: Run tool and wait for barriers Gateway->>Gateway: Check window and advance clock Gateway->>World: Wait for work due now Gateway-->>Agent: Return tool answer Step->>Gateway: Close window and read totalsReviews (7) · Last reviewed commit: "feat(clock): a task sets fixed mode's ch..." · Reviewed by Greptile