Skip to content

feat(durable): resume queued model calls across runtimes and worker attempts - #4218

Merged
chickenlj merged 11 commits into
mainfrom
feat/durable-async-model
Nov 24, 2026
Merged

chickenlj merged 11 commits into
mainfrom
feat/durable-async-model

Conversation

@juruoO-o

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

A durable ReAct or Harness Turn can dispatch a reasoning request to a model queue, release its Runtime invocation, and resume on another Runtime from a complete response or ordered streaming replies.

Workers begin each generation with a unique delivery ID. The backend assigns a transactional epoch, fences superseded replies, and seals the winning generation before tool dispatch. A replacement generation continues the original Turn and replaces partial text through a new message revision. Superseded, sealed and terminal replies return an ignored receipt that consumers can acknowledge.

This change also adds persistent idle deadlines, bounded recovery for uncertain publication and transient provider failures, standard model request observation events, backend wakeup subscriptions with polling repair, and core codec deserialization for tool schemas and generation options. EN/ZH documentation describes the worker protocol and failure semantics. The JEV benchmark fixture now uses isolated state after repeated repository verification exposed state leaking between runs.

Validation

  • All 114 reactor modules passed mvn -B -ntp -T1C -fae verify -DexcludedGroups=e2e -Dmaven.javadoc.skip=true.
  • Affected-module Javadoc generation passed separately. Earlier full clean verify also exercised repository-wide Javadoc generation.
  • Queued model recovery tests passed 21/21, including independent-JVM crashes and cross-Runtime recovery. Model reply protocol regressions passed 2/2.
  • Docker PostgreSQL/RocketMQ acceptance covered streaming and complete replies, Brain and ModelWorker crashes, redelivery, malformed/missing/duplicate/reordered frames, cancellation, fallback, 12 concurrent Turns, slow streams, lost publication acknowledgements, steering and live deltas.
  • Enhanced worker takeover and redelivery tests observed one tool side effect each. Injected stale frames were ignored. Live replacement retained the message ID and replaced revision 0 partial text with revision 1 output.
  • HTTP Mock provider tests recovered from 429 and 503 using the persisted retry budget. HTTP 400 failed after one provider call.
  • In isolated 12-collector PostgreSQL samples, incremental SELECT traffic decreased from 712.5/s with the intermediate 400 ms polling implementation to 312.9/s with wakeups and one-second polling repair, approximately 56%.
  • Documentation tests passed 20/20, with validation and broken-link checks passing.

External provider e2e tests were excluded. Docker provider behavior was verified using a local HTTP Mock. Early broker memory failures were corrected in the test environment, followed by reruns of the affected acceptance scenarios.

Recovery boundaries

Lost publication acknowledgements can still cause another provider call and additional billing. If a Runtime dies after an external tool effect occurs but before its result is persisted, recovery retains WAITING with explicit reconciliation required. The crash regression observes one external receipt and disables automatic repetition.

Checklist

  • Code has been formatted with mvn spotless:apply
  • Local repository tests pass with external provider e2e tests excluded
  • Affected-module Javadoc generation passes
  • Related English and Chinese documentation has been updated
  • Code is ready for review

Copilot AI balanced review requested due to automatic review settings November 17, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chickenlj
chickenlj merged commit a067f5c into main Nov 24, 2026
9 checks passed
xzxiaoshan added a commit to xzxiaoshan/agentscope-java that referenced this pull request Nov 24, 2026
Merge main (a067f5c, 1 commit) into the final-answer-gate branch and resolve:

- ReActAgent.runPostReasoningPipeline (content conflict): main's agentscope-ai#4218 replaces
  reasoningCompleted(iter) with reasoningApplied(iter, answer) — once a round's
  result is in memory, a resumed (handed-off) model call is checkpointed with
  "model_result_applied" and its terminal answer preserved for re-entry — while
  this branch lands a terminal candidate only after the gate verdict. Keep
  main's deferred per-branch bookkeeping without its unconditional memory
  write, and drop this branch's eager reasoningCompleted(iter): it ran before
  the terminal branch and cleared the pending call, which would have silently
  disabled both of main's new effects for every agent.
- FinalAnswerGateEngine: the loop's terminal exit now hands its bookkeeping to
  the gate (new overload taking this::reasoningApplied), which reports each
  round once its outcome is in memory — the landed (certified) message after
  the memory write and before the projection on accept; nothing on a veto,
  before the retry re-entry. Reporting the pre-verdict candidate preserved a
  draft the gate had replaced or rejected as the call's answer; skipping the
  veto report left the retry round rejected with "Cannot call the model while
  waiting for <call>"; reporting after gate() returned re-applied a stale
  iteration. The plain three-argument gate(...) lost its only caller and is
  folded into the transform form.
- New ReActAgentFinalAnswerGateHandoffTest (5 cases) over a handed-off model
  call: the replacement is what lands and ships on resume; a run lost after
  landing re-enters with the preserved certified answer, without a model call
  or another consultation; a veto releases the call for the retry round (plain
  and native structured-output exits); a rejected draft is never the preserved
  answer. The last four cases were checked to fail under the wrong resolutions
  above; the first pins the happy path.

Known gap, not addressed here: the per-call retry fuse does not bound a Turn
whose gate retries run over handed-off model calls. Every resume is a new call
with retryCount 0, so a gate that keeps vetoing re-dispatches the model without
limit instead of failing closed after 10 retries. Settling the budget per Turn
needs a durable design decision.

Verified: mvn -T1C clean test-compile over the whole reactor (114 modules,
spotless:check clean); core and harness full suites (3586 and 1918 tests, 0
failures, 0 errors), including ReActAgentFinalAnswerGateHandoffTest (5),
ReActAgentFinalAnswerGateTest (58) and main's ReActAgentFailoverBoundaryTest
(11).

Not introduced here — the failing set of the durable adapter closure is a
subset of pure main's, reproduced on a067f5c (exported with git archive) on
this Windows machine: the durable adapter module (AgentScopeAdapterTest 4 of
49, ModelWorkerTest 3, ProcessRecoveryTest 2,
HarnessExternalToolProcessRecoveryTest 1) and the sandbox module (13).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants