Built-in `task` tool fails with "No GitHub OAuth token" in BYOK/Azure AI Foundry deployments
Description
When using the Copilot SDK with a BYOK (Bring Your Own Key) Azure AI Foundry provider, the built-in task tool always fails because the sub-agent it spawns cannot authenticate. The parent session authenticates via Azure AI Foundry, but the sub-agent expects GitHub OAuth or Copilot HMAC credentials which don't exist in BYOK mode.
Every task invocation fails immediately with:
{
"message": "Error: No GitHub OAuth token or Copilot HMAC key provided",
"code": "failure"
}
This also means MCP servers configured in the parent session are inaccessible to sub-agents, since they never get past the auth step.
Environment
- Copilot SDK Version: 0.1.26 (.NET)
- .NET Version: 10.0
- OS: Linux (Ubuntu 24.04, containerized)
- Provider: Azure AI Foundry BYOK (
type: "azure") - Model: gpt-5.2
Steps to Reproduce
- Create a Copilot client with a BYOK Azure AI Foundry provider
- Create a session with MCP servers configured
- Send a prompt that causes the agent to use the
tasktool - The model calls the
tasktool to delegate work to a sub-agent - The sub-agent immediately fails with the auth error above
var client = new CopilotClient(new CopilotClientOptions
{
CliPath = "copilot",
UseStdio = true
});
await client.StartAsync();
var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-5.2",
Provider = new ProviderConfig
{
Type = "azure",
BaseUrl = "https://my-resource.services.ai.azure.com/openai/deployments/gpt-5.2",
ApiKey = "<key>"
},
McpServers = new Dictionary<string, McpServerConfig>
{
...
}
});
// Agent will try to use `task` tool to delegate to a sub-agent
// Sub-agent fails with "No GitHub OAuth token or Copilot HMAC key provided"
await session.SendAndWaitAsync(new MessageOptions
{
Prompt = "...."
});
Expected Behavior
The task tool should either:
- Propagate the parent session's auth context (BYOK provider config) and MCP server configurations to the sub-agent, OR
- Fail gracefully with an error indicating that
taskis not supported in BYOK mode, so the model can fall back to direct tool calls
Actual Behavior
The task tool spawns a sub-agent that immediately fails because it tries to authenticate via GitHub OAuth/HMAC, which is not available in BYOK deployments. The error gives the model no indication that it should retry the same work as a direct tool call instead.
Impact
This effectively breaks any multi-step investigation workflow in BYOK mode:
- The model prefers delegating MCP tool calls via
task(likely trained on patterns wheretaskworks) taskalways fails in BYOK mode- The model rarely recovers by calling MCP tools directly
- The session produces empty results despite MCP servers being configured and available
Related Issues
- #553 — MCP servers in CustomAgentConfig are not exposed to the agent during execution (similar MCP propagation problem, but for custom agents rather than built-in
task) - #251 — Custom Agents are not working (custom agent configs overwritten during session init)
- #477 — Sub-agent messages are queued instead of streamed (separate sub-agent issue)
Thanks for the detailed bug report, @jbayardo! This is a well-documented issue with clear reproduction steps.
Labels applied: bug, sdk/dotnet
This appears to be a legitimate issue where the built-in task tool doesn't propagate BYOK authentication context or MCP server configurations to sub-agents, breaking multi-step workflows in Azure AI Foundry deployments. As you noted, it's related to similar configuration propagation issues in #553, #251, and #477.
The team will review this and determine the appropriate fix—either propagating the parent auth context or failing gracefully with a clear error message.
🤖 Triaged by Issue Triage Agent
AI generated by Issue Triage Agent
This applies to Anthropic BYOK as well, since all custom subs hit the same code path.
claude-assist triage here:
Copilot SDK BYOK Subagent Auth Bug (#559)
Deobfuscated from
@github/[email protected]—node_modules/@github/copilot/app.js(16MB minified bundle). Variable names are invented for readability; the structure and logic are faithful to the original.
Summary
When the Copilot SDK spawns a subagent (task tool), it hardcodes the client type to "sweagent-capi" (Copilot API) and never forwards the parent session's BYOK provider config. This means the subagent always tries to authenticate via GitHub OAuth or HMAC — which don't exist in BYOK mode — and immediately throws:
Error: No GitHub OAuth token or Copilot HMAC key provided
The Code
1. createApiClient — the client factory
This is the central routing function. It picks which API backend to create based on the clientType string, unless a providerConfig (BYOK) is passed — in which case it delegates to createByokClient.
// Minified name: wT
// Location: offset ~11455594
function createApiClient(
settings: Settings,
logger: Logger,
clientType: string,
clientOptions: ClientOptions,
providerConfig?: ProviderConfig // ← BYOK config (apiKey, baseUrl, type)
): ApiClient {
// If BYOK provider config was passed, route through the BYOK factory
if (providerConfig) {
return createByokClient(settings, logger, clientOptions, providerConfig);
}
// Otherwise pick by clientType
switch (clientType) {
case "sweagent-capi": return new CopilotApiClient(settings, logger, clientOptions);
case "sweagent-anthropic": return new AnthropicClient(settings, logger, clientOptions);
case "sweagent-aip": return new AzureAIClient(settings, logger, clientOptions);
case "sweagent-openai": return new OpenAIClient(settings, logger, clientOptions);
default: return new CopilotApiClient(settings, logger, clientOptions);
}
}
2. createByokClient — correctly handles BYOK routing
This function already works — it reads the provider type and creates the right client with the user's API key. It's just never called for subagents.
// Minified name: P3s
// Location: offset ~11455700
function createByokClient(
settings: Settings,
logger: Logger,
clientOptions: ClientOptions,
providerConfig: ProviderConfig
): ApiClient {
const providerType = getProviderType(providerConfig); // "anthropic" | "azure" | "openai"
const wireApi = getWireApi(providerConfig); // "responses" | "chat"
switch (providerType) {
case "anthropic": {
const mergedSettings = {
...settings,
api: {
...settings.api,
anthropic: { key: providerConfig.apiKey, baseUrl: providerConfig.baseUrl },
},
};
return new AnthropicClient(mergedSettings, logger, clientOptions);
}
case "azure": {
const mergedSettings = {
...settings,
api: {
...settings.api,
openai: {
apiKey: providerConfig.apiKey,
azure: {
url: providerConfig.baseUrl,
apiVersion: providerConfig.azure?.apiVersion || "2024-10-21",
bearerToken: providerConfig.bearerToken,
},
},
},
};
return wireApi === "responses"
? new OpenAIResponsesClient(mergedSettings, logger, clientOptions)
: new OpenAIChatClient(mergedSettings, logger, clientOptions);
}
case "openai":
default: {
const customFetch = new CustomProviderFetch(providerConfig);
return wireApi === "responses"
? new OpenAIResponsesClient(customFetch, settings, logger, clientOptions)
: new OpenAIChatClient(customFetch, settings, logger, clientOptions);
}
}
}
3. AgentRunner.getOrCreateAgent() — ⚠️ THE BUG
When the SDK decides to spawn a subagent (via the task tool), this method creates the subagent's API client. It hardcodes "sweagent-capi" and never passes providerConfig.
// Part of AgentRunner class (minified name unclear, class around offset ~11481600)
class AgentRunner {
definition: AgentDefinition;
settings: Settings;
config: AgentConfig; // holds .provider, .sessionId, .capiRequestContext, etc.
logger: Logger;
async getOrCreateAgent(
callback: Callback,
toolCallId?: string,
modelOverride?: string
) {
const model = modelOverride || this.resolveDefinitionModel();
const taskId = generateUUID();
const modelConfig = getModelConfig("sweagent-capi", model, this.settings);
const agentConfig = {
// ╔══════════════════════════════════════════════════════════════╗
// ║ BUG: Always creates CopilotApiClient, ignores BYOK config ║
// ╚══════════════════════════════════════════════════════════════╝
client: createApiClient(
this.settings,
this.logger,
"sweagent-capi", // ← hardcoded to Copilot API
{
...modelConfig.clientOptions,
model: model,
capiRequestContext: {
interactionType: "conversation-subagent",
agentTaskId: taskId,
parentAgentTaskId: this.config.capiRequestContext?.parentAgentTaskId,
clientSessionId: this.config.sessionId,
clientMachineId: this.config.capiRequestContext?.clientMachineId,
interactionId: this.config.capiRequestContext?.interactionId,
},
}
// ❌ 5th arg (providerConfig) is MISSING
),
settings: this.settings,
logger: this.logger,
exec: new ShellExecutor(this.logger),
callback: callback,
};
const tools = await this.getToolsForAgent(model, /* ... */);
// ... MCP tool setup ...
return { agent: new Agent(agentConfig, toolCallId), tools };
}
}
4. CopilotApiClient — where it blows up
Since the subagent always gets a CopilotApiClient, it tries to find GitHub OAuth/HMAC credentials — which don't exist in BYOK sessions.
// Minified name: W5e
// Location: offset ~11371400
class CopilotApiClient {
async getClient(settings: Settings, options?: RequestOptions) {
let oauthToken = settings.api?.copilot?.token;
let hmacKey = settings.api?.copilot?.hmacKey;
if (!oauthToken && !hmacKey) {
// Fallback: try secret provider
const secretProvider = createSecretProvider(settings, this.logger);
try { hmacKey = await secretProvider.getSecret("dev-CapiHmacKey"); } catch {}
try { oauthToken = await secretProvider.getSecret("capi-token"); } catch {}
}
if (oauthToken) {
return CopilotApi.createWithOAuthToken(/* ... */);
}
if (hmacKey) {
return CopilotApi.createWithHmac(/* ... */);
}
// 💥 In BYOK mode, neither exists → this throws
throw new Error("No GitHub OAuth token or Copilot HMAC key provided");
}
}
The Fix
One-line change in AgentRunner.getOrCreateAgent() — pass the parent session's provider config as the 5th argument:
client: createApiClient(
this.settings,
this.logger,
"sweagent-capi",
- { ...modelConfig.clientOptions, model, capiRequestContext: { /* ... */ } }
+ { ...modelConfig.clientOptions, model, capiRequestContext: { /* ... */ } },
+ this.config.provider // forward the parent's BYOK provider config
),
The createByokClient function already handles anthropic/azure/openai correctly — it just never gets called because the subagent path doesn't forward the provider.
Update because I was able to patch my local 1.0.5 to get it to work: there was one more code fix:
In Session's method that builds the runner config for subagents (the method that constructs the config object passed to runAgenticLoop). The config includes shellContext, capiRequestContext, location, sessionId, etc. but doesn't include the provider field even though this.provider is available on the Session instance.
So two places. add the provider to the subagent config, and also use it when creating the api client.
@devm33 I see this is marked as completed, can you link the commit(s) or the PR?