← Back to Pull requests

Admin report: Trade matches (mutual ISO/UFT pairs) #235

Closed
unknown closed this pull request without merging on Nov 29, 2026 04:47 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 04:05 UTC
Author

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->

Summary

Adds a Trade matches entry to the admin Reports registry (/admin/reports/trade-matches). The report lists every mutual trade pair site-wide using the same matching engine as the signed-in Matches page (buildMatchesForCaller in functions/matches.js).

What the report shows

  • One row per collector pair (canonical left/right uids) with:

  • - Matched SKU count — distinct SKUs appearing in either direction’s trade piles across enabled lanes
    - Items left → right and items right → left — pile entries (SKU, optional iso / uft flags) the matcher would surface
  • Account (server filter) dropdown to narrow pairs involving one uid (re-fetches on change)

  • Client filters (search, minimum matched SKUs, sort) plus 25-row paging

  • Refresh data — one-shot callable fetch (no live collection listeners)

  • Lists accounts excluded via config/adminReports.isoReportExcludedUids (same list as the Global ISO report); excluded accounts never appear on either side. Matching opt-outs are also suppressed.
  • Data layer

  • New callable: getAdminTradeMatchesReport — assertSiteAdmin / admin custom claim only (same gate as listAdminCollectors)

  • Reads: full collections scan, userPreferences where matchingOptOut == true, batched prefs for collectors with collection data, and config/adminReports for exclusions

  • Returns up to 500 pairs (sorted by match breadth); truncated: true when more exist
  • Metrics not tracked yet

    None — all displayed fields are derived from existing collection tradeFlag / quantity data and userPreferences match settings. No PostHog or separate analytics feed is used for this report.

    Tests

  • functions/adminTradeMatchesReport.test.js — pair dedupe, ISO exclusion list, admin gate

  • frontend/src/pages/Admin/reports/filterAdminTradeMatchPairs.test.js

  • frontend/src/pages/Admin/reports/useAdminTradeMatchesReport.test.js

  • frontend/src/pages/Admin/reports/TradeMatchesReport.test.jsx
  • Setup / deploy checklist

    | Step | Required? |
    |------|-----------|
    | Cloud Functions deploy (getAdminTradeMatchesReport) | Yes — report will 404/fail until deployed |
    | Firestore rules | No change |
    | Firestore indexes | No change |
    | Hosting-only deploy | Not sufficient (callable lives in Functions) |
    | config/adminReports | Uses existing doc; exclusions managed on ISO report |
    <!-- CURSOR_AGENT_PR_BODY_END -->

    <div><a href="https://cursor.com/agents/bc-232735fc-c275-5825-ac11-326b5f5dc36d?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-232735fc-c275-5825-ac11-326b5f5dc36d&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

    Diff: 434 lines (+325 / -109) across 5 files Reviewer: cursor[bot] Review duration: 41m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 434 lines diff across 5 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    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.363
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #235"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    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: 50.2% (MEDIUM) · Higher = larger blast radius
    50.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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 21.7% · Safe to merge
    21.7%