fix(managed-agent): restore JournalCommit under its class-size ratchet (#16323)

#16284 pinned JournalCommit at 880 lines and #16275 grew it to 886, so every
Java lane fails ClassSizeRatchetTest on main.

The hosted-cleanup admission probe that #16275 added belongs with the cleanup
bookkeeping it guards, so move it behind
HostedCleanupReferences.containsCleanup and restore the class to its pin.

Fixes #16321
This commit is contained in:
Shaojin Wen authored and GitHub committed 2026-11-04 23:54:05 +08:00
1 parent d4083f4c82
commit f217a8e5d9
2 files changed
+15 -7

No files matched your search

@@ -8,8 +8,10 @@ import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.JdbcTemplate;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
/** The original Runtime remains referenced until its Hosted cleanup is confirmed. */
@@ -20,6 +22,18 @@ final class HostedCleanupReferences {
return ManagedSchemaKeys.key("hosted-cleanup-binding", tenant, workspace, binding);
}
/**
* True when the transaction carries a Hosted cleanup event. Retention takes
* placement before binding and Session locks, so cleanup admission must
* join that order before it can inspect the original binding.
*/
static boolean containsCleanup(byte[] recordBytes) {
return Arrays.stream(new String(recordBytes, StandardCharsets.UTF_8).split("\n"))
.map(com.alibaba.qwen.code.managedagent.repository.ManagedExtensionRecordStore::parse)
.filter(Objects::nonNull)
.anyMatch(record -> "hosted.cleanup".equals(record.path("managedSession").path("kind").asText()));
}
static void apply(JdbcTemplate jdbc, String tenant, String workspace, String session,
JsonNode payload, Function<String, StoredResource> resources, long revision, long now) {
String scope = com.alibaba.qwen.code.managedagent.repository.ManagedSessionStore.sessionScopeKey(tenant, session);
@@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -74,12 +73,7 @@ final class JournalCommit {
fencing.checkLifecycleWriter(tenantId, sessionId, authority);
JournalStoreRows.validateStableId(request.writerId(), "writerId");
ValidatedCommit validated = validateCommit(request);
if (Arrays.stream(new String(validated.recordBytes(), StandardCharsets.UTF_8).split("\n"))
.map(com.alibaba.qwen.code.managedagent.repository.ManagedExtensionRecordStore::parse)
.filter(Objects::nonNull)
.anyMatch(record -> "hosted.cleanup".equals(record.path("managedSession").path("kind").asText()))) {
// Retention takes placement before binding and Session locks. Cleanup
// admission must join that order before it can inspect the original binding.
if (HostedCleanupReferences.containsCleanup(validated.recordBytes())) {
fencing.lockPlacementBounded(tenantId);
}
// Other ordinary commits queue on their Session before any consistent