Skip to content

Similar past fixes#56

Merged
suggestied merged 27 commits intomainfrom
similar-past-fixes
Feb 16, 2026
Merged

Similar past fixes#56
suggestied merged 27 commits intomainfrom
similar-past-fixes

Conversation

@suggestied
Copy link
Contributor

@suggestied suggestied commented Feb 16, 2026

PR: Similar Past Fixes

Summary

Adds semantic “similar past fixes” for work orders: users see completed work orders that are semantically similar to the current one (or to free text). Uses vector embeddings (OpenAI) stored in Postgres with pgvector; search runs via an Edge Function and RPCs. Only completed work orders are indexed; indexing is done by a cron backfill, not by clients.

Changes

  • DB: pgvector extension; app.work_order_embeddings table (1536-d, HNSW) with RLS. RPCs: rpc_similar_past_work_orders, rpc_get_work_order_embedding, rpc_check_similar_past_fixes_rate_limit, plus backfill RPCs (rpc_upsert_work_order_embedding, rpc_next_work_orders_for_embedding, rpc_backfill_upsert_work_order_embedding). Bulk import extended with optional cause and resolution per row.
  • Edge Functions: similar-past-fixes (POST search by workOrderId or queryText; uses stored embedding when available; rate-limited). similar-past-fixes-backfill (cron: embed completed WOs in batches via RPC).
  • App: SDK client.similarPastFixes.search(...); work order detail page shows “Similar past fixes” table (title, match %, completed, cause, resolution). Docs page for the feature.

Testing

  • npm test
  • E2E not run (needs OPENAI_API_KEY + functions serve)

Checklist

  • Changes focused and scoped
  • Docs updated (Similar Past Fixes page)
  • New migrations include RLS
  • Writes go through RPC (no direct table writes)
  • Naming conventions followed

Notes

  • Backfill: run similar-past-fixes-backfill on a schedule with SUPABASE_SERVICE_ROLE_KEY and OPENAI_API_KEY; optional CRON_SECRET.
  • Feature can be turned off with SIMILAR_PAST_FIXES_ENABLED=false.

Note

High Risk
Touches database schema/migrations, RLS-protected vector search RPCs, and introduces Edge Functions calling external embeddings, so correctness, cost/rate limiting, and tenant isolation need careful review.

Overview
Adds the new “Similar Past Fixes” capability: completed work orders are embedded (pgvector) and searched via a Supabase Edge Function, surfaced through the SDK, and displayed in the web dashboard.

Database changes introduce vector + app.work_order_embeddings (HNSW + RLS) and new/updated RPCs to upsert/fetch embeddings, backfill candidates, search with an optional similarity threshold, and rate-limit search; work orders also gain optional cause/resolution fields and rpc_complete_work_order/views/types are updated accordingly.

App/SKD changes add client.similarPastFixes.search(), a new work order detail route that shows similar results and allows completing with cause/resolution, plus UI hardening around tenant/session refresh and catalog/query invalidation; docs, env/examples, and CI scripts are updated to support optional E2E/backfill flows.

Written by Cursor Bugbot for commit 7cfeacc. This will update automatically on new commits. Configure here.

…ion fields, update relevant SDK types, and modify documentation to reflect these changes.
…ate related SQL function. Enhance tests to validate inclusion and exclusion of work orders based on embedding status.
…r manage work_order_id and enhance SQL interactions. Improve test coverage for work order embedding scenarios.
…and enabling/disabling feature via environment variable. Implement rate limit checks to manage API usage effectively.
…clear stored tenant ID, improving catalog query persistence logic, and updating dashboard components to handle tenant state more effectively. Refactor session management during tenant switching to ensure proper JWT handling.
…ntralized storage key, enhancing consistency and maintainability. Replace direct localStorage access with a utility function for tenant context management in route loading, improving code clarity and reducing duplication.
…a centralized function, improving consistency and maintainability. Update pagination handling to use a default page size, enhancing the user experience in data tables and error handling for asset, department, location, role, user, and work order pages.
…ng with a call to refreshSession() across various components. Introduce a catalog query function to handle tenant synchronization and session refresh when catalog results are empty, improving consistency and reliability in tenant context management.
… multi-select options, improving visual representation in dropdowns and badges. Update related components to utilize this new property for better user experience.
… past fixes search function, reducing unnecessary OpenAI calls by utilizing stored embeddings when available.
…pdating CSV options and template. Enhance import page to support new fields and adjust related interfaces accordingly.
…, enhancing UI with structured display of title, match percentage, completion date, cause, and resolution. Update SDK types to include SimilarPastFixResult.
…afety for table columns and rows, ensuring proper typing for SimilarPastFixResult in header and cell render functions.
…ions for improved text embedding, ensuring cause is prioritized in search results.
… to asset details. If an asset ID is present, the name is now a clickable link; otherwise, it displays as plain text. This improves navigation and user experience in the assets table.
@suggestied suggestied merged commit 6ab8a25 into main Feb 16, 2026
2 checks passed
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 4 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on March 11

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

const err = new (require('../errors.js').SdkError)(message, {
code: resolved.code,
});
throw err;
Copy link

Choose a reason for hiding this comment

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

Runtime crash: require() used in ESM-only SDK module

High Severity

The require('../errors.js') call on line 85 will throw a ReferenceError at runtime. The SDK package is configured as ESM-only ("type": "module" in package.json, format: ['esm'] and platform: 'neutral' in tsup.config.ts), so require is not available. SdkError is already exported from ../errors.js (same module that normalizeError is imported from on line 2) and can simply be imported at the top of the file.

Fix in Cursor Fix in Web

basePath="/dashboard"
rootHref="/dashboard"
rootLabel="Dashboard"
uuidSegmentLabel="Work order"
Copy link

Choose a reason for hiding this comment

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

Breadcrumb shows "Work order" for all UUID segments

Medium Severity

The uuidSegmentLabel is hardcoded to "Work order", but SmartBreadcrumb applies this label to every UUID-shaped path segment regardless of the parent route. On the asset detail page (/dashboard/assets/<uuid>), the breadcrumb incorrectly reads "Dashboard › Assets › Work order" instead of "Dashboard › Assets › Asset". Any future detail page with a UUID param will also show "Work order".

Fix in Cursor Fix in Web

<title>Web App</title>
</head>
<body class="dark">
<body class="">
Copy link

Choose a reason for hiding this comment

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

Dark mode removed from app, unrelated to PR scope

Low Severity

The class="dark" on <body> was changed to class="", switching the entire web app from dark mode to light mode. The CSS framework uses @custom-variant dark (&:is(.dark *)) — the .dark class was the sole mechanism for dark mode and there's no theme toggle. This is unrelated to the "Similar Past Fixes" feature and likely an accidental change that slipped in.

Fix in Cursor Fix in Web

{label}
</Badge>
)
}
Copy link

Choose a reason for hiding this comment

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

StatusBadge and PriorityBadge are fully duplicated components

Low Severity

PriorityBadge and StatusBadge are identical in implementation — same resolveFromCatalog helper (line-for-line), same badge rendering logic, same style computation, same variant handling. Only the prop names differ (statusKey vs priorityKey). A single generic CatalogBadge component could serve both purposes, reducing the risk of future inconsistent bug fixes across the two copies.

Additional Locations (1)

Fix in Cursor Fix in Web

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