Skip to content

[Feature]: Allow application-controlled force-sync subagent timeout beyond 600 seconds #3166

Open

Description

@JesseJI

Is your feature request related to a problem? Please describe.
In AgentScope Java 2.0.2, AgentSpawnTool uses a hard-coded MAX_TIMEOUT_SECONDS = 600. Both the model-provided timeout_seconds and the application-provided CTX_FORCE_SYNC_TIMEOUT_SECONDS are clamped to that value in resolveEffectiveTimeoutMs(). For a long-running remote subagent, the parent agent sometimes needs to wait for the final result in the same run. With CTX_FORCE_SYNC=true, reaching 600 seconds cancels the remote task instead of promoting it to the background. Setting the application override to 1800 still yields a 600-second deadline.

Minimal example:

RuntimeContext ctx = RuntimeContext.builder()
    .sessionId("s-1")
    .put(AgentSpawnTool.CTX_FORCE_SYNC, true)
    .put(AgentSpawnTool.CTX_FORCE_SYNC_TIMEOUT_SECONDS, 1800)
    .build();

Expected: the trusted application override gives the subagent up to 1800 seconds to finish. Actual: it is silently clamped to 600 seconds. This is the parent-to-subagent wait deadline, not an individual model-request timeout.

Describe the solution you'd like
Please provide a supported way to configure a higher maximum for the application-controlled force-sync timeout, separately from the model-controlled timeout_seconds cap. Keeping the latter at 600 seconds would prevent the model from requesting arbitrarily long waits, while allowing an embedding application to set an explicit bounded policy (e.g. 1800 or 3600 seconds). Ideally the effective deadline should be observable, and the local/remote spawn and send paths should have tests for the configured cap.

Describe alternatives you've considered

  • timeout_seconds=0 / timeout promotion: useful for background work, but the parent run may finish before the result is available. It does not fit applications that must return the report before that run finishes.
  • Patching and publishing a private agentscope-harness build: possible, but creates maintenance and upgrade overhead.

Additional context
The relevant logic is in AgentSpawnTool.resolveTimeoutMs() and resolveEffectiveTimeoutMs(); both use Math.min(..., MAX_TIMEOUT_SECONDS). The force-sync setting is an application-provided RuntimeContext value rather than an LLM tool argument.

Activity

  1. added
    enhancement
    on Sep 16, 2026
  2. oss-maintainer commented on Sep 16, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: enhancement | Status: Evaluated — feasible, low-risk, ready for a small PR

    Verified against main @ 6c8ccc5c6. Every factual claim in the report checks out.

    Codebase claims — confirmed

    Claim Location
    MAX_TIMEOUT_SECONDS = 600 is hard-coded AgentSpawnTool.java:110
    Model-provided timeout_seconds is clamped to it resolveTimeoutMs — AgentSpawnTool.java:1505
    The app override CTX_FORCE_SYNC_TIMEOUT_SECONDS is clamped to the same 600s cap resolveEffectiveTimeoutMs — AgentSpawnTool.java:1537
    The clamp is silent (no log, no metadata) AgentSpawnTool.java:1531-1544
    Under force-sync a timeout hard-fails and is not promoted to a background task documented at AgentSpawnTool.java:170-172, asserted by AgentSpawnToolForceSyncTest.timeoutHardFailsWithoutPromotion
    Javadoc already admits the clamp: "values above 600 are clamped" AgentSpawnTool.java:193

    So setting CTX_FORCE_SYNC_TIMEOUT_SECONDS=1800 yielding a 600s deadline is exactly the current behavior — the report is accurate, and the shared cap conflates two different trust levels: an LLM-requested wait vs. an embedding application's explicit policy.

    Blast radius: resolveEffectiveTimeoutMs has three call sites — agent_spawn (:452), agent_send (:622), and the remote sync path (:1626) — all within agentscope-harness. No agentscope-core interface change, fully additive, no breaking API.

    Additional observations beyond the report

    1. asPositiveOrZeroInt does not bound the input before the intValue() coercion, so overflow-path inputs (e.g. 1e10 as a Double) also end up at the clamp; the two-cap design naturally fixes this too.
    2. There is precedent for clamp visibility in the same package: WaitAsyncResultsTool.java:448-450 clamps and logs when the requested value is reduced. The recommended fix should mirror that pattern.

    Recommended fix (minimal, preserves the safety property the reporter asks to keep)

    1. Add APP_MAX_FORCE_SYNC_TIMEOUT_SECONDS = 3600 next to MAX_TIMEOUT_SECONDS; leave the LLM-facing 600s clamp untouched so the model still cannot request arbitrarily long waits.
    2. In resolveEffectiveTimeoutMs (:1537), clamp only the override branch to the new app cap; update the :193 javadoc accordingly.
    3. Warn-log when the effective deadline is reduced (same style as WaitAsyncResultsTool:449), which covers the "observable deadline" ask cheaply; optionally also include effective_timeout_seconds in the sync result metadata.
    4. Extend AgentSpawnToolForceSyncTest with override cases at 599/600/601/1800/3600/3601 and an overflow input, for both the agent_spawn and agent_send resolution paths.

    Design question for maintainers: whether the app-level ceiling should stay a constant (interim, smallest change) or become configurable per harness/agent (builder or policy option). The constant is strictly better than today and can be evolved later without breaking the RuntimeContext contract.

    If the constant-based approach (items 1-4) is agreed, reply /approve and a PR will be generated against agentscope-harness with the described tests.


    Automated evaluation by github-manager-bot

  3. added
    area/harness
    on Sep 16, 2026
  4. philo-x commented on Sep 17, 2026

    @philo-x

    I’m interested in working on this issue and did a quick check against the current main and the related open PR #2749 before starting.

    #2749 overlaps with this area by changing resolveEffectiveTimeoutMs and adding application/operator-controlled timeout precedence, but it still keeps all timeout sources clamped to the existing 600s MAX_TIMEOUT_SECONDS. It is also currently not mergeable against main, so it does not appear to directly resolve the trusted-app-vs-LLM cap distinction raised here.

    One additional edge case I noticed on current main: asPositiveOrZeroInt() calls Number.intValue() before the value is bounded. For sufficiently large positive numeric inputs, narrowing can overflow before the timeout clamp is applied. If we introduce a separate application-side cap, I think the value should be safely range-normalized before narrowing/clamping as part of the same focused change.

    Would you prefer #3166 to proceed as a small standalone fix on current main with a separate trusted application cap, or should it be based on / coordinated with #2749’s timeout-resolution changes?

  5. oss-maintainer commented on Sep 17, 2026

    @oss-maintainer
    Collaborator

    Follow-up evaluation — volunteer question answered

    @philo-x thanks for the careful read. Your asPositiveOrZeroInt() observation was checked against main (be7211d19) and it is a real defect, with one correction to the consequence.

    Confirmed — AgentSpawnTool.java:1556-1568 narrows before bounding: the Number branch is return n.intValue(); (:1558) with no range check, while the String branch is already safe because Integer.parseInt throws and the catch returns null (:1562-1565). So 1e10 → 1,410,065,408 and Long.MAX_VALUE → -1.

    Correction — no bogus negative deadline can escape. resolveEffectiveTimeoutMs evaluates override <= 0 → default at :1536 before the Math.min(seconds, MAX_TIMEOUT_SECONDS) clamp at :1537, so -1 falls back to the 30 s default rather than becoming a negative timeout. That is also why 1e10 lands on 600 s — correct, but by luck.

    What actually breaks is the wrap-small class: any Number whose low 32 bits fall in 1..600 while its true value is larger — e.g. Double 4_294_967_496.0 (2^32 + 100) → 100 — gets a silently shortened 100 s deadline, contradicting the documented "values above 600 are clamped" contract at :191-193. Same class of silent downgrade for a negative residue.

    Containment supports folding it into the same change: asPositiveOrZeroInt has exactly one call site — :1552 in forceSyncTimeoutSeconds (:1548-1553), reached only from :1534. The LLM-facing timeout_seconds argument is Integer-typed (:325, :585), and WaitAsyncResultsTool (:55, :443-457) and TaskTool:105 clamp on their own. Hardening the helper therefore changes nothing outside the force-sync override path: widen before narrowing (n.longValue() against [0, Integer.MAX_VALUE], return null out of range, mirroring the String branch) and the override path provably yields 1–600 s with no behaviour change for in-range inputs. Tests worth adding next to AgentSpawnToolForceSyncTest.java:117-126: 1e10, Long.MAX_VALUE, 2^32 + 100.

    On your question — standalone is the better call, and here is the state that makes it so: #2749 is still OPEN, mergeable=CONFLICTING (mergeStateStatus=DIRTY), REVIEW_REQUIRED, head 9682918f0f, last updated 2026-09-17. It adds operator-controlled precedence but keeps Math.min(operatorSeconds, MAX_TIMEOUT_SECONDS), and its declaration-timeout test asserts the 600 s clamp explicitly — so it does not answer the trusted-app-vs-LLM distinction in this issue. Basing a small fix on an unmergeable branch would only add rebase risk. Two coordination notes: (1) #2749 edits the same two files (AgentSpawnTool.java, SubagentDeclaration.java), so please call out the overlap in your PR description rather than resolve it up front; (2) keep the LLM-facing 600 s clamp untouched so the model still cannot request an arbitrarily long wait.

    We are not opening a PR for #3166 — you have offered to own this change, so the implementation is yours. The remaining decision that is not ours to make is whether the app-side ceiling stays a constant or becomes per-harness/per-agent configuration (the original evaluation raised this); if you go with the constant, that is the smallest reviewable step and can evolve later without breaking the RuntimeContext contract.


    Automated evaluation by github-manager-bot

  6. JesseJI commented on Sep 18, 2026

    @JesseJI
    Author

    Thanks for checking this and for catching the numeric overflow issue.

    I would prefer #3166 to proceed as a small standalone fix against the current main branch rather than depend on #2749. The intended behavior is:

    1. Keep the LLM-controlled agent_spawn.timeout_seconds capped at 600 seconds.
    2. Allow the trusted application-side CTX_FORCE_SYNC_TIMEOUT_SECONDS to exceed 600 seconds under a separate application-controlled cap that can be configured or increased as needed.
    3. Preserve the existing default behavior when no application override is supplied.
    4. Safely normalize Number values before narrowing/clamping so large positive values cannot overflow through intValue().

    The key acceptance criterion is not a specific value such as 86400 seconds. It is that an embedding application can configure a bounded maximum greater than 600 seconds, and a trusted CTX_FORCE_SYNC_TIMEOUT_SECONDS value within that configured policy is honored instead of being clamped to the LLM-facing 600-second limit. A fixed 3600-second application cap alone would not fully address this requirement because applications may need to raise the bound further.

    A focused PR implementing this distinction would address the issue well.

  7. oss-maintainer commented on Sep 19, 2026

    @oss-maintainer
    Collaborator

    Follow-up evaluation — acceptance criterion accepted, my earlier 3600 s constant is superseded

    @JesseJI thanks for stating the acceptance criterion precisely — that correction matters, and it changes the recommendation in my initial evaluation. Confirmed as the requirement:

    1. LLM-facing agent_spawn.timeout_seconds stays capped at 600 s (AgentSpawnTool.java:110, applied at resolveTimeoutMs :1505) — the model must not be able to ask for an arbitrarily long synchronous wait;
    2. the trusted CTX_FORCE_SYNC_TIMEOUT_SECONDS override is bounded by a separate, application-configurable ceiling, not a hard-coded one;
    3. no override ⇒ today's default behaviour is preserved bit-for-bit;
    4. Number values are range-normalized before narrowing, so a large positive value cannot wrap through intValue() (asPositiveOrZeroInt :1556-1568, n.intValue() at :1558).

    Where I was off: item 2 of my initial proposal (APP_MAX_FORCE_SYNC_TIMEOUT_SECONDS = 3600 as a constant) does not satisfy this issue, and you are right that a fixed 3600 s ceiling would only move the wall. I also framed "constant vs configurable" as an open design question for maintainers — your wording resolves it in favour of configurable, so treat the constant version as withdrawn rather than as the interim step.

    What "configurable" should mean here, concretely (so an implementer does not have to guess): the ceiling must be readable without recompiling, per embedding application, at the same layer the override is already injected. The natural shape given the existing code is a value carried in the same RuntimeContext as CTX_FORCE_SYNC_TIMEOUT_SECONDS (a CTX_MAX_FORCE_SYNC_TIMEOUT_SECONDS-style key) with a documented default when absent, resolved in resolveEffectiveTimeoutMs (:1531-1544) — i.e. policy lives next to the value it bounds rather than in a constant. Two properties worth keeping from the original analysis: the clamp must become observable (log when a requested value is reduced, mirroring WaitAsyncResultsTool.java:448-450, otherwise a mis-set ceiling fails silently exactly as the 600 s clamp does today), and the LLM-facing cap and the app-facing ceiling must stay two distinct code paths so a future change to one cannot quiet the other.

    Ownership unchanged: this remains @philo-x's to implement — no bot PR will be opened for #3166, and no PR referencing this issue is open as of this scan. @philo-x: the two-question coordination note from my previous comment still stands (call out the #2749 file overlap in the PR description; keep the 600 s LLM clamp untouched), with the ceiling now configurable per the above. AgentSpawnToolForceSyncTest is the right place for the boundary cases; with a configurable ceiling the set becomes {no override, override ≤ ceiling, override > ceiling, ceiling itself unset/mis-configured} plus the 2^32 + 100 overflow case, rather than the fixed 3600/3601 pair I listed.


    Automated evaluation by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions