Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/contributing/architecture/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ materialized secret's `allowed_hosts` against the token host before the request
placeholder resolution. Platform-lane destinations are operator-pinned rows, so
no user-secret allowlist applies.

Reconnectable caller-errors (`IntegrationTokenRefreshCallerError`: missing
refresh token, provider HTTP 4xx / `invalid_grant`, missing secrets,
host-approval gaps, invalid connection config) best-effort dispatch
`integration.auth.failed` to the owning user's packages that declare the topic.
Every classified attempt emits; the platform does not coalesce repeats. Provider
HTTP 5xx and missing connections do not emit. The payload is metadata-first
(connection name, lane, reason, optional provider error fields, trusted
`reconnect_url`) and never includes token or secret values. See
[Package subscriptions](../../guides/package-subscriptions.md).

On 401, `createAuthenticatedFetch` calls `integration_token_refresh` then
retries with a `{{secret:…}}` placeholder `Authorization` header, so raw tokens
never enter the sandbox heap. Package code that triggers refresh through
Expand Down
9 changes: 9 additions & 0 deletions docs/contributing/packages-and-manifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ emit (recursion guard). See
[Package subscriptions](../guides/package-subscriptions.md) and
[Run records](./architecture/run-records.md).

For reconnectable OAuth refresh failures, `integration.auth.failed` dispatches
best-effort from host-side `refreshIntegrationTokens`
(`createAuthenticatedFetch` 401 retry and explicit `integration_token_refresh`).
The payload is metadata-first (connection name, lane, reason, optional provider
error fields, and a trusted `reconnect_url`); it omits token and secret values.
Every classified attempt emits. Provider HTTP 5xx and missing connections do not
emit. See [Package subscriptions](../guides/package-subscriptions.md) and
[OAuth integrations](./architecture/integrations.md).

Operator system-inbox mail (`system:email` owner) dispatches the separate
`email.system-message.received` topic to packages saved by users who hold the
admin role at dispatch time, only when the message is accepted. Quarantined
Expand Down
38 changes: 19 additions & 19 deletions docs/guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ content:

## Platform guides

| File | Topic |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [what-is-kody.md](./what-is-kody.md) | Pre-account capability tour and discovery-interview notes; needs no account or MCP connection |
| [how-kody-works.md](./how-kody-works.md) | Factory loop as a conversation: ask what your favorite bot shipped, save an export, daily email only when something shipped |
| [google-oauth.md](./google-oauth.md) | Interactive transcript: agent walks a naive user through Lane B Google OAuth for Gmail inbox reading |
| [quick-example.md](./quick-example.md) | **Start here** after a host authorizes: fork a zero-auth example, invoke the owned package, offer optional triggers |
| [first-win.md](./first-win.md) | Optional email → reply → memories loop (not the onboarding Step 2 climax) |
| [package-authoring.md](./package-authoring.md) | General package-authoring guidance, including the README Intent section |
| [package-lifecycle.md](./package-lifecycle.md) | Choose reuse, one-off execute, community fork when close, direct job schedules, or a new durable package |
| [integration-bootstrap.md](./integration-bootstrap.md) | **Start here** for third-party integrations; after the smoke test, prefer a trusted community fork before building |
| [openapi-integrations.md](./openapi-integrations.md) | OpenAPI discover → summarize → scaffold or curated `openapi:<name>` binding (`openapi_integrations`) |
| [secret-backed-integration.md](./secret-backed-integration.md) | Default recipe for non-OAuth integrations that use one or more saved secrets |
| [integration-backed-app-happy-path.md](./integration-backed-app-happy-path.md) | Default package app pattern after integration smoke test passes |
| [package-service-pattern.md](./package-service-pattern.md) | General package-service pattern for native long-lived runtimes inside Kody |
| [package-subscriptions.md](./package-subscriptions.md) | Package subscription manifest shape, discovery, and email / repo lifecycle / run.error.recorded / admin topic payload guidance |
| [platform-friction.md](./platform-friction.md) | Agent self-improvement loop for Kody capability, package, memory, and guide friction |
| [oauth.md](./oauth.md) | **Start here** for third-party OAuth (`/connect/oauth`, redirect URI, params) |
| [account-secret-setup.md](./account-secret-setup.md) | `/account/secrets/new` URL parameters and policies |
| [account-package-invocation-token-setup.md](./account-package-invocation-token-setup.md) | `/account/package-invocation-tokens/new` URL parameters and bearer-token safety policy |
| File | Topic |
| ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [what-is-kody.md](./what-is-kody.md) | Pre-account capability tour and discovery-interview notes; needs no account or MCP connection |
| [how-kody-works.md](./how-kody-works.md) | Factory loop as a conversation: ask what your favorite bot shipped, save an export, daily email only when something shipped |
| [google-oauth.md](./google-oauth.md) | Interactive transcript: agent walks a naive user through Lane B Google OAuth for Gmail inbox reading |
| [quick-example.md](./quick-example.md) | **Start here** after a host authorizes: fork a zero-auth example, invoke the owned package, offer optional triggers |
| [first-win.md](./first-win.md) | Optional email → reply → memories loop (not the onboarding Step 2 climax) |
| [package-authoring.md](./package-authoring.md) | General package-authoring guidance, including the README Intent section |
| [package-lifecycle.md](./package-lifecycle.md) | Choose reuse, one-off execute, community fork when close, direct job schedules, or a new durable package |
| [integration-bootstrap.md](./integration-bootstrap.md) | **Start here** for third-party integrations; after the smoke test, prefer a trusted community fork before building |
| [openapi-integrations.md](./openapi-integrations.md) | OpenAPI discover → summarize → scaffold or curated `openapi:<name>` binding (`openapi_integrations`) |
| [secret-backed-integration.md](./secret-backed-integration.md) | Default recipe for non-OAuth integrations that use one or more saved secrets |
| [integration-backed-app-happy-path.md](./integration-backed-app-happy-path.md) | Default package app pattern after integration smoke test passes |
| [package-service-pattern.md](./package-service-pattern.md) | General package-service pattern for native long-lived runtimes inside Kody |
| [package-subscriptions.md](./package-subscriptions.md) | Package subscription manifest shape, discovery, and email / repo lifecycle / run.error.recorded / integration.auth.failed / admin topic payload guidance |
| [platform-friction.md](./platform-friction.md) | Agent self-improvement loop for Kody capability, package, memory, and guide friction |
| [oauth.md](./oauth.md) | **Start here** for third-party OAuth (`/connect/oauth`, redirect URI, params) |
| [account-secret-setup.md](./account-secret-setup.md) | `/account/secrets/new` URL parameters and policies |
| [account-package-invocation-token-setup.md](./account-package-invocation-token-setup.md) | `/account/package-invocation-tokens/new` URL parameters and bearer-token safety policy |

## Provider guides

Expand Down
4 changes: 3 additions & 1 deletion docs/guides/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ client ID / client secret form) is skipped and token exchange runs server-side
with the operator's credentials. List the available built-in apps with
`integration_platform_app_list`. All integrations refresh host-side through
`createAuthenticatedFetch`, which calls `integration_token_refresh` on 401 and
retries with a secret placeholder — raw tokens never enter the sandbox. Use
retries with a secret placeholder — raw tokens never enter the sandbox.
Reconnectable refresh failures dispatch `integration.auth.failed` to packages
that subscribe (see [package subscriptions](./package-subscriptions.md)). Use
`refreshAccessToken` only for auth that cannot use an Authorization header
(WebSockets, SDK constructors, query-param tokens); it still runs in-sandbox for
user-owned apps and throws for built-ins. The rest of this guide applies to
Expand Down
58 changes: 55 additions & 3 deletions docs/guides/package-subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ summary:
Use package.json#kody.subscriptions for package-owned event handlers; discover
subscribers with package_subscriptions_list; smoke-test handlers with
package_subscription_dispatch; follow metadata-first email, run.error.recorded
activity notifiers, consent-gated admin-only platform.feedback.submitted
notification guidance, and admin-only status.incident.opened /
status.incident.resolved operator telemetry.
activity notifiers, integration.auth.failed reconnect notifiers, consent-gated
admin-only platform.feedback.submitted notification guidance, and admin-only
status.incident.opened / status.incident.resolved operator telemetry.
category: platform
---

Expand Down Expand Up @@ -460,6 +460,58 @@ never emit. Failed `execute` calls do persist and do emit.
Use this topic for notifier packages that email, write to Sheets, spawn an
agent, or otherwise react when something in the user's account fails.

## `integration.auth.failed`

When host-side OAuth token refresh fails with reconnectable caller state —
missing refresh token, provider HTTP 4xx / `invalid_grant`, missing secrets,
host-approval gaps, or invalid connection config — Kody dispatches
`integration.auth.failed` to packages saved by that same user that declare the
topic. Every classified attempt emits. The platform does not coalesce repeats;
notifier packages decide how often to ping. Provider HTTP 5xx and missing
connections do not emit.

Delivery is best-effort after the refresh caller error is classified — there is
no Queue / DLQ for this topic in v1. Failures during subscriber discovery or
package-invocation infrastructure are logged and do not change the refresh error
the caller sees.

Handlers receive a metadata-first payload:

```ts
type IntegrationAuthFailedEvent = {
event: 'integration.auth.failed'
event_id: string
integration: {
name: string
lane: 'user' | 'platform'
account_label: string | null
provider: string | null
platform_app_slug: string | null
}
reason:
| 'missing_refresh_token'
| 'provider_rejected'
| 'missing_secret'
| 'host_not_approved'
| 'invalid_config'
provider: {
error: string | null
error_description: string | null
http_status: number | null
}
reconnect_url: string
occurred_at: string
}
```

`reconnect_url` is built from the trusted deployment origin and links to
`/connect/oauth?provider=<name>`. The event deliberately omits token values,
secret values, client secrets, and secret names. A short-lived access token that
refreshes cleanly never emits.

Use this topic for notifier packages that post to Discord, email, or otherwise
ask the owner to reconnect a dead grant.

## `repo.pushed`

When Cloudflare Artifacts reports commits pushed to a Kody-managed Artifacts
Expand Down
9 changes: 8 additions & 1 deletion docs/use/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ Use the built-in `package_subscriptions_list` capability to discover the
signed-in user's saved package subscriptions, optionally filtered by exact
topic. This is the generic discovery step before building fan-out, debugging why
an event did or did not dispatch, or checking which packages subscribe to
`email.message.received` or `run.error.recorded`.
`email.message.received`, `run.error.recorded`, or `integration.auth.failed`.

For accepted stored inbound email, the topic is `email.message.received`.
Quarantined inbound email dispatches `email.message.quarantined` instead. Both
Expand All @@ -508,6 +508,13 @@ metadata-first (run id, surface, identifiers, truncated error fields, and an
needed. See [Activity](./activity.md) and the
[package subscriptions guide](../guides/package-subscriptions.md).

When host-side OAuth token refresh fails with reconnectable caller state, Kody
dispatches `integration.auth.failed` to your packages that declare that topic.
The payload is metadata-first (connection name, lane, reason, optional provider
error fields, and a trusted `reconnect_url`). Every classified attempt emits;
notifier packages decide how often to ping. See the
[package subscriptions guide](../guides/package-subscriptions.md).

Artifacts-backed plain repos, packages, and job sources also emit `repo.pushed`,
`repo.created`, and `repo.deleted` when Cloudflare Artifacts reports those
lifecycle events. Session workspace branch pushes (`sessions/<id>`) do not fan
Expand Down
31 changes: 30 additions & 1 deletion docs/use/synthetic-event-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ intended owner-scoped package.
adds `synthetic: true`). Shape depends on the topic:

- **Platform-owned topics** (`email.message.received`, `run.error.recorded`,
`repo.pushed`, …) — use the metadata-first payloads documented in the
`integration.auth.failed`, `repo.pushed`, …) — use the metadata-first payloads
documented in the
[package subscriptions guide](../guides/package-subscriptions.md). Include
only fields your handler reads.
- **Package-emitted topics** (`@scope/topic.name`) — use the
Expand Down Expand Up @@ -108,6 +109,34 @@ Example minimal `run.error.recorded` fixture:
}
```

Example minimal `integration.auth.failed` fixture:

```json
{
"kody_id": "integration-auth-notifier",
"topic": "integration.auth.failed",
"params": {
"event": "integration.auth.failed",
"event_id": "00000000-0000-4000-8000-000000000001",
"integration": {
"name": "google",
"lane": "platform",
"account_label": null,
"provider": "google",
"platform_app_slug": "google"
},
"reason": "provider_rejected",
"provider": {
"error": "invalid_grant",
"error_description": "Token has been expired or revoked.",
"http_status": 400
},
"reconnect_url": "https://kody.codes/connect/oauth?provider=google",
"occurred_at": "2026-08-18T17:00:00.000Z"
}
}
```

### Stored-mail replay (`email_message_id`)

For email topics, pass a stored message id instead of hand-building metadata:
Expand Down
Loading
Loading