Skip to content

Add runtime errors resource and tool to clear errors. #94

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

Merged
merged 15 commits into from
May 2, 2025

Conversation

jakemac53
Copy link
Contributor

@jakemac53 jakemac53 commented Apr 29, 2025

This ended up being a fair bit more complicated than I wanted, as it also refactors things and moves us towards a direction where we can support multiple connected apps (which was a natural extension of creating the resource URI, to include the debug session ID in it).

Functionally, this:

  • Starts collecting errors as soon as a debug session is connected, and creates a runtime errors resource for each session.
  • Allows us to fire change notifications for when new errors come in.
  • Also added a clear_runtime_errors tool as well as an argument to the hotReload tool to clear the errors prior to the hot reload.
  • Drops the support for since in favor of just clearing the errors.

Eventually we might want to support pagination of the resource instead (it is already modeled as many parts), I filed a feature request on the MCP repo for this, but it likely won't land for some time if at all.

Copy link

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

@jakemac53 jakemac53 requested a review from kenzieschmoll April 30, 2025 17:55
@jakemac53 jakemac53 marked this pull request as ready for review April 30, 2025 17:55
@jakemac53
Copy link
Contributor Author

cc @gspencergoog

Copy link

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@@ -31,7 +32,7 @@ base mixin DartToolingDaemonSupport on LoggingSupport, ToolsSupport {
/// [VmService] objects are automatically removed from the Map when the
/// [VmService] shuts down.
@visibleForTesting
final activeVmServices = <String, VmService>{};
final activeVmServices = <String, Future<VmService>>{};
Copy link
Contributor

Choose a reason for hiding this comment

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

the dart doc needs to be updated since the key for this map changed (debug session id vs vm service uri).

Generally, why the change from vm service uri as the key to debug session id?

Copy link
Contributor Author

@jakemac53 jakemac53 May 2, 2025

Choose a reason for hiding this comment

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

When we get the event for a debug session starting or ending, a VM service URI is not included, only the debug session ID

Comment on lines +221 to +223
await activeVmServices
.remove((e.data['debugSession'] as DebugSession).id)
?.then((service) => service.dispose());
Copy link
Contributor

Choose a reason for hiding this comment

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

we are already doing this above when the vm service shuts down, do we need to do it here too? will calling dispose twice be a problem? Also, we'd want to avoid calling this here if if doesn't allow us to remove the resource in the onDone handler above

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 is safe to call dispose multiple times.

This also doesn't affect our ability to dispose of the resource (but will trigger it by triggering the onDone future).

Really, this is just defensive, in case somehow the VM service remained active but the debug session was completed. We will shut it down if either DTD tells us to, or the VM service connection closes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did remove the (should be) unnecessary dispose call form the onDone callback though, that only gets completed when the VM service is disposed anyways.

}) => DebugSession.fromJson({
'debuggerType': debuggerType,
'id': id,
'name': name,
'projectRootPath': projectRootPath,
'vmServiceUri': vmServiceUri,
if (vmServiceUri != null) 'vmServiceUri': vmServiceUri,
Copy link
Contributor

Choose a reason for hiding this comment

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

what type of debug sessions do not have a vm service uri?

Copy link
Contributor Author

@jakemac53 jakemac53 May 2, 2025

Choose a reason for hiding this comment

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

When we get the started notification, they don't have a VM service URI yet. Then we get a follow-up changed notification that does contain the VM service URI.

);
expect(
(nextResult.content.first as TextContent).text,
contains('No runtime errors found'),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised there are no errors even though the clearRuntimeErrors arg was not passed, but maybe I'm not following the logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is a bit hard to follow - we are passing clearRuntimeErrors in the retry loop above (which is waiting for the error to show up, this test was flaking without that since there is no explicit 1 second delay any more built into this tool).

This then asks for the errors again - to check that the errors were in fact cleared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment above this tool call

@jakemac53 jakemac53 merged commit 63fa00b into main May 2, 2025
15 checks passed
@jakemac53 jakemac53 deleted the errors-resource branch May 2, 2025 16:45
sigurdm pushed a commit to sigurdm/ai that referenced this pull request May 6, 2025
This ended up being a fair bit more complicated than I wanted, as it also refactors things and moves us towards a direction where we can support multiple connected apps (which was a natural extension of creating the resource URI, to include the debug session ID in it).

Functionally, this:

- Starts collecting errors as soon as a debug session is connected, and creates a runtime errors resource for each session.
- Allows us to fire change notifications for when new errors come in.
- Also added a `clear_runtime_errors` tool as well as an argument to the `hotReload` tool to clear the errors prior to the hot reload.
- Drops the support for `since` in favor of just clearing the errors.

Eventually we might want to support pagination of the resource instead (it is already modeled as many parts), I filed a feature request on the MCP repo for this, but it likely won't land for some time if at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants