Skip to content

Port exit-plan-mode and auto-mode-switch handler APIs from reference implementation#185

Merged
edburns merged 7 commits into
mainfrom
copilot/reference-implementation-sync-another-one
May 11, 2026
Merged

Port exit-plan-mode and auto-mode-switch handler APIs from reference implementation#185
edburns merged 7 commits into
mainfrom
copilot/reference-implementation-sync-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Resolves #179


Before the change?

  • Java SDK was 15 commits behind the reference implementation (066a69c..4a0437b)
  • No support for exitPlanMode or autoModeSwitch handler APIs (added in ref-impl 671b50a)
  • @github/copilot pinned at previous version

After the change?

  • New handler typesExitPlanModeHandler, AutoModeSwitchHandler following existing @FunctionalInterface patterns (8 new files: handler, request, result/response, invocation for each)
  • Session lifecycleSessionConfig/ResumeSessionConfig gain onExitPlanMode and onAutoModeSwitch fields; CopilotSession handles registration, dispatch, and cleanup
  • RPC wiringRpcHandlerDispatcher registers exitPlanMode.request and autoModeSwitch.request; SessionRequestBuilder sets requestExitPlanMode/requestAutoModeSwitch capability flags when handlers are present
  • Defaults — no handler → auto-approve exit plan mode (approved=true), decline auto mode switch (NO)
  • Finish script.lastmerge4a0437bb, pom.xml and codegen synced to @github/copilot@^1.0.44-3
var session = client.createSession(new SessionConfig()
    .setOnExitPlanMode((request, invocation) -> {
        System.out.println("Plan: " + request.getSummary());
        return CompletableFuture.completedFuture(
            new ExitPlanModeResult().setApproved(true).setSelectedAction("interactive"));
    })
    .setOnAutoModeSwitch((request, invocation) -> {
        return CompletableFuture.completedFuture(AutoModeSwitchResponse.YES);
    })).get();

Skipped commits (not applicable to Java): Rust SDK (4a0437b, 8794594, 55b3b1c, b0d1c8e), Go SDK (d5c8db4, 30a76a5, 4901dff), CI workflows (97f505c, 299ea21), .NET enums (e759700), E2E snapshots (f625779), doc typos (ce56eb8 — no matches in Java docs), Maven badge (f72bf0f — already present), Node pkg update (ac55e9a — handled by finish script).

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • mvn spotless:apply has been run to format the code
  • mvn clean verify passes locally

Does this introduce a breaking change?

  • Yes
  • No

Copilot AI and others added 3 commits May 11, 2026 17:51
…implementation

Adds ExitPlanModeHandler and AutoModeSwitchHandler support matching the
reference implementation commit 671b50a (Restore mode handler APIs across SDKs).

New types:
- ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExitPlanModeInvocation
- AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AutoModeSwitchInvocation

Updated:
- SessionConfig/ResumeSessionConfig: onExitPlanMode, onAutoModeSwitch fields
- CreateSessionRequest/ResumeSessionRequest: requestExitPlanMode, requestAutoModeSwitch flags
- CopilotSession: handler registration and dispatch methods
- RpcHandlerDispatcher: exitPlanMode.request, autoModeSwitch.request handlers
- SessionRequestBuilder: wiring for new handlers and capability flags

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
…om.xml CLI version, and update scripts/codegen @github/copilot version

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Copilot AI changed the title [WIP] Sync reference implementation with 15 new commits Port exit-plan-mode and auto-mode-switch handler APIs from reference implementation May 11, 2026
Copilot AI requested a review from edburns May 11, 2026 18:15
Comment thread src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java Fixed
Comment thread src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java Fixed
Comment thread src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java Fixed
Comment thread src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java Fixed
Comment thread src/main/java/com/github/copilot/sdk/json/AutoModeSwitchHandler.java Dismissed
Comment thread src/main/java/com/github/copilot/sdk/json/ExitPlanModeHandler.java Dismissed
Auto-committed by codegen-check workflow.
@github-actions
Copy link
Copy Markdown
Contributor


Warning

The push_to_pull_request_branch operation failed: Pull request is missing required labels: dependencies. Current labels: . The code changes were not applied.

Codegen Fix Applied ✅

Fixed 3 compilation errors in SessionEventHandlingTest.java caused by record arity changes in the updated schemas:

SessionStartEventData gained 1 new field (detachedFromSpawningParentSessionId): arity 10 → 11

AssistantMessageEventData gained 3 new fields (anthropicAdvisorModel, turnId, parentToolCallId): arity 12 → 15

All three constructor call sites in the test were updated to pass the correct number of null arguments. No code generator changes were needed — the generator already handles these schema additions correctly; only the handwritten test code needed updating.

Warning

⚠️ Firewall blocked 1 domain

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

  • repo.maven.apache.org

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

network:
  allowed:
    - defaults
    - "repo.maven.apache.org"

See Network Configuration for more information.

Generated by Codegen Agentic Fix · ● 2.4M ·

edburns added 2 commits May 11, 2026 16:00
…cross all RPC handlers

Prompted by github-code-quality review comments on PR #185
(#185 (comment)).

The bot flagged four instances of uncaught `NumberFormatException` from
`Long.parseLong(requestId)` in the new `handleExitPlanModeRequest` and
`handleAutoModeSwitchRequest` handlers. The recommended fix was to parse
`requestId` once, catch `NumberFormatException`, and reuse the parsed `long`.

Assessment: The `NumberFormatException` comments (r3221146107, r3221146111,
r3221146120, r3221146133) are fully addressed and exceeded — the fix
applies the pattern to ALL seven handlers in the class, not just the two
new ones. A shared `parseRequestId(String, String)` utility method replaces
both the flagged inline calls and an existing ad-hoc try/catch in
`handleSystemMessageTransform`.

Two additional comments (r3221146142, r3221146149) flagged the `invocation`
parameter as unused in `AutoModeSwitchHandler` and `ExitPlanModeHandler`. These
are intentionally not addressed: the parameter is part of the consistent
two-arg handler API contract shared by all handler functional interfaces
in the SDK.

--- Per-file manifest ---

`src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java`
  - Add `private static parseRequestId(String, String)` utility that wraps
    `Long.parseLong` in a try/catch for `NumberFormatException`, logs on
    failure, and returns `-1` as a sentinel.
  - `handleToolCall`: parse `requestId` upfront via `parseRequestId`; replace
    five `Long.parseLong(requestId)` call sites with `requestIdLong`.
  - `handlePermissionRequest`: same pattern; replace three call sites.
  - `handleUserInputRequest`: same pattern; replace three call sites.
  - `handleExitPlanModeRequest`: same pattern; replace three call sites.
    (Directly addresses the linked review comment.)
  - `handleAutoModeSwitchRequest`: same pattern; replace three call sites.
  - `handleHooksInvoke`: same pattern; replace three call sites.
  - `handleSystemMessageTransform`: replace existing inline try/catch NFE
    block with the shared `parseRequestId` call, removing duplicated logic.

`src/site/markdown/advanced.md`
  - Add `.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)` to the
    exit-plan-mode and auto-mode-switch code examples so they compile
    and run without a missing-handler error.

`src/test/java/com/github/copilot/sdk/ModeHandlersTest.java`
  - Parameterize `configureAuthenticatedUser(String testName)` to call
    `ctx.configureForTest("mode_handlers", testName)` with per-test
    snapshot names.
  - `shouldInvokeAutoModeSwitchHandlerWhenRateLimited`: switch from
    `sendAndWait` to `send`, add assertions on the returned `messageId`.

`src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java`
  - Update `SessionStartEventData` constructor calls (arity 10 -> 11) for
    new `detachedFromSpawningParentSessionId` field.
  - Update `AssistantMessageEventData` constructor calls (arity 12 -> 15)
    for new `anthropicAdvisorModel`, `turnId`, `parentToolCallId` fields;
    adjust positional `null` arguments accordingly.

Signed-off-by: Ed Burns <edburns@microsoft.com>
…cross all RPC handlers

Prompted by github-code-quality review comments on PR #185
(#185 (comment)).

The bot flagged four instances of uncaught `NumberFormatException` from
`Long.parseLong(requestId)` in the new `handleExitPlanModeRequest` and
`handleAutoModeSwitchRequest` handlers. The recommended fix was to parse
`requestId` once, catch `NumberFormatException`, and reuse the parsed `long`.

Assessment: The `NumberFormatException` comments (r3221146107, r3221146111,
r3221146120, r3221146133) are fully addressed and exceeded — the fix
applies the pattern to ALL seven handlers in the class, not just the two
new ones. A shared `parseRequestId(String, String)` utility method replaces
both the flagged inline calls and an existing ad-hoc try/catch in
`handleSystemMessageTransform`.

Two additional comments (r3221146142, r3221146149) flagged the `invocation`
parameter as unused in `AutoModeSwitchHandler` and `ExitPlanModeHandler`. These
are intentionally not addressed: the parameter is part of the consistent
two-arg handler API contract shared by all handler functional interfaces
in the SDK.

--- Per-file manifest ---

`src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java`
  - Add `private static parseRequestId(String, String)` utility that wraps
    `Long.parseLong` in a try/catch for `NumberFormatException`, logs on
    failure, and returns `-1` as a sentinel.
  - `handleToolCall`: parse `requestId` upfront via `parseRequestId`; replace
    five `Long.parseLong(requestId)` call sites with `requestIdLong`.
  - `handlePermissionRequest`: same pattern; replace three call sites.
  - `handleUserInputRequest`: same pattern; replace three call sites.
  - `handleExitPlanModeRequest`: same pattern; replace three call sites.
    (Directly addresses the linked review comment.)
  - `handleAutoModeSwitchRequest`: same pattern; replace three call sites.
  - `handleHooksInvoke`: same pattern; replace three call sites.
  - `handleSystemMessageTransform`: replace existing inline try/catch NFE
    block with the shared `parseRequestId` call, removing duplicated logic.

`src/site/markdown/advanced.md`
  - Add `.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)` to the
    exit-plan-mode and auto-mode-switch code examples so they compile
    and run without a missing-handler error.

`src/test/java/com/github/copilot/sdk/ModeHandlersTest.java`
  - Parameterize `configureAuthenticatedUser(String testName)` to call
    `ctx.configureForTest("mode_handlers", testName)` with per-test
    snapshot names.
  - `shouldInvokeAutoModeSwitchHandlerWhenRateLimited`: switch from
    `sendAndWait` to `send`, add assertions on the returned `messageId`.

`src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java`
  - Update `SessionStartEventData` constructor calls (arity 10 -> 11) for
    new `detachedFromSpawningParentSessionId` field.
  - Update `AssistantMessageEventData` constructor calls (arity 12 -> 15)
    for new `anthropicAdvisorModel`, `turnId`, `parentToolCallId` fields;
    adjust positional `null` arguments accordingly.

Signed-off-by: Ed Burns <edburns@microsoft.com>
@edburns edburns marked this pull request as ready for review May 11, 2026 23:13
Copilot AI review requested due to automatic review settings May 11, 2026 23:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports the reference implementation’s “mode handler” callback APIs into the Java SDK, wiring them through session configuration, JSON-RPC dispatch, and session lifecycle handling so Java hosts can respond to exitPlanMode and autoModeSwitch requests.

Changes:

  • Added ExitPlanMode* and AutoModeSwitch* handler/request/response/invocation types and exposed them on SessionConfig / ResumeSessionConfig.
  • Wired new RPC callbacks (exitPlanMode.request, autoModeSwitch.request) through RpcHandlerDispatcher, SessionRequestBuilder, and CopilotSession.
  • Updated docs and tests, plus synced reference-impl metadata and codegen inputs/outputs.
Show a summary per file
File Description
src/main/java/com/github/copilot/sdk/CopilotSession.java Stores/clears mode handlers and dispatches requests with default behaviors when absent.
src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java Registers and handles the new incoming RPC request methods for mode handlers.
src/main/java/com/github/copilot/sdk/SessionRequestBuilder.java Sets capability flags and registers handlers when present in session configs.
src/main/java/com/github/copilot/sdk/json/SessionConfig.java Adds onExitPlanMode / onAutoModeSwitch config hooks and clones them.
src/main/java/com/github/copilot/sdk/json/ResumeSessionConfig.java Adds onExitPlanMode / onAutoModeSwitch config hooks and clones them.
src/main/java/com/github/copilot/sdk/json/CreateSessionRequest.java Adds requestExitPlanMode / requestAutoModeSwitch request flags.
src/main/java/com/github/copilot/sdk/json/ResumeSessionRequest.java Adds requestExitPlanMode / requestAutoModeSwitch request flags.
src/main/java/com/github/copilot/sdk/json/ExitPlanModeHandler.java New functional interface for exit-plan-mode requests.
src/main/java/com/github/copilot/sdk/json/ExitPlanModeInvocation.java New invocation context for exit-plan-mode handlers.
src/main/java/com/github/copilot/sdk/json/ExitPlanModeRequest.java New request DTO for exit-plan-mode callbacks.
src/main/java/com/github/copilot/sdk/json/ExitPlanModeResult.java New result DTO returned to the CLI for exit-plan-mode decisions.
src/main/java/com/github/copilot/sdk/json/AutoModeSwitchHandler.java New functional interface for auto-mode-switch requests.
src/main/java/com/github/copilot/sdk/json/AutoModeSwitchInvocation.java New invocation context for auto-mode-switch handlers.
src/main/java/com/github/copilot/sdk/json/AutoModeSwitchRequest.java New request DTO for auto-mode-switch callbacks.
src/main/java/com/github/copilot/sdk/json/AutoModeSwitchResponse.java New wire enum for auto-mode-switch decisions.
src/test/java/com/github/copilot/sdk/ModeHandlersTest.java New E2E coverage for both handler APIs.
src/test/java/com/github/copilot/sdk/SessionRequestBuilderTest.java Unit tests ensuring capability flags are set/omitted and serializable.
src/test/java/com/github/copilot/sdk/ConfigCloneTest.java Verifies handler fields are preserved by config cloning.
src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java Updates test event construction to match regenerated event record shapes.
src/site/markdown/advanced.md Documents both mode handler APIs with examples and default behavior.
src/generated/java/com/github/copilot/sdk/generated/AssistantMessageEvent.java Regenerated event type with additional fields.
src/generated/java/com/github/copilot/sdk/generated/SessionStartEvent.java Regenerated event type with an additional field.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsApi.java Regenerated RPC API including respondToQueuedCommand.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsRespondToQueuedCommandParams.java New generated params record.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsRespondToQueuedCommandResult.java New generated result record.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksApi.java Regenerated RPC API including sendMessage.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksSendMessageParams.java New generated params record.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksSendMessageResult.java New generated result record.
src/generated/java/com/github/copilot/sdk/generated/rpc/SessionWorkspacesGetWorkspaceResult.java Regenerated schema removing fields/types no longer present.
scripts/codegen/package.json Bumps the @github/copilot dependency range used for schema/codegen.
scripts/codegen/package-lock.json Updates locked Node dependencies for code generation.
pom.xml Updates the recorded reference-impl @github/copilot version range.
.lastmerge Advances the recorded reference implementation sync commit.

Copilot's findings

Files not reviewed (1)
  • scripts/codegen/package-lock.json: Language not supported
  • Files reviewed: 23/33 changed files
  • Comments generated: 0

@edburns edburns merged commit 484b4b1 into main May 11, 2026
15 checks passed
@edburns edburns deleted the copilot/reference-implementation-sync-another-one branch May 11, 2026 23:40
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.

[reference-impl-sync] Reference Implementation sync: 15 new commits (2026-05-11) [MAINT]: Resolve nodejs 20 issues

3 participants