From 07ec10761890f1c6b26741b83cf23ccc8327ef6a Mon Sep 17 00:00:00 2001 From: ryanechternacht Date: Tue, 27 Oct 2026 22:19:39 -0400 Subject: [PATCH] raise the server-mode reservation TTL cap to 24 hours --- README.md | 2 +- src/main/java/com/schematic/api/Schematic.java | 2 +- .../java/com/schematic/api/credits/CreditLeaseConfig.java | 4 ++-- .../com/schematic/api/credits/CreditLeaseDefaults.java | 4 ++-- src/test/java/com/schematic/api/TestSchematic.java | 8 ++++---- .../schematic/api/credits/SchematicCreditLeaseTest.java | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e176b9a9..858d91ef 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ import java.time.Duration; Schematic schematic = Schematic.builder() .apiKey("YOUR_API_KEY") .creditLeases(CreditLeaseConfig.builder() - .defaultReservationTtl(Duration.ofSeconds(60)) // just under an hour at most, which is as far out as the API will reserve credits + .defaultReservationTtl(Duration.ofSeconds(60)) // just under 24 hours at most, which is as far out as the API will reserve credits .build()) .build(); ``` diff --git a/src/main/java/com/schematic/api/Schematic.java b/src/main/java/com/schematic/api/Schematic.java index 4ec1e7ae..3cd9bb2f 100644 --- a/src/main/java/com/schematic/api/Schematic.java +++ b/src/main/java/com/schematic/api/Schematic.java @@ -195,7 +195,7 @@ private Schematic(Builder builder) { Duration configuredTtl = creditLeases.getDefaultReservationTtl() != null ? creditLeases.getDefaultReservationTtl() : CreditLeaseDefaults.RESERVATION_TTL; - // The API refuses a hold expiring more than an hour after its own clock, and this TTL + // The API refuses a hold expiring more than 24 hours after its own clock, and this TTL // is applied to the caller's, so clamp a step below the cap to leave room for skew. // Only server mode sends the value to the API: in client mode it sizes the local // sweep, so clamping it there would shorten holds for no reason. diff --git a/src/main/java/com/schematic/api/credits/CreditLeaseConfig.java b/src/main/java/com/schematic/api/credits/CreditLeaseConfig.java index 8bf12a83..4d5058ac 100644 --- a/src/main/java/com/schematic/api/credits/CreditLeaseConfig.java +++ b/src/main/java/com/schematic/api/credits/CreditLeaseConfig.java @@ -137,8 +137,8 @@ public Builder defaultLeaseDuration(Duration defaultLeaseDuration) { } /** - * Reservation lifetime. Defaults to 60 seconds. In server mode it is capped at an hour - * less a minute of room for clock skew, since an hour out is the furthest the API will + * Reservation lifetime. Defaults to 60 seconds. In server mode it is capped at 24 hours + * less a minute of room for clock skew, since 24 hours out is the furthest the API will * hold credits and it measures that against its own clock. Size it above the longest * expected gap between a check and its settle: a settle arriving after the TTL still * bills the server but no longer re-debits the local lease, so the local balance reads diff --git a/src/main/java/com/schematic/api/credits/CreditLeaseDefaults.java b/src/main/java/com/schematic/api/credits/CreditLeaseDefaults.java index 11e0b0b4..e1a09c9d 100644 --- a/src/main/java/com/schematic/api/credits/CreditLeaseDefaults.java +++ b/src/main/java/com/schematic/api/credits/CreditLeaseDefaults.java @@ -24,10 +24,10 @@ public final class CreditLeaseDefaults { * The furthest out the API will hold credits, so a larger server-mode reservation TTL would * fail every check. */ - public static final Duration MAX_RESERVATION_TTL = Duration.ofHours(1); + public static final Duration MAX_RESERVATION_TTL = Duration.ofHours(24); /** - * Held back from {@link #MAX_RESERVATION_TTL} because the API measures that hour against its + * Held back from {@link #MAX_RESERVATION_TTL} because the API measures that span against its * own clock while the SDK computes {@code expiresAt} against the caller's: a client running * ahead would otherwise be rejected at exactly the cap. */ diff --git a/src/test/java/com/schematic/api/TestSchematic.java b/src/test/java/com/schematic/api/TestSchematic.java index 7e2319f0..5da4a401 100644 --- a/src/test/java/com/schematic/api/TestSchematic.java +++ b/src/test/java/com/schematic/api/TestSchematic.java @@ -510,18 +510,18 @@ void check_AutoModeFallsToServerGatingWhenTheDataStreamIsGone() throws Exception @Test void serverReservationTtl_IsClampedBelowTheApiCapButOnlyForServerMode() throws Exception { - Duration twoHours = Duration.ofHours(2); + Duration overCap = Duration.ofHours(25); Duration clamped = CreditLeaseDefaults.MAX_RESERVATION_TTL.minus(CreditLeaseDefaults.RESERVATION_TTL_SKEW_ALLOWANCE); - try (Schematic server = leasedClient(CreditLeaseMode.SERVER, twoHours); - Schematic client = leasedClient(CreditLeaseMode.CLIENT, twoHours)) { + try (Schematic server = leasedClient(CreditLeaseMode.SERVER, overCap); + Schematic client = leasedClient(CreditLeaseMode.CLIENT, overCap)) { // The API refuses a hold expiring more than its cap ahead of its own clock, and this // TTL is measured on ours, so the clamp leaves a step for the difference. assertEquals(clamped, serverReservationTtl(server)); assertTrue(clamped.compareTo(CreditLeaseDefaults.MAX_RESERVATION_TTL) < 0); // Client mode never sends it, so clamping there would shorten holds for nothing. - assertEquals(twoHours, serverReservationTtl(client)); + assertEquals(overCap, serverReservationTtl(client)); } } diff --git a/src/test/java/com/schematic/api/credits/SchematicCreditLeaseTest.java b/src/test/java/com/schematic/api/credits/SchematicCreditLeaseTest.java index 1ec9cfe3..33fd5f89 100644 --- a/src/test/java/com/schematic/api/credits/SchematicCreditLeaseTest.java +++ b/src/test/java/com/schematic/api/credits/SchematicCreditLeaseTest.java @@ -162,7 +162,7 @@ void aTtlLongerThanTheApiWillHoldIsClampedForServerMode() { .logger(logger) .creditLeases(CreditLeaseConfig.builder() .mode(CreditLeaseMode.SERVER) - .defaultReservationTtl(Duration.ofHours(2)) + .defaultReservationTtl(Duration.ofHours(25)) .build()) .build()) { verify(logger).warn(contains("longer than the API will hold"));