Skip to content

Commit ef0db73

Browse files
author
ben
authored
chore(features): graduate cloud task recovery and per-chat storage (#6274)
Signed-off-by: Benjamin Shafii <ben@prologe.io>
1 parent ed375e0 commit ef0db73

37 files changed

Lines changed: 236 additions & 824 deletions

‎.github/workflows/celld-runner-deploy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
+ { HEADLESS_RUNNER_VERSION: (.HEADLESS_RUNNER_VERSION // $version) }
177177
' "$RUNNER_TEMP/vars.json" > "$RUNNER_TEMP/vars.merged.json"
178178
mv "$RUNNER_TEMP/vars.merged.json" "$RUNNER_TEMP/vars.json"
179-
# Self-resume (headlessDurableTurns): the runner refuses a partial set, so merge all three or none.
179+
# Self-resume (saved step turns): the runner refuses a partial set, so merge all three or none.
180180
if [ -n "${HEADLESS_DEN_API_URL:-}" ] && [ -n "${HEADLESS_DEN_CALLBACK_TOKEN:-}" ] && [ -n "${HEADLESS_GRANT_KEY:-}" ]; then
181181
jq --arg url "$HEADLESS_DEN_API_URL" --arg token "$HEADLESS_DEN_CALLBACK_TOKEN" --arg key "$HEADLESS_GRANT_KEY" \
182182
'. + { HEADLESS_DEN_API_URL: $url, HEADLESS_DEN_CALLBACK_TOKEN: $token, HEADLESS_GRANT_KEY: $key }' \

‎docs/feature-ga-october-2026.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ organization override, deployment rollout row, or operator feature lock.
3131
| --- | --- |
3232
| `workbotGuidedNavigation` | `workbotWorkspaceAssistant` |
3333
| `engineV2Upgrade` (the optional desktop invitation is gone) | `engineV2ForceUpgrade` ("Upgrade to OpenCode v2") |
34-
| `headlessStepTurns` | `headlessDurableTurns` ("Cloud tasks survive restarts and updates") |
34+
| `headlessStepTurns` | Saved step turns (generally available, including `headlessDurableTurns`) |
3535

3636
The remaining switches stay off by default. An old override for a folded key
3737
does not turn on its new switch.
@@ -64,3 +64,16 @@ authenticated installer enrollment or health reports.
6464
Self-hosted installations can use the generally available product features, but
6565
cannot use this hosted control-plane rollout to provision more installations.
6666
Other switches that were not globally enabled are not graduated by this change.
67+
68+
69+
## Durable turns and per-chat cells
70+
71+
`headlessDurableTurns` and `headlessSessionCells` are now generally available on cloud and self-hosted.
72+
Their registry entries, organization checks, Helm keys and off paths are removed. Legacy disabled overrides,
73+
killed rollout rows and operator locks do not disable them. Resume grants retain callback authentication,
74+
turn binding, membership checks, expiry, revocation and rate limits; service configuration is still required.
75+
76+
Den returns `stepTurns: true` and `sessionCells: true` for older clients. Workbot continues treating missing
77+
optional fields from older Dens as false. Existing turns keep their persisted execution mode; existing sessions
78+
remain readable and move only through lossless split logic and forwarding. Owner-shared memory, legacy history,
79+
and fallback event transports remain intact. Deploy a compatible runner before the GA Den.

‎ee/apps/den-api/.env.example‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ DEN_SLACK_ASSISTANT_WORKER_ENABLED=true
201201
# instead of each member's OpenWork Web computer. Unset = no org can use it.
202202
# DEN_HEADLESS_RUNNER_URL=http://headless-runner:8795
203203
# DEN_HEADLESS_RUNNER_TOKEN=<same value as the runner's HEADLESS_API_TOKEN, 32+ chars>
204-
# Lets the runner continue turns on its own after a restart (feature
205-
# headlessDurableTurns, /admin): the token it presents when exchanging a turn's
204+
# Lets the runner continue saved turns on its own after a restart:
205+
# the token it presents when exchanging a turn's
206206
# resume grant at POST /v1/headless/resume-token, and when reporting to Den's
207207
# session index at POST /v1/internal/headless/index. Same value as the runner's
208208
# HEADLESS_DEN_CALLBACK_TOKEN; 32+ chars and different from

‎ee/apps/den-api/src/audit/routes/content.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ export const contentAuditRoutes: readonly AuditRouteDeclaration[] = [
205205
member("GET", "/v1/documents/google-drive/files/:fileId/editor", "tenant_access", "documents.google_drive.open", "documents.editor", "google_drive_file", "fileId", { notes: "Reads bounded document content with pinned authorized connector; both Workbot features required. No content in audit evidence." }),
206206
member("GET", "/v1/documents/google-drive/files/:fileId/content", "tenant_access", "documents.google_drive.preview", "documents.editor", "google_drive_file", "fileId", { notes: "Bounded PDF/image bytes, current pinned connection, no-store; both flags required." }),
207207
member("POST", "/v1/documents/google-drive/files/:fileId/editor", "tenant_external", "documents.google_drive.save", "documents.editor", "google_drive_file", "fileId", { external: "Google Docs/Sheets/Drive API", notes: "Explicit targeted edits, live write permission, pinned connection and revision check. Native Docs also require revision writeControl. No content in audit evidence. Stored files/Sheets have a check-then-write concurrency window." }),
208-
route("POST", "/v1/workbot/run-token", "tenant_access", "workbot.run_token.issue", "workbot.execution", "oauth_access_token", null, "handler", { notes: "Handler verifies the MCP OAuth token, membership and workbot capability, then mints a ≤1h headless-run MCP token (credential issuance; plaintext returned once, never snapshot). mintHeadlessRunMcpToken is also called by the headless automation executor without an HTTP route. With headlessDurableTurns on and sessionId/messageId given it also returns a resume grant (plaintext once; only its SHA-256 hash is stored). With sessionId given it also returns an index capability (HMAC-signed, bound to org, member, session and kind workbot; nothing stored)." }),
209-
route("POST", "/v1/headless/resume-token", "tenant_access", "headless.resume_token.issue", "headless.execution", "oauth_access_token", null, "handler", { notes: "Headless runner callback (Internal, never MCP). Handler verifies DEN_HEADLESS_RUNNER_CALLBACK_TOKEN (constant time; 404 when unset, 401 otherwise) and looks the resume grant up by its SHA-256 hash; unknown grants answer 403 before attribution (request evidence only). Then attributes actor service headless-runner:<grantId> for the grant's organization and active member, checks revoked, expired, turn binding, membership, headlessDurableTurns and the per-grant rate limit, and mints a ≤1h headless-run MCP token (credential issuance; grant and token never logged or snapshot)." }),
208+
route("POST", "/v1/workbot/run-token", "tenant_access", "workbot.run_token.issue", "workbot.execution", "oauth_access_token", null, "handler", { notes: "Handler verifies the MCP OAuth token, membership and workbot capability, then mints a ≤1h headless-run MCP token (credential issuance; plaintext returned once, never snapshot). mintHeadlessRunMcpToken is also called by the headless automation executor without an HTTP route. With sessionId/messageId given it also returns a resume grant (plaintext once; only its SHA-256 hash is stored). With sessionId given it also returns an index capability (HMAC-signed, bound to org, member, session and kind workbot; nothing stored)." }),
209+
route("POST", "/v1/headless/resume-token", "tenant_access", "headless.resume_token.issue", "headless.execution", "oauth_access_token", null, "handler", { notes: "Headless runner callback (Internal, never MCP). Handler verifies DEN_HEADLESS_RUNNER_CALLBACK_TOKEN (constant time; 404 when unset, 401 otherwise) and looks the resume grant up by its SHA-256 hash; unknown grants answer 403 before attribution (request evidence only). Then attributes actor service headless-runner:<grantId> for the grant's organization and active member, checks revoked, expired, turn binding, membership and the per-grant rate limit, and mints a ≤1h headless-run MCP token (credential issuance; grant and token never logged or snapshot)." }),
210210
route("POST", "/v1/internal/headless/index", "platform", "headless.session_index.update", "headless.session_index", "headless_session_index", null, "none", { notes: "Headless runner callback (Internal, never MCP). Handler verifies DEN_HEADLESS_RUNNER_CALLBACK_TOKEN (constant time; 404 when unset, 401 otherwise). One request carries up to 50 updates that may belong to several organizations, so the request evidence stays in the platform store. Each update's organization, member and kind come only from its HMAC-verified index capability (bound to the session, 30-day expiry; a capability for a deleted organization is refused as capability_invalid, so its rows never return); content-free fields only (sizes, dates, state, title). Every rejected update (invalid update, bad/expired/mismatched capability, rate_limited, session_conflict) also writes headless.session_index.update.attempted (outcome denied, reasonCode = the rejection, target the capability's verified organization when there is one) and a throttled Sentry event by code. Capabilities are never logged or stored." }),
211211
route("GET", "/v1/brand-assets/:organizationId/:kind/:version", "tenant_read", "brand_asset.download", "organization.branding", "brand_asset", "version", "handler", { notes: "Public capability URL: the HMAC signature binds organizationId, kind, version and extension, so the handler attributes the path organization only after verifyBrandAssetSignature; actor is the anonymous signed-URL holder. Public, immutable, CDN-cached logo (login pages, emails): read category, not access. Invalid signatures 404 before attribution (platform)." }),
212212

‎ee/apps/den-api/src/automations/headless-agent-executor.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
ACTIVE_TURN_STATUSES,
99
createHeadlessRunnerClient,
1010
defaultHeadlessRunnerDeps,
11-
headlessDurableTurnsEnabled,
1211
type HeadlessRunnerClient,
1312
type RunnerMessage,
1413
type RunnerRepeatLimits,
@@ -62,7 +61,7 @@ export type HeadlessAgentExecutorDeps = {
6261
stillHeadless: (organizationId: string) => Promise<boolean>
6362
cloudModel: typeof organizationCloudModel
6463
gatewayCatalog: typeof cloudAgentGatewayCatalog
65-
/** Feature `headlessDurableTurns`: the run's turn goes to the runner with `execution: "steps"`. */
64+
/** Test injection for protocol compatibility; production always uses saved steps. */
6665
stepTurns: (organizationId: string) => Promise<boolean>
6766
sleep: (ms: number, signal: AbortSignal) => Promise<void>
6867
pollIntervalMs: number
@@ -116,7 +115,7 @@ function defaultDeps(): HeadlessAgentExecutorDeps {
116115
stillHeadless: async (organizationId) => (await cloudAutomationRuntime(organizationId)) === "headless",
117116
cloudModel: organizationCloudModel,
118117
gatewayCatalog: cloudAgentGatewayCatalog,
119-
stepTurns: headlessDurableTurnsEnabled,
118+
stepTurns: async () => true,
120119
sleep: abortableSleep,
121120
pollIntervalMs: POLL_INTERVAL_MS,
122121
}

‎ee/apps/den-api/src/headless-runner/client.ts‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export function defaultHeadlessRunnerDeps(
1717
options: { indexKind?: HeadlessIndexKind } = {},
1818
): HeadlessRunnerDeps | null {
1919
const config = headlessRunnerConfig(env)
20-
// Loaded lazily: the minter pulls in the auth and database modules. A resume grant comes back only where
21-
// `headlessDurableTurns` is on and the turn's session and message are known; an index capability only where the kind
20+
// Loaded lazily: the minter pulls in the auth and database modules. A resume grant comes back when
21+
// the turn's session and message are known; an index capability only where the kind
2222
// and session are known.
2323
const mintToken: HeadlessRunnerDeps["mintToken"] = async (input) => {
2424
const { token, resumeGrant, modelAccess, indexCapability } = await (await import("./resume-grants.js")).mintHeadlessTurnCredentials({
@@ -31,19 +31,3 @@ export function defaultHeadlessRunnerDeps(
3131
const modelAccessRequired: HeadlessRunnerDeps["modelAccessRequired"] = () => true
3232
return config ? { config, fetch, mintToken, modelAccessRequired, maxTokenTtlMs: DEN_MCP_HEADLESS_RUN_TOKEN_MAX_TTL_MS } : null
3333
}
34-
35-
/**
36-
* Feature `headlessDurableTurns`: whether Den sends the organization's headless turns with `execution: "steps"`, so the
37-
* runner runs them one step at a time and a runner deploy switches between steps. The same feature mints the turns'
38-
* resume grants (resume-grants.ts), so one switch turns on both and off both. A failed read sends the turn exactly as
39-
* without the feature.
40-
*/
41-
export async function headlessDurableTurnsEnabled(organizationId: string): Promise<boolean> {
42-
try {
43-
// Loaded lazily: the feature reader pulls in the database modules.
44-
const { organizationFeatureEnabled } = await import("../features.js")
45-
return await organizationFeatureEnabled(organizationId, "headlessDurableTurns")
46-
} catch {
47-
return false
48-
}
49-
}

‎ee/apps/den-api/src/headless-runner/resume-grants.ts‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { and, eq, inArray, isNull, lt, sql } from "@openwork-ee/den-db/drizzle"
33
import { HeadlessResumeGrantTable, HeadlessResumeRevocationTable, MemberTable, RateLimitTable } from "@openwork-ee/den-db/schema"
44
import { createDenTypeId, normalizeDenTypeId } from "@openwork-ee/utils/typeid"
55
import { db } from "../db.js"
6-
import { organizationFeatureEnabled } from "../features.js"
76
import { mintHeadlessRunMcpToken, revokeHeadlessRunMcpToken } from "../mcp/headless-run-token-mint.js"
87
import { appLogger } from "../observability/logger.js"
98
import { checkRateLimit } from "../utils/rate-limit.js"
@@ -13,7 +12,7 @@ import { cloudAgentGatewayAccess } from "../workbot/gateway-model.js"
1312
import { indexCapabilityForTurn, type HeadlessIndexKind } from "./session-index.js"
1413

1514
/**
16-
* Resume grants (feature `headlessDurableTurns`): a narrow credential Den hands the headless runner with each turn,
15+
* Resume grants: a narrow credential Den hands the headless runner with each turn,
1716
* which the runner can only exchange (POST /v1/headless/resume-token) for a fresh member-scoped MCP token for that
1817
* exact turn, its background tasks (`<messageId>.tN`) and their reports (`<messageId>.tN.r`). It lets the runner
1918
* continue a turn on its own after a restart, deploy or failover, and refresh a long turn's token in place.
@@ -68,7 +67,7 @@ async function pruneExpiredHeadlessResumeGrants(now: Date) {
6867

6968
/**
7069
* Mints a resume grant for one turn. Only trusted server code that has already authorized the member for this turn
71-
* may call it, and only where `headlessDurableTurns` is on (see mintHeadlessTurnCredentials).
70+
* may call it (see mintHeadlessTurnCredentials).
7271
*/
7372
export async function mintHeadlessResumeGrant(input: {
7473
userId: string
@@ -104,8 +103,8 @@ function boundId(value: string | undefined): value is string {
104103
}
105104

106105
/**
107-
* A resume grant for the turn, or undefined: when `headlessDurableTurns` is off for the organization, when the turn's
108-
* session or message is unknown, or when minting fails (the turn then runs exactly as without the feature).
106+
* A resume grant for the turn, or undefined when its session or message is unknown, or minting fails.
107+
* Mint failures do not prevent the turn from running.
109108
*/
110109
async function resumeGrantForTurn(input: {
111110
userId: string
@@ -118,7 +117,6 @@ async function resumeGrantForTurn(input: {
118117
const { sessionId, messageId } = input
119118
if (!boundId(sessionId) || !boundId(messageId)) return undefined
120119
try {
121-
if (!(await organizationFeatureEnabled(input.organizationId, "headlessDurableTurns"))) return undefined
122120
const { grant } = await mintHeadlessResumeGrant({ ...input, sessionId, messageId, now: input.authorizedAt })
123121
return grant
124122
} catch (error) {
@@ -129,9 +127,8 @@ async function resumeGrantForTurn(input: {
129127
}
130128

131129
/**
132-
* The credentials Den sends with one headless turn: a member-scoped MCP token and, where `headlessDurableTurns` is on
133-
* and the turn's session and message are known, a resume grant. Without the feature the result has no
134-
* `resumeGrant` field at all, so nothing changes for callers or the runner. `indexCapability`: only where the caller
130+
* The credentials Den sends with one headless turn: a member-scoped MCP token and, when the turn's session and
131+
* message are known, a resume grant. `indexCapability`: only where the caller
135132
* names its kind (`indexKind`) and the session is known (session-index.ts).
136133
*/
137134
export async function mintHeadlessTurnCredentials(input: {
@@ -165,7 +162,6 @@ export type HeadlessResumeGrantError =
165162
| "grant_mismatch"
166163
| "membership_inactive"
167164
| "model_unavailable"
168-
| "feature_disabled"
169165

170166
/** The stored grant behind a presented one, or null when it is malformed or unknown. */
171167
export async function findHeadlessResumeGrant(grant: string): Promise<GrantRow | null> {
@@ -227,7 +223,7 @@ export type HeadlessResumeExchange =
227223

228224
/**
229225
* Exchanges a found grant for a fresh MCP token, checking in order: revoked (marked, or authorized before the member's
230-
* last credential revocation), expired, bound to this turn, member still active, feature on, rate limit. `memberId`
226+
* last credential revocation), expired, bound to this turn, member still active, rate limit. `memberId`
231227
* is the active membership (null when it ended).
232228
*/
233229
export async function exchangeHeadlessResumeGrant(
@@ -248,9 +244,6 @@ export async function exchangeHeadlessResumeGrant(
248244
if (row.expiresAt.getTime() <= now.getTime()) return { ok: false, status: 403, error: "grant_expired" }
249245
if (!headlessResumeGrantCovers(row, input)) return { ok: false, status: 403, error: "grant_mismatch" }
250246
if (!input.memberId) return { ok: false, status: 403, error: "membership_inactive" }
251-
if (!(await organizationFeatureEnabled(row.organizationId, "headlessDurableTurns"))) {
252-
return { ok: false, status: 403, error: "feature_disabled" }
253-
}
254247
const retryAfterSeconds = await checkRateLimit(
255248
headlessResumeGrantRateLimitKey(row.id),
256249
HEADLESS_RESUME_GRANT_EXCHANGES_PER_WINDOW,

‎ee/apps/den-api/src/headless-runner/routes.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { HEADLESS_INDEX_MAX_UPDATES, HEADLESS_INDEX_ROUTE, headlessIndexRequestS
1414
/**
1515
* The headless runner's calls back into Den, both authenticated with DEN_HEADLESS_RUNNER_CALLBACK_TOKEN (404 when
1616
* unset), internal (not in the published API document) and never MCP capabilities:
17-
* - exchanging a turn's resume grant (feature `headlessDurableTurns`) for a fresh member-scoped MCP token, so it can
17+
* - exchanging a turn's resume grant (saved step turns) for a fresh member-scoped MCP token, so it can
1818
* continue the turn after a restart or refresh a long turn's token. Never log the grant or the token.
1919
* - reporting sessions' content-free totals and state to Den's session index, each update with the capability Den
2020
* minted for that session (session-index.ts). Never log a capability.
@@ -125,7 +125,7 @@ export function registerHeadlessRunnerRoutes<T extends Env>(app: Hono<T>) {
125125
security: [{ headlessRunnerCallbackToken: [] }],
126126
summary: "Exchange a headless turn's resume grant for a fresh MCP token",
127127
description:
128-
"For the headless runner only, with `Authorization: Bearer $DEN_HEADLESS_RUNNER_CALLBACK_TOKEN`. Body `{ grant, sessionId, messageId }`. Exchanges the resume grant Den minted with a turn for a fresh member-scoped MCP token (at most an hour, same read-only setting) for that turn, its background tasks and their reports, while the member is still active and `headlessDurableTurns` is on. 403 answers are permanent for the grant. Answers 404 when DEN_HEADLESS_RUNNER_CALLBACK_TOKEN is not configured.",
128+
"For the headless runner only, with `Authorization: Bearer $DEN_HEADLESS_RUNNER_CALLBACK_TOKEN`. Body `{ grant, sessionId, messageId }`. Exchanges the resume grant Den minted with a turn for a fresh member-scoped MCP token (at most an hour, same read-only setting) for that turn, its background tasks and their reports, while the member is still active. 403 answers are permanent for the grant. Answers 404 when DEN_HEADLESS_RUNNER_CALLBACK_TOKEN is not configured.",
129129
responses: {
130130
200: jsonResponse("A fresh MCP token for the turn.", exchangeResponseSchema),
131131
400: jsonResponse("The body is not `{ grant, sessionId, messageId }`.", exchangeErrorSchema),

0 commit comments

Comments
 (0)