Skip to content

Provider plugin system: post-review fixes and runtime improvements#304

Merged
Redth merged 8 commits intomainfrom
fix/provider-plugin-post-review
Mar 7, 2026
Merged

Provider plugin system: post-review fixes and runtime improvements#304
Redth merged 8 commits intomainfrom
fix/provider-plugin-post-review

Conversation

@Redth
Copy link
Copy Markdown
Collaborator

@Redth Redth commented Mar 7, 2026

Summary

Follow-up to #292 — addresses PR review feedback and fixes runtime issues discovered during end-to-end plugin testing.

PR Review Fixes

  • IsProcessing invariant compliance — All 4 provider event handlers (OnTurnEnd/OnError for leader and member sessions) now clear ToolCallCount, IsResumed, and flush accumulated content on error paths, matching the 9-field cleanup invariant.
  • Path traversal protectionPluginLoader.LoadEnabledProviders now validates that resolved DLL paths stay within the plugins root directory via Path.GetFullPath() containment check.
  • Test csproj fix — Added missing PluginFileLogger.cs compile include to the test project.

Runtime Improvements (from e2e testing)

  • Plugin logging infrastructure — Added IPluginLogger interface to abstractions + PluginFileLogger implementation. Plugins get a dedicated logger that writes to ~/.polypilot/plugins/{name}/plugin.log, giving plugin authors runtime diagnostics without coupling to the host logging system.
  • DI resolution hardening — Eagerly materialize ISessionProviderFactory instances from the service provider with full exception logging, catching assembly load failures at startup rather than at first use.
  • PluginLoadContext assembly sharing — Share Microsoft.Extensions.Logging, Microsoft.Extensions.Hosting, Microsoft.Extensions.AI, and native library resolution with the plugin load context. Prevents TypeIdentityConflict when plugins reference the same framework assemblies as the host.
  • Environment forwarding — Forward PATH, HOME, and AZURE_CONFIG_DIR to provider CopilotClientOptions so plugins that spawn CLI processes (e.g., copilot) inherit the correct environment.
  • Provider member re-sync — Call SyncProviderMembers after InitializeAsync completes to pick up any members the provider created during initialization.

Testing

  • All 19 provider plugin tests pass
  • Full test suite passes (2059/2059)

Closes review items from #292.

Redth and others added 8 commits March 7, 2026 15:28
- IPluginLogger interface in abstractions package
- PluginFileLogger writes to ~/.polypilot/logs/plugins/{name}/plugin.log
- PluginLoader logs all discovery, hash checks, loading steps
- CopilotService.Providers logs provider registration and init
- ISessionProviderFactory.ConfigureServices gets optional logger param

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- GetServices<ISessionProvider>() was lazy — construction errors during
  foreach iteration were uncaught and silently swallowed
- Now .ToList() materializes eagerly inside try/catch
- Full stack trace logged to _system plugin log for diagnosability

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Plugin's ILogger<T> was a different type than host's because
Microsoft.Extensions.Logging.Abstractions wasn't in the shared
assembly list. Added Logging, Logging.Abstractions, Options,
and Hosting.Abstractions to prevent type identity conflicts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Plugins with native dependencies (e.g., e_sqlite3) need the load
context to probe runtimes/{rid}/native/ for .dylib/.so files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Host uses AI.Abstractions 10.2.0 but plugins may bundle 10.3.0,
causing MissingMethodException on SessionConfig.set_Tools due to
AIFunction type identity conflict.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ions

MAUI apps launched from Finder don't inherit the terminal's PATH,
so spawned tools (az, gh, git) can't be found or see auth state.
Ensure common tool directories are on PATH and HOME/AZURE_CONFIG_DIR
point to the user's profile so az-cli finds its cached tokens.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The initial SyncProviderMembers in RegisterProvider runs before
the provider has loaded its agents. Added a second sync after
InitializeAsync to pick up the actual squad members.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, test fixes

- CopilotService.Providers.cs: Clear ToolCallCount, IsResumed, and flush
  content on error in all 4 provider event handlers (OnTurnEnd/OnError)
- PluginLoader.cs: Add Path.GetFullPath containment check to prevent
  path traversal attacks in plugin loading
- Tests: Add PluginFileLogger compile include, widen contextmenu
  proximity threshold for provider attributes on session-item div

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth merged commit c1dea53 into main Mar 7, 2026
@Redth Redth deleted the fix/provider-plugin-post-review branch March 7, 2026 21:46
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.

1 participant