Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot Change Detection #2044

Merged
merged 8 commits into from
Apr 27, 2020
Merged

Bot Change Detection #2044

merged 8 commits into from
Apr 27, 2020

Conversation

Stevenic
Copy link
Contributor

Fixes microsoft/botframework-sdk#5495

Description

These changes add logic to automatically detect that a bots dialogs have changed since a persisted dialog stack was started. A hash code is stored with each persisted container dialog that is then checked on each subsequent execution.

When a change is detected a new 'dialogChanged' event is raised which the bot can optionally handle to deal with the change in some custom way. If that event isn't handled and error will be thrown which will trigger the bots standard error handling logic.

note: WaterfallDialog does not currently support change detection as there's no great way to do this. You can check for the number of steps to change but that's about it.

Specific Changes

  • Added new DialogSetchangeHash property.
  • Added new ContainerDialog.checkForChanges() method.
  • Updated ComponentDialog to call new method.
  • Updated AdaptiveDialog to call new method.

Testing

Added unit tests to cover the new feature.

@coveralls
Copy link

coveralls commented Apr 15, 2020

Pull Request Test Coverage Report for Build 125410

  • 47 of 51 (92.16%) changed or added relevant lines in 7 files are covered.
  • 9 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.008%) to 79.786%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/botbuilder-dialogs-adaptive/src/adaptiveDialog.ts 18 20 90.0%
libraries/botbuilder-dialogs/src/componentDialog.ts 2 4 50.0%
Files with Coverage Reduction New Missed Lines %
libraries/botframework-streaming/src/webSocket/webSocketTransport.ts 2 80.65%
libraries/botframework-streaming/src/webSocket/webSocketServer.ts 7 66.67%
Totals Coverage Status
Change from base Build 125266: 0.008%
Covered Lines: 12351
Relevant Lines: 14769

💛 - Coveralls

Copy link
Member

@stevengum stevengum left a comment

Choose a reason for hiding this comment

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

LGTM

Leaving the approval to those more familiar with Adaptive Dialogs and its requirements.

Comment on lines +379 to +380
assert(results.status === DialogTurnStatus.complete, `results.status should be 'complete' not ${ results.status }`);
assert(results.result === undefined, `results.result should be undefined, not ${ results.result }`);
Copy link
Member

Choose a reason for hiding this comment

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

To avoid having to add descriptive error messages, this could be simplified to

Suggested change
assert(results.status === DialogTurnStatus.complete, `results.status should be 'complete' not ${ results.status }`);
assert(results.result === undefined, `results.result should be undefined, not ${ results.result }`);
assert.strictEqual(results.status, DialogTurnStatus.complete);
assert.strictEqual(results.result, undefined);

@@ -143,6 +143,8 @@ export class AdaptiveDialog<O extends object = {}> extends DialogContainer<O> {
public async beginDialog(dc: DialogContext, options?: O): Promise<DialogTurnResult> {
this.onPushScopedServices(dc.context);
try {
await this.checkForChanges(dc);
Copy link
Contributor

@tomlm tomlm Apr 16, 2020

Choose a reason for hiding this comment

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

await this.checkForChanges(dc); [](start = 8, length = 35)

Should checking for changes be built into the dialog context itself? It's the thing that is orchestrating switching between dialogs isn't it? #Closed

Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

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

:shipit:

@@ -11,5 +11,6 @@ export class DialogEvents {
static readonly repromptDialog = "repromptDialog";
static readonly cancelDialog = "cancelDialog";
static readonly activityReceived = "activityReceived";
static readonly versionChanged = "dialogChanged";
Copy link
Contributor

@tomlm tomlm Apr 24, 2020

Choose a reason for hiding this comment

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

dialogChanged [](start = 38, length = 13)

name doesn't match variable name? #Closed

// Simply return the id + number of steps to help detect when new steps have
// been added to a given waterfall.
return `${this.id}:${this.steps.length}`;
}
Copy link
Contributor

@tomlm tomlm Apr 24, 2020

Choose a reason for hiding this comment

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

I wonder if this should be a method.

This requires that the langauge supports virtual properties. For example, WaterfallDialog derives from Dialog and so needs to "override" the base version because it's a property. #Resolved

Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

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

🕐

*/
protected async checkForVersionChange(dc: DialogContext): Promise<void> {
const current = dc.activeDialog.version;
dc.activeDialog.version = this.dialogs.getVersion();
Copy link
Contributor

Choose a reason for hiding this comment

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

this.dialogs.getVersion(); [](start = 33, length = 27)

Instead of this call put this into virtual GetInternalVersion()

Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

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

:shipit:

@Stevenic Stevenic merged commit d1df6cb into master Apr 27, 2020
@Stevenic Stevenic deleted the stevenic/detect-bot-changes branch April 27, 2020 21:52
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.

DCR: detect dialog changes when a bot is deployed
4 participants