Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: use real KV namespace id and move sweep throttle to KV
Gener76fcb7fbfc56
diff --git a/src/web/src/lib/services/sweep.ts b/src/web/src/lib/services/sweep.tsindex c7373323f..7e0c4a9f6 100644--- a/src/web/src/lib/services/sweep.ts+++ b/src/web/src/lib/services/sweep.ts@@ -1,25 +1,30 @@import type { Database } from "@alook/shared";import { queries } from "@alook/shared";import { TaskService } from "./task";+import { cached } from "@/lib/cache";-const SWEEP_INTERVAL_MS = 30_000;-const lastSweepAt = new Map<string, number>();+const SWEEP_INTERVAL_S = 30;/** @internal test-only */-export function _resetSweepThrottle() {- lastSweepAt.clear();-}+export function _resetSweepThrottle() {}/*** Unified workspace housekeeping. Any code path that wants to ensure* stale state is cleaned up just calls this one function.- * Rate-limited to once per 30s per workspace within the same isolate.+ * Rate-limited to once per 30s per workspace via KV.*/export async function sweepStaleState(db: Database, workspaceId: string) {- const now = Date.now();- const last = lastSweepAt.get(workspaceId) ?? 0;- if (now - last < SWEEP_INTERVAL_MS) return;- lastSweepAt.set(workspaceId, now);+ const lockKey = `sweep:${workspaceId}`;+ let locked = false;+ try {+ const val = await cached<string>(lockKey, SWEEP_INTERVAL_S, async () => {+ locked = true;+ return new Date().toISOString();+ });+ if (!locked) return;+ } catch {+ locked = true;+ }// 1. Fail tasks stuck in "dispatched" for >20s (daemon crashed between claim and start)const staleDispatched = await queries.task.failStaleDispatchedTasks(db, workspaceId);diff --git a/src/web/wrangler.toml b/src/web/wrangler.tomlindex b275e2e22..2802631e5 100644--- a/src/web/wrangler.toml+++ b/src/web/wrangler.toml@@ -67,7 +67,7 @@ id = "a3d035bea7bc49d99377b82ec21ce4c1"[[kv_namespaces]]binding = "CACHE_KV"-id = "placeholder-create-via-wrangler-kv-namespace-create"+id = "3aaa92b4c2c74185b888977e5552e9bf"[vars]RUNTIME_MODEL_OPTIONS = '{"claude":["claude-opus-4-6","claude-sonnet-4-6","claude-haiku-4-5"],"codex":["gpt-5.4","gpt-5.3-codex"]}'