Skip to content

Commit 1aa1d39

Browse files
author
Mark Pollack
committed
Show that closing a session signals its running prompt's context
session/close cancels the session's running prompt as session/cancel does, so the prompt's context reports it; documented on isCancelled() and covered by a test.
1 parent 87c8b15 commit 1aa1d39

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎acp-core/src/main/java/com/agentclientprotocol/sdk/agent/PromptContext.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ public interface PromptContext {
203203
// ========================================================================
204204

205205
/**
206-
* Whether this prompt has been cancelled: by {@code session/cancel} for its session, by
207-
* {@code $/cancel_request} for its request, or by the agent itself (the cancel grace
206+
* Whether this prompt has been cancelled: by {@code session/cancel} or {@code session/close}
207+
* for its session, by {@code $/cancel_request} for its request, or by the agent itself (the cancel grace
208208
* period or the maximum prompt duration passed, or the connection closed). Once true, it
209209
* stays true.
210210
*

‎acp-core/src/main/java/com/agentclientprotocol/sdk/agent/SyncPromptContext.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ public interface SyncPromptContext {
204204
// ========================================================================
205205

206206
/**
207-
* Whether this prompt has been cancelled: by {@code session/cancel} for its session, by
208-
* {@code $/cancel_request} for its request, or by the agent itself (the cancel grace
207+
* Whether this prompt has been cancelled: by {@code session/cancel} or {@code session/close}
208+
* for its session, by {@code $/cancel_request} for its request, or by the agent itself (the cancel grace
209209
* period or the maximum prompt duration passed, or the connection closed). Once true, it
210210
* stays true. A long-running handler polls it between steps:
211211
* <pre>{@code

‎acp-core/src/test/java/com/agentclientprotocol/sdk/integration/PromptContextCancellationTest.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,39 @@ void anUncancelledPromptIsNotCancelledAndACallbackRegisteredAfterACancelRunsAtOn
191191
}
192192
}
193193

194+
/** session/close cancels the session's running prompt, which its context reports. */
195+
@Test
196+
void closingTheSessionSignalsItsPrompt() throws Exception {
197+
CountDownLatch sawCancel = new CountDownLatch(1);
198+
InMemoryTransportPair pair = InMemoryTransportPair.create();
199+
AcpSyncAgent agent = AcpAgent.sync(pair.agentTransport())
200+
.requestTimeout(TIMEOUT)
201+
.cancelGracePeriod(LONG_GRACE)
202+
.newSessionHandler(request -> new AcpSchema.NewSessionResponse(SESSION, null, null))
203+
.closeSessionHandler(request -> new AcpSchema.CloseSessionResponse(null))
204+
.promptHandler((request, context) -> {
205+
while (!context.isCancelled()) {
206+
sleep(10);
207+
}
208+
sawCancel.countDown();
209+
return PromptResponse.cancelled();
210+
})
211+
.build();
212+
agent.start();
213+
AcpAsyncClient client = client(pair);
214+
try {
215+
Mono<PromptResponse> response = startPrompt(client);
216+
client.closeSession(new AcpSchema.CloseSessionRequest(SESSION, null)).block(TIMEOUT);
217+
218+
assertThat(sawCancel.await(5, TimeUnit.SECONDS)).isTrue();
219+
assertThat(response.block(TIMEOUT).stopReason()).isEqualTo(AcpSchema.StopReason.CANCELLED);
220+
}
221+
finally {
222+
close(client, pair);
223+
agent.closeGracefully();
224+
}
225+
}
226+
194227
private static AcpAsyncClient client(InMemoryTransportPair pair) {
195228
return AcpClient.async(pair.clientTransport()).requestTimeout(TIMEOUT).build();
196229
}

0 commit comments

Comments
 (0)