Skip to content

Add Github Copilot Provider#1254

Draft
zortos293 wants to merge 3 commits intopingdotgg:mainfrom
zortos293:feat/copilot-integration
Draft

Add Github Copilot Provider#1254
zortos293 wants to merge 3 commits intopingdotgg:mainfrom
zortos293:feat/copilot-integration

Conversation

@zortos293
Copy link
Contributor

@zortos293 zortos293 commented Mar 20, 2026

What Changed

  • Added Copilot provider support across the server, shared contracts, and web UI.
  • Wired up Copilot adapter/session/health handling and related model plumbing.
  • Fixed thread provider binding so threads stay attached to the correct provider.

Why

  • This makes Copilot available as a first-class provider while keeping provider selection and thread routing predictable.

UI Changes

  • Updated provider picker/settings surfaces to include Copilot-related behavior and provider health state.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Add GitHub Copilot as a supported AI provider

  • Introduces a full CopilotAdapter service in CopilotAdapter.ts that integrates @github/copilot-sdk, supporting session start/resume, turn sending/aborting, interactive permission prompts, user-input requests, model/reasoning-effort switching, and thread reading.
  • Adds Copilot to the provider registry, health check system, session directory decoder, and server provider layer so it is available alongside Codex and Claude.
  • Extends contracts, shared model utilities, and app settings to define Copilot model slugs, aliases, default model (claude-sonnet-4.6), reasoning effort options, and persisted settings for copilotCliPath and copilotConfigDir.
  • Adds a settings UI section for Copilot CLI path and config directory, a GitHub icon in the model picker, and a PROVIDER_OPTIONS entry labeled 'GitHub Copilot'.
  • Includes a patch for @github/copilot-sdk@0.1.32 to fix an ESM import path in dist/session.js.
📊 Macroscope summarized 0a91001. 33 files reviewed, 8 issues evaluated, 1 issue filtered, 4 comments posted

🗂️ Filtered Issues

apps/web/src/appSettings.test.ts — 0 comments posted, 1 evaluated, 1 filtered
  • line 233: The test expects claude-sonnet-4.6 (with a period) for the copilot provider, but the analogous claudeAgent test on line 227 expects claude-sonnet-4-6 (with a hyphen). This inconsistency suggests a copy-paste typo - either the model slug format is wrong (period vs hyphen), or the copilot test should be checking for a copilot-specific normalized slug rather than a claude model slug. [ Out of scope (triage) ]

@github-actions github-actions bot added size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 20, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b5b1bdb5-894e-43f4-ac15-c3a88ad754c9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

Copy link
Contributor

Choose a reason for hiding this comment

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

🟢 Low

const runtime = ManagedRuntime.make(layer);
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
const reactor = await runtime.runPromise(Effect.service(ProviderCommandReactor));
scope = await Effect.runPromise(Scope.make("sequential"));
await Effect.runPromise(reactor.start.pipe(Scope.provide(scope)));
const drain = () => Effect.runPromise(reactor.drain);

The local const runtime declared at line 222 shadows the outer let runtime at line 64, so the outer variable remains null. Consequently, afterEach never calls runtime.dispose(), leaking the ManagedRuntime and its resources (SQLite connections, layer finalizers) on every test. Rename the local variable so the outer runtime is assigned.

-    const runtime = ManagedRuntime.make(layer);
+    const testRuntime = ManagedRuntime.make(layer);
 
-    const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
-    const reactor = await runtime.runPromise(Effect.service(ProviderCommandReactor));
+    const engine = await testRuntime.runPromise(Effect.service(OrchestrationEngineService));
+    const reactor = await testRuntime.runPromise(Effect.service(ProviderCommandReactor));
     scope = await Effect.runPromise(Scope.make("sequential"));
     await Effect.runPromise(reactor.start.pipe(Scope.provide(scope)));
     const drain = () => Effect.runPromise(reactor.drain);
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts around lines 222-228:

The local `const runtime` declared at line 222 shadows the outer `let runtime` at line 64, so the outer variable remains `null`. Consequently, `afterEach` never calls `runtime.dispose()`, leaking the `ManagedRuntime` and its resources (SQLite connections, layer finalizers) on every test. Rename the local variable so the outer `runtime` is assigned.

Evidence trail:
apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts lines 64-67 (outer `let runtime = null`), lines 71-79 (`afterEach` that checks `if (runtime)` and calls `runtime.dispose()`), lines 86-269 (`createHarness` function), line 222 (`const runtime = ManagedRuntime.make(layer);` - local shadowing), lines 258-269 (return object does not include runtime)

Comment on lines +43 to +49
export function clearTurnTracking(state: CopilotTurnTrackingState): void {
state.currentTurnId = undefined;
state.currentProviderTurnId = undefined;
state.pendingCompletionTurnId = undefined;
state.pendingCompletionProviderTurnId = undefined;
state.pendingTurnUsage = undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🟠 High Layers/copilotTurnTracking.ts:43

clearTurnTracking does not clear pendingTurnIds, so stale turn IDs persist when a session is aborted or goes idle before assistant.turn_start. On the next turn, beginCopilotTurn shifts the old stale ID instead of the new one, causing a turn ID mismatch. Consider adding state.pendingTurnIds = [] to clear the array.

 export function clearTurnTracking(state: CopilotTurnTrackingState): void {
   state.currentTurnId = undefined;
   state.currentProviderTurnId = undefined;
   state.pendingCompletionTurnId = undefined;
   state.pendingCompletionProviderTurnId = undefined;
   state.pendingTurnUsage = undefined;
+  state.pendingTurnIds = [];
 }
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/server/src/provider/Layers/copilotTurnTracking.ts around lines 43-49:

`clearTurnTracking` does not clear `pendingTurnIds`, so stale turn IDs persist when a session is aborted or goes idle before `assistant.turn_start`. On the next turn, `beginCopilotTurn` shifts the old stale ID instead of the new one, causing a turn ID mismatch. Consider adding `state.pendingTurnIds = []` to clear the array.

Evidence trail:
apps/server/src/provider/Layers/copilotTurnTracking.ts lines 43-49: `clearTurnTracking` function clears all state fields except `pendingTurnIds`. Lines 6-13: `CopilotTurnTrackingState` interface shows `pendingTurnIds: Array<TurnId>` is part of the state. Lines 22-28: `beginCopilotTurn` uses `state.pendingTurnIds.shift()` to obtain the current turn ID. Line 65: `isCopilotTurnTerminalEvent` checks for 'abort' or 'session.idle' events.

threadId: input.threadId,
createdAt: input.createdAt,
...(input.turnId ? { turnId: input.turnId } : {}),
...(input.itemId ? { itemId: toRuntimeItemId(input.itemId) } : {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

🟢 Low Layers/CopilotAdapter.ts:313

The truthy-check at line 313 (input.itemId ?) allows whitespace-only strings like " " to pass, but toRuntimeItemId returns undefined for these. This spreads { itemId: undefined } into the result, explicitly setting the field rather than omitting it. Consider also checking input.itemId.trim() before calling toRuntimeItemId, or have toRuntimeItemId throw on invalid input instead of returning undefined.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/server/src/provider/Layers/CopilotAdapter.ts around line 313:

The truthy-check at line 313 (`input.itemId ?`) allows whitespace-only strings like `"   "` to pass, but `toRuntimeItemId` returns `undefined` for these. This spreads `{ itemId: undefined }` into the result, explicitly setting the field rather than omitting it. Consider also checking `input.itemId.trim()` before calling `toRuntimeItemId`, or have `toRuntimeItemId` throw on invalid input instead of returning `undefined`.

Evidence trail:
apps/server/src/provider/Layers/CopilotAdapter.ts:313 - `...(input.itemId ? { itemId: toRuntimeItemId(input.itemId) } : {})`
apps/server/src/provider/Layers/CopilotAdapter.ts:162-165 - `toRuntimeItemId` implementation that returns `undefined` for whitespace-only strings via `value.trim().length === 0` check

const attachmentPath = resolveAttachmentPath({
stateDir: serverConfig.stateDir,
attachment,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🟠 High Layers/CopilotAdapter.ts:1403

Using throw inside Effect.gen at lines 1405-1409 causes ProviderAdapterRequestError to become an untyped defect (Die) rather than a typed failure (Fail). Downstream error handlers expecting ProviderAdapterError won't catch it. Consider using yield* Effect.fail(new ProviderAdapterRequestError(...)) instead.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/server/src/provider/Layers/CopilotAdapter.ts around line 1403:

Using `throw` inside `Effect.gen` at lines 1405-1409 causes `ProviderAdapterRequestError` to become an untyped defect (`Die`) rather than a typed failure (`Fail`). Downstream error handlers expecting `ProviderAdapterError` won't catch it. Consider using `yield* Effect.fail(new ProviderAdapterRequestError(...))` instead.

Evidence trail:
apps/server/src/provider/Layers/CopilotAdapter.ts lines 1388-1420 (REVIEWED_COMMIT): `sendTurn` defined as `Effect.gen(function* () {...})` with `throw new ProviderAdapterRequestError(...)` at line 1405 inside a `.map()` callback.

apps/server/src/provider/Layers/CopilotAdapter.ts lines 1448-1454: Contrasting pattern showing correct usage with `Effect.tryPromise({ catch: (cause) => new ProviderAdapterRequestError(...) })`.

apps/server/src/provider/Layers/CopilotAdapter.ts lines 1500, 1532: Examples showing correct pattern `return yield* new ProviderAdapterRequestError(...)`.

apps/server/src/provider/Services/ProviderAdapter.ts lines 62-64: Type definition showing `sendTurn: (input) => Effect.Effect<ProviderTurnStartResult, TError>` where TError is ProviderAdapterError.

apps/server/src/provider/Services/CopilotAdapter.ts lines 6-9: CopilotAdapterShape extends ProviderAdapterShape<ProviderAdapterError>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant