Skip to content

Refactor agent-session safe-output parsing to a single shared path - #53840

Closed
pelikhan with Copilot wants to merge 6 commits into
mainfrom
copilot/duplicate-code-deduplicate-create-agent-session
Closed

Refactor agent-session safe-output parsing to a single shared path#53840
pelikhan with Copilot wants to merge 6 commits into
mainfrom
copilot/duplicate-code-deduplicate-create-agent-session

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

parseAgentSessionConfig had two near-identical branches for create-agent-session and deprecated create-agent-task, creating drift risk for future field changes. This PR centralizes parsing while preserving key-precedence and deprecation behavior.

  • What changed

    • Extracted shared parsing into parseAgentSessionConfigMap(configData any).
    • Kept key selection in parseAgentSessionConfig:
      • prefer create-agent-session
      • fallback to create-agent-task with existing warning
  • Behavior preserved

    • base, target-repo, and base safe-output fields are parsed identically for both keys.
    • invalid target-repo still returns nil (validation path unchanged).
    • non-map / empty config still defaults max to 1.
  • Coverage updates

    • Added focused tests for deprecated-key parsing parity.
    • Added a precedence test to ensure create-agent-session wins when both keys are present.
if configData, exists := outputMap["create-agent-session"]; exists {
    return c.parseAgentSessionConfigMap(configData)
}
if configData, exists := outputMap["create-agent-task"]; exists {
    createAgentSessionLog.Print("WARNING: Using deprecated 'create-agent-task' configuration. Please migrate to 'create-agent-session' using 'gh aw fix'")
    return c.parseAgentSessionConfigMap(configData)
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Deduplicate parsing for create-agent-session config keys Refactor agent-session safe-output parsing to a single shared path Aug 18, 2026
Copilot AI requested a review from pelikhan August 18, 2026 22:12
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Part of the same safe-output parsing refactor cluster. Recommend batch review with the other two PRs.

Generated by 🔧 PR Triage Agent · auto · 58.5 AIC · ⌖ 2.15 AIC · ⊞ 8.3K ·

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot Remove create-agent-task add codemod to migrate

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Remove create-agent-task add codemod to migrate

Implemented in ec94ca5. create-agent-task support was removed from runtime parsing/handler aliases and from the main workflow schema, while keeping codemod migration support (gh aw fix) to rewrite safe-outputs.create-agent-task to safe-outputs.create-agent-session.

@github-actions

Copy link
Copy Markdown
Contributor

Triage: category=refactor · risk=medium · score=40/100 (impact 20/50, urgency 10/30, quality 10/20)
Recommended action: batch_review

Part of the B1-safeoutput-refactor batch (with #53841, #53838). Draft, no CI yet, no reviews. Undraft once ready and review together with the batch.

Generated by 🔧 PR Triage Agent · auto · 58.8 AIC · ⌖ 2.56 AIC · ⊞ 8.3K ·

@pelikhan
pelikhan marked this pull request as ready for review August 19, 2026 09:47
Copilot AI balanced review requested due to automatic review settings August 19, 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

Centralizes agent-session configuration parsing, but unintentionally removes the promised deprecated create-agent-task compatibility path.

Changes:

  • Extracts shared agent-session map parsing.
  • Removes deprecated-key handling from parser, registry, and schema.
  • Updates tests to expect deprecated keys to be ignored.
Show a summary per file
File Description
pkg/workflow/create_agent_session.go Extracts parsing helper but removes fallback.
pkg/workflow/create_agent_session_test.go Tests deprecated-key rejection.
pkg/workflow/safe_output_handlers.go Removes deprecated handler alias.
pkg/workflow/safe_outputs_fix_test.go Drops alias regression coverage.
pkg/parser/schemas/main_workflow_schema.json Removes deprecated schema support.

Review details

  • Files reviewed: 5/5 changed files
  • Comments generated: 5
  • Review effort level: Balanced

@@ -34,7 +34,6 @@ var safeOutputHandlers = []safeOutputHandlerDescriptor{
},
{
Key: "create-agent-session",
if configData, exists := outputMap["create-agent-task"]; exists {
createAgentSessionLog.Print("WARNING: Using deprecated 'create-agent-task' configuration. Please migrate to 'create-agent-session' using 'gh aw fix'")
agentSessionConfig := &CreateAgentSessionConfig{}
return nil
Comment on lines +152 to +153
if config != nil {
t.Fatal("parseAgentSessionConfig() should ignore deprecated create-agent-task key")
"safe-outputs": {
"type": "object",
"$comment": "Required if workflow creates or modifies GitHub resources. Operations requiring safe-outputs: approve-workflow-run, autofix-code-scanning-alert, add-comment, add-labels, add-reviewer, assign-milestone, assign-to-agent, assign-to-user, close-discussion, close-issue, close-pull-request, create-agent-session, create-agent-task (deprecated, use create-agent-session), create-check-run, create-code-scanning-alert, create-discussion, create-issue, create-project, create-project-status-update, create-pull-request, create-pull-request-review-comment, dispatch-workflow, hide-comment, link-sub-issue, mark-pull-request-as-ready-for-review, merge-pull-request, missing-data, missing-tool, noop, push-to-pull-request-branch, remove-labels, reply-to-pull-request-review-comment, resolve-pull-request-review-thread, set-issue-field, set-issue-type, submit-pull-request-review, threat-detection, unassign-from-user, update-discussion, update-issue, update-project, update-pull-request, update-release, upload-artifact, upload-asset. See documentation for complete details.",
"$comment": "Required if workflow creates or modifies GitHub resources. Operations requiring safe-outputs: approve-workflow-run, autofix-code-scanning-alert, add-comment, add-labels, add-reviewer, assign-milestone, assign-to-agent, assign-to-user, close-discussion, close-issue, close-pull-request, create-agent-session, create-check-run, create-code-scanning-alert, create-discussion, create-issue, create-project, create-project-status-update, create-pull-request, create-pull-request-review-comment, dispatch-workflow, hide-comment, link-sub-issue, mark-pull-request-as-ready-for-review, merge-pull-request, missing-data, missing-tool, noop, push-to-pull-request-branch, remove-labels, reply-to-pull-request-review-comment, resolve-pull-request-review-thread, set-issue-field, set-issue-type, submit-pull-request-review, threat-detection, unassign-from-user, update-discussion, update-issue, update-project, update-pull-request, update-release, upload-artifact, upload-asset. See documentation for complete details.",
@@ -44,7 +44,6 @@ func TestHasSafeOutputTypeNewKeys(t *testing.T) {
"upload-artifact",
"update-release",
"create-agent-session",
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot remove all code for deprecated create-agent-task and add a codemod to migrate to create-agent-session

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer failed. Please review the logs for details.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by Ponytail Reviewer for #53840

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-19T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - deprecated create-agent-task compatibility was removed from parser/registry/schema
  - regression test codifies the break instead of preserving parity
files_reviewed:
  - pkg/parser/schemas/main_workflow_schema.json
  - pkg/workflow/create_agent_session.go
  - pkg/workflow/create_agent_session_test.go
  - pkg/workflow/safe_output_handlers.go
  - pkg/workflow/safe_outputs_fix_test.go
comment_count: 4

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 6.37 AIC · ⌖ 8.38 AIC · ⊞ 7K ·
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.

Request changes

This patch is not a behavior-preserving refactor. It removes deprecated create-agent-task support from the parser entrypoint, the safe-output handler registry, and the JSON schema, while also adding a test that blesses the break.

Blocking themes
  • legacy create-agent-task workflows no longer parse into agent-session config
  • handler-table lookups stop recognizing the deprecated key, breaking registry-driven behavior
  • schema validation now rejects the deprecated key before runtime parsing can recover
  • the new regression test codifies the incompatible behavior instead of protecting parity

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 6.37 AIC · ⌖ 8.38 AIC · ⊞ 7K
Comment /review to run again

@@ -34,7 +34,6 @@ var safeOutputHandlers = []safeOutputHandlerDescriptor{
},
{
Key: "create-agent-session",

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.

Removing the deprecated alias here is not a harmless cleanup: registry-based callers like hasSafeOutputType, SafeOutputsConfigFromKeys, and any other key lookup through getSafeOutputHandlerByKey will stop recognizing create-agent-task, so existing workflows silently lose the handler before they ever reach your shared parser.

💡 Why this blocks merge

The PR description claims backward compatibility for the deprecated key, but this change severs that compatibility in the central dispatch table. That means legacy configs can now fail capability checks, permission derivation, or handler instantiation even if parsing code were kept compatible elsewhere.

Keep the alias until the deprecated key is intentionally removed everywhere, for example:

{
    Key:       "create-agent-session",
    Aliases:   []string{"create-agent-task"},
    StructField: "CreateAgentSessions",
    ToolName:  "create_agent_session",
}

Without that, this refactor changes behavior, not just structure.

"safe-outputs": {
"type": "object",
"$comment": "Required if workflow creates or modifies GitHub resources. Operations requiring safe-outputs: approve-workflow-run, autofix-code-scanning-alert, add-comment, add-labels, add-reviewer, assign-milestone, assign-to-agent, assign-to-user, close-discussion, close-issue, close-pull-request, create-agent-session, create-agent-task (deprecated, use create-agent-session), create-check-run, create-code-scanning-alert, create-discussion, create-issue, create-project, create-project-status-update, create-pull-request, create-pull-request-review-comment, dispatch-workflow, hide-comment, link-sub-issue, mark-pull-request-as-ready-for-review, merge-pull-request, missing-data, missing-tool, noop, push-to-pull-request-branch, remove-labels, reply-to-pull-request-review-comment, resolve-pull-request-review-thread, set-issue-field, set-issue-type, submit-pull-request-review, threat-detection, unassign-from-user, update-discussion, update-issue, update-project, update-pull-request, update-release, upload-artifact, upload-asset. See documentation for complete details.",
"$comment": "Required if workflow creates or modifies GitHub resources. Operations requiring safe-outputs: approve-workflow-run, autofix-code-scanning-alert, add-comment, add-labels, add-reviewer, assign-milestone, assign-to-agent, assign-to-user, close-discussion, close-issue, close-pull-request, create-agent-session, create-check-run, create-code-scanning-alert, create-discussion, create-issue, create-project, create-project-status-update, create-pull-request, create-pull-request-review-comment, dispatch-workflow, hide-comment, link-sub-issue, mark-pull-request-as-ready-for-review, merge-pull-request, missing-data, missing-tool, noop, push-to-pull-request-branch, remove-labels, reply-to-pull-request-review-comment, resolve-pull-request-review-thread, set-issue-field, set-issue-type, submit-pull-request-review, threat-detection, unassign-from-user, update-discussion, update-issue, update-project, update-pull-request, update-release, upload-artifact, upload-asset. See documentation for complete details.",

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.

Dropping create-agent-task from the schema makes legacy workflows fail validation before runtime parsing ever happens, so this is a hard compatibility break, not just dead-code cleanup.

💡 Why this blocks merge

safe-outputs is schema-validated with additionalProperties: false. Once this property disappears, any existing workflow still using the deprecated key is rejected immediately, which contradicts the PR description's claim that deprecated-key behavior is preserved.

If the intent is a real removal, it needs an explicit breaking-change path. If the intent is a refactor, keep the deprecated schema entry marked as deprecated until all downstream compatibility hooks are removed together.

})

if config != nil {
t.Fatal("parseAgentSessionConfig() should ignore deprecated create-agent-task key")

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.

This test is locking in the regression instead of protecting compatibility: it asserts that the deprecated key should now be ignored, which is the opposite of the documented behavior and the PR description.

💡 Why this blocks merge

The old code intentionally supported create-agent-task with a warning, and the PR body explicitly says that behavior is preserved. A test that expects nil here will bless the breaking change and make future fixes look like regressions.

This should instead verify parity with create-agent-session, plus precedence when both keys are present, e.g. assert that base, target-repo, and default max still parse from the deprecated key.

if configData, exists := outputMap["create-agent-task"]; exists {
createAgentSessionLog.Print("WARNING: Using deprecated 'create-agent-task' configuration. Please migrate to 'create-agent-session' using 'gh aw fix'")
agentSessionConfig := &CreateAgentSessionConfig{}
return nil

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 deprecated-key fallback was removed from parseAgentSessionConfig, so a workflow that still uses safe-outputs.create-agent-task now gets nil instead of a parsed config. That is a breaking change disguised as a refactor.

💡 Why this blocks merge

Before this patch, create-agent-task still parsed with a warning; after this patch the function returns nil as soon as create-agent-session is absent. Any caller expecting deprecated-key compatibility now behaves as if agent-session output was never configured.

The extraction helper is fine, but the entrypoint still needs the old fallback:

if configData, exists := outputMap["create-agent-session"]; exists {
    return c.parseAgentSessionConfigMap(configData)
}
if configData, exists := outputMap["create-agent-task"]; exists {
    createAgentSessionLog.Print("WARNING: Using deprecated 'create-agent-task' configuration. Please migrate to 'create-agent-session' using 'gh aw fix'")
    return c.parseAgentSessionConfigMap(configData)
}

As written, this refactor breaks existing workflows and contradicts the stated preserved behavior.

@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 /codebase-design and /diagnosing-bugs — requesting changes for a backward-compatibility breakage that contradicts the PR's stated goals.

📋 Key Themes

Critical: Stated goal vs. actual behavior are inverted

The PR description says create-agent-task backward compat is preserved, but the diff breaks it in three coordinated places:

Location What was removed Effect
safe_output_handlers.go Aliases: []string{"create-agent-task"} hasSafeOutputType / SafeOutputsConfigFromKeys no longer resolve the deprecated key
create_agent_session.go Entire create-agent-task fallback + deprecation warning Existing workflows using the old key silently produce no config
main_workflow_schema.json Full create-agent-task property definition Legacy workflows fail schema validation before reaching the parser

The new test (TestParseAgentSessionConfigWithDeprecatedKey) asserts config != nil is false when the deprecated key is used — encoding the breakage as expected behaviour rather than catching it as a regression.

What the fix looks like

Re-add the create-agent-task fallback in parseAgentSessionConfig (calling the new shared helper), restore the alias in safe_output_handlers.go, keep create-agent-task in the schema as deprecated, and flip the test assertion to verify the deprecated key does parse correctly with matching field values.

Positive Highlights

  • parseAgentSessionConfigMap extraction is the right shape — a clean deep module
  • ✅ PR description and commit message are clear and well-structured
  • ✅ New precedence test is the right kind of test — just needs the assertion corrected

The inline comments posted already cover each individual site. Addressing all five will bring the implementation in line with the PR's stated backward-compatibility promise.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 20.1 AIC · ⌖ 9.94 AIC · ⊞ 7.8K
Comment /matt 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.

Review: Backward Compatibility Broken

This refactor removes create-agent-task support entirely rather than consolidating it onto the shared path. Three blocking issues:

  1. safe_output_handlers.go — The Aliases field is removed, so registry functions (hasSafeOutputType, SafeOutputsConfigFromKeys) no longer resolve create-agent-task. Existing compiled workflows referencing this key will silently fail.

  2. create_agent_session.go — The deprecated-key fallback block (and its warning log) was deleted. Any workflow using create-agent-task: now returns nil config instead of being parsed and warned to migrate.

  3. main_workflow_schema.json — Removing the create-agent-task schema property causes strict schema validation to reject legacy workflows before they reach the Go parser.

Suggested fix: route the deprecated key through parseAgentSessionConfigMap (call it for both keys in parseAgentSessionConfig), keep the schema entry marked deprecated: true, and restore the alias in the handler descriptor until a proper removal cycle is complete.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 19.6 AIC · ⌖ 8.88 AIC · ⊞ 5.7K

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot set create-agent-task as an x synonym in the json schema

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot remove all code for deprecated create-agent-task and add a codemod to migrate to create-agent-session

Removed runtime/schema support and stale documentation for create-agent-task; the registered gh aw fix codemod remains and migration examples now use agent-session outputs. Addressed in 49aad31.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review "gh agent-task" in docs and update with latest gh command name (checks github docs)

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@pelikhan Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: f7d2e25c-0f4f-48a1-a5e0-29f6ad2f6b4b

Sorry for the inconvenience!

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review "gh agent-task" in docs and update with latest gh command name (checks github docs)

Updated the reference to the current GitHub CLI gh agent-task create command in 2d721cb.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Deduplicate create-agent-session parsing for current and deprecated config keys

3 participants