From 67d45df004e37601e30763ad654ed77284675da2 Mon Sep 17 00:00:00 2001 From: huangruiteng <14976749+huangruiteng@users.noreply.github.com> Date: Fri, 25 Sep 2026 12:24:32 +0800 Subject: [PATCH] refactor(quota): own blocked retry validation in settlement phase Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com> --- loopx/control_plane/goals/vision_checkpoint.ts | 2 +- loopx/control_plane/quota/blocked_retry.ts | 15 --------------- loopx/control_plane/quota/settlement_phase.ts | 15 +++++++++++++++ loopx/control_plane/quota/settlement_readback.ts | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 loopx/control_plane/quota/blocked_retry.ts diff --git a/loopx/control_plane/goals/vision_checkpoint.ts b/loopx/control_plane/goals/vision_checkpoint.ts index 779971caf8..43c1a60427 100644 --- a/loopx/control_plane/goals/vision_checkpoint.ts +++ b/loopx/control_plane/goals/vision_checkpoint.ts @@ -1,6 +1,6 @@ import type { JsonObject } from "../effect_program.ts"; import { EffectRuntimeRequestError } from "../effect_runtime_errors.ts"; -import { isBoundedBlockedRetry } from "../quota/blocked_retry.ts"; +import { isBoundedBlockedRetry } from "../quota/settlement_phase.ts"; import { DELIVERY_BOUNDARIES, type DeliveryBoundary, diff --git a/loopx/control_plane/quota/blocked_retry.ts b/loopx/control_plane/quota/blocked_retry.ts deleted file mode 100644 index bc8aa9e056..0000000000 --- a/loopx/control_plane/quota/blocked_retry.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { jsonObject } from "../runtime_decode.ts"; - -/** A typed blocked Turn may close without spend only with a bounded retry. */ -export function isBoundedBlockedRetry(value: unknown, todoId: string | null): boolean { - const retry = jsonObject(value); - if (!retry || retry.schema_version !== "quota_blocked_retry_v0" || - (retry.source !== "todo" && retry.source !== "turn_settlement") || - typeof todoId !== "string" || retry.todo_id !== todoId || - typeof retry.observed_at !== "string" || typeof retry.due_at !== "string" || - retry.resume_when !== `resume_at:${retry.due_at}`) return false; - const observed = Date.parse(retry.observed_at); - const due = Date.parse(retry.due_at); - const delay = (due - observed) / 1000; - return Number.isFinite(delay) && delay >= 60 && delay <= 30 * 60; -} diff --git a/loopx/control_plane/quota/settlement_phase.ts b/loopx/control_plane/quota/settlement_phase.ts index 01058521a1..c2da7a3e8c 100644 --- a/loopx/control_plane/quota/settlement_phase.ts +++ b/loopx/control_plane/quota/settlement_phase.ts @@ -1,4 +1,19 @@ import type { SettlementIdentity } from "../effect_program.ts"; +import { jsonObject } from "../runtime_decode.ts"; + +/** A typed blocked Turn may close without spend only with a bounded retry. */ +export function isBoundedBlockedRetry(value: unknown, todoId: string | null): boolean { + const retry = jsonObject(value); + if (!retry || retry.schema_version !== "quota_blocked_retry_v0" || + (retry.source !== "todo" && retry.source !== "turn_settlement") || + typeof todoId !== "string" || retry.todo_id !== todoId || + typeof retry.observed_at !== "string" || typeof retry.due_at !== "string" || + retry.resume_when !== `resume_at:${retry.due_at}`) return false; + const observed = Date.parse(retry.observed_at); + const due = Date.parse(retry.due_at); + const delay = (due - observed) / 1000; + return Number.isFinite(delay) && delay >= 60 && delay <= 30 * 60; +} /** Both same-Turn readback and prior-Turn recovery accept the shipped effect identities. */ export function isCommittedMonitorPollEffect( diff --git a/loopx/control_plane/quota/settlement_readback.ts b/loopx/control_plane/quota/settlement_readback.ts index 726169f022..e6f5c5f2f2 100644 --- a/loopx/control_plane/quota/settlement_readback.ts +++ b/loopx/control_plane/quota/settlement_readback.ts @@ -30,12 +30,12 @@ import { type DeliveryWorkspaceCausality, } from "./settlement_workspace_causality.ts"; import { + isBoundedBlockedRetry, isCommittedMonitorPollEffect, receiptBoundMonitorPhase, receiptBoundReplayPhase, } from "./settlement_phase.ts"; import { isTurnScopedSettlementOutcome } from "../work_items/delivery_outcome.ts"; -import { isBoundedBlockedRetry } from "./blocked_retry.ts"; import { decodeRefreshRetry, isMaterialMonitorPoll,