Skip to content

Commit 0fb5e9e

Browse files
author
Mark Pollack
committed
Micronaut: transport type in any case, client beans only for a named transport, stdio close bound
- Bind acp.agent.transport.type and acp.client.transport.type through AcpTransportType.parse, so WebSocket binds; an unknown value fails. - Create the client beans only when transport.type, stdio.command, websocket.uri or http.uri is set, as Spring Boot and AcpClientSettings.hasTransport() do. - Bound a stdio agent's close by the new acp.agent.shutdown-timeout (default 10s) instead of the HTTP listener's shutdown-timeout.
1 parent e94215a commit 0fb5e9e

12 files changed

Lines changed: 264 additions & 31 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10481048

10491049
### Fixed
10501050

1051+
- **Micronaut: `acp.agent.transport.type` and `acp.client.transport.type` bind in any case.**
1052+
`AcpTransportType` reads the type in any case, as Spring Boot and Quarkus do, but Micronaut's own
1053+
enum conversion took only `websocket` or `WEBSOCKET`: a mixed-case `WebSocket` failed the agent's
1054+
startup, and on the client was silently dropped, so the transport was inferred as if no type were
1055+
set. Both now bind through `AcpTransportType.parse`, and an unknown value fails the startup with
1056+
"Unknown ACP transport type '...': use stdio, websocket or http" on both sides.
1057+
1058+
- **Micronaut: only a type, a command or a URI creates the client beans.** Any
1059+
`acp.client.transport.*` property created them, so `acp.client.transport.websocket.connect-timeout`
1060+
alone (or `stdio.args`, `stdio.env.*`) made the client beans, which then failed with "An ACP
1061+
client needs a transport". The beans are now created only when `acp.client.transport.type`,
1062+
`.stdio.command`, `.websocket.uri` or `.http.uri` is set, the test Spring Boot and
1063+
`AcpClientSettings.hasTransport()` use. Behaviour change: such a property alone now leaves the
1064+
application without a client, instead of failing it.
1065+
1066+
- **Micronaut: a stdio agent's close has its own bound, `acp.agent.shutdown-timeout`** (default
1067+
`10s`). Closing the context waited for a stdio agent at most
1068+
`acp.agent.transport.http.shutdown-timeout` plus 5 seconds, a listener setting that a stdio agent
1069+
otherwise ignores. The HTTP listener keeps that bound; a stdio agent, or an `AcpAgentTransport`
1070+
bean of the application's own, now waits at most `acp.agent.shutdown-timeout`, then closes at
1071+
once. The default keeps the old default wait, 10 seconds, which is also as long as the SDK's own
1072+
graceful close takes at most. Behaviour change: an application that set the HTTP key to bound its
1073+
stdio agent's close sets `acp.agent.shutdown-timeout` instead.
1074+
10511075
- **Spring Boot: `spring.acp.agent.enabled=false` turns the agent off on every transport.** The
10521076
stdio transport and the HTTP endpoint already backed off, but `AcpAgentAutoConfiguration` did
10531077
not: it still built the `AcpAgentFactory` from the `@AcpAgent` bean and still served the agent on

‎acp-micronaut/README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ public final class Application {
8787
| `acp.agent.cancel-grace-period` | `60s` | after `session/cancel`, the SDK answers `cancelled` itself; `0s` for never |
8888
| `acp.agent.max-prompt-duration` | `0s` (none) | a longer prompt is answered `-32800` |
8989
| `acp.agent.shutdown-on-transport-end` | `true` | close the context when the stdio input ends |
90-
| `acp.agent.transport.type` | `stdio` | `stdio`, `http` or `websocket` (the last two mean the same listener) |
90+
| `acp.agent.shutdown-timeout` | `10s` | how long closing waits for a stdio agent's graceful close, then closes it at once |
91+
| `acp.agent.transport.type` | `stdio` | `stdio`, `http` or `websocket`, in any case (the last two mean the same listener) |
9192
| `acp.agent.transport.http.port` | `8080` | the listener's own port; `0` for an ephemeral one (`AcpAgentRuntime.port()`) |
9293
| `acp.agent.transport.http.path` | `/acp` | |
9394
| `acp.agent.transport.http.max-post-body-size` | SDK (16MB) | e.g. `4MB` |
94-
| `acp.agent.transport.http.keep-alive-interval`, `mailbox-capacity`, `max-pending-sse-events`, `max-web-socket-pending-frames`, `max-provisional-sessions`, `max-concurrent-streams-per-connection`, `shutdown-timeout` | SDK | `StreamableHttpAcpAgentTransportOptions` |
95+
| `acp.agent.transport.http.keep-alive-interval`, `mailbox-capacity`, `max-pending-sse-events`, `max-web-socket-pending-frames`, `max-provisional-sessions`, `max-concurrent-streams-per-connection`, `shutdown-timeout` | SDK | `StreamableHttpAcpAgentTransportOptions`; closing waits for the listener at most `shutdown-timeout` plus 5 seconds |
9596

9697
An application bean of type `AcpAgentTransport` replaces stdio, for example the in-memory
9798
transport of `acp-test` in a test.
@@ -102,7 +103,8 @@ one, not inside it. It serves HTTP/1.1, cleartext HTTP/2 and WebSocket upgrades
102103

103104
## A client
104105

105-
A client is configured when `acp.client.transport.*` is set. It has three beans: the transport,
106+
A client is configured when a transport is named: `acp.client.transport.type`, `.stdio.command`,
107+
`.websocket.uri` or `.http.uri` is set, as in Spring Boot and Quarkus. It has three beans: the transport,
106108
an `AcpAsyncClient`, and an `AcpSyncClient` facade over that same client, which is one session on
107109
one connection. Creating the client bean connects its transport (for stdio, it starts the agent
108110
process); `initialize()` then performs the ACP handshake. It closes gracefully, once, with the
@@ -123,7 +125,7 @@ class Updates implements AcpClientCustomizer {
123125
|---|---|---|
124126
| `acp.client.request-timeout` | `60s` | |
125127
| `acp.client.prompt-timeout` | none | a longer prompt turn fails and is cancelled |
126-
| `acp.client.transport.type` | inferred | `stdio`, `websocket` or `http`. When it is unset, the transport is the only one whose command or URI is set; with several set, it is required |
128+
| `acp.client.transport.type` | inferred | `stdio`, `websocket` or `http`, in any case. When it is unset, the transport is the only one whose command or URI is set; with several set, it is required |
127129
| `acp.client.transport.stdio.command`, `.args`, `.env.*` | | the agent process; `env` keys keep their case |
128130
| `acp.client.transport.websocket.uri`, `.connect-timeout` | `10s` | `ws://host:port/acp` |
129131
| `acp.client.transport.http.uri` | | `http://host:port/acp` |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025-2026 the original author or authors.
3+
*/
4+
5+
package com.agentclientprotocol.sdk.micronaut;
6+
7+
import java.util.Optional;
8+
9+
import com.agentclientprotocol.sdk.integration.AcpTransportType;
10+
import io.micronaut.core.convert.ConversionContext;
11+
import io.micronaut.core.convert.TypeConverter;
12+
import jakarta.inject.Singleton;
13+
14+
/**
15+
* Binds {@code acp.agent.transport.type} and {@code acp.client.transport.type} by
16+
* {@link AcpTransportType#parse(String)}: in any case, ignoring surrounding white space, as the
17+
* Spring Boot and Quarkus integrations do. Micronaut's own enum conversion accepted only the
18+
* constant's name or its lower-case form, so {@code WebSocket} failed to bind.
19+
*/
20+
@Singleton
21+
final class AcpTransportTypeConverter implements TypeConverter<CharSequence, AcpTransportType> {
22+
23+
@Override
24+
public Optional<AcpTransportType> convert(CharSequence value, Class<AcpTransportType> targetType,
25+
ConversionContext context) {
26+
// Thrown, not rejected: Micronaut skips a rejected value of a @Nullable property, and the
27+
// client's type would then be inferred as if it were unset.
28+
return Optional.of(AcpTransportType.parse(value.toString()));
29+
}
30+
31+
}

‎acp-micronaut/src/main/java/com/agentclientprotocol/sdk/micronaut/agent/AcpAgentConfiguration.java‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* acp.agent.cancel-grace-period 60s after session/cancel, then answer "cancelled"
2626
* acp.agent.max-prompt-duration 0s none; else answer -32800 after it
2727
* acp.agent.shutdown-on-transport-end true close the context when stdio input ends
28+
* acp.agent.shutdown-timeout 10s closing waits this long for a stdio agent
2829
* acp.agent.transport.type stdio stdio | http | websocket
2930
* acp.agent.transport.http.port 8080 0 for an ephemeral port
3031
* acp.agent.transport.http.path /acp
@@ -47,6 +48,12 @@ public class AcpAgentConfiguration {
4748
/** The prefix of the agent's settings. */
4849
public static final String PREFIX = "acp.agent";
4950

51+
/**
52+
* The default of {@code acp.agent.shutdown-timeout}, 10 seconds: as long as the SDK's own
53+
* graceful close of an agent takes at most.
54+
*/
55+
public static final Duration DEFAULT_SHUTDOWN_TIMEOUT = Duration.ofSeconds(10);
56+
5057
private boolean enabled = true;
5158

5259
private Duration requestTimeout = Duration.ofSeconds(60);
@@ -57,6 +64,8 @@ public class AcpAgentConfiguration {
5764

5865
private boolean shutdownOnTransportEnd = true;
5966

67+
private Duration shutdownTimeout = DEFAULT_SHUTDOWN_TIMEOUT;
68+
6069
private Transport transport = new Transport();
6170

6271
/**
@@ -159,6 +168,29 @@ public void setShutdownOnTransportEnd(boolean shutdownOnTransportEnd) {
159168
this.shutdownOnTransportEnd = shutdownOnTransportEnd;
160169
}
161170

171+
/**
172+
* Returns how long closing the application context waits for a stdio agent to close
173+
* gracefully, answering or cancelling what is in flight, before it closes the agent at once
174+
* ({@code acp.agent.shutdown-timeout}). Default 10 seconds
175+
* ({@link #DEFAULT_SHUTDOWN_TIMEOUT}), as long as the SDK's graceful close takes at most, so a
176+
* longer value changes nothing. It applies to a single transport (stdio, or an
177+
* {@code AcpAgentTransport} bean of the application's own); the HTTP listener has its own,
178+
* {@code acp.agent.transport.http.shutdown-timeout}. Spring Boot and Quarkus have no such
179+
* property: they wait at most 30 seconds.
180+
* @return the shutdown timeout
181+
*/
182+
public Duration getShutdownTimeout() {
183+
return shutdownTimeout;
184+
}
185+
186+
/**
187+
* Sets how long closing waits for a stdio agent to close gracefully; default 10 seconds.
188+
* @param shutdownTimeout the timeout; zero closes the agent at once
189+
*/
190+
public void setShutdownTimeout(Duration shutdownTimeout) {
191+
this.shutdownTimeout = shutdownTimeout;
192+
}
193+
162194
/**
163195
* Returns the transport properties, {@code acp.agent.transport.*}.
164196
* @return the transport properties
@@ -227,7 +259,7 @@ public static class Transport {
227259
* without it the startup fails naming the module.</li>
228260
* <li>{@code websocket}: the same listener as {@code http}.</li>
229261
* </ul>
230-
* The value is read in lower or upper case.
262+
* The value is read in any case, such as {@code http} or {@code Http}.
231263
* @return the transport type
232264
*/
233265
public AcpTransportType getType() {
@@ -477,8 +509,10 @@ public void setMaxConcurrentStreamsPerConnection(@Nullable Integer maxConcurrent
477509
* Returns how long closing the listener waits for its connections' agents to close
478510
* before it closes the rest at once
479511
* ({@code acp.agent.transport.http.shutdown-timeout}). Default: unset, which keeps the
480-
* SDK's default of 5 seconds. Closing the application context waits for the agent at
481-
* most this long plus 5 seconds. Maps to the transport option {@code shutdownTimeout}.
512+
* SDK's default of 5 seconds. Closing the application context waits for the listener at
513+
* most this long plus 5 seconds. Only the listener reads it: a stdio agent's close is
514+
* bounded by {@code acp.agent.shutdown-timeout}. Maps to the transport option
515+
* {@code shutdownTimeout}.
482516
* @return the timeout, or {@code null} for the SDK's default
483517
*/
484518
public @Nullable Duration getShutdownTimeout() {

‎acp-micronaut/src/main/java/com/agentclientprotocol/sdk/micronaut/agent/AcpAgentRuntime.java‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@
7474
* may also return a {@code Mono}, a {@code CompletionStage} or a single-value Reactive Streams
7575
* {@code Publisher}, which {@code AcpAgentSupport} waits for.
7676
*
77-
* <p>Stopping: closing the context closes the agent gracefully, waiting at most
78-
* {@code acp.agent.transport.http.shutdown-timeout} (5 seconds by default) plus 5 seconds, then at
79-
* once. With {@code micronaut.lifecycle.graceful-shutdown.enabled} the listener drains through
80-
* Micronaut's graceful shutdown first. An application without an embedded server has no shutdown
77+
* <p>Stopping: closing the context closes the agent gracefully, then at once: over stdio after at
78+
* most {@code acp.agent.shutdown-timeout} (10 seconds by default), over HTTP after at most
79+
* {@code acp.agent.transport.http.shutdown-timeout} (5 seconds by default) plus 5 seconds. With
80+
* {@code micronaut.lifecycle.graceful-shutdown.enabled} the listener drains through Micronaut's
81+
* graceful shutdown first. An application without an embedded server has no shutdown
8182
* hook of Micronaut's, so the runtime registers one that closes the agent and the context on
8283
* SIGTERM. With {@code acp.agent.enabled=false} this bean does not exist.
8384
*/
@@ -87,7 +88,7 @@ public final class AcpAgentRuntime implements ApplicationEventListener<StartupEv
8788

8889
private static final Logger logger = LoggerFactory.getLogger(AcpAgentRuntime.class);
8990

90-
/** Margin over the agent's own shutdown bound when closing waits for it. */
91+
/** Margin over the listener's own shutdown bound when closing waits for it. */
9192
private static final Duration CLOSE_MARGIN = Duration.ofSeconds(5);
9293

9394
private final ApplicationContext context;
@@ -213,9 +214,10 @@ public CompletionStage<?> shutdownGracefully() {
213214
}
214215

215216
/**
216-
* Closes the agent gracefully, waiting at most
217-
* {@code acp.agent.transport.http.shutdown-timeout} (5 seconds by default) plus 5 seconds, then
218-
* at once; the application context's close does this. Later calls do nothing.
217+
* Closes the agent gracefully, then at once: over stdio after at most
218+
* {@code acp.agent.shutdown-timeout} (10 seconds by default), over HTTP after at most
219+
* {@code acp.agent.transport.http.shutdown-timeout} (5 seconds by default) plus 5 seconds. The
220+
* application context's close does this. Later calls do nothing.
219221
*/
220222
@PreDestroy
221223
public void close() {
@@ -238,9 +240,13 @@ public void close() {
238240
}
239241
}
240242

241-
private Duration closeTimeout() {
242-
Duration shutdownTimeout = config.getTransport().getHttp().getShutdownTimeout();
243-
Duration bound = (shutdownTimeout != null) ? shutdownTimeout : Duration.ofSeconds(5);
243+
/** How long {@link #close()} waits for the graceful close, by transport. */
244+
Duration closeTimeout() {
245+
if (!config.toSettings().servesHttp()) {
246+
return config.getShutdownTimeout();
247+
}
248+
Duration listenerTimeout = config.getTransport().getHttp().getShutdownTimeout();
249+
Duration bound = (listenerTimeout != null) ? listenerTimeout : Duration.ofSeconds(5);
244250
return bound.plus(CLOSE_MARGIN);
245251
}
246252

‎acp-micronaut/src/main/java/com/agentclientprotocol/sdk/micronaut/client/AcpClientBeans.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
/**
2020
* Creates the application's ACP client from {@code acp.client.*} ({@link AcpClientConfiguration})
21-
* when any {@code acp.client.transport.*} property is set: its transport, an
21+
* when a transport is named, that is when {@code acp.client.transport.type},
22+
* {@code .stdio.command}, {@code .websocket.uri} or {@code .http.uri} is set: its transport, an
2223
* {@link AcpAsyncClient}, and an {@link AcpSyncClient} facade over that same client, so both share
23-
* one transport connection. Inject either. An application without client properties gets none of
24-
* these beans.
24+
* one transport connection. Inject either. An application that sets none of these four gets none
25+
* of these beans, even with other client properties set, such as
26+
* {@code acp.client.transport.websocket.connect-timeout}; Spring Boot and Quarkus decide the same
27+
* way ({@link com.agentclientprotocol.sdk.integration.AcpClientSettings#hasTransport()}).
2528
*
2629
* <p>The beans are singletons, created when first injected or looked up. Creating the client
2730
* connects its transport (for stdio, starts the agent process); the application then calls
@@ -34,7 +37,7 @@
3437
* annotated {@code @Replaces(bean = AcpClientTransport.class, factory = AcpClientBeans.class)}.
3538
*/
3639
@Factory
37-
@Requires(property = AcpClientConfiguration.PREFIX + ".transport")
40+
@Requires(condition = AcpClientTransportCondition.class)
3841
public class AcpClientBeans {
3942

4043
/**

‎acp-micronaut/src/main/java/com/agentclientprotocol/sdk/micronaut/client/AcpClientConfiguration.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
* a WebSocket or Streamable HTTP endpoint), set the client's timeouts, and say which capabilities
2626
* the client advertises. {@link AcpClientBeans} builds the client from them.
2727
*
28-
* <p>Setting a transport is what creates the client beans: any {@code acp.client.transport.*}
29-
* property does, and then {@code acp.client.transport.stdio.command}, {@code .websocket.uri} or
30-
* {@code .http.uri} must name the agent (with {@code acp.client.transport.type} when more than one
31-
* is set).
28+
* <p>Naming a transport is what creates the client beans: setting
29+
* {@code acp.client.transport.type}, {@code .stdio.command}, {@code .websocket.uri} or
30+
* {@code .http.uri}, as in Spring Boot and Quarkus. Another transport property alone, such as
31+
* {@code .websocket.connect-timeout}, creates none. Then {@code .stdio.command},
32+
* {@code .websocket.uri} or {@code .http.uri} must name the agent (with
33+
* {@code acp.client.transport.type} when more than one is set). The type binds in any case, such
34+
* as {@code websocket} or {@code WebSocket}.
3235
*
3336
* <pre>
3437
* acp.client.request-timeout 60s
@@ -181,7 +184,8 @@ public static class Transport {
181184

182185
/**
183186
* Returns the transport ({@code acp.client.transport.type}): {@code stdio},
184-
* {@code websocket} or {@code http}. Maps to {@link AcpClientSettings#transport()}.
187+
* {@code websocket} or {@code http}, in any case. Maps to
188+
* {@link AcpClientSettings#transport()}.
185189
*
186190
* <p>Unset (the default), the transport is the one whose {@code stdio.command},
187191
* {@code websocket.uri} or {@code http.uri} is set; with more than one set, creating the
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025-2026 the original author or authors.
3+
*/
4+
5+
package com.agentclientprotocol.sdk.micronaut.client;
6+
7+
import java.util.List;
8+
9+
import com.agentclientprotocol.sdk.integration.AcpClientSettings;
10+
import io.micronaut.context.condition.Condition;
11+
import io.micronaut.context.condition.ConditionContext;
12+
13+
/**
14+
* Whether the application asks for a client: {@code acp.client.transport.type},
15+
* {@code .stdio.command}, {@code .websocket.uri} or {@code .http.uri} is set. The same test as
16+
* {@link AcpClientSettings#hasTransport()} and the Spring Boot autoconfiguration's; another
17+
* transport property alone, such as {@code .websocket.connect-timeout}, names no agent.
18+
*/
19+
final class AcpClientTransportCondition implements Condition {
20+
21+
private static final List<String> KEYS = List.of("type", "stdio.command", "websocket.uri", "http.uri");
22+
23+
@Override
24+
public boolean matches(ConditionContext context) {
25+
for (String key : KEYS) {
26+
if (context.containsProperty(AcpClientConfiguration.PREFIX + ".transport." + key)) {
27+
return true;
28+
}
29+
}
30+
context.fail("No ACP client transport is set: " + AcpClientConfiguration.PREFIX
31+
+ ".transport.type, .stdio.command, .websocket.uri or .http.uri");
32+
return false;
33+
}
34+
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2025-2026 the original author or authors.
3+
*/
4+
5+
/**
6+
* What the {@code agent} and {@code client} packages share: binding {@code transport.type} in any
7+
* case.
8+
*
9+
* <p>
10+
* The package is null-marked: every type is non-null unless annotated
11+
* {@link org.jspecify.annotations.Nullable @Nullable}.
12+
* </p>
13+
*/
14+
@NullMarked
15+
package com.agentclientprotocol.sdk.micronaut;
16+
17+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)