Skip to content

fix: send agent_assignment in assignAgentToIssue REST payload#47047

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-custom-agent-logging
Jul 21, 2026
Merged

fix: send agent_assignment in assignAgentToIssue REST payload#47047
pelikhan merged 4 commits into
mainfrom
copilot/fix-custom-agent-logging

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

assignAgentToIssue accepted model, customAgent, customInstructions, baseBranch, and pullRequestRepoSlug parameters but never included them in the API request — the Copilot coding agent was always assigned with a bare { assignees: [...] } payload, silently ignoring all custom configuration.

Changes

  • assign_agent_helpers.cjs: Build and attach agent_assignment to the POST assignees payload when any of the relevant fields are non-null:
const agentAssignment = {};
if (pullRequestRepoSlug) agentAssignment.target_repo = pullRequestRepoSlug;
if (baseBranch)          agentAssignment.base_branch = baseBranch;
if (customInstructions)  agentAssignment.custom_instructions = customInstructions;
if (customAgent)         agentAssignment.custom_agent = customAgent;
if (model)               agentAssignment.model = model;
if (Object.keys(agentAssignment).length > 0) assignParams.agent_assignment = agentAssignment;
  • assign_agent_helpers.test.cjs: Four new tests covering: no agent_assignment when all optional fields are null, all fields populated, partial fields, and pullRequestRepoSlugtarget_repo mapping.

Build and include agent_assignment in the POST assignees payload when
model, customAgent, customInstructions, baseBranch, or pullRequestRepoSlug
are provided, so the Copilot coding agent receives custom instructions and
agent configuration.

Closes #46799"

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix logging of custom agent configurations fix: send agent_assignment in assignAgentToIssue REST payload Jul 21, 2026
Copilot AI requested a review from pelikhan July 21, 2026 09:19
@github-actions

Copy link
Copy Markdown
Contributor

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output.

Review the workflow run logs for details.

🤖 Great work! This PR looks ready for review. The fix directly addresses issue #46799 by ensuring agent_assignment is properly included in the REST API payload when custom agent configuration is provided.

What's working well:

  • ✅ The implementation correctly builds the agent_assignment object conditionally (only when fields are non-null)
  • ✅ Four focused test cases cover the key scenarios: null fields, all fields, partial fields, and the pullRequestRepoSlugtarget_repo mapping
  • ✅ The fix aligns with GitHub's documented agent API contract
  • ✅ Clear problem statement and changes in the PR body

The PR is in draft status. Once you mark it ready for review, it should be good to merge pending any review feedback from maintainers.

Generated by ✅ Contribution Check · 61.3 AIC · ⌖ 11.2 AIC · ⊞ 6.2K ·

@pelikhan
pelikhan marked this pull request as ready for review July 21, 2026 09:47
Copilot AI review requested due to automatic review settings July 21, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Copilot assignment options to the REST request, addressing #46799.

Changes:

  • Builds agent_assignment from configured agent options.
  • Adds unit coverage for full, partial, and absent options.
Show a summary per file
File Description
actions/setup/js/assign_agent_helpers.cjs Adds the REST payload fields.
actions/setup/js/assign_agent_helpers.test.cjs Tests payload construction.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

};
const agentAssignment = {};
if (pullRequestRepoSlug) agentAssignment.target_repo = pullRequestRepoSlug;
if (baseBranch) agentAssignment.base_branch = baseBranch;
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #47047 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — changes look good.

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Root cause properly fixed: agent_assignment is now built and attached to the REST payload
  • ✅ Four tests cover the null, full, partial, and target_repo-only cases — solid regression protection
  • ✅ Guard prevents an empty object from being sent when no optional fields are provided
  • ✅ Consistent truthy checks mirror the existing style in the file

Minor Note

The existing review comment (line 408) raises a valid point about baseBranch not always being resolved when target_repo is an override — worth tracking as a follow-up if cross-repo assignments are a real use case.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 13.9 AIC · ⌖ 4.4 AIC · ⊞ 6.6K
Comment /matt to run again

@github-actions github-actions Bot mentioned this pull request Jul 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks correct — agent_assignment is populated conditionally and only included when at least one field is set, avoiding sending an empty object. Tests cover key scenarios (all fields, partial fields, no fields). The existing inline comment about baseBranch resolution for per-item target_repo overrides is the only outstanding concern and is already captured.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 12.6 AIC · ⌖ 4.34 AIC · ⊞ 4.9K

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 77/100 — Acceptable

Analyzed 4 test(s): 4 design, 0 implementation, 0 violation(s).

📊 Metrics (4 tests)
Metric Value
Analyzed 4 (Go: 0, JS: 4)
✅ Design 4 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 3 (75%)
Duplicate clusters 1
Inflation YES (89 test lines added vs 8 prod lines, ~11:1)
🚨 Violations 0
Test File Classification Issues
should not include agent_assignment when all optional fields are null assign_agent_helpers.test.cjs:460 design_test / high_value None
should include agent_assignment with all fields when all are provided assign_agent_helpers.test.cjs:474 design_test / high_value Minor overlap with target_repo test
should include agent_assignment with only the provided fields assign_agent_helpers.test.cjs:508 design_test / high_value None
should include agent_assignment with target_repo when pullRequestRepoSlug is provided assign_agent_helpers.test.cjs:537 design_test / high_value Slight overlap with all-fields test
⚠️ Flagged Tests (1 — inflation only)

Test inflation — 89 lines added to assign_agent_helpers.test.cjs vs 8 lines to assign_agent_helpers.cjs (ratio ~11:1). This is expected for parametric payload coverage; the tests are valuable despite the ratio. No action required.

Verdict

Passed. 0% implementation tests (threshold: 30%). All 4 new tests verify the agent_assignment REST payload shape — directly covering the behavioral contract introduced by this fix.

🧪 Test quality analysis by Test Quality Sentinel · 42 AIC · ⌖ 7.1 AIC · ⊞ 6.9K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 77/100. 0% implementation tests (threshold: 30%).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

REQUEST_CHANGES — one correctness bug must be fixed before merging.

### Findings

High — truthy checks silently drop empty-string values (assign_agent_helpers.cjs lines 407–411)

All five conditionals use bare truthiness (if (model), if (baseBranch), etc.). Any caller that passes an empty string "" for any of those fields will have it silently omitted from the agent_assignment payload. Since all parameters default to null and the intent is clearly "skip when not provided", replace with != null guards throughout.

Medium — no empty-string test coverage (assign_agent_helpers.test.cjs)

The four new tests only cover null and non-empty strings. There is no test that pins the behavior for "", meaning the bug above is invisible in CI.

Low — inconsistent assertion style (assign_agent_helpers.test.cjs line 541)

One test uses objectContaining while the others use exact matching, weakening regression protection for that case.

🔎 Code quality review by PR Code Quality Reviewer · 39.4 AIC · ⌖ 4.78 AIC · ⊞ 5.6K
Comment /review to run again

if (baseBranch) agentAssignment.base_branch = baseBranch;
if (customInstructions) agentAssignment.custom_instructions = customInstructions;
if (customAgent) agentAssignment.custom_agent = customAgent;
if (model) agentAssignment.model = model;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Truthy checks silently drop empty-string values — any caller passing "" for model, customAgent, customInstructions, baseBranch, or pullRequestRepoSlug will have that field quietly omitted from agent_assignment, with no error.

💡 Suggested fix

Replace bare truthiness with explicit null checks:

const agentAssignment = {};
if (pullRequestRepoSlug != null) agentAssignment.target_repo = pullRequestRepoSlug;
if (baseBranch != null)         agentAssignment.base_branch = baseBranch;
if (customInstructions != null) agentAssignment.custom_instructions = customInstructions;
if (customAgent != null)        agentAssignment.custom_agent = customAgent;
if (model != null)              agentAssignment.model = model;

This preserves the skip-when-not-provided intent for null (the declared default) while forwarding empty strings a caller explicitly passes. Since all parameters default to null, != null is the correct narrowing predicate.


await assignAgentToIssue("id", "copilot-swe-agent[bot]", [], "copilot", null, null, null, null, null, restClient, taskContext);

expect(mockRequest).toHaveBeenCalledWith("POST /repos/{owner}/{repo}/issues/{issue_number}/assignees", {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No test coverage for empty-string inputs — the empty-string edge case (which the current implementation silently swallows) is not exercised by any test.

💡 Suggested test to add
it("should not include agent_assignment field for empty-string model", async () => {
  const mockRequest = vi.fn().mockResolvedValue({ status: 201 });
  const restClient = { request: mockRequest };

  await assignAgentToIssue(
    "id", "copilot-swe-agent[bot]", [], "copilot",
    null, "", null, null, null, restClient, taskContext
  );

  // With truthy check: agent_assignment is omitted (silent data loss)
  // With null check fix: agent_assignment contains { model: "" }
  // Add the assertion that matches your intended behavior.
});

Without this test, the regression introduced by truthy vs. null-check semantics is invisible in CI.

const mockRequest = vi.fn().mockResolvedValue({ status: 201 });
const restClient = { request: mockRequest };

await assignAgentToIssue("id", "copilot-swe-agent[bot]", [], "copilot", null, null, null, null, null, restClient, taskContext, "otherorg/otherrepo");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inconsistent assertion style — this test uses expect.objectContaining, while the other three use exact payload matching; a regression that sneaks extra keys into agent_assignment would be invisible here.

💡 Suggested fix

Use exact matching for consistency:

expect(mockRequest).toHaveBeenCalledWith(
  "POST /repos/{owner}/{repo}/issues/{issue_number}/assignees",
  {
    owner: "myorg",
    repo: "myrepo",
    issue_number: 42,
    assignees: ["copilot-swe-agent[bot]"],
    agent_assignment: { target_repo: "otherorg/otherrepo" },
  }
);

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address the remaining review feedback, and rerun checks once done:

  • PR Code Quality Reviewer flagged three follow-ups in the review comments: switch truthy checks to != null for agent_assignment fields, add explicit empty-string coverage, and tighten the target_repo assertion to exact matching.
  • Failed checks to fix: lint-js, lint-js.

Run: https://github.com/github/gh-aw/actions/runs/29826418446

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pi.dev

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "pi.dev"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · gpt54 13.2 AIC · ⌖ 6.32 AIC · ⊞ 7K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address the remaining review feedback, and rerun checks once done:

  • PR Code Quality Reviewer flagged three follow-ups in the review comments: switch truth...

Addressed in b20e323. Switched the agent_assignment guards to != null, added explicit empty-string coverage, tightened the target_repo assertion to exact matching, and fixed per-item pull_request_repo base-branch propagation. Local checks passed with make agent-report-progress && make test; PR CI on this head still needs a maintainer re-trigger.

Copilot AI requested a review from gh-aw-bot July 21, 2026 12:00
@pelikhan
pelikhan merged commit 531bfd2 into main Jul 21, 2026
8 checks passed
@pelikhan
pelikhan deleted the copilot/fix-custom-agent-logging branch July 21, 2026 12:13
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.0

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.

assign-to-agent: custom-agent/custom-instructions/model/base-branch are logged but never sent to GitHub's API

4 participants