File tree Expand file tree Collapse file tree
src/main/java/io/github/easy4j/kimi/acp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ public String connect() {
137137 process = builder .start ();
138138 } catch (IOException e ) {
139139 connected .set (false );
140- state .set ( KimiAcpState .NEW );
140+ state .compareAndSet ( KimiAcpState . CONNECTING , KimiAcpState .NEW );
141141 throw new KimiException ("Failed to spawn kimi acp: " + config .getLocalExecutable (), e );
142142 }
143143 state .set (KimiAcpState .INITIALIZING );
@@ -158,7 +158,10 @@ public String connect() {
158158 if (result .hasNonNull ("agentInfo" )) {
159159 agentVersion = result .path ("agentInfo" ).path ("version" ).asText (null );
160160 }
161- state .set (KimiAcpState .READY );
161+ if (!state .compareAndSet (KimiAcpState .INITIALIZING , KimiAcpState .READY )) {
162+ throw new KimiException ("kimi acp initialize completed after lifecycle left INITIALIZING: "
163+ + state .get ());
164+ }
162165 return agentVersion ;
163166 } catch (RuntimeException e ) {
164167 // Handshake failure leaves the child alive — destroy it here so a
@@ -170,7 +173,7 @@ public String connect() {
170173 process = null ;
171174 stdin = null ;
172175 connected .set (false );
173- state .set ( KimiAcpState .NEW );
176+ state .compareAndSet ( KimiAcpState . INITIALIZING , KimiAcpState .NEW );
174177 throw e ;
175178 }
176179 }
You can’t perform that action at this time.
0 commit comments