Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Miniswen: `agent.request_timeout` (and `miniswen --request-timeout`) bounds one model call, so a model that answers in one long turn (Gemini 4 Carbon took 627 s for a 28K-token reply) isn't cut at ruby_llm's 300 s and retried until the step limit.

## [1.6.0] - 2026-11-03

- Miniswen: upgrade ruby_llm to 2.1.1 (use its new built-in caching, finish reasons and reasoning replay, keep the ~10 min retry window, honor `RUBYLLM_DEBUG`, allow JSON 3).
Expand Down
2 changes: 2 additions & 0 deletions lib/lemans/agents/miniswen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def agent_for(environment, workdir: nil)
max_time: profile.timeout,
max_cost: profile.cost_limit,
exec_timeout: profile.exec_timeout,
request_timeout: profile.request_timeout,
max_output_tokens: profile.max_output_tokens
)
end
Expand Down Expand Up @@ -121,6 +122,7 @@ def agent_extra
cost_limit: profile.cost_limit,
wall_time_limit_seconds: profile.timeout,
exec_timeout_seconds: profile.exec_timeout,
request_timeout_seconds: profile.request_timeout,
max_output_tokens: profile.max_output_tokens,
max_consecutive_format_errors: ::Miniswen::Agent::MAX_CONSECUTIVE_FORMAT_ERRORS
}.compact }
Expand Down
1 change: 1 addition & 0 deletions lib/lemans/agents/miniswen_installed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def command_for(task, history: nil)
"--exec-timeout", profile.exec_timeout.to_i,
"--max-output-tokens", profile.max_output_tokens ]
argv += [ "--max-cost", profile.cost_limit.to_i ] if profile.cost_limit
argv += [ "--request-timeout", profile.request_timeout.to_i ] if profile.request_timeout
argv += [ "--workdir", task.environment.workdir ]
argv += [ "--allow-hosts", allowed_hosts.join(",") ] if allowed_hosts.any?
argv.map { Shellwords.escape(it.to_s) }.join(" ")
Expand Down
4 changes: 4 additions & 0 deletions lib/lemans/cli/templates/bench/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ agent:
# Timeout (in seconds) for a single command the agent runs
exec_timeout: 300

# Timeout for a single model call (default: ruby_llm's 300s). Raise it for
# models that answer in one long turn, e.g. 20m.
# request_timeout: 20m

# The sandbox network while the agent works: just enough to reach the model
# Use mode: none when using a local agent (miniswen)
# With mode allowlist, agent commands reach these hosts through the jail's proxy
Expand Down
5 changes: 4 additions & 1 deletion lib/lemans/config/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def from_config(data)
conf.cost_limit = float!(data["cost_limit"]) if data["cost_limit"]
conf.timeout = seconds!(data["timeout"]) if data["timeout"]
conf.exec_timeout = seconds!(data["exec_timeout"]) if data["exec_timeout"]
conf.request_timeout = seconds!(data["request_timeout"]) if data["request_timeout"]
conf.max_output_tokens = integer!(data["max_output_tokens"]) if data.key?("max_output_tokens")

if (network_data = data.dig("environment", "network"))
Expand All @@ -31,7 +32,7 @@ def from_config(data)
end

attr_accessor :name, :models, :timeout,
:step_limit, :cost_limit, :exec_timeout, :max_output_tokens,
:step_limit, :cost_limit, :exec_timeout, :request_timeout, :max_output_tokens,
:environment

def model = models.first
Expand All @@ -44,6 +45,7 @@ def to_h
"step_limit" => step_limit,
"cost_limit" => cost_limit,
"exec_timeout" => exec_timeout,
"request_timeout" => request_timeout,
"max_output_tokens" => max_output_tokens,
"environment" => { "network" => environment.network.to_h }
}.compact
Expand All @@ -57,6 +59,7 @@ def initialize(name, model)
@step_limit = 100
@cost_limit = nil
@exec_timeout = 300
@request_timeout = nil
@max_output_tokens = 0
@timeout = 30 * 60
@environment = Environment.new(network: NetworkPolicy.new)
Expand Down
19 changes: 15 additions & 4 deletions lib/miniswen/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ def to_h = { name:, model:, priced_as:, registry: }.compact

attr_reader :messages, :environment

private attr_reader :workdir, :max_steps, :max_time, :max_cost, :exec_timeout, :max_output_tokens,
private attr_reader :workdir, :max_steps, :max_time, :max_cost, :exec_timeout, :request_timeout, :max_output_tokens,
:cache_id, :clock, :reporter

# `model` is a litellm-style name ("openrouter/z-ai/glm-5.2"), optionally
# suffixed with a reasoning effort ("openrouter/openai/gpt-5.6-luna#xhigh").
# Limits of 0 or nil are disabled.
# Limits of 0 or nil are disabled. `request_timeout` bounds one model call
# (ruby_llm's default when nil).
def initialize(model:, environment:, workdir: nil, max_steps: 0, max_time: 0, max_cost: nil,
exec_timeout: 30, max_output_tokens: 0,
exec_timeout: 30, request_timeout: nil, max_output_tokens: 0,
clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) },
reporter: nil)
name, @effort = model.split("#", 2)
Expand All @@ -233,6 +234,7 @@ def initialize(model:, environment:, workdir: nil, max_steps: 0, max_time: 0, ma
@max_time = max_time.to_f
@max_cost = max_cost
@exec_timeout = exec_timeout
@request_timeout = request_timeout
@max_output_tokens = max_output_tokens.to_i

@clock = clock
Expand Down Expand Up @@ -576,7 +578,16 @@ def cost_source
end

def resolved
@resolved ||= RubyLLM::Models.resolve(@id, provider: @provider, assume_model_exists: !@provider.nil?)
@resolved ||= RubyLLM::Models.resolve(@id, provider: @provider, assume_model_exists: !@provider.nil?,
config: llm_config)
end

# Some models answer in one long turn (Gemini 4 Carbon: 10+ minutes for a
# 28K-token reply), which ruby_llm's default timeout would cut and retry forever.
def llm_config
return RubyLLM.config unless request_timeout

RubyLLM.context { it.request_timeout = request_timeout }.config
end

def as_ruby_llm(entry)
Expand Down
4 changes: 4 additions & 0 deletions lib/miniswen/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def parse_args!
options[:exec_timeout] = v
end

opts.on("--request-timeout=SECONDS", Float, "Model call timeout (default: ruby_llm's)") do |v|
options[:request_timeout] = v
end

opts.on("--max-output-tokens=TOKENS", Integer, "Output cap per model call (default: the provider's)") do |v|
options[:max_output_tokens] = v
end
Expand Down
11 changes: 11 additions & 0 deletions test/lemans/agents/test_miniswen_installed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_a_remote_run_is_downloaded_and_reported_through_the_shared_atif_tail
assert_includes command, "--max-cost 5"
assert_includes command, "--workdir "
assert_includes command, "--allow-hosts openrouter.ai"
refute_includes command, "--request-timeout"

response.trajectory.session_id = "test-session"
trajectory = JSON.parse(JSON.generate(response.trajectory.to_atif))
Expand All @@ -87,6 +88,16 @@ def test_a_history_ships_to_the_sandbox_in_place_of_the_prompt
refute_includes shell.commands.last, " -p "
end

def test_a_request_timeout_is_passed_to_the_sandboxed_cli
agent, task = build_agent
agent.profile.request_timeout = 1200
shell = TestEnvironment.new(files: { Lemans::Agents::MiniswenInstalled::RESULTS_PATH => remote_result_json })

with_openrouter_key { agent.run(task, shell) }

assert_includes shell.commands.last, "--request-timeout 1200"
end

def test_jailed_commands_get_no_network_outside_an_allowlist
config = load_config
config.agent.environment.network = Lemans::Config::NetworkPolicy.new("none")
Expand Down
3 changes: 3 additions & 0 deletions test/lemans/config/agent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def full_config
"step_limit" => 200,
"cost_limit" => 5.0,
"exec_timeout" => "5m",
"request_timeout" => "20m",
"max_output_tokens" => 65_536,
"environment" => {
"network" => { "mode" => "allowlist", "hosts" => [ "openrouter.ai" ] }
Expand All @@ -27,6 +28,7 @@ def test_full_section
assert_equal 200, agent.step_limit
assert_in_delta 5.0, agent.cost_limit
assert_in_delta 300.0, agent.exec_timeout
assert_in_delta 1200.0, agent.request_timeout
assert_equal 65_536, agent.max_output_tokens
assert_equal "allowlist", agent.environment.network.mode
assert_equal [ "openrouter.ai" ], agent.environment.network.hosts
Expand All @@ -39,6 +41,7 @@ def test_minimal_section_with_defaults
assert_nil agent.cost_limit
assert_equal 30 * 60, agent.timeout
assert_equal 300, agent.exec_timeout
assert_nil agent.request_timeout
assert_equal 0, agent.max_output_tokens
assert_equal "public", agent.environment.network.mode
assert_nil agent.environment.network.hosts
Expand Down
12 changes: 12 additions & 0 deletions test/miniswen/agent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,18 @@ def test_the_output_cap_is_sent_only_when_set_and_clamped_to_the_advertised_maxi
assert_equal 4096, RubyLLM::Test.last_request.max_output_tokens
end

def test_a_request_timeout_reaches_the_provider_without_touching_the_global_config
with_api_key(:openrouter) { build_agent(model: "openrouter/anthropic/test", request_timeout: 1200) }
_, provider = agent.send(:resolved)

assert_equal 1200, provider.config.request_timeout
refute_equal 1200, RubyLLM.config.request_timeout

with_api_key(:openrouter) { build_agent(model: "openrouter/anthropic/test") }

assert_same RubyLLM.config, agent.send(:resolved).last.config
end

def test_an_effort_suffix_sets_the_reasoning_effort_and_stays_out_of_the_model_id
with_api_key(:openrouter) { build_agent(model: "openrouter/anthropic/test#xhigh") }
stub_llm(SUBMIT)
Expand Down