Skip to content

fix(ai): scope stream replay to the requested run - #7393

Merged
lizhimins merged 2 commits into
apache:masterfrom
zmuxuny:fix/ai-run-scoped-replay-oct20
Nov 27, 2026
Merged

lizhimins merged 2 commits into
apache:masterfrom
zmuxuny:fix/ai-run-scoped-replay-oct20

Conversation

@zmuxuny

@zmuxuny zmuxuny commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Fixes #7146. Replaces stale-closed #7147, preserving the replay contribution and its current-base merge. Both the old PR and issue were closed by the inactivity bot.

Brief Description

The run-stream endpoint queries conversation-wide event pages. Replaying every row can put other turns' answers and terminal statuses into the requested run, including reporting a reaped FAILED run as COMPLETED.

  • Start at the later of the caller's cursor and a positive stored startSeq - 1, so earlier runs do not consume the requested run's replay budget.
  • Advance the scan cursor across every row, but check runId before decoding, projection, terminal detection, or the live deduplication watermark.
  • Keep the null/zero startSeq fallback. Do not cap at endSeq, which can retain its admission-time value after a run is reaped.

The delta is limited to AiRunService.attach and its regression tests: two files, +208/-1. SQL, replay limits, observer registration, completion behavior, API shapes, dependencies, and build configuration are unchanged. This addresses content/status correctness within one owned conversation.

Tested head: 604a1125610ef98c2fc7cd94e2c6ec1e3bb85b73, based on rocketmq-studio@7abf8adaf660d75f2d686bbe8741be76c3a5ddd3. Admission and executor terminal/EOF changes are not included. Static patch compatibility with the separate admission replacement #7390 was checked; no combined-tree runtime validation is claimed.

How Did You Test This Change?

Fresh local verification on November 4, 2026, with Temurin 21.0.13+9 and Maven 3.9.9:

  • Exact candidate AiRunServiceTest: 43 passed, zero failures/errors/skips.
  • Base negative control: replaced only production AiRunService.java with the current base, retaining the new tests. The seven new methods ran as nine instances: 8 expected assertion failures and 1 passing control, zero errors/skips. The after=8 control already works on base because no later rows remain. Failures cover middle-run isolation, reaped FAILED status, active tailing, history budget, null/zero start metadata, cursor-at-end handling, and the later-run watermark.
  • Independent start-boundary mutation: removed only the positive startSeq lower bound while retaining run filtering. The budget regression failed because the requested answer was not reached.
  • Independent watermark mutation: moved only noteWatermark before the foreign-run filter while retaining the start boundary and projection filter. The between-pages regression failed because the requested buffered COMPLETED terminal was dropped. Each mutation produced one expected assertion failure, zero errors/skips.
  • Restored exact candidate source: 251 passed across all 16 direct conversation-package classes, zero failures/errors/skips, including 9 H2 persistence integration cases and 4 schema migration cases.
  • Related stream/projector/event contract selection: 423 passed across 9 classes, zero failures/errors/skips.
  • RAT and Checkstyle passed in the normal test lifecycle. Final source/test hashes, git diff --check, and the clean-tree check passed.

The history-budget fixture has exactly 5,000 earlier-run rows, followed by the requested text and terminal at 5001/5002. Null/zero legacy start metadata retains the existing total-row ceiling. Test selections overlap; their counts should not be added as unique tests.

From server/, each test invocation used these common options with the relevant selection:

mvn -o -B -ntp -s "$MAVEN_SETTINGS" \
  -Dmaven.repo.local="$MAVEN_REPO" -DforkCount=1 \
  "-DargLine=-Xmx512m -javaagent:$MAVEN_REPO/org/mockito/mockito-core/5.23.0/mockito-core-5.23.0.jar" \
  "-Dtest=$TEST_SELECTION" test

MAVEN_SETTINGS and MAVEN_REPO denote the existing local settings and cache. The final related selection was AiRunExecutorTest,AiRunServiceTest,AgentStreamSessionTest,AgentRunRegistryTest,AgentRunHandleStopTest,AgentEventProjectorTest,AiEventSeqAllocationTest,AiEventContractTest,AiEventJsonSerializationTest. The explicit Mockito startup agent avoids dynamic attachment; no project configuration, assertion, or timeout was changed.

Packaging limitation: the subsequent offline package -DskipTests attempt stopped during plugin resolution because org.apache.maven.plugins:maven-jar-plugin:3.5.0 was not cached. The package lifecycle did not execute. This attempt is not reported as a successful package build.

The service regressions exercise real replay/projector/session/registry logic with controlled repository fixtures. H2 persistence/migration coverage is separate. These local selections are not a full backend or frontend aggregate. No live-provider test, multi-connection MySQL concurrency demonstration, or browser reproduction is claimed. Historical CI results from the old PR are not treated as current results.

Fresh CI for this replacement PR

CI run 41919028108, triggered by opening #7393 at head 604a1125610ef98c2fc7cd94e2c6ec1e3bb85b73, completed successfully on November 4, 2026: all 6 jobs passed.

  • Backend Tests (Java 21): 4,190 tests, zero failures/errors/skips, including all 43 AiRunServiceTest cases. The full job log reports BUILD SUCCESS.
  • Frontend Build (Node 20): 2,037 tests across 167 files passed; the separate frontend license test step also passed all 8 cases.
  • Backend Build, Apache RAT, Frontend Docker Build, and rmqctl Build also passed.

These are results from this replacement's new CI run, separate from the local selections and negative controls above. The successful remote build does not change the recorded local offline package-cache limitation or extend the regression fixtures into live-provider or MySQL concurrency evidence.

AI assistance was used for investigation, source review, and validation.

Checklist

  • One coherent replay change; no unrelated changes bundled in
  • Conventional Commit subject
  • Regression methods use the ...Test suffix
  • Existing ASF headers retained; no new source files or UI text
  • Replay boundary comments explain the behavior
  • Fresh CI for this replacement passed all six jobs; backend 4,190/4,190 and frontend 2,037/2,037
  • Full backend aggregate and ArchUnit checks were not rerun locally
  • Local package build remains unverified because of the offline plugin-cache limitation

@lizhimins
lizhimins changed the base branch from rocketmq-studio to master November 27, 2026 04:29
@lizhimins
lizhimins merged commit 7938919 into apache:master Nov 27, 2026
6 checks passed
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.

[Bug] Attaching to one AI run replays other runs and can report the wrong terminal status

2 participants