Skip to content

feat(worker): more verified news sources, data-driven source registry, per-source + stale observability - #241

Merged
duyet merged 1 commit into
masterfrom
feat/more-sources
Sep 27, 2026
Merged

duyet merged 1 commit into
masterfrom
feat/more-sources

Conversation

@duyet

@duyet duyet commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Implements #230 (umbrella #232). Three parts: more verified sources, a declarative source registry that makes adding one a data operation, and per-source + stale observability so a bad source is visible instead of invisible.

Everything is behind one registry. worker/sources/catalog.ts is the only place a source is declared; the runtime seed, the migration, and the /api/system/sources + /data surfaces all consume it, and a test asserts all three agree byte for byte.


1. New sources — all verified live

pnpm --filter @aidr/web run verify:source-feeds runs the production parseRssItems and the production flood gate against every registry row, so a green result means the Worker can actually read the feed. 18/18 PASS. New-source rows, with real output:

Vietnamese (this is the one that exercises the dead source_lang path)

### vnexpress-tech — VnExpress Khoa học & Công nghệ [rss]
  url         https://vnexpress.net/rss/khoa-hoc-cong-nghe.rss
  status      200 application/xml; charset=utf-8 (62742 bytes)
  parsed      60 items, 60 usable (title + absolute URL + date)
  this run    6 after window+gate (6 in the 26h window)
  gate        maxItems=6
  newest      2026-09-27T11:21:06.000Z   oldest 2026-09-21T22:00:00Z
  first 3 the Worker would return this run:
    - 2026-09-27T11:21:06.000Z  'Bão bài đăng' về Muse của tỷ phú AI Alexandr Wang
      https://vnexpress.net/bao-bai-dang-ve-muse-cua-ty-phu-ai-alexandr-wang-5125399.html
    - 2026-09-27T06:00:00.000Z  Nhân viên Google từ chức vì lo AI 'phát triển quá nhanh'
      https://vnexpress.net/nhan-vien-google-tu-chuc-vi-lo-ai-phat-trien-qua-nhanh-5125305.html
    - 2026-09-27T01:00:00.000Z  Giá RAM laptop tăng sáu lần sau một năm
      https://vnexpress.net/gia-ram-laptop-tang-sau-lan-sau-mot-nam-5124978.html
  verdict     PASS

sourceLang: "vi" is declared metadata in the row config, never inferred from diacritics. Its pubDate is RFC-822 with an explicit +0700, which the test asserts lands on the correct instant (2026-09-27T08:00:00 +0700 → 01:00:00Z) — a 7-hour error here would land every VI item in the future and sort it above fresh stories.

AI newsrooms

### techcrunch-ai — TechCrunch AI [rss]
  status      200 application/rss+xml; charset=UTF-8 (18460 bytes)
  parsed      20 items, 20 usable   this run 3 after window+gate   gate maxItems=6
  newest      2026-09-27T16:30:00.000Z
    - 2026-09-27T16:30:00.000Z  Anthropic's Dario Amodei gets the SNL treatment
      https://techcrunch.com/2026/09/27/anthropics-dario-amodei-gets-the-snl-treatment/
    - 2026-09-27T01:30:00.000Z  Google tests buying from Walmart-owned Flipkart through Gemini and AI Mode in India
      https://techcrunch.com/2026/09/26/google-tests-buying-from-walmart-owned-flipkart-through-gemini-and-ai-mode-in-india/
    - 2026-09-26T21:02:06.000Z  Insurers claim AI is already increasing healthcare costs
      https://techcrunch.com/2026/09/26/insurers-claim-ai-is-already-increasing-healthcare-costs/
  verdict     PASS

### theverge-ai — The Verge AI [rss]
  status      200 application/xml; charset=UTF-8 (124231 bytes)
  parsed      10 items, 10 usable   this run 2 after window+gate   gate maxItems=6
  newest      2026-09-27T17:21:07.000Z
    - 2026-09-27T17:21:07.000Z  OpenAI agents tried to 'bruteforce' a UN website
      https://www.theverge.com/ai-artificial-intelligence/1001178/openai-agents-bruteforce-un-website
    - 2026-09-26T16:34:59.000Z  OpenAI pauses training of its 'most capable models'
      https://www.theverge.com/ai-artificial-intelligence/1001049/openai-training-pause
  verdict     PASS

### arstechnica-ai — Ars Technica AI [rss]
  status      200 application/rss+xml; charset=utf-8 (76745 bytes)
  parsed      20 items, 20 usable   gate maxItems=6
  note        feed is valid but nothing in the 26h ingest window
  newest      2026-09-25T21:36:20.000Z
    - 2026-09-25T21:36:20.000Z  Court rules Pentagon can blacklist Anthropic for refusing to enable Claude features
      https://arstechnica.com/tech-policy/2026/09/court-rules-trump-can-blacklist-anthropic-for-refusing-to-enable-claude-features/
    - 2026-09-25T21:10:51.000Z  Tesla workers balk at training Optimus humanoid robots as replacements
      https://arstechnica.com/ai/2026/09/tesla-workers-balk-at-training-optimus-humanoid-robots-as-replacements/
    - 2026-09-25T19:11:05.000Z  AI was supposed to hit new grads hard. So far, unemployment data says otherwise.
      https://arstechnica.com/ai/2026/09/ai-was-supposed-to-hit-new-grads-hard-so-far-unemployment-data-says-otherwise/
  verdict     PASS

### wired-ai — WIRED AI [rss]
  status      200 application/xml (10200 bytes)
  parsed      10 items, 10 usable   gate maxItems=6
  newest      2026-09-26T10:30:00.000Z
    - 2026-09-26T10:30:00.000Z  Meta's Muse Is Adults-Only. Why Does It Look Like a Kids' Toy?
      https://www.wired.com/story/meta-muse-is-adults-only-why-does-it-look-like-a-cute-kids-toy/
    - 2026-09-25T20:30:40.000Z  Thieves Stole 'Nvidia' Trailers. They Got 20 Tons of Sand
      https://www.wired.com/story/thieves-stole-nvidia-trailers-they-got-20-tons-of-sand/
    - 2026-09-25T16:58:20.000Z  Appeals Court Lets the Pentagon Designate Anthropic a Supply-Chain Risk
      https://www.wired.com/story/appeals-court-lets-the-pentagon-designate-anthropic-a-supply-chain-risk/
  verdict     PASS

Net: 16 → 20 registry rows (5 new). No new adapter type — all five are rss, which already handled Atom as well as RSS.

Evaluated and rejected, with the reason recorded in the code and the migration header

candidate why not
arXiv cs.AI/cs.LG/cs.CL robots-disallowed. export.arxiv.org/robots.txt is User-agent: * / Disallow: /; arxiv.org/robots.txt lists Disallow: /api. The sortable Atom API is therefore out under this repo's "no robots.txt disallow" rule. The one allowed surface (rss.arxiv.org, no robots.txt, already newest-first RSS so the gate applies unchanged) was serving an empty channel — it declares <skipDays>Saturday, Sunday</skipDays> and the next announcement was not due until Mon 04:00 UTC — so it could not clear the "≥1 usable item verified live" bar. See §2.
VentureBeat HTTP 429 on bot fetches (already noted in migration 0022). Its FeedBurner mirror is stale — newest item Sep 3, 24 days old.
Engadget HTTP 202 challenge instead of the feed.
ZDNet the "AI topic" RSS URL redirects to /rss/news/, i.e. general tech news, not AI.
Tuổi Trẻ cong-nghe 200 and 50 genuinely-Vietnamese items, but <pubDate>9/27/2026 4:04:00 PM</pubDate> has no timezone, so every item would land ~7h in the future. VnExpress was chosen over it for exactly this.
cafebiz.vn / techrum.vn / zingnews.vn 404 / 404 / 403.
vinai / genk / newsroom.vn / baotrimai no reachable feed.

2. arXiv: the flood gate ships, the source does not

This is the one acceptance criterion I did not meet, and the reason is a hard constraint, not effort.

The gate is fully built and tested against the arXiv case — applyFloodGate runs the AI-keyword pre-filter first and then a newest-first maxItems cap, both config-driven, so it is reusable by any firehose:

worker/__tests__/arxiv-flood-gate.test.ts  (12 tests, all pass)
  ✓ bounds a >500-entry feed to the documented cap
  ✓ keeps only the AI-keyword subset before capping
  ✓ is the same regex the HN adapter uses, not a second keyword list
  ✓ does nothing when the feed is smaller than the cap
  ✓ caps the whole added source set inside the existing score budget
  ✓ filters before capping, so the cap fills with relevant items
  ✓ ignores an unknown keyword profile rather than throwing
  ✓ ignores a nonsense cap rather than returning nothing
  ✓ throws a typed fetch_failed for a non-2xx
  ✓ throws a typed parse_failed for a 200 that is really an HTML page
  ✓ carries no URL or header in the error message
  ✓ reports a genuinely empty feed as empty, not as a failure

The 640-entry fixture asserts the capped, keyword-filtered result through rssAdapter.fetchItems — the real production path — so a regression that removed the gate, moved it after the cap, or made it oldest-first fails in CI. The "filters before capping" test builds the specific trap (two off-topic entries strictly newer than every relevant one) that a cap-first implementation would fall into.

To finish arXiv (after 04:00 UTC on a weekday) it is one row plus a regeneration; ARXIV_NOT_ADDED_REASON in worker/sources/catalog.ts has the copy-pasteable config and the measured weekend freeze its staleAfterRuns: 72 has to account for:

{
  id: "arxiv-research",
  name: "arXiv cs.AI / cs.LG / cs.CL",
  type: "rss",
  config: {
    feed: "https://rss.arxiv.org/rss/cs.AI+cs.LG+cs.CL",
    homepage: "https://arxiv.org/list/cs.AI/recent",
    keywordFilter: "ai",
    maxItems: 6,
  },
  enabled: true,
  staleAfterRuns: 72,
}

rss.arxiv.org accepts a combined category list — verified live, the channel comes back as cs.AI, cs.LG, cs.CL updates on arXiv.org — so that is one request per run and needs no per-host pacing.

3. Adding a source is a data operation, not a migration

seed.ts used to hand-copy every row out of migrations 0018/0020/0021/0022 and its own header called that a maintenance hazard. Now:

consumer source of truth
worker/sources/seed.ts buildSourceSeedSql() from the registry
migrations/0027_source_registry.sql pnpm run gen:source-migration
/api/system/sources + /data Sources tab the same SOURCE_REGISTRY rows
worker/__tests__/source-catalog.test.ts  (14 tests, all pass)
  ✓ the checked-in migration is exactly what the registry generates
  ✓ the migration and the runtime seed list identical rows
  ✓ the seed SQL is derived from the registry, not hand-copied
  ✓ the seed upserts identity and config but never re-enables a source
  ✓ the migration inserts only, leaving an operator's enabled flag alone
  ✓ keeps no robots-disallowed source, and records why arXiv is absent
  ✓ points no registry row at a robots-disallowed host
  ✓ only uses adapter types the registry can actually dispatch
  ✓ gives every rss row a feed URL and the flood-gate keys it needs
  ✓ marks exactly the Vietnamese sources with explicit sourceLang: vi
  ✓ documents a stale threshold for every row and defaults sensibly
  ✓ has unique ids and a name/type/config for every row
  ✓ is identical in the worker and the web read model   (skip-reason enum)
  ✓ covers exactly the reasons #230 asked for

Ownership rules, and they are load-bearing. The registry owns name/type/config for the ids it declares — the seed uses ON CONFLICT DO UPDATE on those three, so a corrected feed URL actually reaches an existing row. That is the entire point: INSERT OR IGNORE (what it replaced) would have left a fixed URL stranded on whatever the row already held, i.e. the drift this removes. enabled is operator-owned and never written by the seed, so switching a noisy source off survives every run. Rows the registry does not declare are entirely operator-owned.

No deploy, end to end. The existing upsert_source MCP tool already covers a new rss row and needs no change. Documented with copy-pasteable curl in apps/web/worker/README.md → "Add a source without a deploy", including the "poll /api/system until lastRun.id matches the POST id" step. Production already proves the path: the user submissions source in the live sources table was created that way.

4. Per-source observability + the stale detector

workflow_runs.stats.sourceHealth now carries, per source: fetched / scored / accepted / rejected / merged, a closed skip-reason enum, and a consecutive-empty-run streak.

  • Skip reasons: fetch_failed, parse_failed, empty, all_rejected_below_relevance, disabled. No free text, no URLs, no provider bodies — and a test asserts the worker enum and the web read-model enum are identical, since they are declared separately on purpose.
  • A 200 that is really an HTML page is parse_failed, not empty. That is the most common silent rot (paywall, challenge page) and it used to look like a quiet feed. The rss adapter throws a typed SourceFetchError; the message is sanitizeError'd before it can reach D1 or an API response.
  • Streaks are carried, not recomputed. The worker reads the previous run's stats (one single-row read) and increments or resets. Surfacing "stale" on the read path therefore costs nothing no matter how long a feed has been dead — no history scan.

Threshold: 168 consecutive runs (7 days at the hourly cadence). This is a deliberate deviation from the "e.g. 48 runs" in #230, and it is measured rather than opinionated. When the registry was verified live, 11 of 18 feeds returned nothing inside the 26h window — and 6 of those are pre-existing:

11 valid feed(s) had nothing in the 26h window right now (openai, google-ai,
hf-blog, deepmind, aws-ml, mit-tr-ai, google-research, mit-news-ai,
lastweekin-ai, arstechnica-ai, wired-ai)

lastweekin-ai is a weekly newsletter and google-research publishes a few times a week. A 48-run default would have flagged most of them as broken on a quiet weekend — and an alarm that cries wolf is an alarm nobody reads. A row may override with staleAfterRuns; the one known case (arXiv, no weekend submissions, a measured ~54 consecutive silent runs) is documented with the follow-up row.

worker/__tests__/source-health.test.ts  (21 tests, all pass)
  ✓ reports a transport failure, a bad body, and a quiet feed differently
  ✓ calls out a source whose every item fell below the relevance floor
  ✓ never invents a reason for a source that delivered items
  ✓ has a human label for every enum value
  ✓ reads a well-formed record
  ✓ rejects a non-record and repairs a partially-written one
  ✓ does the same on the web read model side
  ✓ resets on any delivered item and increments on silence
  ✓ carries streaks forward per source and starts newcomers at zero
  ✓ reads the previous run's streaks out of a stats blob
  ✓ flags a source only once it passes its own threshold
  ✓ never calls a disabled source stale
  ✓ keeps the default above the quietest real feed in the registry
  ✓ gives arXiv a lower threshold when it is added, and not before
  ✓ keeps the read model's thresholds in step with the worker
  ✓ reports the streak and threshold together for the dashboard
  ✓ keeps disabled, observed, and unknown as three distinct states
  ✓ flags the stale ids and leaves the rest out
  ✓ treats a run with no sourceHealth at all as unknown, not as a mass failure
  ✓ treats an unparseable health value as unknown
  ✓ never emits a skip reason outside the shared enum

Surfaces: /api/system/sources gains health, stale, healthRunAt and a last_item_at per row; the /data Sources table gains Fetched / New / Accepted / Rejected / Last item / Health columns; the /data Algo tab gains a Source health card (run totals, stale list, top problems).

Disabled ≠ stale. A source that is off is reported disabled, never flagged — flagging it would train an operator to ignore the alarm.

5. The Vietnamese path — verified, including what it does NOT cover

The link that was dead is now live. No adapter emitted sourceLang: "vi", so the entire VI→EN branch was unreachable. The rss adapter now reads config.sourceLang, and only "vi" counts — a typo ("VI", "fr", true) is ignored rather than guessed, because a bad config value must not put an item on the wrong side of the QA path.

Disjoint chain, fail-closed. resolveIndependentReviewerChain requires ANYROUTER_REVIEW_MODEL to be concrete and disjoint from ANYROUTER_TRANSLATE_MODEL ∪ ANYROUTER_ENGLISH_TRANSLATE_MODEL; a missing or overlapping config returns an empty chain and the runtime reports "not configured" with zero LLM calls rather than self-reviewing with the generator. That behaviour is unchanged and already covered; the new tests exercise the VI branch on top of it.

No silent substitution. I reproduced the real production failure visible in /api/system's llm_calls: the EN generator (google/gemini-3.5-flash) works, but both configured reviewer ids (x-ai/grok-4.7, z-ai/glm-5.3-flash) return 404 from the provider, so a VI item cannot be reviewed at all. The new test never silently substitutes a VI item when the reviewer chain is dead drives exactly that and asserts:

  • accepted === 0
  • no UPDATE translations SET … title = ? — the original candidate is preserved
  • a review_failed attempt is persisted with a scheduled retry, not swallowed
  • attempt 1 does not jump straight to the terminal state

The 3-attempts → terminal human_review → exactly-one-authenticated-retry transition is already proven end to end in translation-qa.integration.test.ts ("caps automatic attempts and permits exactly one authenticated retry", asserting attempt_count: 3, manual_retry_count: 0, then a permitted 4th, then a rejected second human retry with HTTP 409). I did not duplicate it.

One honest gap I found and did not fix. If EN generation fails (before any candidate exists) there is no candidate to review or preserve, so the code increments budget.failed and logs translation_review.english_candidate_failed but creates no human_review row. The item keeps its own Vietnamese title — correct, and it renders with no EN badge — and is not substituted, but it does not enter the review queue. That is pre-existing generator-stage behaviour, not something this change introduced, and fixing it means touching the QA state machine, which #230 explicitly scopes out. It is pinned by a new test (leaves a VI item's Vietnamese title intact when EN generation itself fails) so it cannot regress unnoticed. A second, related pre-existing issue: with both reviewer ids 404ing, no VI item can ever be accepted until ANYROUTER_REVIEW_MODEL is pointed at working ids. That is a deploy/secret change, not a code change, and it is out of scope here.

6. LLM budget: unchanged, and the arithmetic is asserted

No hang-cap, batch size, model chain, or prompt is touched. rank_score and the relevance < 0.4 hide rule are untouched — worker/ranking.ts is not modified, and no source-specific boost or penalty exists anywhere in the diff. New sources compete on the existing formula.

The flood gate is what makes the added volume fit. From ALGORITHM.md § LLM transport: scoreItems chunks into batches of 5, runs 3 concurrently, each attempt bounded by the 70s score hang-cap, all inside one 4-minute step. The measured steady state is ~4 new items per run (observed across the last 12 production runs: 8, 4, 4, 4, 0, 12, 1, 3, 1, 0, 4, 3).

  • Each new row's maxItems ceiling is 6.
  • Per-run ceiling across all five new rows: 30 → 6 batches → 2 rounds → 2 × 70s = 140s worst case, inside the 240s step budget.

That whole derivation is asserted in ✓ caps the whole added source set inside the existing score budget, so a future cap change fails in CI with the numbers in the diff rather than in a stale PR description. Steady state is far lower than the ceiling: the caps bound a 26h window that dedupe then collapses, so a newsroom publishing 4/day contributes ~0.2 items per run.

7. Verification

gate result
pnpm exec biome check apps/web/worker apps/web/src apps/web/scripts pass, 503 files, 0 errors 0 warnings
pnpm --filter @aidr/web test pass, 176/176 files
pnpm --filter @aidr/web check-types pass, tsc --noEmit clean
pnpm --filter @aidr/web run build pass, ✓ built in 1.90s + Clerk proxy config assertion passed
pnpm run gen:source-migration -- --check pass, 0027_source_registry.sql matches the registry.
pnpm run check:migration-order pass, media manifest migration file order check passed
pnpm run verify:translation-schema fails on wrangler auth, not on this change — see below
pnpm run verify:source-feeds 18/18 PASS

All re-run after git rebase origin/master (which pulled in #233 and #236). The rebase was conflict-free: master and this branch share no file.

A real ingest was run and its completion was proven, not assumed. Per ALGORITHM.md § Ops pitfalls, a 2xx POST and a green GitHub Actions run are not a finished ingest. gh workflow run ingest.yml reported completed success in 9s; polling GET /api/system with cache-control: no-store showed the truth:

poll 1..4:  lastRun=8e21bbd6…  finished_at=1790528801  items_new=0  runsToday=16
POST id:    e36120de-c0fd-440e-979b-b0809ec3a904
poll 5:     lastRun=e36120de…  finished_at=1790528851  items_new=0  runsToday=17
poll 23:    lastRun=e36120de…  finished_at=1790529224  items_new=5  published=1  runsToday=17

The run took ~6 minutes to finish behind a 9-second "success". runsToday 16 → 17.

What I could NOT verify, and exactly why

The Cloudflare credentials on this machine do not have access to the production account, and the local NEWS_ADMIN_TOKEN no longer matches the deployed secret, so I could not apply migration 0027, could not deploy, and could not add the new rows to production:

$ env -u CLOUDFLARE_API_TOKEN pnpm exec wrangler d1 list --config wrangler.toml
WARNING The `account_id` in your Wrangler configuration (7df185a1…) does not
        match any of your authenticated accounts.
Token Permissions: account (read)        # authenticated account is 23050adb…

$ curl …/api/admin/mcp -H "authorization: Bearer $NEWS_ADMIN_TOKEN"   # 401 unauthorized
$ curl -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" …/user/tokens/verify
{"success":false,"errors":[{"code":1000,"message":"Invalid API Token"}]}

pnpm run verify:translation-schema fails for exactly this reason, and fails identically on a clean tree with my changes stashed — it is not caused by migration 0027:

$ git stash push -u && pnpm run verify:translation-schema
wrangler schema verification failed; deploy is blocked      # exit 1, no 0027 present
$ git stash pop

I did confirm the half of the gate that does not need the network, and that 0027 does not interact with it (it is a pure INSERT OR IGNORE INTO sources; no column, no trigger, and it does not shadow 0023/0024/0025):

last 3 migration files: 0025_llm_call_run_identity.sql, 0026_clerk_users.sql,
                         0027_source_registry.sql
required by the gate:    0023_translation_reviews.sql, 0024_item_media_manifest.sql,
                         0025_llm_call_run_identity.sql
assertMigrationFileOrder: PASS

Reviewer re-verification, on a machine with production credentials

pnpm install
pnpm --filter @aidr/web run check:migrations      # applies 0027; needs wrangler auth
pnpm --filter @aidr/web run verify:translation-schema
pnpm --filter @aidr/web exec tsx scripts/gen-source-migration.ts -- --check
pnpm --filter @aidr/web run verify:source-feeds   # 18/18, re-confirm the 5 new rows
pnpm --filter @aidr/web run deploy

# Real ingest, then poll (do NOT trust the POST or the green Actions run):
curl -X POST "https://aidr.today/api/admin/ingest?force=1" -H "Authorization: Bearer $NEWS_ADMIN_TOKEN"
# until lastRun.id == the POST id AND finished_at advanced
curl -s https://aidr.today/api/system -H 'cache-control: no-store'

Then the three measurements that need the deploy:

  1. items/day before → after. BEFORE, measured on /api/feed?days=2&lang=en twice for stability: 106 items over 3 days = 35.3/day (25/51/30 and 28/51/27). Re-run the same call after the deploy and diff it — I have deliberately not predicted the number, because the relevance < 0.4 hide rule decides how many Vietnamese and newsroom items survive and that needs the LLM.

  2. Per-source distribution and the ≤25% share. BEFORE, the largest single source is already at 29–30% (marketbrief 31–32/106) — a pre-existing condition this change neither introduces nor worsens. The distribution to compare against:

    marketbrief    31-32  29-30%     the-decoder   10   9.4%
    huggingnews    26-27  25-26%     marktechpost    6   5.7%
    hn             17-18  16-17%     simonwillison   1-2 0.9-1.9%
    lobsters       11     10.4%     mit-news-ai    1   0.9%
                                     openai          1   0.9%
    
  3. The new surfaces. /api/system/sources → health / stale / healthRunAt and last_item_at; /data → Sources (new columns) and Algo (Source health card); a VI item rendering with the Vietnamese title and no EN badge at its /{8hex}?lang= permalink; and 5 sampled story URLs checked for no robots.txt / canonical / X-Robots-Tag regression. I did not touch src/lib/sitemap.ts, apps/web/public/robots.txt, src/lib/llms-txt.ts, src/lib/locale-response.ts, or src/styles.css.

8. Notes for the reviewer

  • One existing test was changed, not just added. algo-tab-dedupe.test.ts asserted the Algo tab does not contain useSystemData at all, as a proxy for "must not fetch the model chains it no longer renders". P2 Coverage: add more verified news sources, make source config data-driven, and add per-source/stale observability #230 requires per-source health on that tab, so the guard is narrowed to its real intent: no API.overview, no models.scoring, and exactly one fetch (API.sources). The duplicate-chain assertions are untouched.
  • loadSystemSources now selects all source rows, not just enabled = 1, in the same single round trip, so the fetch loop can skip disabled rows while the health map still records an explicit disabled reason. It also makes the dedupe step's sources.find(...) lookup correct for a disabled source's already-stored items.
  • SourceFetchError is thrown for parse_failed, which the existing 3× exponential fetch retry will repeat. Two extra GETs against a publisher's own feed, once an hour, on a per-source step that runs in parallel with its group. That is the price of a feed that quietly became an HTML page being visible the next hour instead of after a week of silence. Documented at the class.
  • Per-host pacing (minRequestIntervalMs) ships with no user. It was built for arXiv's 406-on-concurrent-requests behaviour, which I measured live. It is ~30 lines, keyed by host, only active when a row opts in, and it never delays the first request to a host. The combined-category arXiv row in the follow-up does not need it, so this is currently unused config surface — worth a follow-up to either exercise it or drop it. Flagging rather than hiding it.
  • Migration 0027 is INSERT OR IGNORE with no conflict clause. Reconciling an existing row is the runtime seed's job; the migration only ever creates a row that does not exist yet.

Refs #230, umbrella #232.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @duyet, your pull request is larger than the review limit of 150,000 diff characters

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 25351bf0-69f6-435f-9261-ed64d160e534


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…, per-source + stale observability

Implements #230. Three parts: more verified sources, a declarative source
registry that makes adding one a data operation, and per-source + stale
observability so a bad source is visible instead of invisible.

Sources (16 -> 20 registry rows, no new adapter type; all `rss`, which already
handled Atom as well as RSS). Every feed verified live with the production
parser and the production flood gate — `pnpm run verify:source-feeds`, 18/18:

  vnexpress-tech  VnExpress Khoa hoc & Cong nghge. The first VI-native source.
                  Declares sourceLang: "vi", which is what puts items on the
                  real VI->EN translation-QA path — no adapter ever emitted it,
                  so that whole branch was dead code. Chosen over Tuoi Tre
                  cong-nghe, which is also a working VI feed but whose pubDate
                  has no timezone and would land every item ~7h in the future.
  techcrunch-ai / theverge-ai / arstechnica-ai / wired-ai

Evaluated and rejected, reason recorded in the code and the migration header:
arXiv (export.arxiv.org is robots Disallow-all and arxiv.org lists
Disallow: /api, so the sortable API is out; the one allowed surface,
rss.arxiv.org, declares skipDays and was serving an empty channel so it could
not be verified live), VentureBeat (429; its FeedBurner mirror is 24 days
stale), Engadget (202 challenge), ZDNet (its "AI topic" RSS redirects to general
news), cafebiz/techrum/zingnews (404/404/403).

Declarative registry. worker/sources/catalog.ts is now the only place a source
is declared; the runtime seed, the generated migration, and the
/api/system/sources + /data surfaces all consume it, and a test asserts all
three agree byte for byte. This replaces the hand-copied rows in seed.ts and
migrations 0018/0020/0021/0022 that seed.ts's own header called a maintenance
hazard. The seed upserts name/type/config on conflict so a corrected feed URL
actually reaches an existing row, and deliberately never writes `enabled`, so
switching a noisy source off survives every run. Rows the registry does not
declare stay entirely operator-owned, and adding an rss source through the
existing upsert_source admin tool still needs no deploy — documented with
copy-pasteable curl in worker/README.md.

Per-source observability. workflow_runs.stats.sourceHealth carries fetched /
scored / accepted / rejected / merged per source, a closed skip-reason enum
(fetch_failed, parse_failed, empty, all_rejected_below_relevance, disabled), and
a consecutive-empty-run streak. A 200 that is really an HTML page now reports
parse_failed rather than looking like a quiet feed, via a typed
SourceFetchError whose message is sanitizeError'd before it can reach D1 or an
API response. Streaks are carried forward from the previous run's stats (one
single-row read) rather than recomputed, so surfacing staleness on the read path
costs nothing. Threshold is 168 consecutive runs (7 days at the hourly
cadence), which is measured rather than round: when the registry was verified
live, 11 of 18 feeds had nothing inside the 26h window, six of them
pre-existing (lastweekin-ai is a weekly newsletter, google-research publishes a
few times a week), so the "e.g. 48 runs" in the issue would have flagged
healthy sources most of the weekend. A row may override with staleAfterRuns.
Disabled is never reported stale — off is a decision, not a fault.

Vietnamese path. The adapter reads config.sourceLang and only "vi" counts, so a
typo cannot put an item on the wrong side of the QA path. A new test reproduces
the real production failure observed in /api/system's llm_calls (the EN
generator works, both configured reviewer ids 404) and asserts nothing is
accepted, the original candidate is never overwritten, and a review_failed
attempt is persisted with a scheduled retry. The 3-attempts -> terminal
human_review -> one authenticated retry transition is already proven end to end
in translation-qa.integration.test.ts. One pre-existing gap is pinned by a test
rather than fixed here: if EN *generation* fails there is no candidate to
review, so no human_review row is created.

Flood gate. applyFloodGate runs a named keyword pre-filter (the same regex the
HN adapter uses, now in one shared module) and then a newest-first maxItems cap,
both config-driven. Newest-first is what makes the cap safe: the 26h window
means the head of the feed at the next run is what was published since the last
one, so the cap samples the live edge and dedupe drops the rest. Exercised
against a 640-entry fixture through the real adapter.

No ranking, hide-rule, prompt, or LLM-budget change. rank_score and the
relevance < 0.4 rule are untouched and worker/ranking.ts is not modified; no
new source is boosted or penalised. No hang-cap, batch size, or model chain is
changed. The added volume fits the existing budgets and the arithmetic is
asserted in a test: five new rows at maxItems 6 is a per-run ceiling of 30, or
6 batches, 2 concurrent rounds, 140s worst case inside the 240s score step.
@duyet

duyet commented Sep 27, 2026

Copy link
Copy Markdown
Owner Author

Reviewer note from the orchestrator — the one verification I could not reproduce locally.

pnpm run verify:translation-schema fails in this worktree, but it is not caused by migration 0027:

$ pnpm exec wrangler d1 migrations list aidr --config wrangler.toml --remote
ERROR A request to the Cloudflare API
  (/accounts/7df185a1.../d1/database/0c8f3efe.../query) failed.
  The given account is not valid or is not authorized to access this service
  [code: 7403]

The script wraps any wrangler failure in the generic wrangler schema verification failed; deploy is blocked, which hides the real cause. I confirmed it is environmental by running the same gate on a tree with no 0027 at all (migrations end at 0026) — it fails identically. The local CLOUDFLARE_API_TOKEN in .env.local is not scoped for D1.

So: 0027 does not block the gate, and CI's Lint, test, types check passed on this PR. But the honest gap is that the live remote-schema probe (the translation_reviews / media_manifest / run_id token list) has not been executed against production from here, and pnpm run deploy runs that gate before the build.

What I did verify locally:

✓ worker/__tests__/source-catalog.test.ts  14
✓ worker/__tests__/source-health.test.ts   21
✓ worker/__tests__/arxiv-flood-gate.test.ts 12
✓ worker/__tests__/source-seed.test.ts      4      (51 total)

Before deploying 0027 to production, please run the gate with a D1-scoped token:

cd apps/web && pnpm run verify:translation-schema

and apply 0027 in order per ALGORITHM.md (apply/verify migrations in order, and never from the QA worker). 0027 is insert-only and does not touch the translation contract, but the deploy gate should be observed green rather than assumed.

@duyet
duyet merged commit dda036f into master Sep 27, 2026
5 checks passed
duyet added a commit that referenced this pull request Sep 28, 2026
* fix(web): harden non-HTML navigation routing

Reserve the TanStack server-function transport in asset routing, reject malformed RPC paths with JSON, and keep non-HTML document requests out of document redirects. Add EN/VI navigation regression coverage and Cloudflare config assertions.

* fix(web): bound the server-function registry and the logo link contract

Two review follow-ups on #186, on top of the #181 transport fix.

A. Server-function ids are validated against Start's real manifest

The previous pass only rejected empty and nested transport paths. Any
single-segment id still reached `getServerFnById`, and an id that is not in
the build-generated manifest made that throw an unhandled error: a 500 whose
message embeds the requested id, skipping Start's serialized-envelope
contract entirely. That covers stale ids from a renamed function still held
by an already-served client bundle, and every percent-encoded traversal form,
none of which the old shape check could see.

- `server-fn-registry.ts` (new, server-only) loads the same generated
  resolver the handler uses and asks it whether an id is registered. A
  resolver that cannot be loaded answers `null`, and the Worker then defers
  to Start, so an infrastructure failure can never turn a working RPC call
  into a 404. For a registered id the lookup warms the resolver's own module
  cache, so the handler's later lookup costs nothing extra. The file is
  server-only because the virtual module is materialized for the server
  environment alone; importing it from the shared path helpers breaks the
  client build.
- `Object.prototype` members are rejected by an explicit own-property check.
  They satisfy the id charset, and the generated resolver reads
  `manifest[id]`, so each one passes its own "not found" guard and only fails
  a line later on `importer()`. Recognising them therefore depended on
  catching that TypeError, i.e. on how the generated lookup happened to be
  written. `Object.hasOwn(Object.prototype, id)` makes the rejection
  deliberate and local, and keeps the verdict independent of the resolver.
  The outcome was already a bounded 404; what changes is that it is now
  reached on purpose rather than by accident, which a test pins.
- `serverFnIdOf` replaces the shape-only check with a charset that covers
  both alphabets Start's compiler emits -- `base64url` in dev, `sha256` hex
  in a build, `_N` on a dedup collision -- and retires `.`, `..`, `%`,
  encoded separators, nul bytes, standard-base64 `+`/`=`, and over-long
  segments before a resolver is consulted. The charset is pinned by a test
  that builds a real dev id the same way the compiler does.
- The bare base `/_serverFn` is now bounded too. Start treats it as an
  ordinary unknown route, so it used to hand a document back to a request
  that claimed to be RPC. `/_serverFnx` and `/_serverFnOLD` are not claimed.
- Every rejection is the same fixed `404 server_function_not_found` JSON
  with no id, no stack, and no function detail. Auth is untouched: the
  bounded 404 returns before Start's middleware and discriminates only on
  structure and manifest membership, never on a credential, so it adds no
  enumeration oracle.
- The `run_worker_first` entry is now documented as what it is -- pinning
  the transport to the Worker so the bounded 404 holds for a navigation
  request too. It is not the fix: a non-navigation request to a non-asset
  path already reaches the Worker, and the array form already disables
  `assets_navigation_prefers_asset_serving`. Measured delta over 80
  differential probes against master: zero.

B. The logo link test exercises the real router

`Brand.test.tsx` mocked `Link`, so its `not.toContain("payload")` and
`not.toContain("locale")` assertions only exercised the mock's own
`URLSearchParams` logic. A `payload` param leaking through the root search
validation passes the old test and fails the new one.

It now drives a real TanStack router (memory history, the app's real
`validateRootSearch` and `preserveRootLangFromMiddleware`, `Brand` mounted
as a layout above `Outlet` the way `HeaderBar` mounts it) and reads the href
the real `Link` builds. It also asserts the href against
`router.buildLocation`, clicks the link and checks the resulting location,
and covers the VI-copy/EN-navigation split.

Test counts (measured, not estimated): 156 files / 1613 web tests, 9 files
/ 122 focused, 61 extension.

Verified against the real production bundle under workerd with the seven
manifest ids: 62/62 transport assertions and 29/29 EN/VI navigation
assertions, including `Sign in required` still arriving as Start's
serialized envelope with no Worker cache, Content-Language or robots policy
stamped on it.

Refs #180
Related: #181

* fix(web): remove mobile Get AI;DR trigger circle background (#206)

* feat(web): redesign /data and sync Clerk signups from a verified webhook (#205)

* feat(web): redesign /data and sync Clerk signups from a verified webhook

The /data page showed a single lonely "AIDR user signups" card in the
top-right corner, and its number came from a live Clerk Admin API call on
every page load — slow when Clerk was slow, "Unavailable" when Clerk was
down, and a public endpoint taking a third-party dependency per visitor.

Redesign

- Page header is now just the title and one line of context; the model
  attribution card is a quiet full-width strip instead of a loud header
  card, and the tab list is lighter. Tabs are unchanged: Overview, Content,
  Runs, Sources, LLM, Algo (+ Admin for admins).
- Signups is a first-class StatTile-family metric in the Overview row,
  beside Stories, Tokens, Runs today, Subscribers, and Last run. D1
  subscribers (email subscriptions) stay a separate, clearly labelled
  metric — a subscription is not an account.
- StatTile gains a `value: string | null` placeholder state, a `numeric`
  flag for non-numeric values, and a shared min-height so a tile never
  shifts the row as endpoints resolve. The Overview charts stack full
  width. CardData takes an optional className so a caller can inject into
  a parent grid; the unused DataSkeleton is gone.

Signups source: Clerk → D1

- New migration 0026_clerk_users.sql creates clerk_users (Clerk id primary
  key, email, created_at, updated_at, deleted_at) plus two indexes. The
  table starts empty on purpose: rows only come from a verified webhook or
  an explicit backfill, never from a guess.
- POST /api/webhooks/clerk handles user.created/updated/deleted. Every
  delivery must carry Svix's headers and is verified with HMAC-SHA256 over
  `svix-id.svix-timestamp.body` against CLERK_WEBHOOK_SECRET (WebCrypto,
  constant-time compare, 5-minute replay window). Bad or missing signature
  is 401, oversized body 413, missing secret/binding 503, D1 write failure
  500 so Svix redelivers. Other event types are acknowledged and ignored.
- Upserts are replay-safe (ON CONFLICT never rewrites created_at) and
  deletes are soft, so the live count only falls when Clerk says a user is
  gone.
- POST /api/admin/clerk-sync is the admin-gated one-shot backfill (100 per
  page, 20 pages max) using CLERK_SECRET_KEY, plus a "Sync Clerk users"
  button in the admin panel. It exists so the metric is real before the
  first webhook lands; the webhook keeps it current afterwards.
- GET /api/system/accounts is now a single indexed COUNT over the mirror,
  returning { total, source: "d1", status }. A missing binding or unmigrated
  database is `unconfigured` and a read failure is `error`; both report
  null and the UI says "Unavailable" instead of rendering a fabricated 0.
  migration-gate.ts treats 0026 as required once its file is present, so a
  deploy against an unmigrated database fails loudly.

Docs and tests

- CLERK_WEBHOOK_SECRET added to .env.example and to the worker/GitHub
  optional secret lists in scripts/sync-env.ts; the mirror is documented in
  worker/README.md including the migration-apply step.
- New unit tests cover signature verification (401 on bad signatures,
  replay window, multi-signature headers), the D1 upsert/soft-delete
  statements against real SQLite, backfill paging, the migration's schema
  and ordering, and the new signups tiles (including that the Overview
  batch failing never hides the signup total and that no zero is invented
  before the endpoint answers).

Fixes #198

* test(web): construct Svix webhook fixtures so GitGuardian ignores them

---------

Co-authored-by: duyet <5009534+duyet@users.noreply.github.com>
Co-authored-by: duyetbot <duyetbot@users.noreply.github.com>

* wip(extension,web): extension web header, channel analytics, newtab polish

Work in progress, captured before rebasing onto master (43 commits behind).

- extension: web header + newtab polish, settings panel, manifest 0.1.18
- ui: add trackChannelClick / TrackChannel for chrome|telegram|email funnels
- web: stop double-counting page views (gtag send_page_view: false)
- web: header menu split (GetAIDRMenu, PhoneMenu, Compact/Wide rows)
- verify-aidr skill: analytics + telegram features, refreshed driver
- tests: feed-queries, tldr-section, chrome copy, campaign, analytics

Excluded QA artifacts (.playwright-mcp/, design-preview.html).

* fix(web): gate CLERK_WEBHOOK_SECRET and stop /data inventing a signup 0

Production probe: POST /api/webhooks/clerk returns 503
{"error":"clerk webhook not configured"} on every delivery, and
/api/system/accounts returns {"total":0,"status":"available"} — so /data
renders "Signups 0" for a mirror that has never received an event.

2b63ced shipped CLERK_WEBHOOK_SECRET as WORKER_OPTIONAL, so `pnpm sync-env`
silently skipped it. 8554148 had already added exactly this gate for the
sibling secret CLERK_SECRET_KEY (WORKER_REQUIRED + a fail-closed deploy
smoke); the new secret never got one.

- sync-env.ts: CLERK_WEBHOOK_SECRET -> WORKER_REQUIRED
- deploy-web.yml: fail-closed smoke asserting the endpoint is not 503/404,
  mirroring the /__clerk/v1/environment gate. Asserts status only, never the
  body. The probe posts a non-user event type, which the handler ignores, so
  even a signature-verification regression could not write a clerk_users row
  and inflate the public count.
- account-count.ts: an empty mirror is now `unconfigured` (total: null) rather
  than a real 0. An empty table cannot distinguish "Clerk has no accounts"
  from "no webhook delivery yet", and worker/README.md:93-96 already
  specified `unconfigured` for "table missing / no rows yet" — the code had
  drifted from its own documented contract. /data now says "Unavailable"
  instead of a fabricated count, and becomes available once a row lands.

Verified: 1656 web tests, 65 extension tests, tsc --noEmit clean, biome clean.
Live gate confirmed red today (503) and passing for 400/401/405/200.

* fix(worker): let media backfill reach rows that already have a legacy image_url

Closes the remaining half of #207.

buildMissingMediaQuery gated candidates on
`image_url IS NULL OR image_url = ''`, so every published row that already
carried a legacy og:image was excluded — precisely the rows that most need a
media_manifest, and the reason the backfill "cannot enrich rows with a legacy
image_url". The only remaining gate is media_manifest being absent/empty/[].

`image_url` is still selected so the manifest can be built from it.

The old predicate was pinned by an assertion in backfill.test.ts; it is
replaced by a regression test asserting the clause stays gone and the column
stays selected.

The other half of #207 (the stale 0025 migration-gate assertion) already
landed in cc460b3 and needed no change here.

* fix(worker): let the Clerk handshake redirect back to the app origin (login 502) (#212)

* fix(worker): let the Clerk handshake redirect back to the app origin

Clerk login was broken in production: every session refresh failed with

  GET /__clerk/v1/client/handshake -> 502 "Clerk upstream redirect rejected"

while /__clerk/v1/environment and /__clerk/v1/client returned 200. Only the
handshake path was affected, which is why sign-in appeared to work right up
until the session needed renewing.

Cause: rewriteSameOriginRedirect accepted a redirect only when the Location
resolved to CLERK_FAPI_ORIGIN (frontend-api.clerk.dev). But the handshake is
*defined* as ending with a redirect back to the application: Clerk's
HandshakeService.resolveHandshake() builds the Location from
`authenticateContext.clerkUrl`, the endpoint documents itself as "redirect
back to after the handshake" and answers 307, and clerk/javascript#8186
records FAPI returning "a 302 back to the app origin". That is the app origin,
so the check rejected it and the proxy answered 502 instead of forwarding the
hop. Introduced by 488a9c0, whose redirect hardening was otherwise sound.

Fix: allow a redirect whose origin is exactly publicProxy.origin and pass it
through unchanged — the browser is already on that origin, so this cannot
become an open redirect. The caller-supplied `redirect_url` parameter is never
consulted; comparing against publicProxy.origin is precisely what stops an
attacker-chosen redirect target from turning this into a redirector.

Tests: the 12 existing path-canonicalization/credential/suffix vectors plus
new cases for scheme downgrade, port swap, credentialed app origin, suffix
attack and unrelated origin all still 502. Verified the new test fails without
the source change.

* style(web): apply biome formatting to the new clerk-proxy test

CI runs `biome check .` in apps/web, which includes the formatter; `biome
lint` alone does not, so the 3-line mockFetch call was not collapsed locally
and the Lint job failed. Formatting only.

* chore(skill): add aidr-ops to validate, sync, and deploy secrets

Operational skill for Worker secret/deploy work, gated on a read-only
preflight that catches the failure modes hit this session:

- expired CLOUDFLARE_API_TOKEN (CF 1000 / wrangler 9109), the silent reason
  `pnpm sync-env` fails
- mixed Clerk instances (pk_test + sk_live), which authenticate the browser
  and the Worker against different instances and break sign-in quietly
- the two publishable keys disagreeing when sync-env treats them as aliases
- missing required Worker secrets
- live probes: handshake 502 (login broken), webhook 503 (secret missing),
  signups unconfigured (mirror empty)

`sync` and `deploy` refuse to run while preflight fails. `sync` also works
around the underlying sync-env bug where wrangler is spawned with
`env: process.env` and never sees a token stored in .env.local.

Secret values are never printed; output is masked and JSON on stdout.
Non-zero exit means not ready.

* chore(herdr): add herdr-desk config and ignore run artifacts

Registers this repo with the herdr-desk plugin. The 2-line config relies on
the plugin defaults, which supply the `desk:github-issues` job (agent
`aidr-desk`, cron 0 7 * * *) that triages issues and PRs and spawns worktrees.
No `extra` overrides, so nothing repo-specific is pinned.

`herdr plugin action invoke herdr-desk.status` reports the daemon running and
aidr scheduled; `herdr-desk.validate` reports 0 errors across 3 desks.

* feat(reel): per-story vertical reels from the live digest

A HyperFrames composition that renders one 18s 1080x1920 short per trending
story, in English and Vietnamese, from real /api/feed fields only. One
composition, N outputs: every per-story value is a declared variable, so no
HTML is ever generated per story and a batch is one render command.

Content leads. The headline is the hero and lands at 0.14s; the rank score is
supporting evidence, counting up inside an icon chip rather than filling the
frame. Beats are title, source, stats, pull-quote, publisher's words, end card.

The thumbnail is fitted, never cropped: the image card absorbs all leftover
column height and the image sits inside it contained and centred, so a wide OG
card letterboxes against the panel instead of being blown up.

The dither field is pinned to a single Bayer level over the content column,
which is the brightest it can be while secondary text still clears WCAG AA at
4.5:1 - verified against the field's real luminance range, because the auditor
reports a false pass when every text block rests at opacity 0.

Composes with: 47 source files, 2076 lines. Rendered MP4s and build scratch are
gitignored - the binaries are ~150MB for 12 outputs and one `render --batch`
away.

* fix(web): unbreak the /data runs charts, dedupe algo tab, pad tabs (#219)

* fix(web): unbreak the /data runs charts, dedupe algo tab, pad tabs

The Runs tab's Duration and Outcomes cards have always rendered empty. Both
hand-rolled their bars as percentage-height divs nested inside a flex item
whose own height was `auto`, and a percentage height against an indefinite
parent resolves to `auto` — so every bar collapsed to 0px and only the legend
showed. Measured in Chromium against the exact pattern: 0px bars inside a
112px plot box. The API data was fine all along (`stats.new: 5, merged: 1`).

Rebuild both on the dither-kit `BarChart` the Overview tab already uses, so
they get measured plot geometry, axes, gridlines and tooltips. Extract the
series derivation (`outcomeRows`, `durationRows`) and pin it with tests: a
DOM assertion on pixel height could never have caught this, but asserting the
series handed to the chart does.

Also:

- /data padding: tab strip `p-1.5`/`gap-1.5`/`min-h-11` with `px-4 py-2`
  triggers, and one shared `TAB_PANEL` gap so no tab body is glued to the
  strip (was a mix of `mt-0` and `mt-4`).
- /data?tab=algo: the four model chains rendered in both the Ranking card and
  the AnyRouter card, and a third time in the attribution strip above the
  tabs. Ranking keeps them; the AnyRouter card drops its duplicate list and
  becomes a gateway pitch. Explainer compacted to 2-up grids.
- /subscribe?tab=telegram: was the only channel tab with no visual proof.
  Added a Telegram message mock in the shared frame, matching the two message
  shapes worker/notify/telegram.ts actually sends, plus a feature list.
  EN + VI.

Refs #215, #216, #217, #218

* fix(web): address review on the runs charts, axis labels and preview mock

Real defects found reviewing #219:

- The duration y-axis formatter rounded minutes, so distinct ticks collapsed
  onto one label (`0s 50s 2m 3m 3m`) and `100` printed as `2m`. It now keeps
  one decimal above a minute, so neighbouring ticks can never agree.
- The `total` readout used `Math.round(total / 60)`, printing a flat `0m` for
  a 20s window. It now shares a formatter that keeps sub-minute totals in
  seconds; avg and peak stay in seconds too, since the card is "seconds per
  run" and a ~3m pipeline otherwise reported avg and peak as the same "3m".
- `runAxisTime` hardcoded `en-US` and omitted `timeZone`, contradicting
  `formatTimestamp` in the same file — a UTC+7 viewer would see one wall clock
  on the axis and another in the run's detail row, and the label would shift
  with the client machine's timezone. Both helpers are now UTC-anchored and
  lang-aware, and `lang` is threaded through RunsTab. Covered by a test that
  pins the output across three `process.env.TZ` values.
- `SERIES` duplicated the `CONFIG` keys, so a renamed series would silently
  vanish from the stack (`Bar` renders null for an unconfigured dataKey).
  `CONFIG` is now typed against a `SeriesKey` union, making that a compile
  error, and `SERIES` derives from it.
- The Telegram mock claimed to mirror `buildStoryCaption` but shipped a
  prettified date and a `#hạ_tầng` hashtag the bot can never emit (it
  replaces every non-alphanumeric). It now uses the digest's YYYY-MM-DD stamp
  and the ASCII slug. Its test asserts against the real `buildDigestMessage` /
  `buildStoryCaption` rather than against a comment mentioning them.
- `<article>` mock bubbles had no accessible name, so they added two unnamed
  landmarks; they are `<div>`s now, and the 🗞/🔥 glyphs are `aria-hidden`
  like every other icon in the file.

Tests also tightened: the `p-1.5` assertion was a substring check that also
matched `gap-1.5` and would have kept passing with the padding reverted, and
the duration summary was asserted through `<dt>/<dd>` adjacency that a wrapper
element would silently turn into a pass.

1679 -> 1691 passing. Each of the three new guards was mutation-checked by
reintroducing the regression it guards (padding, duplicate chains, accented
hashtag) and confirming the test fails.

* feat(web): put the AnyRouter mark on the /data surfaces (#221)

The attribution strip said "Powered by AnyRouter" and the Algo tab had an
"AnyRouter" card, but neither carried the mark — the gateway was named in
text only. Inline the official monogram beside both headings.

- AnyRouterMark: their brand mark inlined from
  https://anyrouter.dev/brand/anyrouter-logo-black.svg (both paths,
  viewBox and transform are byte-identical to the asset). Inlined rather
  than hot-linked so a third-party outage cannot break /data, and painted
  `currentColor` so one copy serves both themes instead of shipping a
  black and a white one. `aria-hidden`: the wordmark text already carries
  the name, so the mark adds no accessible text.
- ModelAttribution: the mark is a sibling of the baseline-aligned
  title/subtitle pair, not a child. As a child it would set that flex
  item's baseline to the bottom of the square and break the 13px/11px
  pairing.
- AlgoTab: the gateway card heading gets the mark, same 14px.
- ChartCard: title/subtitle widen from string to ReactNode so a heading
  can carry a mark. Backwards compatible — every other caller passes a
  plain string.

* feat(web): link anyrouter.dev from the footer More column (#222)

The More column had one link (duyet.net) and the site had no footer route
to the gateway that runs every LLM call in the pipeline. /data and /about
both credit AnyRouter; the footer did not mention it at all.

- NewsFooter: anyrouter.dev under More, same link treatment as duyet.net
  (external, new tab, `rel="noopener noreferrer"`, `nav_click` tracked).
- site.ts: ANYROUTER_URL is now the single definition of the credited
  referral URL. The literal was already copy-pasted into ModelAttribution,
  AlgoTab, and about.tsx; a fourth copy in the footer would have let the
  `?ref=aidr.today` partner param drift off one surface, so those three now
  import it instead.
- algo-tab-dedupe.test: the assertion that AlgoTab keeps the referral link
  now checks the import plus the definition in site.ts, so the link cannot
  be dropped and the credited URL cannot silently change.

* fix(web): index bare localized URLs, 308 legacy story hops, valid robots.txt (#233)

#223 (umbrella #232). Three measured indexing blockers, all live on
https://aidr.today as of 2026-09-27.

1. Bare localized HTML was `noindex, follow`. locale-response.ts stamped the
   directive on every localized SSR response without an explicit `?lang=`,
   which is the URL a human types, a Telegram link carries, or a backlink
   points at: 1,005 GSC "Discovered - currently not indexed" URLs plus
   Lighthouse "Page is blocked from indexing". `private, no-store` is a
   cache-isolation requirement, not a robots one, so the cache-isolation
   contract in LOCALE_URLS.md is unchanged. Indexability now has one owner:
   routeIndexability() feeds both X-Robots-Tag and <meta name="robots">, and
   the locale layer sets cache and Vary only. Dedup rides on the existing
   self-referencing ?lang= canonical + vi/en/x-default hreflang.

2. Legacy /{category}/{slug} and over-long id hashes answered 307, so Google
   never consolidated ranking signals onto the documented /{8-hex} canonical.
   They now answer 308 through a shared localeRedirect() helper, so the
   temporary and permanent hops cannot drift apart: still private, no-store,
   varied, no-referrer, noindex/nofollow — permanence is for crawlers, the
   target still depends on the requester's locale. The in-router copy in
   $cat.$slug.tsx is 308 too. Locale alias normalization stays 307.

3. robots.txt failed to parse: `LLMs-txt:` is not a directive and failed the
   whole file (Lighthouse line 5, "Unknown directive"). It is now a comment;
   Sitemap: stays; the committed public/robots.txt duplicate is fixed to match
   byte-for-byte. Diff in sitemap.ts is robotsTxt() only — #225 is rewriting
   that file in parallel, #226 owns llms-txt.ts.

Also: LOCALE_URLS.md now describes the new contract instead of the old
sentences, and worker/README.md gains the 403 diagnostic plus the post-deploy
re-verification runbook that #223 asks for.

Tests pin bare-locale indexable, explicit-locale indexable, private paths and
4xx/5xx noindex/nofollow, 308 permanence, single hop, and the reserved-path
guard (including _serverFn).

* feat(worker): automated Telegram IV field gate, explicit link-preview format, runnable editor checklist (no-go unchanged) (#235)

Makes the executable parts of docs/decisions/telegram-instant-view.md real
without changing its no-go status. No template, no rhash, no Bot API IV
lifecycle call, no production rollout, no delivery-key change.

The field gate (worker/telegram-iv.ts) answers "is this story IV-eligible?"
as a query instead of a manual read. For a candidate
https://aidr.today/{id8}?lang=vi|en it checks all six record fields against
the same helpers the public page renders (localizedTitle,
renderStoryMarkdown), so the verdict cannot disagree with the page:

  title          localizedTitle(); a VI request with no title_vi reports an
                 explicit fallback_from_en, never a Vietnamese render
  body           requires a real summary AND >=1 source link, counted from
                 the rendered Markdown (the renderer's "No summary is
                 available." placeholder is not accepted as a body)
  published_date Unix seconds; normalizePublishedAtSeconds handles the
                 documented epoch ms/seconds bug class and rejects anything
                 outside 2000-2100, so a millisecond value can never become
                 a year-2286 date
  image_url      the generated first-party card /api/og/{id8}.png (1200x630
                 image/png by construction) — the same image articleHead
                 already emits as og:image, so hotlinking, MIME, and
                 dimensions are deterministic
  site_name      read from the single shared SITE_NAME constant, so it
                 cannot drift from og:site_name
  description    first summary paragraph of the RENDERED locale

TELEGRAM_IV_LIMITS encodes the documented ceilings with their sources: 5 MB
HTTP-URL photo, 10 MB multipart, width+height <= 10,000, aspect <= 20,
caption <= 1,024 chars, plus the separate IV rendering guidance. A
non-generated candidate goes through a byte-bounded, SSRF-checked probe
(isFetchableUrl/fetchWithSafeRedirects, Range request, strict byte budget,
explicit body cancel) — the Worker never downloads or proxies a whole media
file. It fails closed on a missing image, private-literal/credentialed/
plain-HTTP URL, oversized, unsupported container, and ambiguous id prefix.
Logs and verdicts go through telemetry-safe redaction; the probe reports only
the origin, never a signed query string.

Format, which needs no Telegram approval and no rhash:
- link_preview_options is set explicitly on all three sends
  (DIGEST/STORY_PHOTO/STORY_TEXT_LINK_PREVIEW). All is_disabled, with the
  reason and the rejected prefer_small_media / prefer_large_media /
  show_above_text values documented next to them: a preview would attach to
  one arbitrary digest bullet or double the photo.
- The trending sendPhoto path attaches the generated card instead of the
  upstream thumb, so a link preview can never be a 404 hotlink-hostile image.
  The normalized manifest thumbnail stays as the fallback for an id that
  cannot address a card. This is the same choice articleHead already made.
- A story with several manifest images says so (N more) instead of silently
  shipping one photo that looks complete — the record's "omit rather than
  silently drop" rule applied to the fallback path.

The manual checklist is now runnable:
  verify-aidr doctor iv --id <8hex> --lang vi|en
It prints the field verdict, range-probes the card (200 image/png 1200x630),
and ends with the exact source URL to paste into the IV Editor plus the
unresolved items as labelled placeholders. It needs no bot token and no
channel id, and a unit test asserts the lever, the gate script, and the
record contain no invented rhash, no real t.me/iv link, no bot token, and no
channel id. The same gate is served to authenticated operators at
GET /api/admin/notify/iv.

The record now references the SITE_NAME constant instead of site_name: null,
documents what the gate proves and what it still does not, carries the
evidence template for the manual checks (both lang variants, mobile +
desktop, disposable channel), and keeps its no-go status.

Delivery is untouched: one message per delivery key, digest:<local-date> or
the story id, notifications PK (channel, item_id), no lang-keyed row, and a
failed media call still falls back to text once.

Refs #231, #232, #146

* feat(web): public RSS at /feed.xml, Google News sitemap, sharded sitemap index, feed autodiscovery (#236)

aidr.today publishes no feed at all: `/feed.xml` is 404 today, and the repo
only *consumes* RSS. This adds the three discovery surfaces that were missing
and removes the self-imposed sitemap coverage cap.

- New Worker-owned route in `src/server.ts` next to `/sitemap.xml`, so it runs
  before the SPA catch-all; `/rss.xml` serves the identical bytes and
  `atom:link rel="self"` always advertises `/feed.xml` so a reader cannot
  register two feeds. Both paths are in `[assets] run_worker_first`.
- Rendered from the existing `getFeed` loader — no second D1 query. The
  `days` 1-14 clamp and the `before` YYYY-MM-DD validation moved into one
  exported `feedDaysAndBefore()` shared by `/api/feed` and the feed.
- Locale: `resolveApiRequestLocale` / `localeCacheControl` reused verbatim, so
  the document has exactly the `/api/feed` contract (bare = private +
  `Vary: Cookie, Accept-Language`; explicit `lang` = public; one legacy
  `locale` = one 307; invalid/repeated/conflicting = 400).
- Every `<item>` is canonical: `<link>` and `<guid isPermaLink="true">` are
  `storyPath(item, lang)` with explicit `lang`, no UTM and no fragment, so the
  feed cannot advertise a `noindex` URL regardless of #223. `<pubDate>` is
  RFC-822 from `published_at` **seconds** through one normalizer (a
  millisecond row would render a year-2286 date). `<category>` is the scored
  enum plus normalized topics. `<media:content>` requires both
  `canonicalizeMediaImageUrl` and `isFetchableUrl`. `dc:creator` is omitted
  rather than fabricated, and `enclosure` is not used because RSS 2.0
  requires a truthful byte `length` we do not have.
- Bounds: 100 items, 512-char titles, 600-char descriptions, 8 categories,
  and a 262,144-byte document assembled under budget rather than trimmed
  afterwards. A 1,200-item hostile fixture renders 100 items / 175 KB.
- `/feed.json` is a thin alias: it rewrites to the existing `/api/feed` route
  handler, so the document and its bounds are identical by construction.
- `<link rel="alternate" type="application/rss+xml">` on the homepage,
  localized pages, story pages, and /subscribe.

- `/sitemap.xml` is now a `<sitemapindex>`: `/sitemaps/static.xml`, one child
  per UTC publication month (split at 1,000 items per part), and `/news.xml`.
  This removes `SITEMAP_ITEM_LIMIT`, which silently dropped every story older
  than the 1,000th newest from the sitemap entirely.
- `lastmod` on every `<loc>`, including the 15 static paths. Story `lastmod` is
  the newest of `published_at`, `fetched_at`, and the latest translation
  review, so a correction signals an update.
- `<image:image>` points at the generated `/api/og/{id}.png` (always 200,
  1200x630) for the default-locale story variant.
- `/news.xml`: `news:` namespace, `news:publication > news:name` = the aidr
  publication, `news:language` = the locale actually rendered for the story,
  W3C `+07:00` publication dates, newest 2 days, hard cap of 1,000
  `news:news` entries. Entries beyond the cap stay in the date shards, so
  nothing is lost. aidr is an aggregator: nothing claims Google News
  publisher status.
- Fail-closed preserved everywhere: every child is `200 application/xml` and a
  D1 error returns a valid static-only document, exactly like the previous
  `safeSitemapResponse`.

llms.txt `## Consume` gains the feed and news sitemap; SKILL.md and
openapi.json document both as machine-readable surfaces; /changelog announces
the shape change. robots.txt keeps a single `Sitemap:` line and is untouched
(that file and `robotsTxt()` belong to #223).

Refs #225, umbrella #232.

* feat(worker): anonymous read-only MCP news tools + truthful discovery docs (#237)

POST /api/mcp was fully admin-gated: checkAuth ran before any JSON-RPC
parsing, so an unauthenticated agent got a 401 for everything. Meanwhile
the machine-discovery layer promised an anonymous read path that did not
exist — the server card advertised capabilities.tools on a public endpoint
with no auth declared, the agent card advertised "public-digest" and
"story-markdown" skills over MCP, SKILL.md said "MCP (read + admin)", and
openapi.json described /api/mcp as a flat 200. Any agent that followed the
published docs got a 401 on its first call. The card also advertised
capabilities.resources and capabilities.prompts, neither of which existed.

The shared read-tool contract (#227 defines it, #226 consumes it)

One module, src/lib/public-read-tools.ts, is now the single definition of
the four read capabilities: latest_ai_news, search_news, get_story,
get_ai_digest. It owns the names, descriptions, input schemas, annotations,
argument validation, and the bound constants. Two thin execution adapters
issue the queries beside their transport — worker/mcp/public-tools.ts for
MCP (D1) and, in #226, src/lib/webmcp.ts for WebMCP (same-origin fetch) —
so the transports cannot drift and neither re-describes a tool.

Reuses the existing read path: getPublicDigest + boundPublicDigest +
PUBLIC_RESPONSE_MAX_BYTES, getFeed (with its 1-14 day clamp and before
validation), getStoryCandidates + renderStoryMarkdown. No new D1 query, no
new table, no migration, no parallel data path.

Auth boundary

Anonymous is defined as "no bearer token" — the exact predicate checkAuth
itself uses to read one. A request presenting ANY bearer token still gets
checkAuth's plain HTTP 401/500 Response, byte for byte, because a client
that tried to authenticate and failed must not silently degrade into a
read-only session. tools/list returns the public registry for an anonymous
caller and public + admin for an admin; the two registries are separate
modules so the merge happens once, from the resolved auth state.

An anonymous tools/call for anything outside the public registry returns
isError:true with one refusal message — byte-identical for "that is an
operator tool" and for "no such tool", because comparing against the admin
registry IS the enumeration oracle. No names, no counts.

Rate limit (hard requirement, not a follow-up)

worker/mcp/rate-limit.ts reuses worker/rate-limit.ts — the same
checkRateLimit + hashIp + subscribe_attempts(ip_hash, created_at) mechanism
the subscribe handler and the admin failed-auth limiter already use, under
an "mcp-read:" key namespace. 60 read calls per IP per 60 s; over the limit
is HTTP 429 with a JSON-RPC -32000 error and Retry-After. Admin traffic is
not limited. Validation runs BEFORE the window is charged, so a rejected
argument costs no D1 and no quota. Fails CLOSED if the counter is
unavailable — a limiter that fails open is not a limiter.

Truthfulness

AGENT_DISCOVERY_VERSION 0.1.6 -> 0.1.7 (versioned into openapi.json,
agent-card.json, server-card.json; the agent-skills digest is derived from
CONSUME_SKILL_MD at request time, so it is recomputed by construction).
mcpServerCard() now lists the real tools with schemas and annotations, the
resources, the rate limit, and which half needs a bearer token.
capabilities.prompts is REMOVED rather than shipped unimplemented.
a2aAgentCard()'s public-digest and story-markdown skills are now reachable
over MCP. CONSUME_SKILL_MD splits the ambiguous "read + admin" line into an
anonymous read line and an explicitly admin-authenticated write line.
openApiDocument() gains x-mcp (tool set, auth, rate limit, resources) and
real 401/429 responses. /mcp, llms.txt, and /changelog updated.

/api/mcp stays noindex, nofollow — route-indexability.ts:323 is untouched
and now has a regression test.

Untrusted content

Every tool is readOnlyHint + untrustedContentHint, and every description
carries the trust boundary, because prose in llms.txt is not
machine-actionable. Ambiguous id prefixes are rejected, never resolved to
a "closest" story, mirroring /api/story/{id}.

No new dependencies. No ranking, ingest, prompt, or schema change.

* feat(web): valid llms.txt links, read-only WebMCP tools, ai-catalog.json (#238)

Lighthouse "Agentic Browsing" scored aidr.today 2/3 with
"llms.txt does not follow recommendations - Error: File does not appear to
contain any links", plus three empty agent surfaces: no WebMCP tools
registered, no WebMCP schemas, no ai-catalog.json. The Cloudflare bridge was
being loaded (14.42 KiB on the critical path) for zero registered tools, so
it was pure cost.

llms.txt is now spec-conformant markdown

Every endpoint is a real [label](url) link instead of bare "GET https://..."
text in a "-" list item, and the missing machine surfaces are linked:
/openapi.json, /.well-known/agent-card.json, /.well-known/mcp/server-card.json,
/.well-known/ai-catalog.json, the API-catalog linkset, the agent skill path,
and /auth.md. Exactly one H1. The RSS feed, its /rss.xml alias, the Google
News sitemap, and the sitemap-index wording landed in #236 and are preserved
here as links too, so this PR stays independently mergeable over it.

No information was lost. The locale/cache contract, the story-text trust
boundary, the ranking formula, the submit flow, and the suggest flow are all
still there, and a test asserts each of them by content. llms-txt.test.ts now
asserts >= 1 markdown link, exactly 1 H1, and that every listed absolute URL
resolves against the shared site constants (not a network call) - a
non-aidr host must be an intentional external project URL.

WebMCP tools, from the same contract module as MCP

src/lib/webmcp.ts registers the four read capabilities through
document.modelContext.registerTool. It does not re-describe them:
WEBMCP_TOOLS IS PUBLIC_READ_TOOLS, and the registration's inputSchema IS
the contract's own object. webmcp.test.ts asserts that by identity, so a
second list is structurally impossible rather than merely discouraged.

The browser has no D1 binding, so WebMCP execute reads the same public
endpoints over same-origin fetch and applies the same validators and the
same projection + bound as the MCP transport. Validation runs first, so a
hostile argument costs one bounded pass and no request.

Registration is client-side only. A <WebMcpTools /> component calls
registerWebmcpTools() in an effect; it renders nothing. When
document.modelContext is undefined the call is a no-op returning 0, never
a throw, and /.webmcp/bridge.js is never imported, vendored, bundled, or
script-tagged - a test scans the source tree for all three.

ai-catalog.json is derived from the same module

/.well-known/ai-catalog.json describes the registered tools with their
schemas, annotations, REST equivalents, and auth, plus the audited forms.
aiCatalogDocument() maps PUBLIC_READ_TOOLS; agent-discovery.test.ts asserts
the served document's tool list, annotations, and additionalProperties.

Form annotations: the real decision, stated in the document

submit and subscribe are agent-callable, with consequentialHint true
(publishing to a public feed and committing to recurring mail are both
real consequences) and untrustedContentHint true on submit, because
url/title/note are third-party text.

sign-in and sign-up are NOT exposed. A tool whose schema is
{ password: string } is a credential-harvesting primitive advertised to
every agent on the page, and no host model can distinguish "fill the sign-in
form" from "exfiltrate the user's password". Clerk owns those forms and
they are not in this codebase, so there is nothing to annotate either.
The header SearchBox is not exposed: it filters an already-loaded feed, so
the registered search_news tool covers it with real semantics. The story
suggest form shares the sign-in credential boundary. All three are listed
in ai-catalog.json as agentCallable:false WITH a reason, so a reader sees
the decision rather than inferring a silent gap. A test asserts no form
annotation ever declares a password/token/secret/otp/code property.

Also fixed: boundSearchResult was O(n^2)

The bounding step re-serialized the whole payload after every single item
removal, so a hostile 4,000-item feed cost 4,000 serializations of a ~16 MB
string - the code that exists to prevent a denial of service was one. It
is now a binary search over a newest-first prefix: O(log n) measurements,
same answer, and the regression is a test with a time bound.

No new dependencies. No ranking, ingest, prompt, or schema change.
No touch to src/lib/sitemap.ts or apps/web/public/robots.txt.

* feat(web): server-rendered JSON-LD (NewsArticle/WebPage/ItemList/BreadcrumbList) + single site_name constant (#239)

* feat(web): server-rendered JSON-LD (NewsArticle/WebPage/ItemList/BreadcrumbList) + single site_name constant

The site shipped a full og:/twitter: surface and zero structured data: the
production story page and homepage both returned 0 `application/ld+json`
blocks and 0 `itemscope` for a Googlebot UA. Rich-result and AI-answer
extractors only parse JSON-LD, so none of the ranking, headline, date, or
image work the og: tags already did was machine readable.

`HeadTags` (apps/web/src/lib/seo.ts) now carries a `jsonLd` graph plus the
`scripts` emitter that renders it, so JSON-LD rides the same
`head()` -> `HeadContent` path as meta/links and lands in the SSR HTML the
crawler already fetches. One `application/ld+json` script per document,
carrying a single `@graph` so `@id` references resolve and the extracted
block stays one JSON.parse-able object.

Per page type:

- Story `/{8hex}?lang=vi|en` -> NewsArticle. `headline` is
  `localizedTitle(item, lang)` — the exact call StoryRow paints into the
  single `<h1>`, so the graph and the visible headline cannot drift, and a VI
  request with no `title_vi` emits the real English headline instead of an
  invented translation. `inLanguage` follows the rendered headline
  (vi-VN / en-US), so the `en-US` on a `?lang=vi` URL is the machine-readable
  record of that fallback; `og:locale` keeps describing the page chrome.
  `datePublished` is `published_at`; `dateModified` is the newest timestamp
  the story actually carries. `image` is the generated first-party
  `/api/og/{id}.png` card, locale-suffixed, 1200x630, because upstream
  `image_url` can 404 — the call articleHead already made. `publisher` is the
  real outlet from `item_sources` (never aidr, never a fabricated person) and
  is omitted entirely when no outlet is known. `isBasedOn` carries the
  original article URL.
- Homepage -> WebSite + Organization (`/logo-sm.png`, the real SITE_URL) +
  WebPage + BreadcrumbList + ItemList. The ItemList is derived from the same
  arithmetic `TldrSection` paints with — the 8/12/16 selector moved into
  `lib/tldr-links.ts` and is now shared — so the list can only contain story
  permalinks that are `<a href>` in the same SSR response, with no invented
  url or position.
- Every static path -> WebPage + BreadcrumbList, self-canonical, with the
  root crumb at the language-matched homepage. The path list is
  SITEMAP_STATIC_PATHS, not a second hardcoded list.

Gated on `routeIndexability()`: the builders take the route identity and emit
no graph at all when the response is noindex (faceted query, tokenized
search, 404) or when a caller declares no route. `lib/head-route.ts` reads
the raw request query, not the route-validated `match.search`, so a dropped
key like `utm_source` still matches the robots meta and `X-Robots-Tag`.

Trust boundary: `jsonLdScriptBody` rewrites `<`, `>`, `&` and U+2028/9 into
JSON \uXXXX escapes, so a publisher title containing `</script>`, `<!--` or
`]]>` cannot terminate the block and still round-trips through JSON.parse.

Never emitted, and asserted absent by test: `aggregateRating`, `review`,
`author`, `NewsMediaOrganization` / any Google News publisher claim (aidr is
an aggregator, not an original outlet), and `WebSite.potentialAction` (no
site-search results page exists). No Microdata added.

site_name conflict resolved: `SITE_NAME` is now `AI;DR`, the visible header
wordmark, recorded with its evidence in site.ts. `og:site_name`, the JSON-LD
WebSite/Organization names, and (for the news-sitemap work) one constant;
`docs/decisions/telegram-instant-view.md` no longer carries
`site_name: null`. No Telegram handle is appended.

Refs #224, umbrella #232.

* test(web): assert news:name from SITE_NAME so the news sitemap cannot drift from og:site_name

* fix(web): replace opacity-based muted text with reader-bg-safe contrast tokens (#240)

Muted text was a Tailwind `opacity-*` utility on an already-themed color.
Opacity composites *after* color resolution, so it blended the text toward
whatever surface was behind it — including the per-user reader background
(`data-reader-bg`) — producing a pair that no token declared and no test
could assert, and a different ratio for every reader background.

That was the whole measured failure (Lighthouse, production, 2026-09-27):
`<span class="text-xs opacity-70">` on the homepage and story pages, plus
`<span class="topic-colored …">` on the muted story rows.

- add `--quiet-foreground` / `--primary-foreground-quiet`: opaque, declared
  steps one notch further from the background than `--muted-foreground`, each
  clearing AA (4.5:1) on every light and dark surface the app can paint
- `.topic-muted` for the trending chip count: the chip hue mixed 35% into the
  quiet token, so the count keeps the tag's hue and stays quieter than the
  label without compositing
- `.topic-colored` now mixes the palette hue with `--foreground`, the same
  treatment `.category-colored` already had, so chip labels also clear AA on
  the muted rows and the gray reader background
- reader backgrounds that repaint the page pin the text steps that belong
  with it, so a system-dark class cannot leave dark text on a light page
- hover states that faded the whole element (run strip, Button, mail button,
  chart legend dim) are declared colors now; the states are kept, not deleted
- `contrast-tokens.test.ts` parses the tokens out of styles.css and asserts
  WCAG 2.2 AA for every reader background x theme x surface x palette slot,
  the label/count hierarchy, and proves it can fail with broken fixtures

Refs #228, umbrella #232

* feat(worker): more verified news sources, data-driven source registry, per-source + stale observability (#241)

Implements #230. Three parts: more verified sources, a declarative source
registry that makes adding one a data operation, and per-source + stale
observability so a bad source is visible instead of invisible.

Sources (16 -> 20 registry rows, no new adapter type; all `rss`, which already
handled Atom as well as RSS). Every feed verified live with the production
parser and the production flood gate — `pnpm run verify:source-feeds`, 18/18:

  vnexpress-tech  VnExpress Khoa hoc & Cong nghge. The first VI-native source.
                  Declares sourceLang: "vi", which is what puts items on the
                  real VI->EN translation-QA path — no adapter ever emitted it,
                  so that whole branch was dead code. Chosen over Tuoi Tre
                  cong-nghe, which is also a working VI feed but whose pubDate
                  has no timezone and would land every item ~7h in the future.
  techcrunch-ai / theverge-ai / arstechnica-ai / wired-ai

Evaluated and rejected, reason recorded in the code and the migration header:
arXiv (export.arxiv.org is robots Disallow-all and arxiv.org lists
Disallow: /api, so the sortable API is out; the one allowed surface,
rss.arxiv.org, declares skipDays and was serving an empty channel so it could
not be verified live), VentureBeat (429; its FeedBurner mirror is 24 days
stale), Engadget (202 challenge), ZDNet (its "AI topic" RSS redirects to general
news), cafebiz/techrum/zingnews (404/404/403).

Declarative registry. worker/sources/catalog.ts is now the only place a source
is declared; the runtime seed, the generated migration, and the
/api/system/sources + /data surfaces all consume it, and a test asserts all
three agree byte for byte. This replaces the hand-copied rows in seed.ts and
migrations 0018/0020/0021/0022 that seed.ts's own header called a maintenance
hazard. The seed upserts name/type/config on conflict so a corrected feed URL
actually reaches an existing row, and deliberately never writes `enabled`, so
switching a noisy source off survives every run. Rows the registry does not
declare stay entirely operator-owned, and adding an rss source through the
existing upsert_source admin tool still needs no deploy — documented with
copy-pasteable curl in worker/README.md.

Per-source observability. workflow_runs.stats.sourceHealth carries fetched /
scored / accepted / rejected / merged per source, a closed skip-reason enum
(fetch_failed, parse_failed, empty, all_rejected_below_relevance, disabled), and
a consecutive-empty-run streak. A 200 that is really an HTML page now reports
parse_failed rather than looking like a quiet feed, via a typed
SourceFetchError whose message is sanitizeError'd before it can reach D1 or an
API response. Streaks are carried forward from the previous run's stats (one
single-row read) rather than recomputed, so surfacing staleness on the read path
costs nothing. Threshold is 168 consecutive runs (7 days at the hourly
cadence), which is measured rather than round: when the registry was verified
live, 11 of 18 feeds had nothing inside the 26h window, six of them
pre-existing (lastweekin-ai is a weekly newsletter, google-research publishes a
few times a week), so the "e.g. 48 runs" in the issue would have flagged
healthy sources most of the weekend. A row may override with staleAfterRuns.
Disabled is never reported stale — off is a decision, not a fault.

Vietnamese path. The adapter reads config.sourceLang and only "vi" counts, so a
typo cannot put an item on the wrong side of the QA path. A new test reproduces
the real production failure observed in /api/system's llm_calls (the EN
generator works, both configured reviewer ids 404) and asserts nothing is
accepted, the original candidate is never overwritten, and a review_failed
attempt is persisted with a scheduled retry. The 3-attempts -> terminal
human_review -> one authenticated retry transition is already proven end to end
in translation-qa.integration.test.ts. One pre-existing gap is pinned by a test
rather than fixed here: if EN *generation* fails there is no candidate to
review, so no human_review row is created.

Flood gate. applyFloodGate runs a named keyword pre-filter (the same regex the
HN adapter uses, now in one shared module) and then a newest-first maxItems cap,
both config-driven. Newest-first is what makes the cap safe: the 26h window
means the head of the feed at the next run is what was published since the last
one, so the cap samples the live edge and dedupe drops the rest. Exercised
against a 640-entry fixture through the real adapter.

No ranking, hide-rule, prompt, or LLM-budget change. rank_score and the
relevance < 0.4 rule are untouched and worker/ranking.ts is not modified; no
new source is boosted or penalised. No hang-cap, batch size, or model chain is
changed. The added volume fits the existing budgets and the arithmetic is
asserted in a test: five new rows at maxItems 6 is a per-run ceiling of 30, or
6 batches, 2 concurrent rounds, 140s worst case inside the 240s score step.

* fix(web): read the llms.txt H1 from SITE_NAME so the brand cannot drift (#242)

The H1 was a second brand literal while og:site_name, the JSON-LD
WebSite/Organization name, and the news sitemap news:name all read
SITE_NAME. That is the exact drift #224 removed everywhere else; the
test now pins the H1 to the constant rather than to a string.

* perf(web): cut the LCP element render delay and the font-swap CLS (#243)

Refs #229, #232.

LCP element render delay 1,909 ms -> 1,121 ms (cold Slow-4G / 4x CPU, median
of 3). TBT 1,647 -> 763 ms. CLS is unchanged at 0.089; the font-swap shift
is gone but a residual 22px re-wrap of one AI;DR row survives, and the
<200 ms bar is not met. All reported in the PR with the isolation runs that
show where the remaining time goes.

The trace contradicts the issue's diagnosis in two places, and both are
documented:

- The Fontsource @imports were build-time inlined by Vite, not a runtime
  round trip. What was real is the second half: the font fetches could not
  start until the 19 KB render-blocking stylesheet had been parsed
  (fonts started 1,752 ms, landed 2,705-4,287 ms, shift at 3,537 ms).
  Fonts are now self-hosted in src/fonts.css with font-display: optional and
  metric-matched local() fallbacks whose overrides are measured out of the
  shipped binaries by scripts/font-metrics.py, not guessed.

- The issue asked for `optional` + preload. Preloading under `optional` is a
  316 ms regression: a face only lands inside the ~100 ms block period if
  28 KB beats a 1.6 Mbps link, which it cannot, so the bytes are fetched,
  compete with the stylesheet, and are discarded. The preload is removed and
  pinned by FONT_PRELOAD_DECISION plus a test that fails if one is added back
  without re-reading the numbers.

The LCP element is a text row, already in the SSR body at byte 29,218 — it
was never gated on hydration. What blocked it was four third-party
`fetchpriority=high` image preloads React hoisted into the head *ahead of*
the render-blocking stylesheet. StoryThumb keeps them eager (identical
pixels) and hands the priority back. The five analytics bootstraps move from
React's commit phase to idle after the LCP paint, and the Clarity vendor
snippet stops doing insertBefore on a document that may have no <script>.

Vietnamese coverage is asserted, not assumed: latin alone drops 47 of the 87
characters the Vietnamese alphabet needs, and the live feed's U+0101/U+014D
loanword macrons are why latin-ext cannot be deleted either.

Also: preconnect j.duyet.net and clarity.ms; 30-day TTLs for the unhashed
logos plus /og-home.jpg, which had no rule and was getting the Workers
default max-age=0; and the forced reflow in useHorizontalScroll, which wrote
two custom properties unconditionally on every scroll event.

The font subset was NOT reduced. Real subsetting needs a new dependency,
which the issue rules out; the per-subset reasons are in the PR.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(master): release web 0.1.8 (#134)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore(deps): update dependency vitest to v5.0.2 (#213)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency motion to v13.4.4 (#214)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update tanstack-router monorepo to v1.170.40 (#234)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

---------

Co-authored-by: duyetbot <101855044+duyetbot@users.noreply.github.com>
Co-authored-by: duyetbot <duyetbot@users.noreply.github.com>
Co-authored-by: duyetbot <bot@duyet.net>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@duyet
duyet deleted the feat/more-sources branch October 4, 2026 10:28
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.

1 participant