Skip to content

feat(magpie): port huginn's geekhack crawler as a batch job - #2

Open
im6h wants to merge 11 commits into
mainfrom
feat/magpie
Open

im6h wants to merge 11 commits into
mainfrom
feat/magpie

Conversation

@im6h

@im6h im6h commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Add the magpie command: crawl lists the Geekhack boards down to the last run's watermark, fetches new or changed threads politely, and stores them with keyset candidates in the ingest schema; promote inserts complete, unmatched candidates into Keebdex as Pending keysets with the forum revision source. topic parses one thread without a database.

fetch_all now takes a schema client and an order column. The workflow has no schedule until the ingest schema is applied.

im6h and others added 2 commits November 20, 2026 16:30
Add the magpie command: `crawl` lists the Geekhack boards down to the last
run's watermark, fetches new or changed threads politely, and stores them
with keyset candidates in the ingest schema; `promote` inserts complete,
unmatched candidates into Keebdex as Pending keysets with the `forum`
revision source. `topic` parses one thread without a database.

fetch_all now takes a schema client and an order column. The workflow has
no schedule until the ingest schema is applied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fetcher compared time.monotonic(), which counts from boot, against an
initial last-request time of 0. On a machine up for less than the delay,
such as a fresh CI runner, the first request (robots.txt) waited too, so
test_requests_wait_for_the_delay failed in CI but passed locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@anhthang anhthang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes: three issues worth fixing before merge (promotion ordering, rollback failure, retry counter) and three minor ones. A related trigger issue is commented on keebdex/supabase#7.

Comment thread src/aviary/magpie/apply.py Resolved
Comment thread src/aviary/magpie/apply.py Resolved
Comment thread src/aviary/magpie/plan.py Resolved
Comment thread src/aviary/magpie/fetch.py Resolved
Comment thread src/aviary/magpie/apply.py Resolved
Comment thread AGENTS.md Resolved
- promote: when the candidate was triaged after it was read, delete the
  keyset and kits just inserted instead of leaving an orphan; a failed
  rollback is logged and no longer stops the other promotions
- plan: new activity in a listing resets fetch_attempts and fetch_error,
  so a thread that gave up gets the full backoff again
- fetch: retry robots.txt; 4xx means no rules, 5xx, 429 or network errors
  after retries fail the run instead of crawling without rules (RFC 9309)
- crawl: a unique violation on the one-running index becomes RunningError
- docs: re-wrap an overlong AGENTS.md line and describe the new behavior

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@anhthang anhthang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes in 36c6206: all six earlier points look resolved (the magpie tests pass locally, 152 passed). The rework added one issue worth fixing before merge (a rollback after a claim that actually committed) and two minor summary-count issues.

Comment thread src/aviary/magpie/apply.py Resolved
Comment thread src/aviary/magpie/__main__.py Resolved
Comment thread src/aviary/magpie/apply.py Resolved
…restored candidates

- promote: run the claim outside the kits rollback; when it raises, read
  the candidate back and remove the keyset only when the candidate is not
  promoted to it (kept when it cannot be read), so no candidate points at
  a deleted keyset
- promote: return the topics staff triaged meanwhile apart from failed
  ones and list them on their own line instead of under Inserted
- crawl: count candidates the supersede trigger puts back to new when a
  first post reverts (keebdex/supabase#7), from the state read before the
  insert

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@anhthang anhthang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks: 24f31c5 resolves all three points. Reading the candidate back after a failed claim covers every case, and the summary now reports triaged and restored candidates separately. Tests (250 passed), ruff, and markdownlint are clean locally. One small summary nit below; it doesn't block merging.

Comment thread src/aviary/magpie/apply.py Resolved
anhthang and others added 2 commits November 22, 2026 12:43
Keebdex now takes revision sources as `<job>.<origin>` and no longer
accepts `forum`, which would record promoted keysets as `sql`. Build the
source with revision_source() and drop the docs' mention of a `forum`
source in the ingest migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anhthang

Copy link
Copy Markdown
Member

I merged main into this branch and switched magpie's revision source from forum to magpie.geekhack (Keebdex now takes <job>.<origin> sources, see revision_source() in common/db.py), with the conflicts in AGENTS.md and README.md resolved. Please pull before pushing again.

im6h and others added 4 commits November 22, 2026 15:37
A topic went into `triaged` before its keyset was removed, so a failed
removal listed it both as "keyset removed again" and as failed while the
keyset stayed in Keebdex. It is now listed as triaged only when the
removal succeeds, and only as failed otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r job

apply.py and __main__.py had grown to hold every command's logic. Move the
ingest-table reads and writes to ingest.py, the Keebdex reads and promotion
writes to keebdex.py, and each command to its own module (crawl, promote,
reextract) with summary.py for what their summaries share. __main__.py keeps
only argument parsing and `topic`. Tests follow the same split, with the
shared fakes in tests/magpie_fakes.py. No behavior change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants