Skip to content

Commit 630cedc

Browse files
author
ben
authored
feat(workbot): track content-free adoption in Den (#6156)
* feat(workbot): track content-free adoption in Den Record member-scoped admission and completion from trusted services rather than browser relay events. Reuse the telemetry tables and existing service credential, preserve first sightings atomically, and distinguish provider-reported model identity from configured fallback. Add a bounded read-only platform-admin funnel and content/privacy/authentication integration coverage. Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * fix(workbot): preserve sign-in time across readiness probes Record the authenticated sign-in instant before its asynchronous connection snapshot so a fast greeting cannot fall outside its adoption cohort. Exercise runner telemetry and Workbot sign-in tests in the existing CI lanes. Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * test(workbot): keep fast greetings in delayed sign-in cohorts Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * fix(workbot): correlate OAuth telemetry by public nonce Never pass signed OAuth state through telemetry identity derivation. Reuse the transaction's public UUID directly for deduplication, keep signed state and credentials outside the sink, and preserve first lifecycle identifiers. Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * fix(workbot): keep telemetry outcomes content-free Use a shared closed error-code vocabulary at producer and sink rather than accepting arbitrary provider-defined slugs. Derive contextual-turn counts from trusted policy instead of message text. Cover both privacy boundaries and build the shared runner protocol in its existing CI lane. Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * fix(workbot): reject credential-like model telemetry Do not treat reflected model keys, turn tokens or provider prose as model identifiers. Protect both admission and terminal delivery, omit unsafe identities at the sink and retain unknown attribution without dropping the outcome. Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com> * fix(workbot): bind telemetry to an explicit trusted Den origin * fix(workbot): preserve Responses attribution and prove key redaction --------- Signed-off-by: Benjamin Shafii <benjamin.shafii@gmail.com>
1 parent 2f11350 commit 630cedc

34 files changed

Lines changed: 2007 additions & 13 deletions

‎.github/workflows/ci-tests.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ jobs:
8484
uses: ./.github/actions/setup-tests
8585
- name: Check Den web hook order
8686
run: pnpm --filter @openwork-ee/den-web lint
87+
- name: Build the shared headless protocol
88+
run: pnpm --filter @openwork-ee/headless-protocol build
8789
- name: Typecheck the headless runner
8890
run: pnpm --filter @openwork-ee/headless-runner typecheck
8991
- name: Test shared headless computer and configuration
@@ -95,6 +97,8 @@ jobs:
9597
run: |
9698
pnpm --filter @openwork-ee/headless-runner test:conversation
9799
pnpm --filter @openwork-ee/headless-runner test:transfer
100+
- name: Test Workbot sign-in and adoption boundary
101+
run: pnpm --filter @openwork-ee/workbot test:auth
98102
- name: Test opt-in error reporting (runner and Workbot)
99103
run: |
100104
pnpm --filter @openwork-ee/headless-runner test:error-reporting

‎docs/workbot-adoption.md‎

Lines changed: 328 additions & 0 deletions
Large diffs are not rendered by default.

‎ee/apps/den-api/src/audit/COVERAGE.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Generated by `pnpm --filter @openwork-ee/den-api audit:coverage --write` from `src/audit/routes`. Do not edit by hand; CI fails when this file is stale.
44

5-
- 613 den-api route keys (`app.routes`), 143 HTTP-reachable better-auth endpoints, 738 declarations.
5+
- 614 den-api route keys (`app.routes`), 143 HTTP-reachable better-auth endpoints, 739 declarations.
66
- Tenant capture requires `DEN_AUDIT_CAPTURE_ENABLED`, an enabled policy and the class category; with capture off no audit database work happens.
77
- Request evidence: declared resource type, validated path-parameter id (`unparseable` otherwise) or `collection:<type>`, parent organization, method, route template and status. Never bodies, query strings, headers, IPs or secrets.
88
- One operation per request: intent, outcome and domain change events (`appendAuditChanges`) share it. Requests without trustworthy tenant attribution go to `platform_audit_event` (no organization column, not tenant-visible) with a target: the declared resource type plus validated path id, else the first handler-named resource; an organization target only when it is the authenticated context's organization.
@@ -19,7 +19,7 @@ Generated by `pnpm --filter @openwork-ee/den-api audit:coverage --write` from `s
1919
| tenant_change | 218 | requested before handler; succeeded/attempted after (request) | .requested .succeeded .attempted | intent: up to 3 attempts on transient database errors, then 503, handler not run; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] |
2020
| tenant_external | 87 | requested before handler; confirmed/attempted, 5xx unknown (request) | .requested .confirmed .attempted .unknown | intent: up to 3 attempts on transient database errors, then 503, handler not run; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] |
2121
| tenant_job | 12 | requested before handler; accepted/attempted after (execution) | .requested .accepted .attempted | intent: up to 3 attempts on transient database errors, then 503, handler not run; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] |
22-
| tenant_signal | 14 | one outcome after handler: observed/attempted (category read, off by default; denials use security when selected); no intent | .observed .attempted | never fail-closed: capture-start failure served without capture; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] |
22+
| tenant_signal | 15 | one outcome after handler: observed/attempted (category read, off by default; denials use security when selected); no intent | .observed .attempted | never fail-closed: capture-start failure served without capture; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] |
2323
| domain_provider | 14 | provider emitter (src/audit/provider.ts) | none | evidence failure rolls back (in-transaction, not retried); attempts outside rollback: up to 3 attempts on transient database errors, then propagated |
2424
| domain_audit | 6 | audit emitter (src/routes/org/audit.ts) | none | up to 3 attempts on transient database errors, then fails closed with 503 |
2525
| platform | 149 | platform_audit_event after handler with target | .succeeded .attempted | written before the response is released; up to 3 attempts on transient database errors, then a failed insert never fails the request ([platform-audit-lost]) |
@@ -910,6 +910,7 @@ When tenant capture is active the domain emitter appends the new change event in
910910
| POST | `/v1/workbot/documents/*` | proxy | `workbot.documents.save` | workbot.execution | google_drive_file | handler | destination route records | | none | Verified MCP OAuth membership, write scope and both flags; allowlisted editor/session actions only, strict destination schemas and connector policy. |
911911
| POST | `/v1/workbot/run-token` | tenant_access | `workbot.run_token.issue` | workbot.execution | oauth_access_token | handler | requested before handler; served before release (access) | request evidence only | intent or served: up to 3 attempts on transient database errors, then 503, no content | 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. |
912912
| GET | `/v1/workbot/session` | tenant_read | `workbot.session.read` | workbot.execution | workbot_session | handler | served before release (category read, off by default) | request evidence only | capture-start failure: served without capture; served append after capture started: up to 3 attempts on transient database errors, then 503, no content | Handler verifies the MCP OAuth token (verifyMcpRequest) and active membership, then attributes the token's org and user. |
913+
| POST | `/v1/workbot/telemetry` | tenant_signal | `workbot.telemetry.ingest` | telemetry.adoption | telemetry_event | handler | one outcome after handler: observed/attempted (category read, off by default; denials use security when selected); no intent | request evidence only | never fail-closed: capture-start failure served without capture; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] | Service credential plus verified MCP member token; bounded identifiers, counts and outcomes only. Best-effort telemetry, never message content. |
913914
| GET | `/v1/workers` | tenant_read | `worker.list` | worker.management | worker | org_context | served before release (category read, off by default) | request evidence only | capture-start failure: served without capture; served append after capture started: up to 3 attempts on transient database errors, then 503, no content | orgMemberRoute({ useUserOrganizations: true }): resolveUserOrganizationsMiddleware calls beginUserOrganizationsAuditRequest with the active organization, which is always one of the caller's verified memberships (API-key org or X-OpenWork-Org-Id filtered to them, else the session active org); actor = user + that membership's member id. These handlers act only on that organization's rows (getWorkerByIdForOrg / listWorkersPage). No active organization: platform store. |
914915
| DELETE | `/v1/workers/:id` | tenant_external | `worker.delete` | worker.management | worker (:id) | org_context | requested before handler; confirmed/attempted, 5xx unknown (request) | request evidence only | intent: up to 3 attempts on transient database errors, then 503, handler not run; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] | external: cloud_runtime (Daytona deprovision); orgMemberRoute({ useUserOrganizations: true }): resolveUserOrganizationsMiddleware calls beginUserOrganizationsAuditRequest with the active organization, which is always one of the caller's verified memberships (API-key org or X-OpenWork-Org-Id filtered to them, else the session active org); actor = user + that membership's member id. These handlers act only on that organization's rows (getWorkerByIdForOrg / listWorkersPage). No active organization: platform store. |
915916
| POST | `/v1/workers/:id/activity-heartbeat` | tenant_signal | `worker.activity.heartbeat` | worker.runtime | worker (:id) | handler | one outcome after handler: observed/attempted (category read, off by default; denials use security when selected); no intent | request evidence only | never fail-closed: capture-start failure served without capture; outcome: up to 3 attempts on transient database errors, then logged [audit-outcome-lost] | Org proof: activity-scope WorkerTokenTable match for :id -> worker org (actor service worker:<id>). High volume. |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export const contentAuditRoutes: readonly AuditRouteDeclaration[] = [
183183
// Resources, Workbot, brand assets
184184
member("GET", "/v1/resources", "tenant_read", "resource_snapshot.read", "resource.discovery", "resource_snapshot", null, { notes: "Desktop polling endpoint; ids and timestamps only." }),
185185
member("GET", "/v1/resources/marketplace-capabilities", "tenant_read", "marketplace_capability.list", "resource.discovery", "marketplace_capability", null),
186+
route("POST", "/v1/workbot/telemetry", "tenant_signal", "workbot.telemetry.ingest", "telemetry.adoption", "telemetry_event", null, "handler", { notes: "Service credential plus verified MCP member token; bounded identifiers, counts and outcomes only. Best-effort telemetry, never message content." }),
186187
route("GET", "/v1/workbot/session", "tenant_read", "workbot.session.read", "workbot.execution", "workbot_session", null, "handler", { notes: "Handler verifies the MCP OAuth token (verifyMcpRequest) and active membership, then attributes the token's org and user." }),
187188
route("GET", "/v1/workbot/connections", "tenant_read", "workbot.connection.list", "workbot.execution", "mcp_connection", null, "handler", { notes: "Handler verifies the MCP OAuth token and active membership, returns 403 while the workbot feature is off, then lists the Gmail/Google Workspace, Slack and Microsoft 365 connections this member may use (id, name, readiness, Den connect URL; no secrets)." }),
188189
route("GET", "/v1/workbot/calendar/*", "proxy", "workbot.calendar.read", "workbot.execution", "automation", null, "handler", { notes: "Handler verifies the MCP OAuth token, membership and the workbot feature, then re-dispatches an allowlisted read (the member's Automations, runs, run receipts, native calendar events, and usable LLM providers trimmed to names and model IDs) through app.fetch with a signed internal principal; the destination route records." }),

‎ee/apps/den-api/src/mcp/admin-tools.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { updateFeatureRollout, updateOrganizationFeatureOverrides } from "../fea
1313
import { FEATURE_KEYS, featureAvailableOn, featureDefinition, featureKeySchema, featureRollout, resolveFeature } from "@openwork/features"
1414
import { updateOrganizationMetadata } from "../organization-metadata.js"
1515
import { runPlatformAdminPlatformAction, runPlatformAdminServiceAction, type PlatformAdminAuditActor } from "../audit/mcp-service-audit.js"
16+
import { readWorkbotAdoptionReport, workbotAdoptionInputSchema } from "../workbot/adoption-report.js"
1617

1718
/**
1819
* den-admin MCP toolset: read-only Den analytics for allowlisted platform
@@ -28,7 +29,7 @@ import { runPlatformAdminPlatformAction, runPlatformAdminServiceAction, type Pla
2829
* timeout so one expensive SELECT cannot pin an API worker indefinitely.
2930
*/
3031

31-
export const DEN_ADMIN_MCP_VERSION = "0.7.0"
32+
export const DEN_ADMIN_MCP_VERSION = "0.8.0"
3233

3334
const QUERY_TIMEOUT_MS = 15_000
3435
const DEFAULT_ROW_LIMIT = 200
@@ -703,6 +704,21 @@ export function registerAdminMcpTools(server: McpServer, admin: PlatformAdminAud
703704
}),
704705
)
705706

707+
server.registerTool(
708+
"den_workbot_adoption",
709+
{
710+
description:
711+
"Platform-admin read-only Workbot adoption funnel, grouped by first recorded sign-in day (UTC) and organization: signed in, greeting completed, first message, at least one connected service. Includes id-only member pages with initial/greeting ready counts, later connection success counts, completion model/source details, and greeting failures by error code/model. Dates are inclusive, at most 90 days; totals cover the full cohort even when breakdowns are truncated. Never reads messages or profile fields.",
712+
inputSchema: workbotAdoptionInputSchema,
713+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
714+
},
715+
async (input) =>
716+
run(async () => {
717+
if (!admin) throw new Error("Workbot adoption reports require an authenticated platform admin.")
718+
return readWorkbotAdoptionReport(input, rows)
719+
}),
720+
)
721+
706722
server.registerTool(
707723
"den_company_users",
708724
{

‎ee/apps/den-api/src/routes/org/mcp-connections.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { cache, type CachedOrgMember } from "../../cache.js"
3030
import { db } from "../../db.js"
3131
import { requestReadFor } from "../../request-reads.js"
3232
import { env } from "../../env.js"
33+
import { recordWorkbotConnection } from "../../workbot/telemetry.js"
3334
import { memberSignInLink } from "../../agent-links.js"
3435
import { appLogger } from "../../observability/logger.js"
3536
import {
@@ -1645,7 +1646,7 @@ async function handleExternalMcpOAuthCallback(input: {
16451646
// change this separate grant binding.
16461647
await rotateReadinessCredentialBinding(connection, statePayload.orgMembershipId)
16471648
const refreshedConnection = await getExternalMcpConnection({ organizationId: connection.organizationId, connectionId: connection.id })
1648-
if (refreshedConnection) await checkConnectionReadiness(refreshedConnection, statePayload.orgMembershipId, input.requestId)
1649+
const readiness = refreshedConnection ? await checkConnectionReadiness(refreshedConnection, statePayload.orgMembershipId, input.requestId) : null
16491650
if (member) {
16501651
const { bindSlackOAuthMember } = await import("../../slack-assistant/repository.js")
16511652
try {
@@ -1654,6 +1655,9 @@ async function handleExternalMcpOAuthCallback(input: {
16541655
return mcpOAuthCallbackHtml(connectCallbackPage({ ok: false, name: connection.name, message: "Slack connected, but the assistant identity could not be verified. Connect the Slack account for this workspace and try again." }), 400)
16551656
}
16561657
}
1658+
if (readiness?.status === "ready") void recordWorkbotConnection({ organizationId: statePayload.organizationId, memberId: statePayload.orgMembershipId }, {
1659+
attemptId: statePayload.nonce, connectionId: connection.id, appId: "external_mcp",
1660+
})
16571661
return mcpOAuthCallbackHtml(connectCallbackPage({ ok: true, name: connection.name }))
16581662
}
16591663

‎ee/apps/den-api/src/routes/org/oauth-providers.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from "zod"
44
import { normalizeDenTypeId, type DenTypeId } from "@openwork-ee/utils/typeid"
55
import { attributeOAuthCallbackMember } from "../../audit/request-capture.js"
66
import { env } from "../../env.js"
7+
import { recordWorkbotConnection } from "../../workbot/telemetry.js"
78
import {
89
jsonValidator,
910
orgMemberRoute,
@@ -718,6 +719,9 @@ export function registerOAuthProviderRoutes<T extends { Variables: OrgRouteVaria
718719
}), 200)
719720
}
720721

722+
void recordWorkbotConnection({ organizationId: statePayload.organizationId, memberId: statePayload.orgMembershipId }, {
723+
attemptId: statePayload.nonce, connectionId: credentialProviderId, appId: provider.providerId,
724+
})
721725
return c.html(connectCallbackPage({ ok: true, name: provider.displayName }))
722726
},
723727
)

‎ee/apps/den-api/src/routes/telemetry/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function registerTelemetryRoutes<T extends { Variables: TelemetryRouteVar
7575
const batch = c.req.valid("json")
7676

7777
try {
78-
const accepted = batch.events.filter((event) => isKnownTelemetryEventType(event.type))
78+
const accepted = batch.events.filter((event) => isKnownTelemetryEventType(event.type)
79+
&& !event.type.startsWith("workbot.") && event.type !== "connection.connected" && event.source !== "workbot")
7980

8081
const eventRows = accepted.map((event) => ({
8182
id: createDenTypeId("telemetryEvent"),

0 commit comments

Comments
 (0)