Skip to content

Conversation

@aussedatlo
Copy link
Contributor

πŸ“ Description

This PR improves the device session refresher to work better with the new intent queue implementation. The main improvement is that the refresher now avoids unnecessary pings when the device is already busy processing an intent.

What changed:

  • Refresher now tracks device busy state and skips refresh attempts during intent processing
  • Removed disableRefresher from InternalApi since it's no longer needed, the refresher is smart enough to know when to run
  • Intent queue now dispatches session events to coordinate with the refresher
  • Better device state tracking with a pending status system
  • Cleaned up the session initialization to remove unnecessary initial ping

This makes the device communication more efficient by avoiding conflicts between the refresher and ongoing operations.

Warning:

InternalApi type changed.

❓ Context

  • JIRA or GitHub link: [DSDK-945]
  • Feature:

βœ… Checklist

Pull Requests must pass CI checks and undergo code review. Set the PR as Draft if it is not yet ready for review.

  • Covered by automatic tests
  • Changeset is provided
  • Documentation is up-to-date
  • Impact of the changes:
    • list of the changes

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.

@aussedatlo aussedatlo requested a review from a team as a code owner November 10, 2025 10:24
@vercel
Copy link

vercel bot commented Nov 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
device-sdk-ts-sample Ready Ready Preview Comment Dec 4, 2025 10:38am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
doc-device-management-kit Ignored Ignored Dec 4, 2025 10:38am

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Messages
βœ… Danger: All checks passed successfully! πŸŽ‰

Generated by 🚫 dangerJS against 287db77

intentQueueServiceFactory: (
sessionEventDispatcher: DeviceSessionEventDispatcher,
) => IntentQueueService = (sessionEventDispatcher) =>
new IntentQueueService(loggerModuleFactory, sessionEventDispatcher),

Choose a reason for hiding this comment

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

[ASK] Why are you using a factory here when you instantiate the class immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's easier to test it as I can just inject a mock

Copy link
Contributor

@ofreyssinet-ledger ofreyssinet-ledger left a comment

Choose a reason for hiding this comment

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

changes requested in #1111 to either do there first or here

Copilot AI review requested due to automatic review settings December 2, 2025 10:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves device session management by introducing a new intent queue system that coordinates with the device session refresher. The main enhancement is that the refresher now intelligently avoids pinging the device when it's already busy processing operations, preventing conflicts and unnecessary network calls.

Key Changes:

  • Replaces MutexService with a new IntentQueueService that provides better coordination between operations and the refresher through event dispatching
  • Removes disableRefresher from InternalApi as the refresher is now smart enough to automatically skip refreshes during active operations
  • Implements a pending device status system in DeviceSessionStateHandler to better track device state transitions

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/device-management-kit/src/internal/device-session/service/IntentQueueService.ts New intent queue implementation with comprehensive documentation and FIFO sequential processing
packages/device-management-kit/src/internal/device-session/service/IntentQueueService.test.ts Comprehensive test coverage for the new intent queue service
packages/device-management-kit/src/internal/device-session/model/DeviceSession.ts Refactored sendApdu, sendCommand, and executeDeviceAction to use the intent queue; added bypass capability for testing
packages/device-management-kit/src/internal/device-session/model/DeviceSession.test.ts New comprehensive tests for DeviceSession functionality
packages/device-management-kit/src/internal/device-session/model/DeviceSessionRefresher.ts Enhanced to track device busy state and skip refreshes during intent processing
packages/device-management-kit/src/internal/device-session/model/DeviceSessionStateHandler.ts Implements pending status system for better state tracking; adds exhaustive switch case handling
packages/device-management-kit/src/internal/device-session/model/DeviceSessionEventDispatcher.ts Adds NEW_STATE and DEVICE_STATE_UPDATE_UNKNOWN events for improved state coordination
packages/device-management-kit/src/internal/device-session/service/MutexService.ts Removed - replaced by IntentQueueService
packages/device-management-kit/src/internal/device-session/service/MutexService.test.ts Removed - no longer needed
packages/device-management-kit/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.ts New use case to bypass intent queue for testing purposes
packages/device-management-kit/src/api/device-action/DeviceAction.ts Removes disableRefresher from InternalApi interface
packages/device-management-kit/src/api/DeviceManagementKit.ts Adds _unsafeBypassIntentQueue public API method
packages/device-management-kit/src/api/transport/model/Errors.ts Adds SendCommandTimeoutError for command timeout handling
packages/device-management-kit/src/api/secure-channel/task/ConnectToSecureChannelTask.ts Removes manual refresher disabling as it's now automatic
packages/device-management-kit/src/internal/send/use-case/SendApduUseCase.test.ts Refactored to use mocks instead of full service instantiation
packages/device-management-kit/src/internal/discovery/use-case/ConnectUseCase.test.ts Updated to use proper mocking and added test for TransportNotSupportedError
packages/device-management-kit/src/api/logger-subscriber/service/WebLogsExporterLogger.test.ts Uses deviceSessionStubBuilder instead of direct DeviceSession instantiation
packages/signer/signer-{solana,eth,btc}/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts Removes disableRefresher mock from test utilities
.changeset/*.md Changeset files documenting the breaking and patch changes

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

4 participants