Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(serve-http): keep handleIngest under the function-size limit; slug-limit wording matches the index

garrytane4d9417e4c89
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e3041f19e7..5017d333fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ identifiers and attribution are available in the pre-removal Git revision
## [0.60.609.0] - 2026-11-07
-**`POST /ingest` no longer answers 202 for a capture it drops, and an unsigned GitHub webhook can no longer tell from response time which repositories a brain syncs.** The same body sent to two slugs now queues two captures, where the second caller used to get the first job back and nothing written to its slug. A capture over the 50-capture waiting cap now gets 429 `ingest_backlog_full` with `Retry-After: 30` and nothing queued, where it used to get another capture's job id. A slug over 1024 bytes gets 400 `invalid_slug` before anything is queued, because no page can be stored under it. Every webhook request now computes the HMAC over its body, whether the repository is unknown, has no secret or is covered by a source, so a 401 takes the same work either way.
+**`POST /ingest` no longer answers 202 for a capture it drops, and an unsigned GitHub webhook can no longer tell from response time which repositories a brain syncs.** The same body sent to two slugs now queues two captures, where the second caller used to get the first job back and nothing written to its slug. A capture over the 50-capture waiting cap now gets 429 `ingest_backlog_full` with `Retry-After: 30` and nothing queued, where it used to get another capture's job id. A slug over 1024 bytes gets 400 `invalid_slug` before anything is queued, well short of the roughly 2.7 KB where no page can be stored under it. Every webhook request now computes the HMAC over its body, whether the repository is unknown, has no secret or is covered by a source, so a 401 takes the same work either way.
### Itemized changes
diff --git a/src/commands/serve-http-webhooks.ts b/src/commands/serve-http-webhooks.ts
index 1d82afc9cb..701a07f565 100644
--- a/src/commands/serve-http-webhooks.ts
+++ b/src/commands/serve-http-webhooks.ts
@@ -244,9 +244,16 @@ async function handleGitHubItemEvent(
}
}
-/** A longer slug cannot be stored under the page key index, so its capture would be accepted and never land. */
+/** Slugs near 2.7 KB exceed the page key index's row size, so a capture with one would be accepted and never land; 1024 bytes leaves a wide margin. */
const MAX_INGEST_SLUG_BYTES = 1024;
+/** The normalized target slug for an X-Gbrain-Slug header; throws on an invalid slug or one over MAX_INGEST_SLUG_BYTES. */
+function ingestTargetSlug(callerSlug: string): string {
+ const bytes = Buffer.byteLength(callerSlug, 'utf8');
+ if (bytes > MAX_INGEST_SLUG_BYTES) throw new Error(`Invalid slug: X-Gbrain-Slug is ${bytes} bytes; the limit is ${MAX_INGEST_SLUG_BYTES}.`);
+ return validateSlug(callerSlug);
+}
+
/** Stands in for a missing webhook secret; no source holds it and a match against it is still refused. */
const THROWAWAY_WEBHOOK_KEY = randomBytes(32);
@@ -502,16 +509,8 @@ async function handleIngest(
const writer = authInfo.principal ? { principal: { kind: authInfo.principal.kind, id: authInfo.principal.id } } : undefined;
let targetSlug = '';
if (callerSlug) {
- const slugBytes = Buffer.byteLength(callerSlug, 'utf8');
- if (slugBytes > MAX_INGEST_SLUG_BYTES) {
- res.status(400).json({
- error: 'invalid_slug',
- message: `Invalid slug: X-Gbrain-Slug is ${slugBytes} bytes; the limit is ${MAX_INGEST_SLUG_BYTES}.`,
- });
- return;
- }
try {
- targetSlug = validateSlug(callerSlug);
+ targetSlug = ingestTargetSlug(callerSlug);
} catch (err) {
res.status(400).json({ error: 'invalid_slug', message: err instanceof Error ? err.message : String(err) });
return;
@@ -527,8 +526,7 @@ async function handleIngest(
// The same body sent to two slugs is two writes, so the normalized target slug (empty when the job picks one) is part
// of the key next to the write source; dropping it handed the second caller the first job, a 202 with nothing
- // written to its slug (#8769). The slug goes in hashed: a caller's slug has no length limit, and a raw one past the
- // key index's row size would turn the insert into a 500.
+ // written to its slug (#8769). The slug goes in hashed so the key stays well inside the key index's row size.
const slugKey = targetSlug ? createHash('sha256').update(targetSlug).digest('hex') : '';
const idempotencyKey = `ingest:webhook:${authInfo.clientId}:${writeSourceId}:${slugKey}:${contentHash}`;
try {