Skip to content

Commit 67d45df

Browse files
committed
refactor(quota): own blocked retry validation in settlement phase
Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>
1 parent 166c68b commit 67d45df

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

‎loopx/control_plane/goals/vision_checkpoint.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JsonObject } from "../effect_program.ts";
22
import { EffectRuntimeRequestError } from "../effect_runtime_errors.ts";
3-
import { isBoundedBlockedRetry } from "../quota/blocked_retry.ts";
3+
import { isBoundedBlockedRetry } from "../quota/settlement_phase.ts";
44
import {
55
DELIVERY_BOUNDARIES,
66
type DeliveryBoundary,

‎loopx/control_plane/quota/blocked_retry.ts‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎loopx/control_plane/quota/settlement_phase.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
import type { SettlementIdentity } from "../effect_program.ts";
2+
import { jsonObject } from "../runtime_decode.ts";
3+
4+
/** A typed blocked Turn may close without spend only with a bounded retry. */
5+
export function isBoundedBlockedRetry(value: unknown, todoId: string | null): boolean {
6+
const retry = jsonObject(value);
7+
if (!retry || retry.schema_version !== "quota_blocked_retry_v0" ||
8+
(retry.source !== "todo" && retry.source !== "turn_settlement") ||
9+
typeof todoId !== "string" || retry.todo_id !== todoId ||
10+
typeof retry.observed_at !== "string" || typeof retry.due_at !== "string" ||
11+
retry.resume_when !== `resume_at:${retry.due_at}`) return false;
12+
const observed = Date.parse(retry.observed_at);
13+
const due = Date.parse(retry.due_at);
14+
const delay = (due - observed) / 1000;
15+
return Number.isFinite(delay) && delay >= 60 && delay <= 30 * 60;
16+
}
217

318
/** Both same-Turn readback and prior-Turn recovery accept the shipped effect identities. */
419
export function isCommittedMonitorPollEffect(

‎loopx/control_plane/quota/settlement_readback.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import {
3030
type DeliveryWorkspaceCausality,
3131
} from "./settlement_workspace_causality.ts";
3232
import {
33+
isBoundedBlockedRetry,
3334
isCommittedMonitorPollEffect,
3435
receiptBoundMonitorPhase,
3536
receiptBoundReplayPhase,
3637
} from "./settlement_phase.ts";
3738
import { isTurnScopedSettlementOutcome } from "../work_items/delivery_outcome.ts";
38-
import { isBoundedBlockedRetry } from "./blocked_retry.ts";
3939
import {
4040
decodeRefreshRetry,
4141
isMaterialMonitorPoll,

0 commit comments

Comments
 (0)