← Back to Pull requests

Sourcing phase 1 (S1): Feeds and Relay move into Sources; relay switches; sources_v2; change log old → new; migrate commands #71

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 25, 2026 13:17 UTC
Author

Sourcing restructure, phase 1, site part (S1), as the owner approved on 25 Oct 2026 (plan: Claude outputs/sourcing-restructure-plan-2026-10-25.md, §2–§5.2, §8 S1, §9).

Merge order: the workers PR merges first: wugweb-git/animal-writes-workers#19 (W1). S1 only adds blocks that W1 reads, and every v1 key stays. Nothing changes for the workers until wp aw-sourcing migrate --phase=1 runs on live.

What changes


  • Feeds and Relay move into Sources (core parts only: WP_List_Table, form-table, core notices and buttons, help tabs; no CSS or JS added):

  • - Sources list (AW_Sourcing_Publishers_Table):
    - New Feeds column (how many, how many on, how many read by code).
    - New Relay column (the switch and its last result).
    - New views: With feeds, Read by code, Relay, plus links to the Feeds and Relay log screens.
    - Row and bulk actions: Relay on / off (once migrated), and Delete for a source with no items, feeds or press search (core's showNotice.warn() first).
    - Rows also cover a relay-only site (record kind=relay) and a site only feeds come from.
    - Source edit: "Fetch through this site (relay)" with its last result, then that site's feeds (the feeds list filtered to it) with Add New Feed.
    - Feeds (AW_Sourcing_Sources_Table, reused):
    - A Publisher column.
    - A Publisher field on the feed form. A Google News search limited to one site belongs to that site (owner's decision 2); an open-web search belongs to news.google.com.
    - Delete for feeds. Sources read by code are only turned off.
    - Relay log: AW_Sourcing_Simple_Table, searchable.
    - The old tab=feeds, library, opportunities and relay addresses 301 to Sources. A feed's edit= becomes feed=.
    - The explanation paragraphs moved into Help tabs (Overview, Feeds, Relay, Columns).
  • Relay from the switches.

  • - Once aw_sourcing_phase >= 1, aw_relay_hosts() is the hosts whose switch is on (aw_publishers[host].relay, subdomains included). Before migration, and after a rollback, it is the list of before.
    - The ingest gate makes a relay-only site a publisher on its first item.
  • Change log:

  • - kits_sourcing_log( $tab, $what, $old = null, $new = null ) keeps the newest 1,000 entries (was 300).
    - The Change log tab gets an Old → new column.
    - Every add, edit and delete in Sources, Feeds and Relay logs its old and new values. Bulk actions log in one write.
    - Old tab names show as Sources (feeds / Library feeds / Opportunity feeds / relay).
  • Policy:

  • - config.category_names is always sent.
    - Once migrated, config.schema {sources: 2} and config.sources_v2 (each v1 source plus host, relay, read_by, check) are sent.
    - Every v1 key (publishers, relevance, config., relay_hosts) is unchanged.
  • WP-CLI: wp aw-sourcing backup | migrate [--dry-run] | verify | rollback [--restore-all] --phase=1. Details are in "After merge" below.

  • Shared matcher: aw_match_term() (includes/sources-model.php) is the workers' matcher. aw_has_term understands a trailing . It is not used for matching yet; phase 2 switches it on with match: "word".

  • Tests without WordPress (owner rule):

  • - plugins/aw-sourcing/tests/run.php checks the shared match_cases.json (the same file as W1) and the Sources model against the live shapes of 25 Oct (tests/fixtures/phase1_live_sample.json, read-only wp option get).
    - The Deploy check now runs it.

    What the migration does on live (computed from the live options, 25 Oct)


    | | Before | After |
    |---|---|---|
    | aw_sources.sources | 20 | 20, same ids and order; each gains host |
    | Site-limited Google News searches | court-news-animals, court-news-barandbench, court-news-scobserver, pib-releases | feeds of livelaw.in, barandbench.com, scobserver.in, pib.gov.in (all four already have publisher records) |
    | Publishers | 359 | 360 (+ ccsea.gov.in, kind=relay) |
    | Relay hosts | substack.com, zoomtventertainment.com, awbi.gov.in, ccsea.gov.in, egazette.gov.in | peopleforanimals.substack.com, zoomtventertainment.com, awbi.gov.in, egazette.gov.in, ccsea.gov.in (switches on 4 publishers plus the relay-only record) |
    | Relay log (48 rows) | PFA Substack 43, Zoom TV (www.) 1, CCSEA 1, refused tests 4 | every host relayed before is still allowed; substack.com is narrowed to PFA only (owner's decision 8) |

    After merge (owner): live steps


    Run from ~/domains/animalwrites.in/public_html, after the W1 merge and the S1 deploy:
    1. wp aw-sourcing backup --phase=1: prints the counts and the sha256 of each option. Check that the file size is not 0.
    2. wp aw-sourcing migrate --phase=1 --dry-run: read the report. It should show 20 → 20 sources, publishers 359 → 360, relay hosts 5 → 5 with the substack.com narrowing, and 0 conflicts.
    3. wp aw-sourcing migrate --phase=1
    4. wp aw-sourcing verify --phase=1: should print 0 differences apart from the planned changes.
    5. Round trip: open Sources → Edit on PFA Substack and press Update without changing anything; then a feed's Edit → Update. Then wp option get kits_sourcing_log --format=json | head -c 600 should show no new entry from those saves.
    6. Check the next Sourcing run: relay: … read through the site for peopleforanimals.substack.com, lists: from the site (… sources, sources_v2), and sources= the same as before.
    7. If anything is wrong: wp aw-sourcing rollback --phase=1 (or --restore-all to put back the backed-up options exactly).

    Review


  • Lint: php -l on every changed file: clean.

  • Tests: php plugins/aw-sourcing/tests/run.php: OK, 98 checks.

  • PHPCS security delta: python3 tools/ci/phpcs_delta.py origin/wordpress-dev HEAD with WPCS 3: no new findings in 10 changed files.

  • Deploy check (CI): runs on this PR. The workers-registry step is unaffected (no registry change).

  • Code review of my own diff (code-review skill, high). It found 10 points; all were fixed in commit "review fixes":

  • - A stale Relay form could have replaced all of aw_sources. It is now a no-op, and unknown tabs keep the stored option.
    - The feed form pinned the old host when only the address changed.
    - Rollback removed hosts set by hand. It now removes only the hosts the migration added.
    - A backup taken after the migration could be used for rollback. It is now refused, the migration records which backup it used, and rollback clears the pointer.
    - A typo in Publisher cleared the host.
    - A relay-only record given a status (quick add, one-click block, bulk) stayed "relay only".
    - Other Substack hosts in the relay log blocked the planned narrowing.
    - Change log entries are now written in one update per bulk action.
    - The relay log is indexed once per screen.
    - verify's relay check compared a value with itself. It now checks the migration's starting list.
    - A pre-existing issue was also fixed: an unchanged Source edit save rewrote the record in a new key order.
  • wp-plugin-audit skill: not available in this session, so reviewed by hand:

  • - Capability AW_SRC_CAP and the aw_sourcing nonce on every new action. The new row actions are buttons inside the existing nonce'd form.
    - Every new output is escaped.
    - No new $_GET/$_POST read without sanitising.
    - No direct SQL.
    - The backup folder has .htaccess deny and index.php.
    - WP-CLI code loads only under WP_CLI.
  • No local WordPress (owner rule). The admin screens were not rendered locally. CI's smoke test boots WordPress with the plugin.

  • Read-only live checks: wp option get aw_sources | aw_publishers | aw_relay_log, and wp term list category, to build the fixture and the table above.
  • Not in this PR: the audit doc and the Notion "Workers" page updates (after the live check), and phases 2–4.

    Wugweb

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: chatgpt-codex-connector[bot] Review duration: 5m
    All Vouch review confidence checks passed
    Residual risk 0.61 = Change Risk (0.80) × (1 − Review Confidence (0.23)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.80 · 650 lines diff across 8 files
    0.80
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 34% · Reviewer familiarity: 35%
    23%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.080
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #71"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 23.3% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 80.2% (HIGH) · Higher = larger blast radius
    80.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 23.3% · Lower = rushed or shallow review
    23.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 61.5% · Moderate risk
    61.5%