diff --git a/apps/sim/connectors/website/website.integration.ts b/apps/sim/connectors/website/website.integration.ts
index 48993cdd32a..10622e5dc69 100644
--- a/apps/sim/connectors/website/website.integration.ts
+++ b/apps/sim/connectors/website/website.integration.ts
@@ -1150,6 +1150,27 @@ describe('website connector over real HTTP', () => {
})
})
+ it('withdraws a crawled page that is now gone, even from a crawl that could not read every page', async () => {
+ extraLinks = 'Gone'
+ for (const incomplete of [false, true]) {
+ lockedLink = incomplete
+ const context: Record = {}
+ const listed = await websiteConnector.listDocuments(
+ `X-Api-Key: ${KEY}`,
+ { ...config(), discovery: 'links', maxDepth: '1' },
+ undefined,
+ context
+ )
+ expect(context.reconciliationUnsafe).toBe(incomplete || undefined)
+ expect(
+ listed.documents.find((document) => document.externalId === `${site}/gone`)
+ ).toMatchObject({
+ skippedReason: 'The page no longer exists on the site',
+ skippedExistingDisposition: 'replace',
+ })
+ }
+ })
+
it('counts a page listed under the URL it redirects to once against the page cap', async () => {
bareHome = true
extraLinks = 'Guide'
diff --git a/apps/sim/connectors/website/website.ts b/apps/sim/connectors/website/website.ts
index b170afd2483..af214ca9a4a 100644
--- a/apps/sim/connectors/website/website.ts
+++ b/apps/sim/connectors/website/website.ts
@@ -294,14 +294,14 @@ type PageRead = CrawledPage
* the site's robots.txt asks for, and `retryOptions.signal`, when given, bounds that wait too.
*
* What a page itself says is permanent until the page changes, so it withdraws the page rather
- * than leaving the listing incomplete: a redirect out of the scope, a size or markup past what is
- * read, no text, or a request not to be indexed. A crawl does not reach pages linked only from
- * such a page, as it does not reach pages past its depth. A redirect out of the scope throws instead
- * when the site URL redirects away too ({@link siteRedirectsAway}); otherwise only a fetch failure
- * (network, 5xx, deadline) throws, leaving a crawl incomplete. With `identify`, a crawl's page is
- * listed under the URL a redirect finally served it from, and a page naming another in-scope page
- * as `rel="canonical"` hands the crawl that page instead of being listed; a read by external ID
- * keeps that ID.
+ * than leaving the listing incomplete: gone from the site (404 or 410), a redirect out of the
+ * scope, a size or markup past what is read, no text, or a request not to be indexed. A crawl does
+ * not reach pages linked only from such a page, as it does not reach pages past its depth. A
+ * redirect out of the scope throws instead when the site URL redirects away too
+ * ({@link siteRedirectsAway}); otherwise only a fetch failure (network, 5xx, deadline) throws,
+ * leaving a crawl incomplete. With `identify`, a crawl's page is listed under the URL a redirect
+ * finally served it from, and a page naming another in-scope page as `rel="canonical"` hands the
+ * crawl that page instead of being listed; a read by external ID keeps that ID.
*/
async function readPage(
session: WebsiteSession,
@@ -312,7 +312,6 @@ async function readPage(
identify = false,
}: { retryOptions?: SecureFetchRetryOptions; scope?: WebsiteScope; identify?: boolean } = {}
): Promise {
- const unlisted = (value: ExternalDocument): PageRead => ({ value, links: [] })
const excluded = (reason: string, read?: { links: string[]; base: string }): PageRead => ({
value: withdrawn(page, reason),
withdrawn: true,
@@ -346,7 +345,7 @@ async function readPage(
if (!isPayloadSizeLimitError(error)) throw error
return excluded(sizeLimitSkipReason(PAGE_MAX_BYTES))
}
- if (!resource) return unlisted(withdrawn(page, 'The page no longer exists on the site'))
+ if (!resource) return excluded('The page no longer exists on the site')
const contentType = resource.headers.get('content-type') ?? ''
if (!/html/i.test(contentType)) return excluded('The URL serves a file, not an HTML page')
const header = robotsDirectives(resource.headers.get('x-robots-tag'))
diff --git a/apps/sim/lib/billing/core/organization-adoption.integration.ts b/apps/sim/lib/billing/core/organization-adoption.integration.ts
index 1a8318c4238..9471911a1fd 100644
--- a/apps/sim/lib/billing/core/organization-adoption.integration.ts
+++ b/apps/sim/lib/billing/core/organization-adoption.integration.ts
@@ -99,6 +99,8 @@ describe('organization adoption', () => {
[
['search', 'success', '2026-11-10T09:00:00Z', null],
['search', 'error', '2026-11-10T09:05:00Z', null],
+ ['search', 'rate_limited', '2026-11-10T09:06:00Z', null],
+ ['search', 'rate_limited', '2026-11-13T09:00:00Z', null, cal],
['chat', 'success', '2026-11-11T09:00:00Z', 'Claude'],
['search', 'success', '2026-10-31T23:59:00Z', null],
['search', 'success', '2026-11-12T09:00:00Z', null, formerId],
@@ -110,7 +112,7 @@ describe('organization adoption', () => {
oauthClientId: clientName ? 'client' : null,
clientName,
toolName: toolName as 'search' | 'chat',
- outcome: outcome as 'success' | 'error',
+ outcome: outcome as 'success' | 'error' | 'rate_limited',
durationMs: 5,
createdAt: new Date(createdAt as string),
}))
@@ -290,7 +292,7 @@ describe('organization adoption', () => {
])
})
- it('breaks Search MCP calls by current members in the window down by tool and by client', async () => {
+ it('breaks admitted Search MCP calls by current members in the window down by tool and by client', async () => {
const tools = await readAdoptionBreakdown(days, 'mcp_tool')
expect(tools.rows.map((row) => [row.label, row.total, row.failed, row.activeMembers])).toEqual([
['search', 2, 1, 1],
diff --git a/apps/sim/lib/billing/core/organization-adoption.ts b/apps/sim/lib/billing/core/organization-adoption.ts
index bf29c14780f..5fb1d5c2c87 100644
--- a/apps/sim/lib/billing/core/organization-adoption.ts
+++ b/apps/sim/lib/billing/core/organization-adoption.ts
@@ -17,6 +17,7 @@ import {
type OrganizationAdoptionMember,
type OrganizationAdoptionSummary,
} from '@/lib/api/contracts/organization-adoption'
+import { countedSearchMcpCall } from '@/lib/knowledge/mcp/activity'
const DAY_MS = 86_400_000
/** Groups per breakdown; past this the response says it is truncated. */
@@ -266,6 +267,7 @@ export async function readAdoptionBreakdown(
FROM ${organizationSearchMcpInvocation} i
JOIN ${member} m ON m.user_id = i.user_id AND m.organization_id = i.organization_id
WHERE i.organization_id = ${days.organizationId}
+ AND ${countedSearchMcpCall(sql`i.outcome`)}
AND i.created_at >= (${days.from}::timestamp AT TIME ZONE 'UTC')
AND i.created_at < (${days.to}::timestamp AT TIME ZONE 'UTC')
GROUP BY 1
diff --git a/apps/sim/lib/knowledge/mcp/activity.ts b/apps/sim/lib/knowledge/mcp/activity.ts
index cb7ade5a272..74be2d9888f 100644
--- a/apps/sim/lib/knowledge/mcp/activity.ts
+++ b/apps/sim/lib/knowledge/mcp/activity.ts
@@ -3,7 +3,7 @@ import { organizationSearchMcpInvocation } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { getErrorMessage } from '@sim/utils/errors'
import { generateId } from '@sim/utils/id'
-import { sql } from 'drizzle-orm'
+import { type SQL, sql } from 'drizzle-orm'
import { recordMemberActivity } from '@/lib/organizations/member-activity/record'
const logger = createLogger('OrganizationSearchMcpActivity')
@@ -21,6 +21,17 @@ export type SearchMcpActivityInput = Pick<
| 'createdAt'
>
+/** A rate-limited call was refused before it ran, so it is never a member's use of Search MCP. */
+const UNCOUNTED_OUTCOME = 'rate_limited' satisfies SearchMcpActivityInput['outcome']
+
+/**
+ * The SQL condition that an invocation row's `outcome` counts as a member's use: the same rule the
+ * live recorder applies, for every read and backfill of the invocation log.
+ */
+export function countedSearchMcpCall(outcome: SQL): SQL {
+ return sql`${outcome} <> ${UNCOUNTED_OUTCOME}`
+}
+
/**
* Stores content-free metadata from an admitted MCP request, independently of tool success, and
* counts a person's call that was not rate limited toward their adoption.
@@ -49,7 +60,7 @@ export async function recordOrganizationSearchMcpActivity(
error: getErrorMessage(error),
})
}
- if (input.userId && input.outcome !== 'rate_limited') {
+ if (input.userId && input.outcome !== UNCOUNTED_OUTCOME) {
recordMemberActivity({
userId: input.userId,
surface: 'search_mcp',
diff --git a/apps/sim/lib/organizations/member-activity/backfill.ts b/apps/sim/lib/organizations/member-activity/backfill.ts
index d9b12e12890..278fff64c25 100644
--- a/apps/sim/lib/organizations/member-activity/backfill.ts
+++ b/apps/sim/lib/organizations/member-activity/backfill.ts
@@ -8,6 +8,7 @@ import {
workspace,
} from '@sim/db/schema'
import { type SQL, sql } from 'drizzle-orm'
+import { countedSearchMcpCall } from '@/lib/knowledge/mcp/activity'
import { isInboxTurn } from '@/lib/mothership/inbox/turns'
const DAY_MS = 86_400_000
@@ -54,7 +55,7 @@ function searchMcpActivity(from: string, to: string): SQL {
min(i.created_at) AS first_at, max(i.created_at) AS last_at
FROM ${organizationSearchMcpInvocation} i
JOIN ${member} mb ON mb.user_id = i.user_id AND mb.organization_id = i.organization_id
- WHERE i.user_id IS NOT NULL AND i.outcome <> 'rate_limited'
+ WHERE i.user_id IS NOT NULL AND ${countedSearchMcpCall(sql`i.outcome`)}
AND i.created_at >= (${from}::timestamp AT TIME ZONE 'UTC')
AND i.created_at < (${to}::timestamp AT TIME ZONE 'UTC')
GROUP BY 1, 2, 3, 4`