Repository navigation
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
chcodex
marked this pull request as draft
November 7, 2026 06:03
chcodex
force-pushed
the
feat/agui-live-handoff
branch
from
November 7, 2026 14:27
d5a7bff to
c72c6f6
Compare
chcodex
force-pushed
the
feat/agui-live-handoff
branch
2 times, most recently
from
November 8, 2026 07:15
0c4f2db to
a9052c5
Compare
chcodex
added a commit
to chcodex/agentscope-java
that referenced
this pull request
Nov 8, 2026
JournalSessionLog.scan unconditionally called loadCommitSegments(), so every incremental read (after > 0, e.g. the AG-UI connect poll every 200ms) listed and read every commit segment in the journal even though only the head -> after suffix is needed. Bulk pre-read is now limited to a full replay (after == 0); incremental reads fall back to per-segment reads via committedSegment(id, null). The commit walk and event filtering are unchanged. Tests: add a counting AtomicSessionStorage and assert incremental scans never call listPaths/readAll, full replays still do, and both paths return the same event sequence.
Bridge attach from the session log to a process-local live tail, with a bounded recent-frame buffer, source-sequence deduplication and a log-polling fallback. Propagate session sequence metadata through the core model and tool boundaries, keep forwarded subagent frames uncursored, and document the handoff contract.
AguiRequestProcessor now invokes runFramed, so the test adapter must override the framed entry point to keep exercising controller cancellation and completion paths.
Recovery previously replayed the whole EVENT_LOG journal, costing one remote read per commit segment (about 35s on a 445-segment session). Maintain an O(1) anchors.json next to the journal head with the latest checkpoint and run/start sequences. Anchors update only after the commit and head are durable, only increase, and are rebuilt from the committed chain when missing or corrupt. Start projection at the earlier of the two anchors so stateJson, activeRuns, and uncertainToolCalls match a full replay. Transcript now merges checkpoint state without dropping history, and the export cursor advances in batches of 200 events with at-least-once replay. Refs agentscope-ai#3987
chcodex
force-pushed
the
feat/agui-live-handoff
branch
from
November 10, 2026 03:00
0d774f1 to
e490fdc
Compare
chcodex
force-pushed
the
feat/agui-live-handoff
branch
from
November 10, 2026 03:17
e490fdc to
a386210
Compare
pollOnce read the log with readAfter(cursor, 256). Every call walks the commit chain from the head down to the cursor, so a full replay (afterSequence=0) paid that walk once per 256 events: quadratic in the number of commit segments and visibly stalled for seconds between batches. Read the whole committed delta of a poll with a single scan(cursor, through) instead, bounded by REPLAY_CHUNK so a very long session still yields between polls. Measured on a 5,704-frame replay: 72.8s -> 6.0s.
…delta A poll now scans from the cursor to the current head in one pass and forwards each projected frame to the sink as it is produced. The first frame no longer waits for the whole delta, and cancellation is checked per event. The cursor advances per event, so a projection failure stops at the last frame the client already received (attachKeepsCursorWhenEventProjectionFails expects 1 instead of 0).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Depends on #4026 and #3988; both are contained in this branch. The branch is also prepared on top of #4085 and #4068, which merge first. Until those four land, this PR also contains their commits; the #4039-specific changes start at
feat(agui): hand off active runs to live frames.This PR also aligns replay and live delivery on one message identity: text uses the SessionLog turn id, reasoning uses
turnId:reasoning, and tool-bound interrupt ids useturnId:toolCallId.This PR adds process-local live handoff on top of the session-log replay path: attach first bridges from the caller's cursor to the broadcaster's recent frames, then continues with the live tail, without a gap or a duplicate frame for recent cursors.
Older cursors still replay the session log up to the oldest buffered event and then continue from the buffer and tail. If no live tail is available, attach falls back to the existing log polling path.
What changed
Live handoff
AguiRunBroadcaster, a process-local broadcaster keyed byuserId + agentId + threadId.AguiAgentAdapter.runFramed/framesForexpose every AG-UI frame together with its source sequence and optional replay cursor.AguiRequestProcessorpublishes complete source events and keepsRUN_STARTEDlog-replayed.AguiSessionLogAttachnow bridges[log up to oldest buffered - 1] + [recent frames] + [live tail], then drains the remaining committed log.Recovery anchors
AguiSessionLogAttach.runStartedPrefixreadsSessionLog.lastRunStartSeq()first, whichJournalSessionLoganswers fromanchors.jsoninstead of walking back through commit segments. Stores whoselastRunStartSeq()returns0keep the previous per-segment scan as a fallback.Replay/live message identity
SessionEvent.turnId(); reasoning ids useturnId + ":reasoning"(from feat(agui): resume active runs from the session log #4026's presentation change).TextBlock/ThinkingBlockconversion resolves the same ids fromAgentEvent.execution.turnId(), with the previous per-block id only as a fallback for streams that carry no execution identity.AguiInterruptsnow scopes tool-bound interrupts by turn: replay takesSessionEvent.turnId(), live takesAgentEvent.execution.turnId(), and both produceturnId:toolCallId. The reply id remains in interrupt metadata; streams without a turn id keep the legacyreplyId:toolCallId/toolCallIdform.Replay performance
runAttach → startAttach → pollOncenow scans from the cursor to the current head in one pass (log.scan(cursor, head.seq())) instead ofreadAfter(cursor, 256)batches that re-walked the commit chain.sink.isCancelled().1instead of0.AguiSessionLogAttach.attachUntilstill replays the live catch-up/drain range with a single scan; uncommitted-boundary wait, timeout, cancellation and error-frame semantics are unchanged.after=0first frame 1.49s → 0.32s;after=1000total 1.65s;after=5000total 0.68s. The earlier 5,704-frame full replay went from 72.80s with 13+ stalls to 6.01s with one 1.67s stall.after=0segment location still depends on perf(core): locate journal segments by sequence and load them in bounded batches #4085 (fdbfb34fe): this PR does not cherry-pick the core change. Once perf(core): locate journal segments by sequence and load them in bounded batches #4085 lands, rebasing this branch obtains sequence-indexed segment loading instead of a bulk load.Flux.createuses the default BUFFER strategy, so a slow client can accumulate frames. This PR does not change the backpressure strategy.Core sequence propagation
SessionRecorder:SESSION_SEQ_KEY/SESSION_SOURCE_SEQ_KEY;lastAppendedSeq, type-checked boundary reads;recordMessage/recordAssistantMessagewithmessageId -> seq;SessionModelstags each model chunk with its session sequence.ReActAgent:model/end,run/end, tool result ends carry cursors;tool/requestedare recorded before tool results, keeping log order equal to conversation order;PostActinghooks may rewrite the result; the final result is recorded after the hook and is the only conversation-history record.ChatResponse.withMetadataEntry;ReasoningContextexcludes the internal seq key from persisted message metadata.Docs
English and Chinese AG-UI protocol docs updated for the live/recent-buffer handoff, cursor boundaries, and uncursored subagent frames.
Tests
agentscope-core: 3001 tests, 1 known pre-existing failure (SkillBoxTest$SkillBoxUploadSecurityGate), 9 skipped.agentscope-extensions-agui: 660 tests, all passing.agentscope-harness: 1619 tests, 0 failures, 12 skipped. The inbox scheduling regression test disables background memory hooks so unrelated flush/consolidation model calls cannot overwrite its last-request assertion.spotless:checkfor both modules passes.git diff --checkpasses.npm test,npm run validate,npm run broken-linkspass.JevSupervisionMiddlewareTest#humanAdviceDoesNotInterruptOrReplayTheWorkerwithexpected MANUAL_REVIEW but was CONTINUE. Six consecutive local reruns passed; the failure is a pre-existing timer race in that test (the adjacent synchronous-worker test documents the same scheduling race) and is unrelated to the AG-UI/session-log changes.New coverage includes:
Limitations
SessionLogStore; the recent buffer does not cross processes.PostActinghooks present, tool-result live frames intentionally do not advance the SSE id; reconnecting from the previous cursor replays the finalized result once.Merge order
JournalSessionLogonly, soAguiSessionLogAttachis not expected to conflict.TextBlockEventConverter+docs/.../agui.md×2; keepAgentEventIds.textMessageId).perf(agui): replay the session log in one pass,perf(agui): replay committed session-log delta in one scan, andperf(agui): stream session-log replay instead of buffering the whole delta.Commits
perf(core): anchor session recovery at latest checkpoint and run start,fix(agui): prefer recovery anchors when announcing RUN_STARTEDfeat(agui): resume active runs from the session log,fix(agui): emit RUN_STARTED first on session-log attach,fix(agui): use turnId for session-log replay message ids,docs(agui): document turn-scoped session-log message idsfeat(agui): hand off active runs to live frames,test(agui): adapt MVC controller fixture to framed runs,fix(agui): publish live frames and keep per-segment boundaries,fix(agui): use session turn ids for replay and live message identities,test(harness): isolate inbox scheduling test from memory hooks,perf(agui): replay the session log in one pass,perf(agui): replay committed session-log delta in one scan,perf(agui): stream session-log replay instead of buffering the whole delta,test(agui): align replay coverage with streaming one-scan polls