Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(session-replay): honor fractional crawl-delay and unscoped noai (#88268)

Robbie25cfd8c27893
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
index cd15a4fb393a..801cc098f8c3 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
@@ -404,7 +404,7 @@ A terminal refusal has no destination Kafka record, so it starts at step 2. A de
}
```
-`v` is the integer `2`. `jobs` contains 1 to 1,000 entries, and the decoded JSON record cannot exceed 512 KiB. `originalRef` is the ref calculated for the URL first seen in the replay. `currentUrl` is the next URL to request after any redirects. `remainingHops`, `notBeforeMs`, `firstSeenAtMs`, `fetchCount`, and `republishCount` are non-negative safe integers. `firstSeenAtMs` is the Unix time when the producer first collected the URL. `fetchCount` counts image HTTP requests, and `republishCount` counts frontier and delay-topic republishes. `lastRepublishReason` is `null`, `redirect`, `retry`, `not_ready`, `pass_deadline`, `origin_map_full`, or `registrable_domain_map_full`.
+`v` is the integer `2`. The parser also accepts the two version `1` shapes that preceded this schema, so records already in a topic drain across an upgrade. `jobs` contains 1 to 1,000 entries, and the decoded JSON record cannot exceed 512 KiB. `originalRef` is the ref calculated for the URL first seen in the replay. `currentUrl` is the next URL to request after any redirects. `remainingHops`, `notBeforeMs`, `firstSeenAtMs`, `fetchCount`, and `republishCount` are non-negative safe integers. `firstSeenAtMs` is the Unix time when the producer first collected the URL. `fetchCount` counts image HTTP requests, and `republishCount` counts frontier and delay-topic republishes. `lastRepublishReason` is `null`, `redirect`, `retry`, `not_ready`, `pass_deadline`, `origin_map_full`, or `registrable_domain_map_full`.
The parser ignores unknown fields so that a producer can add optional data without breaking an older consumer. It rejects a missing field, an invalid field type or value, an unsupported version, or a record whose jobs do not all match the Kafka key. It derives the current origin and registrable domain from `currentUrl` with the shared URL-policy implementation. It uses `originalRef` as the crawl-history key so that a redirect result completes the URL that the recording referenced.
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
index 7a1921d2c125..3f386c3f61a9 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
@@ -102,13 +102,15 @@ describe('robots policy', () => {
'Crawl-delay: 0x10',
'Crawl-delay: 1e3',
'Crawl-delay: 2.5',
+ // 16.1 * 1000 is 16100.000000000002, which is not a safe integer.
+ 'Crawl-delay: 16.1',
'Allow: /',
].join('\n')
const result = await parseRobotsPolicy(body, `${ORIGIN}/image.png`)
expect(result).toMatchObject({
allowed: true,
- crawlDelayMs: 2_500,
+ crawlDelayMs: 16_100,
})
})
@@ -162,11 +164,32 @@ describe('response opt-out policy', () => {
expect(responseOptOutReason([{ name: 'tdm-reservation', value: '1' }], false)).toBe('tdm_reservation')
})
- it('applies a bot-specific X-Robots-Tag refusal', () => {
- expect(
- responseOptOutReason([{ name: 'x-robots-tag', value: 'PostHogImageFetcherBot: noindex, noimageai' }], false)
- ).toBe('x_robots_tag')
- expect(responseOptOutReason([{ name: 'x-robots-tag', value: 'OtherBot: noai' }], false)).toBeUndefined()
+ it.each([
+ ['a scope for this bot', 'PostHogImageFetcherBot: noindex, noimageai', 'x_robots_tag'],
+ ['a scope for another bot', 'OtherBot: noai', undefined],
+ [
+ 'no scope beside a colon-bearing directive',
+ 'noai, unavailable_after: 25 Jun 2026 15:00:00 PST',
+ 'x_robots_tag',
+ ],
+ [
+ 'a scope for another bot beside a colon-bearing directive',
+ 'OtherBot: noai, unavailable_after: 25 Jun 2026 15:00:00 PST',
+ undefined,
+ ],
+ [
+ 'no scope after a leading valued directive',
+ 'unavailable_after: 25 Jun 2026 15:00:00 PST, noai',
+ 'x_robots_tag',
+ ],
+ ['no scope after a leading max-image-preview', 'max-image-preview: large, noai', 'x_robots_tag'],
+ [
+ 'a scope for another bot before a valued directive',
+ 'OtherBot: unavailable_after: 25 Jun 2026 15:00:00 PST, noai',
+ undefined,
+ ],
+ ])('applies an X-Robots-Tag value with %s', (_name, value, expected) => {
+ expect(responseOptOutReason([{ name: 'x-robots-tag', value }], false)).toBe(expected)
})
})
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
index 9f1b33ec1c98..a2552b53b638 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
@@ -493,7 +493,8 @@ function evaluateRobotsPolicy(
if (!/^\d+(?:\.\d+)?$/.test(value)) {
return []
}
- const milliseconds = Number(value) * 1000
+ // A decimal multiplied by 1000 is not always exact. 16.1 * 1000 is 16100.000000000002. The safe-integer guard below rejects that value, but README 7.9 accepts the delay.
+ const milliseconds = Math.round(Number(value) * 1000)
return Number.isSafeInteger(milliseconds) ? [milliseconds] : []
})
)
@@ -617,13 +618,20 @@ export function responseOptOutReason(
return undefined
}
+// X-Robots-Tag directives that carry a value, from https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag. A colon inside one of these does not start a bot scope.
+const VALUED_X_ROBOTS_DIRECTIVES = ['unavailable_after', 'max-snippet', 'max-image-preview', 'max-video-preview']
+
function xRobotsTagRefuses(value: string): boolean {
const lower = value.toLowerCase()
const colon = lower.indexOf(':')
- const directives = colon >= 0 ? lower.slice(colon + 1) : lower
- if (colon >= 0 && lower.slice(0, colon).trim() !== BOT_NAME.toLowerCase()) {
+ // A bot scope is one token before the first colon. A valued directive looks the same, so the lane must tell the two apart. Otherwise it reads `unavailable_after: <date>, noai` as another bot's scope and ignores an opt-out that README 2.6 requires.
+ // A prefix that names no listed directive reads as a bot scope. This keeps another bot's scope intact. A new valued directive therefore needs an entry in the list above, because until then the lane skips a `noai` that follows it.
+ const prefix = colon >= 0 ? lower.slice(0, colon).trim() : ''
+ const scoped = colon >= 0 && !prefix.includes(',') && !VALUED_X_ROBOTS_DIRECTIVES.includes(prefix)
+ if (scoped && prefix !== BOT_NAME.toLowerCase()) {
return false
}
+ const directives = scoped ? lower.slice(colon + 1) : lower
return directives.split(',').some((directive) => ['noai', 'noimageai'].includes(directive.trim()))
}