Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/sdk-java/qwencode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ try (HostedHarnessClient harness = HostedHarnessClient.builder()

The client permits only one active prompt identity per Session while allowing different Sessions to run concurrently. A retry after `PromptAdmissionUnknownException` must reuse the same `promptId`, payload digest, prompt content, and deadline. The payload digest is a cross-language contract: it is the SHA-256 of a canonical form of the prompt content, sent on the wire as `sha256:<64 lowercase hex>` (object members appear in JavaScript `JSON.stringify` own-key order — array-index keys (`"0"` through `"4294967294"`, no leading zero) ascending numerically first, then the remaining keys in insertion order — applied recursively, array order preserved), the client emits as the wire `prompt` exactly the key order its digest covers, and the server re-derives the identical value by re-serializing the parsed `prompt` member with JavaScript `JSON.stringify` semantics (compact separators, literal non-ASCII). The canonical form is versioned by the SDK: the digest is reproducible across JVM processes for a given release, but a release that changes it changes every persisted digest whose stored key order was not already canonical, so the client accepts a persisted digest computed over the as-built key order when the canonical recomputation does not match, and re-sends the prompt in exactly the shape that digest covers — a legacy row reaches its replay path instead of failing the client-side self-check. That compatibility arm covers one generation: it rescues a row written before the form changed, not a row this release writes, so a second consecutive form change still needs the stored rows quiesced. Do not rewrite a stored digest or a stored input to make it match. SSE boot, epoch, or sequence changes fail closed for transcript/status reconciliation. `close()` releases local HTTP, heartbeat, timer, and stream resources only; it never destroys remote Sessions implicitly. Event streams are bounded by a 45-second idle watchdog that measures peer silence while a consumer is parked in `next()` — time between `next()` calls is not charged (see `Builder.sseIdleTimeout`; `Duration.ZERO` disables it for callers that own the deadline). The watchdog checks every tenth of the budget but no more often than every 100 ms, so an idle abort lands between the budget and the budget plus max(100 ms, a tenth of the budget) — 45 to 49.5 seconds at the default — and any outer supervisor deadline should sit above that upper bound. The abort surfaces as `HostedHarnessStreamIdleException`, a `DaemonTransportException`: it proves the stream went silent, never that the reported work stopped. The hosted events route emits keepalive comments every 15 seconds so legitimately silent phases — long tool calls, slow model phases, approval waits — do not trip the bound, which a custom `sseIdleTimeout` should therefore stay comfortably above. The Harness advertises those keepalives as the `event-keepalive/1` feature; against a Harness that does not advertise it, the client arms no watchdog, so a rolling upgrade never aborts the quiet streams of an older Harness.

Transcript pages expose the same deeply immutable event snapshot through `getEvents()` and `getRaw().get("events")`. Retaining a page therefore retains one event object graph; both views reject changes to nested event maps and lists.

## Legacy stdio API

The existing `com.alibaba.qwen.code.cli` API remains available:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.alibaba.qwen.code.daemon;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -14,11 +13,13 @@ public final class HarnessTranscriptPage {

HarnessTranscriptPage(String harnessSessionId, List<Object> events,
String nextCursor, boolean more, Map<String, Object> raw) {
// getTranscript supplies a deeply immutable parsed response and its
// events view. Retain them together instead of copying the event graph.
this.harnessSessionId = harnessSessionId;
this.events = Collections.unmodifiableList(events);
this.events = events;
this.nextCursor = nextCursor;
this.more = more;
this.raw = JsonSupport.immutableObject(raw);
this.raw = raw;
}

public String getHarnessSessionId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -1306,6 +1307,41 @@ void doesNotRetryATargetedCancelAsALegacyCancel() {
assertEquals(1, requests.get());
}

@Test
void sharesOneDeeplyImmutableTranscriptSnapshot() {
createSessionRoute();
server.createContext("/session/" + SESSION_ID + "/transcript",
exchange -> sendSessionJson(exchange, 200,
"{\"v\":1,\"sessionId\":\"" + SESSION_ID
+ "\",\"events\":[{\"type\":\"user\","
+ "\"content\":[{\"type\":\"text\",\"text\":\"hello\"}]}],"
+ "\"nextCursor\":\"next\",\"hasMore\":true}"));

try (HostedHarnessClient client = newClient()) {
HarnessTranscriptPage page = client.getTranscript(
GetHarnessTranscript.builder().session(createSession(client)).build());
List<?> rawEvents = (List<?>) page.getRaw().get("events");
Map<?, ?> event = (Map<?, ?>) page.getEvents().get(0);
List<?> content = (List<?>) event.get("content");
Map<?, ?> part = (Map<?, ?>) content.get(0);

assertSame(page.getEvents(), rawEvents,
"A transcript page must not retain two copies of its event graph");
assertSame(event, rawEvents.get(0));
assertEquals("hello", part.get("text"));
assertEquals(SESSION_ID, page.getHarnessSessionId());
assertEquals("next", page.getNextCursor());
assertTrue(page.hasMore());

assertThrows(UnsupportedOperationException.class, () -> page.getRaw().put("hasMore", false));
assertThrows(UnsupportedOperationException.class, () -> page.getEvents().add(Map.of()));
assertThrows(UnsupportedOperationException.class, rawEvents::clear);
assertThrows(UnsupportedOperationException.class, event::clear);
assertThrows(UnsupportedOperationException.class, content::clear);
assertThrows(UnsupportedOperationException.class, part::clear);
}
}

@Test
void coversLoadStatusTranscriptHeartbeatAndLifecycleMutations() {
AtomicReference<String> loadBody = new AtomicReference<>();
Expand Down
Loading