Skip to content
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7d8a36d
Fence direct executor progress after Brain ownership changes
juruoO-o Nov 16, 2026
0d8cf9f
Bound consecutive losses of unfinished native runs
juruoO-o Nov 16, 2026
ac346d6
Reconcile uncertain native tool outcomes under a fenced operator lease
juruoO-o Nov 16, 2026
f6f0f2c
Resume long threads from settled native state snapshots
juruoO-o Nov 16, 2026
ab84869
Include the worker runtime in packaged distributed echo applications
juruoO-o Nov 16, 2026
d486ec1
Scan PostgreSQL durable record keys independently of database collation
juruoO-o Nov 16, 2026
8f7e89b
Bound PostgreSQL idle record transactions after owner disconnects
juruoO-o Nov 16, 2026
cb64b6c
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Nov 16, 2026
1c8421c
Exercise expired Hands ownership across independent consumers
juruoO-o Nov 16, 2026
48cc2aa
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Nov 16, 2026
c5cc1ed
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Nov 16, 2026
d859fc1
Reuse model provider idempotency keys across Brain takeover
juruoO-o Nov 16, 2026
72947a5
Fence late invocation commits after cancellation is accepted
juruoO-o Nov 16, 2026
2dc1143
Advance native recovery cursor on terminal settlement
juruoO-o Nov 16, 2026
b46d6ab
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Nov 16, 2026
af091cd
Reconcile delayed live previews across subscription snapshot resets
juruoO-o Nov 16, 2026
be1a94e
Scope durable live previews to the subscribed session
juruoO-o Nov 16, 2026
b40de32
Bound subscriber preview work and check committed projections by iden…
juruoO-o Nov 16, 2026
071e700
Read preview projections without rewriting session state
juruoO-o Nov 16, 2026
cbff92d
Bound preview payloads and query versioned identities across HTTP
juruoO-o Nov 16, 2026
ca8fb3c
Exercise bounded subscribers and crash recovery against Docker Postgr…
juruoO-o Nov 16, 2026
e3d1f2e
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Nov 16, 2026
f8f3e30
Reject truncated OpenAI streams without a terminal signal
juruoO-o Nov 16, 2026
6b7e717
Park uncertain native turns, honor recovery budgets and share journal…
juruoO-o Nov 16, 2026
a1b6317
Cover missing and uncertain lookups after a running tool is reclaimed
juruoO-o Nov 16, 2026
f3fe6ef
Avoid repeat database transactions for recently verified immutable ch…
juruoO-o Nov 16, 2026
7f24002
Share growing journal indexes at immutable descriptor boundaries
juruoO-o Nov 16, 2026
fa8845a
Exercise paired RocketMQ consumers and attribute shared journal storage
juruoO-o Nov 16, 2026
dcb774f
Bound database prefix scans with matching binary-order indexes
juruoO-o Nov 16, 2026
7cf9c44
Verify RocketMQ direct-memory limits and resume publication from rece…
juruoO-o Nov 16, 2026
6e8f755
Bound uncertain Hands recovery and retain acknowledged provider handles
juruoO-o Nov 16, 2026
f3c40d1
Cache error responses by provider key in the Docker model fixture
juruoO-o Nov 16, 2026
c2e59a9
Compress immutable record chunks and attribute journal writes by even…
juruoO-o Nov 16, 2026
a22f5da
Publish immutable objects with a write-through move on Windows
juruoO-o Nov 17, 2026
72116f2
Freeze native replay policy at dispatch and settle uncertain calls wi…
juruoO-o Nov 17, 2026
33bf983
Use a published RocketMQ image for the Docker regression
juruoO-o Nov 17, 2026
f8219b6
Merge main and preserve returnDirect when reconciling interrupted nat…
juruoO-o Nov 25, 2026
4e7c08a
Merge upstream/main into durable recovery
juruoO-o Nov 30, 2026
ea18a42
Merge remote-tracking branch 'upstream/main' into fix/durable-recovery
juruoO-o Dec 1, 2026
8044606
Resume committed native tool and model answers after Brain loss
juruoO-o Dec 1, 2026
3bf005d
Limit model continuation to recovery-aware hosts
juruoO-o Dec 1, 2026
91ccf70
Isolate RocketMQ redelivery from model connection loss
juruoO-o Dec 1, 2026
5c5ecf8
Preserve durable recovery on the per-Thread runtime
juruoO-o Dec 1, 2026
e33a158
Keep JDBC lease timeout independent of snapshot setup
juruoO-o Dec 1, 2026
20ebf2d
Keep the recovery and subscriber pull requests independently mergeable
juruoO-o Dec 1, 2026
0b0a10a
Gate failed Turn recovery only after the PostgreSQL commit
juruoO-o Dec 1, 2026
ed6b69e
Make the DashScope async response check reliable in CI
juruoO-o Dec 1, 2026
d9e5d6e
Merge branch 'main' into fix/durable-recovery
juruoO-o Dec 2, 2026
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
32 changes: 6 additions & 26 deletions agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ private List<Map.Entry<ToolUseBlock, ToolResultBlock>> pairProvidedToolResults(
* Build placeholder-shaped copies of the caller-supplied messages for a returnDirect
* short-circuit: every {@link ToolResultBlock}'s output is replaced with the
* returnDirect placeholder sentence (id/name preserved, state normalized via {@link
* #determineToolResultState(ToolResultBlock)} like the in-framework path) while
* ToolResultBlock#completedState()} like the in-framework path) while
* non-tool-result content passes through unchanged. New {@link Msg}s are built — the
* caller's objects are never mutated — keeping the context invariant {@code [tool_use,
* tool_result(placeholder), assistant(full result)]}.
Expand All @@ -3155,7 +3155,7 @@ private ContentBlock placeholderToolResultContent(ContentBlock block) {
return block;
}
return placeholderResultBlock(
result.getId(), result.getName(), determineToolResultState(result));
result.getId(), result.getName(), result.completedState());
}

/**
Expand Down Expand Up @@ -3768,8 +3768,7 @@ private List<AgentEvent> serverToolResultEvents(ToolResultBlock result, String r
}

events.add(
new ToolResultEndEvent(
replyId, toolId, toolName, determineToolResultState(result))
new ToolResultEndEvent(replyId, toolId, toolName, result.completedState())
.withMetadata(eventMetadata));

return events;
Expand Down Expand Up @@ -4689,7 +4688,7 @@ public void onResult(ToolUseBlock call, ToolResultBlock result) {
replyId,
call.getId(),
call.getName(),
determineToolResultState(result))
result.completedState())
.withMetadata(metadata));
}

Expand All @@ -4699,25 +4698,6 @@ private ToolResultBlock resolvedResult(ToolUseBlock call) {
}
}

private ToolResultState determineToolResultState(ToolResultBlock result) {
if (result.isSuspended()) {
return ToolResultState.SUSPENDED;
}
if (result.getState() != null && result.getState() != ToolResultState.RUNNING) {
return result.getState();
}
if (result.getOutput() != null
&& result.getOutput().stream()
.anyMatch(
b ->
b instanceof TextBlock tb
&& tb.getText() != null
&& tb.getText().startsWith("[ERROR]"))) {
return ToolResultState.ERROR;
}
return ToolResultState.SUCCESS;
}

/**
* Build a message containing suspended tool calls for user execution.
*
Expand Down Expand Up @@ -4967,7 +4947,7 @@ private Mono<PostActingEvent> notifyPostActingHook(
// adding to contextMutable(), so that history queries via
// agent.getAgentState(ctx).contextMutable() reflect the correct
// final state instead of always showing RUNNING.
ToolResultState finalState = determineToolResultState(result);
ToolResultState finalState = result.completedState();
ToolResultBlock updatedResult = result.withState(finalState);

Msg toolMsg =
Expand Down Expand Up @@ -5032,7 +5012,7 @@ private boolean isReturnDirectToolCall(Map.Entry<ToolUseBlock, ToolResultBlock>
if (tool == null || !tool.isReturnDirect()) {
return false;
}
return determineToolResultState(entry.getValue()) == ToolResultState.SUCCESS;
return entry.getValue().completedState() == ToolResultState.SUCCESS;
}

/** Builds the placeholder tool_result, replacing only the output while keeping id/name/state. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public InvocationRecorder(
executionPosition = initial.executionPosition();
previousPosition = executionPosition;
}
if (previousState != null) previousMessages = messageJson(initial.restore());
if (previousState != null) {
var restored = initial.restore();
previousMessages = messageJson(restored);
if (log.recoveryCursor() > 0)
restored.getContext().forEach(message -> recordedMessages.add(message.getId()));
}
} catch (RuntimeException e) {
log.release(writer);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static JournalProjection read(ThreadJournal log, Consumer<JournalEvent> o
var verifications = new ArrayList<io.agentscope.core.state.TaskVerification>();
var extensions = new ArrayList<JournalEvent>();
long upper = log.head().seq();
for (var event : log.scanMetadata(0, upper)) {
for (var event : log.scanMetadata(log.recoveryCursor(), upper)) {
JournalEventTypes.validate(event);
observer.accept(event);
var data = event.data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
/** Optional call-scoped host replay boundary. Invoking next preserves recording and model policy. */
@FunctionalInterface
public interface ModelInvocation {
/** Transport options for this recorded dispatch. The journal retains the original input. */
default GenerateOptions providerOptions(String callId, GenerateOptions options) {
return options;
}

Flux<ChatResponse> stream(
String model,
String purpose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@ private Flux<ChatResponse> invoke(
context.getAgentState()))
.thenReturn(callId),
id ->
Flux.defer(() -> delegate.stream(messages, tools, options))
Flux.defer(
() -> {
var host =
context.get(
ModelInvocation.class);
return delegate.stream(
messages,
tools,
host == null
? options
: host.providerOptions(
id, options));
})
.doOnNext(
chunk -> {
last.set(chunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Map<String, JournalEvent> continuationRequests(
public static Map<String, JournalEvent> pending(ThreadJournal log) {
long upper = log.head().seq();
var result = new LinkedHashMap<String, JournalEvent>();
for (var event : log.scanMetadata(0, upper)) {
for (var event : log.scanMetadata(log.recoveryCursor(), upper)) {
if (event.type().equals("interaction/requested"))
result.put(String.valueOf(event.data().get("requestId")), event);
if (event.type().equals("interaction/resolved"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public JournalEvent next() {

Head head();

/** Cursor immediately before a settled state snapshot. Historical reads still start at zero. */
default long recoveryCursor() {
return 0;
}

Writer acquire(String owner, Duration lease);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@ private ThreadRecovery() {}

public static void reconcile(
ThreadJournal log, Map<String, ToolResultBlock> outcomes, String reason) {
reconcile(log, outcomes, reason, false);
}

/** Persist one independently verified outcome while other dispatches may still need evidence. */
public static void reconcileOne(ThreadJournal log, ToolResultBlock outcome, String reason) {
reconcile(log, Map.of(outcome.getId(), outcome), reason, true);
}

private static void reconcile(
ThreadJournal log,
Map<String, ToolResultBlock> outcomes,
String reason,
boolean partial) {
if (reason == null || reason.isBlank())
throw new IllegalArgumentException("A reconciliation reason is required");
var writer = log.acquire(UUID.randomUUID().toString(), Duration.ofMinutes(2));
try {
var projection = JournalProjection.read(log);
if (!projection.uncertainToolCalls().equals(outcomes.keySet()))
boolean complete = projection.uncertainToolCalls().equals(outcomes.keySet());
if (!complete
&& !(partial && projection.uncertainToolCalls().containsAll(outcomes.keySet())))
throw new IllegalArgumentException("Supply exactly the unresolved tool outcomes");
var state = projection.restore();
if (state == null) throw new JournalException("No recoverable state baseline");
Expand Down Expand Up @@ -91,7 +106,9 @@ public static void reconcile(
"outcomes",
outcomes,
"interruptedRuns",
projection.activeRuns())));
complete
? projection.activeRuns()
: java.util.List.of())));
var checkpointData = new LinkedHashMap<String, Object>();
checkpointData.put("stateJson", state.toJson());
checkpointData.put("projectorVersion", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ public ToolResultState getState() {
return state;
}

/** Resolve the final state of a returned local tool invocation, including plain text results. */
public ToolResultState completedState() {
if (isSuspended()) {
return ToolResultState.SUSPENDED;
}
if (getState() != null && getState() != ToolResultState.RUNNING) {
return getState();
}
if (getOutput() != null
&& getOutput().stream()
.anyMatch(
b ->
b instanceof TextBlock tb
&& tb.getText() != null
&& tb.getText().startsWith("[ERROR]"))) {
return ToolResultState.ERROR;
}
return ToolResultState.SUCCESS;
}

/**
* Returns a copy of this block with the given state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ public class HttpRequest {
private final String method;
private final Map<String, String> headers;
private final String body;
private final boolean includeSseDone;

private HttpRequest(Builder builder) {
this.url = builder.url;
this.method = builder.method;
this.headers = Collections.unmodifiableMap(new HashMap<>(builder.headers));
this.body = builder.body;
this.includeSseDone = builder.includeSseDone;
}

public boolean includeSseDone() {
return includeSseDone;
}

/**
Expand Down Expand Up @@ -92,6 +98,13 @@ public static class Builder {
private String method = "GET";
private final Map<String, String> headers = new HashMap<>();
private String body;
private boolean includeSseDone;

/** Deliver the terminal SSE marker to protocols that validate stream completion. */
public Builder includeSseDone(boolean value) {
includeSseDone = value;
return this;
}

/**
* Set the request URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ private Flux<String> processStreamResponse(InputStream inputStream, HttpRequest
new BufferedReader(
new InputStreamReader(
inputStream, StandardCharsets.UTF_8));
return isNdjson ? readNdJsonLines(reader) : readSseLines(reader);
return isNdjson
? readNdJsonLines(reader)
: readSseLines(reader, request.includeSseDone());
})
// reader.lines() uses blocking I/O internally
.subscribeOn(streamScheduler);
Expand All @@ -353,11 +355,12 @@ private Flux<String> processStreamResponse(InputStream inputStream, HttpRequest
/**
* Extract non-empty SSE data payloads and stop before the terminal marker.
*/
private Flux<String> readSseLines(BufferedReader reader) {
private Flux<String> readSseLines(BufferedReader reader, boolean includeDone) {
return Flux.fromStream(reader.lines())
.filter(line -> line.startsWith(SSE_DATA_PREFIX))
.map(line -> line.substring(SSE_DATA_PREFIX.length()).trim())
.takeWhile(data -> !SSE_DONE_MARKER.equals(data))
.takeUntil(SSE_DONE_MARKER::equals)
.filter(data -> includeDone || !SSE_DONE_MARKER.equals(data))
.doOnNext(data -> log.debug("Received SSE data chunk"))
.filter(data -> !data.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ public Flux<String> stream(HttpRequest request) {
SSE_DATA_PREFIX
.length())
.trim())
.takeWhile(
.takeUntil(SSE_DONE_MARKER::equals)
.filter(
data ->
!SSE_DONE_MARKER.equals(
data))
request.includeSseDone()
|| !SSE_DONE_MARKER
.equals(
data))
.filter(data -> !data.isEmpty());
},
this::closeQuietly)
Expand Down
Loading
Loading