Repository navigation
Conversation
ningmao-hlyz
left a comment
There was a problem hiding this comment.
[P1] The new cancellation test does not exercise the change. Instrumenting settle shows uncertain=[] for the CANCELLED case in cancelReconcilesDispatchedNativeCallSoSettlementCanCommit, so !lost.isEmpty() never fires; deleting the whole if (status == TurnStatus.CANCELLED) block leaves the test green (1/1 pass). The blocking tool writes its result before the turn settles. To cover the fix the dispatch has to still be unresolved at settle time, and the assertion should read the journal (uncertainToolCalls empty after settle), not just the next turn succeeding. The FAILED case in the other new test does produce uncertain=[call-1], so the shape is reachable.
[P2] lost is read outside ThreadRecovery.reconcile, which re-reads the projection under its own lease and requires an exact key-set match. A late tool/result landing between the two reads turns settle into IllegalArgumentException("Supply exactly the unresolved tool outcomes") — the same dead end this PR removes. Reading inside one acquire, or retrying once on mismatch, would close it.
[P2] names.getOrDefault(id, "tool") invents a name when tool/requested is missing from the scan window; replay paths that match on the tool name would see a tool that never existed.
|
@ningmao-hlyz [P1] The new cancellation test is vacuous — confirmed
ticking.start();
assertTrue(entered.await(...));
backend.cancel(thread, turnId, "ui-cancel");
release.countDown(); // <- the blocking tool immediately returns
ticking.join(...);
Your note that the FAILED test does produce
[P2] Race on
|
|
Split the two statuses. The difference is what the runtime already knows, not what On main: Two things to change before rebasing:
Suggested shape: keep one write path. Extract the body of Tests: your reading of Scope: leave |
AgentScope-Java Version
2.1.0-SNAPSHOT(main @ea2aed13221c9b6fcbd44ba0f2c359d7dbfd4786)Description
Closes #4393 .
Background
A Durable Turn that is cancelled while an in-process (non-executor) tool is running can never
settle. Cancelling sets
turn.cancel = trueand moves the Turn toCANCELLING, but theinvocation is torn down before the tool reports a result, so the native Thread journal keeps a
tool/dispatchwith no matchingaction/end.JournalProjectiontherefore reports a non-emptyuncertainToolCalls, and every subsequentclaim re-enters
AgentScopeAdapter.settleand throws:reconciledis derived only fromframe.tools(), i.e. executor-backed (Hands) calls. Anin-process call never appears there, so this gate cannot open by any automatic means. The Turn
stays
CANCELLINGforever, the Thread's head never becomes terminal, and every later Turn onthat Thread stays QUEUED. The only remediation today is stopping the host and running
ThreadRecovery.reconcileoffline.Note that the same method already synthesizes
INTERRUPTEDresults for pendinginteractions a few lines below, so the two categories were handled inconsistently.
Root cause of the missing
action/endNot changed by this PR, but relevant to the fix:
DurableRuntimecancels by settingstoppedand then interrupting the worker thread.HarnessContext.check()rejects any durable write whilestoppedis set, so theMono.usingWhencancel handler inActionObservations(which recordsaction/end(INTERRUPTED)) is fenced before it can commit.agent.stream(...).blockLast(), so a thread interrupt disposes thesubscription instead of emitting an error signal.
AgentBase.createErrorHandlerneverroutes it to
handleInterrupt, sosynthesizeErrorResultsForPendingToolCalls()never runs.tool/resultwould not clear the gate:JournalProjectiononly removesids on
action/endand onrecovery/applied.resolvedToolCallIds.Changes
AgentScopeAdapter:settle, whenstatus == CANCELLED, reconcile the uncertain native calls through thepublic
ThreadRecovery.reconcileAPI withINTERRUPTEDoutcomes, then re-read the projectionbefore the existing gate. When nothing is uncertain the call is skipped, so an ordinary
cancellation is unaffected.
interrupted(ThreadJournal, Set<String>)helper. It resolves tool names fromthe
tool/requestedevents and buildsToolResultBlocks withToolResultState.INTERRUPTED. The model-visible text states that the call was interrupted bythe user, that its side effect is unknown, and that it will not be retried.
FAILEDis deliberately unchanged and still requires operator reconciliation.AgentScopeAdapterTest:cancelReconcilesDispatchedNativeCallSoSettlementCanCommit— a native tool dispatches and thenblocks; the Turn is cancelled mid-flight; after settlement the Turn is
CANCELLEDwith norecorded runtime failure, and the Thread accepts a subsequent Turn.
failedSettlementStillRequiresReconciliationForLostNativeCalls— the same shape underFAILEDstill throws
Native tool outcome requires reconciliation, pinning the retained manual gate.Why this is not "guessing an outcome"
HarnessAdapter.settlealready documents the required behaviour:A user cancellation is a fact: the call was abandoned. Recording it as
INTERRUPTEDdoes notclaim success, does not invent an output, and does not authorize re-execution — which is exactly
what
ThreadRecoveryexists to prevent. The repair is written through the same public API anoperator would use, so the journal shape (
tool/result(reconciled),recovery/applied,state/checkpoint) is unchanged.FAILEDstays manual on purpose: after a crash or exhausted retries the Turn may be replayed andthe model may re-issue the same call, so a human must decide whether the lost side effect
happened.
Scope / risk
CANCELLEDbranch changes;FAILEDbehaviour and both existing gates are untouched.ThreadRecoveryand the existingBackendThreadJournal, sofencing, sequencing and receipt semantics are preserved.
cooperative interrupt, and back off a cancelled Turn instead of re-claiming every ~100 ms.
How to test
mvn spotless:apply mvn -pl agentscope-durable/durable-adapters/durable-adapter-harness-agentscope -am testTargeted:
mvn -pl agentscope-durable/durable-adapters/durable-adapter-harness-agentscope \ test -Dtest='AgentScopeAdapterTest#cancelReconcilesDispatchedNativeCallSoSettlementCanCommit+failedSettlementStillRequiresReconciliationForLostNativeCalls'Checklist
mvn spotless:applymvn test)