-
Notifications
You must be signed in to change notification settings - Fork 930
Fix Python permission handler in custom agents guide #672
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
Closed
patniko
wants to merge
8
commits into
custom-agents-guide
from
agent/20260304-164612-session-68acdc6d
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
427205f
Fix CI detection in tests (#659)
SteveSandersonMS 93ca61a
Further E2E tests for resume (#665)
SteveSandersonMS ee18f6e
Add cross-repo issue analysis agentic workflow (#670)
patniko a28f2d2
Pass RUNTIME_TRIAGE_TOKEN to GitHub tools for cross-repo reads
patniko 811f835
Rename workflow to Copilot CLI Runtime Triage
patniko 7ad1de3
Clone runtime repo for local search, rename to SDK Runtime Triage
patniko 8898aea
Clone runtime repo inside workspace for sandbox access
patniko 8058f4f
Add patterns to Dependabot config for weekly batched PRs
patniko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,377 changes: 1,377 additions & 0 deletions
1,377
.github/workflows/cross-repo-issue-analysis.lock.yml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| --- | ||
| description: Analyzes copilot-sdk issues to determine if a fix is needed in copilot-agent-runtime, then opens a linked issue and suggested-fix PR there | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| workflow_dispatch: | ||
| inputs: | ||
| issue_number: | ||
| description: "Issue number to analyze" | ||
| required: true | ||
| type: string | ||
| permissions: | ||
| contents: read | ||
| issues: read | ||
| pull-requests: read | ||
| steps: | ||
| - name: Clone copilot-agent-runtime | ||
| run: git clone --depth 1 https://x-access-token:${{ secrets.RUNTIME_TRIAGE_TOKEN }}@github.com/github/copilot-agent-runtime.git ${{ github.workspace }}/copilot-agent-runtime | ||
| tools: | ||
| github: | ||
| toolsets: [default] | ||
| github-token: ${{ secrets.RUNTIME_TRIAGE_TOKEN }} | ||
| edit: | ||
| bash: | ||
| - "grep:*" | ||
| - "find:*" | ||
| - "cat:*" | ||
| - "head:*" | ||
| - "tail:*" | ||
| - "wc:*" | ||
| - "ls:*" | ||
| safe-outputs: | ||
| github-token: ${{ secrets.RUNTIME_TRIAGE_TOKEN }} | ||
| allowed-github-references: ["repo", "github/copilot-agent-runtime"] | ||
| add-comment: | ||
| max: 1 | ||
| target: triggering | ||
| add-labels: | ||
| allowed: [runtime-fix-needed, sdk-fix-only, needs-investigation] | ||
| max: 3 | ||
| target: triggering | ||
| create-issue: | ||
| title-prefix: "[copilot-sdk] " | ||
| labels: [upstream-from-sdk, ai-triaged] | ||
| target-repo: "github/copilot-agent-runtime" | ||
| max: 1 | ||
| create-pull-request: | ||
| title-prefix: "[copilot-sdk] " | ||
| labels: [upstream-from-sdk, ai-suggested-fix] | ||
| draft: true | ||
| target-repo: "github/copilot-agent-runtime" | ||
|
|
||
| timeout-minutes: 20 | ||
| --- | ||
|
|
||
| # SDK Runtime Triage | ||
|
|
||
| You are an expert agent that analyzes issues filed in the **copilot-sdk** repository to determine whether the root cause and fix live in this repo or in the **copilot-agent-runtime** repo (`github/copilot-agent-runtime`). | ||
|
|
||
| ## Context | ||
|
|
||
| - Repository: ${{ github.repository }} | ||
| - Issue number: ${{ github.event.issue.number || inputs.issue_number }} | ||
| - Issue title: ${{ github.event.issue.title }} | ||
|
|
||
| The **copilot-sdk** repo is a multi-language SDK (Node/TS, Python, Go, .NET) that communicates with the Copilot CLI via JSON-RPC. The **copilot-agent-runtime** repo contains the CLI/server that the SDK talks to. Many issues filed against the SDK are actually caused by behavior in the runtime. | ||
|
|
||
| ## Your Task | ||
|
|
||
| ### Step 1: Understand the Issue | ||
|
|
||
| Use GitHub tools to fetch the full issue body, comments, and any linked references for issue `${{ github.event.issue.number || inputs.issue_number }}` in `${{ github.repository }}`. | ||
|
|
||
| ### Step 2: Analyze Against copilot-sdk | ||
|
|
||
| Search the copilot-sdk codebase on disk to understand whether the reported problem could originate here. The repo is checked out at the default working directory. | ||
|
|
||
| - Use bash tools (`grep`, `find`, `cat`) to search the relevant SDK language implementation (`nodejs/src/`, `python/copilot/`, `go/`, `dotnet/src/`) | ||
| - Look at the JSON-RPC client layer, session management, event handling, and tool definitions | ||
| - Check if the issue relates to SDK-side logic (type generation, streaming, event parsing, client options, etc.) | ||
|
|
||
| ### Step 3: Investigate copilot-agent-runtime | ||
|
|
||
| If the issue does NOT appear to be caused by SDK code, or you suspect the runtime is involved, investigate the **copilot-agent-runtime** repo. It has been cloned to `./copilot-agent-runtime/` in the current working directory. | ||
|
|
||
| - Use bash tools (`grep`, `find`, `cat`) to search the runtime codebase at `./copilot-agent-runtime/` | ||
| - Look at the server-side JSON-RPC handling, session management, tool execution, and response generation | ||
| - Focus on the areas that correspond to the reported issue (e.g., if the issue is about streaming, look at the runtime's streaming implementation) | ||
|
|
||
| Common areas where runtime fixes are needed: | ||
| - JSON-RPC protocol handling and response formatting | ||
| - Session lifecycle (creation, persistence, compaction, destruction) | ||
| - Tool execution and permission handling | ||
| - Model/API interaction (prompt construction, response parsing) | ||
| - Streaming event generation (deltas, completions) | ||
| - Error handling and error response formatting | ||
|
|
||
| ### Step 4: Make Your Determination | ||
|
|
||
| Classify the issue into one of these categories: | ||
|
|
||
| 1. **SDK-fix-only**: The bug/feature is entirely in the SDK code. Label the issue `sdk-fix-only` and comment with your analysis. | ||
|
|
||
| 2. **Runtime-fix-needed**: The root cause is in copilot-agent-runtime. Do ALL of the following: | ||
| - Label the original issue `runtime-fix-needed` | ||
| - Create an issue in `github/copilot-agent-runtime` that: | ||
| - Clearly describes the problem and root cause | ||
| - References the original SDK issue (e.g., `github/copilot-sdk#123`) | ||
| - Includes the specific files and code paths involved | ||
| - Suggests a fix approach | ||
| - Create a draft PR in `github/copilot-agent-runtime` with a suggested fix: | ||
| - Make the minimal, targeted code changes needed | ||
| - Include a clear PR description linking back to both issues | ||
| - If you're uncertain about the fix, still create the PR as a starting point for discussion | ||
| - Comment on the original SDK issue summarizing your findings and linking to the new runtime issue and PR | ||
|
|
||
| 3. **Needs-investigation**: You cannot confidently determine the root cause. Label the issue `needs-investigation` and comment explaining what you found and what needs further human review. | ||
|
|
||
| ## Guidelines | ||
|
|
||
| 1. **Be thorough but focused**: Read enough code to be confident in your analysis, but don't read every file in both repos | ||
| 2. **Err on the side of creating the runtime issue**: If there's a reasonable chance the fix is in the runtime, create the issue. False positives are better than missed upstream bugs. | ||
| 3. **Make actionable PRs**: Even if the fix isn't perfect, a draft PR with a concrete starting point is more useful than just an issue description | ||
| 4. **Link everything**: Always cross-reference between the SDK issue, runtime issue, and runtime PR so maintainers can follow the trail | ||
| 5. **Be specific**: When describing the root cause, point to specific files, functions, and line numbers in both repos | ||
| 6. **Don't duplicate**: Before creating a runtime issue, search existing open issues in `github/copilot-agent-runtime` to avoid duplicates. If a related issue exists, reference it instead of creating a new one. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| using GitHub.Copilot.SDK.Test.Harness; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace GitHub.Copilot.SDK.Test; | ||
|
|
||
| public class StreamingFidelityTests(E2ETestFixture fixture, ITestOutputHelper output) : E2ETestBase(fixture, "streaming_fidelity", output) | ||
| { | ||
| [Fact] | ||
| public async Task Should_Produce_Delta_Events_When_Streaming_Is_Enabled() | ||
| { | ||
| var session = await CreateSessionAsync(new SessionConfig { Streaming = true }); | ||
|
|
||
| var events = new List<SessionEvent>(); | ||
| session.On(evt => events.Add(evt)); | ||
|
|
||
| await session.SendAndWaitAsync(new MessageOptions { Prompt = "Count from 1 to 5, separated by commas." }); | ||
|
|
||
| var types = events.Select(e => e.Type).ToList(); | ||
|
|
||
| // Should have streaming deltas before the final message | ||
| var deltaEvents = events.OfType<AssistantMessageDeltaEvent>().ToList(); | ||
| Assert.NotEmpty(deltaEvents); | ||
|
|
||
| // Deltas should have content | ||
| foreach (var delta in deltaEvents) | ||
| { | ||
| Assert.False(string.IsNullOrEmpty(delta.Data.DeltaContent)); | ||
| } | ||
|
|
||
| // Should still have a final assistant.message | ||
| Assert.Contains("assistant.message", types); | ||
|
|
||
| // Deltas should come before the final message | ||
| var firstDeltaIdx = types.IndexOf("assistant.message_delta"); | ||
| var lastAssistantIdx = types.LastIndexOf("assistant.message"); | ||
| Assert.True(firstDeltaIdx < lastAssistantIdx); | ||
|
|
||
| await session.DisposeAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Should_Not_Produce_Deltas_When_Streaming_Is_Disabled() | ||
| { | ||
| var session = await CreateSessionAsync(new SessionConfig { Streaming = false }); | ||
|
|
||
| var events = new List<SessionEvent>(); | ||
| session.On(evt => events.Add(evt)); | ||
|
|
||
| await session.SendAndWaitAsync(new MessageOptions { Prompt = "Say 'hello world'." }); | ||
|
|
||
| var deltaEvents = events.OfType<AssistantMessageDeltaEvent>().ToList(); | ||
|
|
||
| // No deltas when streaming is off | ||
| Assert.Empty(deltaEvents); | ||
|
|
||
| // But should still have a final assistant.message | ||
| var assistantEvents = events.OfType<AssistantMessageEvent>().ToList(); | ||
| Assert.NotEmpty(assistantEvents); | ||
|
|
||
| await session.DisposeAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Should_Produce_Deltas_After_Session_Resume() | ||
| { | ||
| var session = await CreateSessionAsync(new SessionConfig { Streaming = false }); | ||
| await session.SendAndWaitAsync(new MessageOptions { Prompt = "What is 3 + 6?" }); | ||
| await session.DisposeAsync(); | ||
|
|
||
| // Resume using a new client | ||
| using var newClient = Ctx.CreateClient(); | ||
| var session2 = await newClient.ResumeSessionAsync(session.SessionId, | ||
| new ResumeSessionConfig { OnPermissionRequest = PermissionHandler.ApproveAll, Streaming = true }); | ||
|
|
||
| var events = new List<SessionEvent>(); | ||
| session2.On(evt => events.Add(evt)); | ||
|
|
||
| var answer = await session2.SendAndWaitAsync(new MessageOptions { Prompt = "Now if you double that, what do you get?" }); | ||
| Assert.NotNull(answer); | ||
| Assert.Contains("18", answer!.Data.Content ?? string.Empty); | ||
|
|
||
| // Should have streaming deltas before the final message | ||
| var deltaEvents = events.OfType<AssistantMessageDeltaEvent>().ToList(); | ||
| Assert.NotEmpty(deltaEvents); | ||
|
|
||
| // Deltas should have content | ||
| foreach (var delta in deltaEvents) | ||
| { | ||
| Assert.False(string.IsNullOrEmpty(delta.Data.DeltaContent)); | ||
| } | ||
|
|
||
| await session2.DisposeAsync(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title/description describe a documentation-only fix in the custom agents guide, but this PR also adds/changes multiple E2E tests and snapshots across Node/Python/Go/.NET and introduces a new GitHub Actions workflow. Please update the PR title/description to reflect the broader scope, or split unrelated changes into separate PRs to keep review and rollback risk manageable.