Skip to content

An open-source, faster Devin alternative

TypeScript

P2/P3 review fixes: dashboard idempotency, event reset/cap, secret hygiene, docs

Igor Zalutskic698b842092f
diff --git a/.agents/work/agent-sandbox-ownership.md b/.agents/work/agent-sandbox-ownership.md
index 15b4273a..48365cc0 100644
--- a/.agents/work/agent-sandbox-ownership.md
+++ b/.agents/work/agent-sandbox-ownership.md
@@ -99,8 +99,8 @@ edge→cell cap-token and avoids a credential-custody surface entirely.
- **Quota** — agent boxes count against the customer org's concurrency. Intended,
but means agents and interactive sandboxes share the limit; flag for the quota
owner.
-- **`osb_` → org resolution** — needs an OC endpoint returning org for a key (the
- edge can expose `GET /api/org-for-key`, D1-backed).
+- **`osb_` → org resolution** — BUILT as edge `GET /api/whoami` (D1-backed,
+ returns `{org_id, user_id}`); sessions-api `resolveOrgForKey` calls it. LIVE on prod.
## Invariants
diff --git a/.agents/work/durable-agent-sessions-ui.md b/.agents/work/durable-agent-sessions-ui.md
index d27f5763..8afa08c9 100644
--- a/.agents/work/durable-agent-sessions-ui.md
+++ b/.agents/work/durable-agent-sessions-ui.md
@@ -1,9 +1,9 @@
# Durable Agent Sessions — dashboard UI
-Status: **draft, decisions converging** — exploration done. First cut = Agents +
-Sessions + session webhooks; Repos and the rest follow. Blocked on the `/v3`
-credential + tenant decision (#1) before the management screens can be built.
-Lands in the same dashboard (`web/`) and PR lineage as the modernization work.
+Status: **building** — exploration done; the `/v3` credential + tenant decision
+(#1) is RESOLVED (org-token + act-as-org ownership; see agent-sandbox-ownership.md,
+LIVE on prod). First cut = Agents + Sessions + session webhooks; Repos and the rest
+follow. Lands in the same dashboard (`web/`) and PR lineage as the modernization work.
Engineering principles: `.agents/reference/web-frontend.md`.
Goal: bring Durable Agent Sessions to the dashboard. Scope is the **stable v1
diff --git a/cloudflare-workers/api-edge/src/dashboard.ts b/cloudflare-workers/api-edge/src/dashboard.ts
index 87695d84..62a3239e 100644
--- a/cloudflare-workers/api-edge/src/dashboard.ts
+++ b/cloudflare-workers/api-edge/src/dashboard.ts
@@ -842,6 +842,10 @@ async function proxyToV3(
if (accept) headers.set("accept", accept);
const lastEventID = req.headers.get("last-event-id");
if (lastEventID) headers.set("last-event-id", lastEventID);
+ // Forward client idempotency keys so dashboard create-session / steer are safe
+ // to retry end-to-end (sessions-api dedups on this header).
+ const idem = req.headers.get("idempotency-key");
+ if (idem) headers.set("idempotency-key", idem);
const init: RequestInit = { method: req.method, headers, redirect: "manual" };
if (req.method !== "GET" && req.method !== "HEAD") {
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 4be44db3..386f8738 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -405,10 +405,19 @@ export const getSession = (id: string) =>
// /v3 wants { agent: <id>, input } (input required). The response is an envelope
// { session, client_token } — return the session.
-export const createSession = (body: { agent: string; input: string }) =>
+export const createSession = (
+ body: { agent: string; input: string },
+ idempotencyKey?: string,
+) =>
apiFetch(
'/v3/sessions',
- { method: 'POST', body: JSON.stringify(body) },
+ {
+ method: 'POST',
+ body: JSON.stringify(body),
+ // sessions-api dedups create on the Idempotency-Key header (the edge proxy
+ // forwards it) so a retried start-session is safe.
+ headers: idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined,
+ },
z.object({ session: S.SessionSchema, client_token: z.string().optional() }),
).then((r) => r.session)
diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsx
index 3a4e8955..ac294698 100644
--- a/web/src/pages/Agents.tsx
+++ b/web/src/pages/Agents.tsx
@@ -186,7 +186,13 @@ export default function Agents() {
/>
</Panel>
- <Dialog open={showCreate} onOpenChange={setShowCreate}>
+ <Dialog
+ open={showCreate}
+ onOpenChange={(open) => {
+ setShowCreate(open)
+ if (!open) setApiKey('') // never leave a model key in state after close
+ }}
+ >
<DialogContent>
<DialogHeader>
<DialogTitle>Create agent</DialogTitle>
@@ -277,7 +283,12 @@ export default function Agents() {
<Dialog
open={editing !== null}
- onOpenChange={(open) => !open && setEditing(null)}
+ onOpenChange={(open) => {
+ if (!open) {
+ setEditing(null)
+ setEditKey('') // never leave a model key in state after close
+ }
+ }}
>
<DialogContent>
<DialogHeader>
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index b9cecec4..c2c7ad51 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -78,6 +78,9 @@ export default function SessionDetail() {
// auto-reconnects with Last-Event-ID. Skipped under the preview mock (no
// backend) — the query renders there.
useEffect(() => {
+ // Reset per session so a previously-viewed session's events never bleed in.
+ setLiveEvents([])
+ setStreamOk(false)
if (!sessionId || import.meta.env.VITE_PREVIEW === '1') return
const es = new EventSource(
`/api/dashboard/v3/sessions/${sessionId}/events?stream=sse`,
@@ -95,7 +98,8 @@ export default function SessionDetail() {
if (!parsed.success) return
const ev = parsed.data
setLiveEvents((prev) =>
- prev.some((x) => x.id === ev.id) ? prev : [...prev, ev],
+ // Cap the in-memory live buffer (older events remain in query history).
+ prev.some((x) => x.id === ev.id) ? prev : [...prev, ev].slice(-2000),
)
}
es.onerror = () => setStreamOk(false) // EventSource retries on its own
@@ -110,7 +114,7 @@ export default function SessionDetail() {
}
const steerMutation = useMutation({
- mutationFn: () => sendMessage(sessionId, draft.trim()),
+ mutationFn: () => sendMessage(sessionId, draft.trim(), crypto.randomUUID()),
onSuccess: () => {
setDraft('')
invalidate()
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sessions.tsx
index 0815728e..165510d0 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sessions.tsx
@@ -46,7 +46,7 @@ export default function Sessions() {
}
const startMutation = useMutation({
- mutationFn: () => createSession({ agent: agentId, input: message.trim() }),
+ mutationFn: () => createSession({ agent: agentId, input: message.trim() }, crypto.randomUUID()),
onSuccess: (session) => {
setShowStart(false)
void queryClient.invalidateQueries({ queryKey: ['sessions'] })