From 15ba3fa3e8404802ea56353a3da118cac2b4dfc0 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 10 Dec 2025 13:40:27 +0900 Subject: [PATCH] fix pds-subscriberepos-no-auth patch --- install.zsh | 43 ++++-- patching/210-pds-subscriberepos-no-auth.patch | 133 ++++++++++++++++++ 2 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 patching/210-pds-subscriberepos-no-auth.patch diff --git a/install.zsh b/install.zsh index 1845aac..3be7eb9 100755 --- a/install.zsh +++ b/install.zsh @@ -67,6 +67,7 @@ PATCH_FILES_CURL=( typeset -a PATCH_FILES PATCH_FILES=( "170-pds-oauth-same-site-fix.patch" + "210-pds-subscriberepos-no-auth.patch" "8980-social-app-disable-proxy.diff" "disable-statsig-sdk.diff" "140-social-app-yarn-network-timeout.patch" @@ -411,28 +412,54 @@ function at-repos-reset-bgs-db() { echo "⚙️ Updating Slurp Config..." docker exec -i $dp psql -U postgres -d bgs -c "UPDATE slurp_configs SET new_subs_disabled = false, new_pds_per_day_limit = 1000 WHERE id = 1;" - echo "🔗 Registering Trusted Domain & Resetting Repos..." + echo "🔗 Registering Trusted Domain..." # Retry loop for addTrustedDomain as BGS might still be warming up for i in {1..5}; do if curl -f -X POST "https://bgs.${host}/admin/pds/addTrustedDomain?domain=${host}" -H "Authorization: Bearer ${BGS_ADMIN_KEY}"; then + echo "" echo "✅ Trusted domain registered" break fi - echo "Bot failed to contact BGS (attempt $i/5)... waiting 5s" + echo "Failed to contact BGS (attempt $i/5)... waiting 5s" sleep 5 done + echo "🔗 Requesting PDS Crawl..." + # Request BGS to crawl the PDS - this registers the PDS and starts subscription + for i in {1..5}; do + result=$(curl -s -X POST "https://bgs.${host}/admin/pds/requestCrawl" \ + -H "Authorization: Bearer ${BGS_ADMIN_KEY}" \ + -H "Content-Type: application/json" \ + -d "{\"hostname\":\"${host}\"}" \ + -w "%{http_code}" -o /dev/null) + if [ "$result" = "200" ]; then + echo "✅ PDS crawl requested successfully" + break + fi + echo "Failed to request crawl (attempt $i/5, status: $result)... waiting 5s" + sleep 5 + done + + echo "⏳ Waiting 5s for BGS to connect to PDS..." + sleep 5 + + echo "🔄 Triggering repo sync for existing users..." for ((i=1; i<=${#handles}; i++)); do handle=${handles[$i]} - did=`curl -sL "https://${host}/xrpc/com.atproto.repo.describeRepo?repo=${handle}" |jq -r .did` - if [ ! -z "$did" ] && [ "$did" != "null" ]; then - echo "Resetting repo: $handle ($did)" - curl -X POST "https://bgs.${host}/admin/repo/reset?did=${did}" \ - -H "Authorization: Bearer ${BGS_ADMIN_KEY}" + did=$(curl -sL "https://${host}/xrpc/com.atproto.repo.describeRepo?repo=${handle}" | jq -r .did) + if [ -n "$did" ] && [ "$did" != "null" ]; then + echo " Syncing repo: $handle ($did)" + # Use takedown=false to trigger a resync without actually taking down + curl -s -X POST "https://bgs.${host}/admin/repo/takedown?did=${did}&takedown=false" \ + -H "Authorization: Bearer ${BGS_ADMIN_KEY}" || true else - echo "Skipping reset for $handle (DID not found)" + echo " Skipping $handle (DID not found)" fi done + + echo "" + echo "✅ BGS reset complete!" + echo " PDS should now be subscribed and syncing repos." } function at-repos-feed-generator-start-push() { diff --git a/patching/210-pds-subscriberepos-no-auth.patch b/patching/210-pds-subscriberepos-no-auth.patch new file mode 100644 index 0000000..2783588 --- /dev/null +++ b/patching/210-pds-subscriberepos-no-auth.patch @@ -0,0 +1,133 @@ +diff --git a/packages/pds/src/api/com/atproto/sync/subscribeRepos.ts b/packages/pds/src/api/com/atproto/sync/subscribeRepos.ts +index c2418d343..f81789df0 100644 +--- a/packages/pds/src/api/com/atproto/sync/subscribeRepos.ts ++++ b/packages/pds/src/api/com/atproto/sync/subscribeRepos.ts +@@ -5,68 +5,71 @@ import { httpLogger } from '../../../../logger' + import { Outbox } from '../../../../sequencer/outbox' + + export default function (server: Server, ctx: AppContext) { +- server.com.atproto.sync.subscribeRepos(async function* ({ params, signal }) { +- const { cursor } = params +- const outbox = new Outbox(ctx.sequencer, { +- maxBufferSize: ctx.cfg.subscription.maxBuffer, +- }) +- httpLogger.info({ cursor }, 'request to com.atproto.sync.subscribeRepos') ++ server.com.atproto.sync.subscribeRepos({ ++ auth: undefined, ++ handler: async function* ({ params, signal }) { ++ const { cursor } = params ++ const outbox = new Outbox(ctx.sequencer, { ++ maxBufferSize: ctx.cfg.subscription.maxBuffer, ++ }) ++ httpLogger.info({ cursor }, 'request to com.atproto.sync.subscribeRepos') + +- const backfillTime = new Date( +- Date.now() - ctx.cfg.subscription.repoBackfillLimitMs, +- ).toISOString() +- let outboxCursor: number | undefined = undefined +- if (cursor !== undefined) { +- const [next, curr] = await Promise.all([ +- ctx.sequencer.next(cursor), +- ctx.sequencer.curr(), +- ]) +- if (cursor > (curr ?? 0)) { +- throw new InvalidRequestError('Cursor in the future.', 'FutureCursor') +- } else if (next && next.sequencedAt < backfillTime) { +- // if cursor is before backfill time, find earliest cursor from backfill window +- yield { +- $type: '#info', +- name: 'OutdatedCursor', +- message: 'Requested cursor exceeded limit. Possibly missing events', ++ const backfillTime = new Date( ++ Date.now() - ctx.cfg.subscription.repoBackfillLimitMs, ++ ).toISOString() ++ let outboxCursor: number | undefined = undefined ++ if (cursor !== undefined) { ++ const [next, curr] = await Promise.all([ ++ ctx.sequencer.next(cursor), ++ ctx.sequencer.curr(), ++ ]) ++ if (cursor > (curr ?? 0)) { ++ throw new InvalidRequestError('Cursor in the future.', 'FutureCursor') ++ } else if (next && next.sequencedAt < backfillTime) { ++ // if cursor is before backfill time, find earliest cursor from backfill window ++ yield { ++ $type: '#info', ++ name: 'OutdatedCursor', ++ message: 'Requested cursor exceeded limit. Possibly missing events', ++ } ++ const startEvt = await ctx.sequencer.earliestAfterTime(backfillTime) ++ outboxCursor = startEvt?.seq ? startEvt.seq - 1 : undefined ++ } else { ++ outboxCursor = cursor + } +- const startEvt = await ctx.sequencer.earliestAfterTime(backfillTime) +- outboxCursor = startEvt?.seq ? startEvt.seq - 1 : undefined +- } else { +- outboxCursor = cursor + } +- } + +- for await (const evt of outbox.events(outboxCursor, signal)) { +- if (evt.type === 'commit') { +- yield { +- $type: '#commit', +- seq: evt.seq, +- time: evt.time, +- ...evt.evt, +- } +- } else if (evt.type === 'sync') { +- yield { +- $type: '#sync', +- seq: evt.seq, +- time: evt.time, +- ...evt.evt, +- } +- } else if (evt.type === 'identity') { +- yield { +- $type: '#identity', +- seq: evt.seq, +- time: evt.time, +- ...evt.evt, +- } +- } else if (evt.type === 'account') { +- yield { +- $type: '#account', +- seq: evt.seq, +- time: evt.time, +- ...evt.evt, ++ for await (const evt of outbox.events(outboxCursor, signal)) { ++ if (evt.type === 'commit') { ++ yield { ++ $type: '#commit', ++ seq: evt.seq, ++ time: evt.time, ++ ...evt.evt, ++ } ++ } else if (evt.type === 'sync') { ++ yield { ++ $type: '#sync', ++ seq: evt.seq, ++ time: evt.time, ++ ...evt.evt, ++ } ++ } else if (evt.type === 'identity') { ++ yield { ++ $type: '#identity', ++ seq: evt.seq, ++ time: evt.time, ++ ...evt.evt, ++ } ++ } else if (evt.type === 'account') { ++ yield { ++ $type: '#account', ++ seq: evt.seq, ++ time: evt.time, ++ ...evt.evt, ++ } + } + } +- } ++ }, + }) + }