Skip to content

fix(ui): ensure correct event order in streaming callbacks - #811

Merged
haiphucnguyen merged 7 commits into
mainfrom
feature/fix-not-right-order-messages-and-cover-tests
Nov 9, 2026
Merged

haiphucnguyen merged 7 commits into
mainfrom
feature/fix-not-right-order-messages-and-cover-tests

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

⚠️ First-time contributor? This PR cannot be merged until you sign the CLA.
The CLA Assistant bot will post a comment below — reply to it with exactly:
I have read the CLA Document and I hereby sign the CLA
(Separate from this: all commits must also be signed off with git commit -s — see the Checklist.)

Summary

  • Introduce OrderedEventQueue to serialize concurrent event processing during agent runs and sessions
  • Add custom Detekt rule UnsafeLaunchInStreamingCallback to prevent unsafe scope.launch usage in streaming contexts
  • Add Lincheck concurrency tests and unit tests to verify thread safety and ordering guarantees
  • Integrate Kover test coverage reporting and configure CI build workflows for test verification

Related Issue(s)

#804

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • I signed the CLA (first-time contributors — reply to the CLA Assistant bot comment)
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Introduce OrderedEventQueue to serialize concurrent event processing during agent runs and sessions
- Add custom Detekt rule UnsafeLaunchInStreamingCallback to prevent unsafe scope.launch usage in streaming contexts
- Add Lincheck concurrency tests and unit tests to verify thread safety and ordering guarantees
- Integrate Kover test coverage reporting and configure CI build workflows for test verification
Copilot AI lite review requested due to automatic review settings November 8, 2026 07:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Approval is blocked by active critical build and timeline-concurrency defects, plus a moderate coroutine leak in image-generation handling.

2 open issues
What changed in this PR

This PR fixes out-of-order streaming updates by serializing session and agent callbacks through FIFO event queues. It also adds static analysis, concurrency tests, coverage tooling, and CI integration.

Changes:

  • Added OrderedEventQueue integration for session and agent timeline processing.
  • Added the UnsafeLaunchInStreamingCallback Detekt rule and supporting tests.
  • Added Lincheck tests, Kover coverage reporting, Gradle verification, and CI workflows.

This pull request requires changes.

File Description
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​config/​AppConfig.kt Switches file-level logging to the caller-aware logger.
gradle/​libs.versions.toml Adds Kover and Lincheck versions, dependencies, and plugin aliases.
gradle/​gradle-daemon-jvm.properties Configures the Gradle daemon toolchain for JVM 25.
gradle.properties Enables Gradle tooling parallelism.
detekt.yml Activates the custom Askimo Detekt rules.
detekt-rules/​src/​test/​kotlin/​io/​askimo/​detekt/​UnsafeLaunchInStreamingCallbackTest.kt Tests unsafe streaming callback launch detection.
detekt-rules/​src/​main/​resources/​META-INF/​services/​dev.detekt.api.RuleSetProvider Registers the custom Detekt rule provider.
detekt-rules/​src/​main/​kotlin/​io/​askimo/​detekt/​UnsafeLaunchInStreamingCallback.kt Implements the streaming callback launch rule.
detekt-rules/​src/​main/​kotlin/​io/​askimo/​detekt/​AskimoRuleSetProvider.kt Registers UnsafeLaunchInStreamingCallback.
desktop/​src/​main/​kotlin/​io/​askimo/​desktop/​settings/​LocalLlmQuickSetupDialog.kt Simplifies the Alignment reference through an import.
desktop-shared/​src/​test/​kotlin/​io/​askimo/​ui/​session/​StreamingThreadOrderingTest.kt Verifies ordered session event processing.
desktop-shared/​src/​test/​kotlin/​io/​askimo/​ui/​common/​UnsafeLaunchCanaryLincheckTest.kt Validates detection of the unsafe launch pattern.
desktop-shared/​src/​test/​kotlin/​io/​askimo/​ui/​common/​OrderedEventQueueTest.kt Tests FIFO processing, draining, concurrency, and post-close behavior.
desktop-shared/​src/​test/​kotlin/​io/​askimo/​ui/​common/​OrderedEventQueueLincheckTest.kt Stress-tests queue ordering under concurrent workloads.
desktop-shared/​src/​test/​kotlin/​io/​askimo/​ui/​common/​keymap/​KeyMapManagerTest.kt Pins and restores the modifier scheme for deterministic tests.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​session/​SessionManager.kt Serializes streaming session mutations through the event queue.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​common/​OrderedEventQueue.kt Provides FIFO single-consumer event processing.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​common/​keymap/​KeyModifierScheme.kt Exposes modifier schemes for deterministic tests.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​common/​keymap/​KeyMapManager.kt Makes the active modifier scheme test-configurable.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatInputField.kt Suppresses the streaming callback rule for a non-streaming tool callback.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​agent/​AgentRunViewModel.kt Serializes agent timeline callbacks and drains them before finalization.
desktop-shared/​build.gradle.kts Adds Lincheck dependencies and a dedicated concurrency test task.
cli/​src/​test/​kotlin/​io/​askimo/​core/​providers/​gemini/​GeminiModelFactoryTest.kt Updates the model used by Gemini streaming tests.
build.gradle.kts Configures Kover aggregation, coverage reporting, regression checks, and Detekt enforcement.
.github/​workflows/​shared-tests.yml Runs Lincheck tests and uploads test and coverage reports in CI.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active critical and moderate findings remain in the Kover build configuration, coverage regression baseline handling, and agent turn lifecycle, preventing reliable build verification and correct concurrent turn behavior.

1 open issue
2 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change still contains a build-configuration error and unguarded asynchronous turn-finalization races that can corrupt newer runs, while coverage task wiring may omit per-module reports.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Guard completion finalization against newer turns

desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​agent/​AgentRunViewModel.kt:688

The local response builder fixes one shared-field race, but this completion path still mutates shared messages, completedGroups, activeAgentSessionId, and invokes onRunCompleted() after isRunning was set false and the coroutine suspended in join(). A new turn can start in that window, so the old turn can finalize the new turn's streaming message and save its record under the new conversation. Keep turn ownership until all finalization is complete, or guard every shared-state write and callback with the captured turnId.

1 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Approval is blocked by a critical race in turn finalization that can corrupt persisted timeline data, along with a moderate test-helper issue that mutates the developer or CI user's global Testcontainers configuration.

1 open issue
1 resolved since last review

Review effort: Lite

@haiphucnguyen
haiphucnguyen merged commit 103242b into main Nov 9, 2026
14 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/fix-not-right-order-messages-and-cover-tests branch November 9, 2026 01:10
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.

2 participants