Skip to content

feat(scanner): add Trustabl Enrich for scanner findings - #1973

Open
ericksondelacruz wants to merge 5 commits into
openlit:mainfrom
ericksondelacruz:feat/trustabl-enrich
Open

ericksondelacruz wants to merge 5 commits into
openlit:mainfrom
ericksondelacruz:feat/trustabl-enrich

Conversation

@ericksondelacruz

Copy link
Copy Markdown

Issue number:

Change description:

Adds Trustabl Enrich to scanner findings. From a finding's suggested fix, you can copy the fix or run trustabl enrich. Enrich asks an LLM to produce a concrete fix for the finding, optionally re-checks it, and shows the resulting diff.

  • Runner and API: OpenLIT downloads a GitHub working copy of the scanned commit with ref and path guards. It then runs trustabl enrich --apply --diff on the selected finding with the LLM provider's key from Vault. Each connector runs one enrich at a time, with a 10-minute timeout and cancel. Provider keys are redacted by value from logs and errors. Runs are kept in connector metadata so the UI can poll, cancel or discard them. Endpoints, all project-scoped:
    • GET/POST /api/scanners/{id}/enrich
    • GET /api/scanners/{id}/enrich/providers
    • GET/DELETE /api/scanners/{id}/enrich/{runId}
    • POST /api/scanners/{id}/enrich/{runId}/cancel
  • Fallback when the CLI declines --apply: The CLI writes a fix only when the model's verbatim echo of the lines matches the file exactly. When the fix stays on the finding's lines and is not a false positive, OpenLIT splices it into the review copy itself, and the usual re-check decides the result.
  • UI: The finding sheet gets Copy and Enrich actions on the suggested fix, plus an Enrich dialog for provider, model, attempts and re-check. A panel shows the running command, its progress, failures and the resulting diff. Polling keeps going through network and server errors.
  • Tests: Unit and component tests. A Playwright suite (e2e/scanner-enrich.spec.ts) drives the finding sheet against a fake trustabl CLI and a local GitHub API stub, using a throwaway ClickHouse from E2E_CLICKHOUSE_URL.
  • Docs: Copy and Enrich on the Scanner connectors page, including Vault provider keys and what is sent to the provider. The API reference and OpenAPI spec cover the enrich endpoints.

Checks on the branch rebased onto current main, from src/client:

  • npm run lint: no warnings or errors
  • npx tsc --noEmit: 0 errors
  • npx jest: 436/436 suites, 6260/6260 tests

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • PR title follows Conventional Commit format.
  • I have reviewed the contributing guidelines
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

Erick dela Cruz added 5 commits November 20, 2026 15:23
… the API

Downloads a GitHub working copy of the scanned commit, runs
`trustabl enrich --apply --diff` on the selected finding with the provider
key from Vault, optionally re-checks the result, and keeps the run in
connector metadata so the UI can poll, cancel or discard it.

- Contracts, input validation and Vault provider-key lookup
- Tarball workspace with ref and path guards
- Background runner with one run per connector, 10-minute timeout and cancel
- Provider keys redacted by value from logs and errors
- Project-scoped enrich API routes
Adds Copy and Enrich actions to the suggested fix, an Enrich dialog for
provider, model, attempts and re-check, and a panel that shows the
running command, its progress, failures and the resulting diff. Polling
keeps going through network and server errors and clears the panel only
when the server no longer has the run.
Playwright drives the finding sheet against a fake trustabl CLI and a
local GitHub API stub, using a throwaway ClickHouse from
E2E_CLICKHOUSE_URL.
Covers the Copy and Enrich actions, the Vault provider keys, what is sent
to the provider, and the six enrich API operations in the OpenAPI spec and
the API reference.
The CLI only writes a fix when the model's verbatim echo of the lines
matches the file exactly, so a range ending in a blank line the model
dropped is refused. When the fix stays on the finding's lines and is
not a false positive, OpenLIT splices it into the review copy itself
and the usual re-check decides the result.
@ericksondelacruz
ericksondelacruz requested a review from a team as a code owner November 20, 2026 07:25
@mintlify

mintlify Bot commented Nov 20, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 9521503.

Approve preview

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add Trustabl Enrich to scanner findings

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Add Copy and Enrich actions so users can turn scanner findings into reviewable fixes.
• Run Enrich in an isolated working copy with Vault credentials, optional re-checks, cancellation,
 and persisted progress.
• Document the API and validate the workflow with unit, integration, component, and browser tests.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: scanner_enrichment_integration.
  • The UI finding sheet, Enrich routes, connector metadata, Trustabl adapter, temporary workspace, provider call, re-check, and diff display are hops in one bounded Scanner enrichment integration.
  • They produce one end-to-end outcome: a reviewable proposed fix for a selected scanner finding.
  • Enrich run state is one persistence hop of the same bounded Scanner enrichment integration; losing it affects the user's ability to observe, cancel, retry, or discard the review run.
  • Scan-job history is a distinct user-visible Scanner operation but remains within the same bounded Scanner connector integration; the changed shared metadata writer is the common persistence boundary.
Behavioral complexity 🔴 High 🧩 Coordinated invariants, Concurrent ordering

  • Before: scan job persistence performed an independent read-modify-write.
  • After: scan jobs and Enrich runs share a queued read-modify-write helper keyed by connector instance.
  • New correctness condition: every writer participating in the metadata invariant must use the same serialization domain, and each queued update must observe the latest metadata without dropping the other state's keys.
  • The queue's ordering and error recovery are new coordination behavior; routine JSON parsing is not itself treated as complex.
Potential damage 🟡 Medium 🩹 Recoverable

  • Lost or stale metadata can temporarily hide an Enrich run or remove recent scan-job history from the Scanner UI.
  • The repository and external GitHub state remain unchanged.
  • Recovery requires rerunning the scan or Enrich operation, and any already-lost metadata may require a new run; code rollback alone does not reconstruct missing persisted metadata.
  • Generally recoverable by rerunning the affected scan or enrichment.
  • Existing overwritten metadata is not automatically reconstructed, and no cross-process repair mechanism is established.
Assessed commit 9521503
Diagram

graph TD
  UI["Finding sheet"] --> API["Enrich API"] --> RUN["Run coordinator"] --> COPY["GitHub workspace"] --> CLI["Trustabl CLI"]
  RUN --> KEY["Vault keys"] --> CLI
  CLI --> RUN --> STORE[("Connector metadata")] --> UI
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Durable job queue for Enrich
  • ➕ Coordinates one-run-per-connector limits across server processes.
  • ➕ Can recover or explicitly fail work after restarts.
  • ➖ Requires queue infrastructure and worker lifecycle management.
  • ➖ Adds substantial complexity to this connector-scoped feature.

Recommendation: The in-process runner and connector-metadata persistence fit the existing scanner design and avoid new infrastructure. Consider a durable queue if deployments run multiple application instances or require runs to survive restarts: cancellation and concurrency ownership currently reside in process memory.

Files changed (67) +7152 / -42

Enhancement (25) +2579 / -10
route.tsExpose Enrich cancellation +23/-0

Expose Enrich cancellation

• Adds an authenticated, audited, project-scoped endpoint to cancel a run.

src/client/src/app/api/scanners/[id]/enrich/[runId]/cancel/route.ts

route.tsExpose run lookup and discard +37/-0

Expose run lookup and discard

• Adds project-scoped GET and audited DELETE handlers with run-ID validation.

src/client/src/app/api/scanners/[id]/enrich/[runId]/route.ts

route.tsExpose available Enrich providers +16/-0

Expose available Enrich providers

• Returns supported providers and Vault key presence under scanner access controls.

src/client/src/app/api/scanners/[id]/enrich/providers/route.ts

route.tsExpose start and latest-run endpoints +57/-0

Expose start and latest-run endpoints

• Validates finding inputs and provides project-scoped handlers to start an Enrich run or retrieve a finding's latest run.

src/client/src/app/api/scanners/[id]/enrich/route.ts

scanner-enrich-dialog.tsxAdd Enrich configuration dialog +366/-0

Add Enrich configuration dialog

• Lets users choose a Vault-backed provider, model, attempts, re-check setting, and repository ref before starting.

src/client/src/components/(playground)/scanner/scanner-enrich-dialog.tsx

scanner-enrich-diff.tsxRender a reviewable unified diff +44/-0

Render a reviewable unified diff

• Displays changed lines with visual highlighting and addition and deletion counts.

src/client/src/components/(playground)/scanner/scanner-enrich-diff.tsx

scanner-enrich-panel.tsxShow Enrich progress and results +311/-0

Show Enrich progress and results

• Presents steps, logs, errors, re-check outcomes, and diffs, with cancel, retry, discard, and copy actions.

src/client/src/components/(playground)/scanner/scanner-enrich-panel.tsx

scanner-finding-sheet.tsxAdd Copy and Enrich to findings +99/-9

Add Copy and Enrich to findings

• Adds suggested-fix copying, an Enrich launch button, configuration dialog, and run panel to the finding sheet.

src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx

scanner-page.tsxPass connector context to findings +1/-0

Pass connector context to findings

• Supplies the selected connector ID to the finding sheet so it can call Enrich endpoints.

src/client/src/components/(playground)/scanner/scanner-page.tsx

use-scanner-enrich.tsManage Enrich state in the browser +170/-0

Manage Enrich state in the browser

• Loads and polls runs, tolerates transient polling failures, and implements start, cancel, retry, and discard actions.

src/client/src/components/(playground)/scanner/use-scanner-enrich.ts

en.tsAdd Enrich interface and error messages +116/-0

Add Enrich interface and error messages

• Defines validation, failure, progress, and UI text for the complete Enrich workflow.

src/client/src/constants/messages/en.ts

scanner-route.tsRecognize Enrich scanner actions +1/-1

Recognize Enrich scanner actions

• Extends the scanner route action type to include Enrich operations.

src/client/src/lib/access/scanner-route.ts

base-adapter.tsAdd a default unsupported Enrich method +6/-0

Add a default unsupported Enrich method

• Extends the base scanner adapter with an Enrich method that rejects unsupported implementations.

src/client/src/lib/platform/connectors/scanner/base-adapter.ts

crud.tsKeep Enrich runs out of connector summaries +1/-0

Keep Enrich runs out of connector summaries

• Omits detailed run records from public connector metadata responses.

src/client/src/lib/platform/connectors/scanner/crud.ts

enrich-crud.tsCoordinate connector Enrich runs +240/-0

Coordinate connector Enrich runs

• Validates the selected finding, resolves secrets, limits active runs, manages cancellation and timeouts, and persists background progress.

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts

enrich-params.tsValidate Enrich requests +76/-0

Validate Enrich requests

• Defines providers, run limits, credential environment names, and parsing rules for Enrich inputs.

src/client/src/lib/platform/connectors/scanner/enrich-params.ts

enrich-providers.tsResolve provider keys from Vault +67/-0

Resolve provider keys from Vault

• Lists supported models and key availability, and reads the selected provider key only when starting a run.

src/client/src/lib/platform/connectors/scanner/enrich-providers.ts

enrich-result.tsInterpret Enrich findings and results +235/-0

Interpret Enrich findings and results

• Matches findings across scans, parses CLI output, applies eligible declined fixes, compares re-check results, and calculates unified diffs.

src/client/src/lib/platform/connectors/scanner/enrich-result.ts

enrich-runs.tsStore bounded Enrich run records +53/-0

Store bounded Enrich run records

• Adds metadata helpers for upserting and removing runs, capping stored output, and identifying interrupted runs.

src/client/src/lib/platform/connectors/scanner/enrich-runs.ts

enrich-workspace.tsCreate guarded GitHub working copies +164/-0

Create guarded GitHub working copies

• Resolves a commit, downloads a size-limited archive, checks flagged-file containment, and removes temporary workspaces.

src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts

metadata.tsSerialize connector metadata writes +51/-0

Serialize connector metadata writes

• Introduces a per-connector, in-process update queue shared by scan jobs and Enrich runs.

src/client/src/lib/platform/connectors/scanner/metadata.ts

process.tsAllow cancellation of scanner subprocesses +3/-0

Allow cancellation of scanner subprocesses

• Passes an optional abort signal to the process runner so cancellation can stop the Trustabl CLI.

src/client/src/lib/platform/connectors/scanner/process.ts

adapter.tsAdvertise and implement Trustabl Enrich +11/-0

Advertise and implement Trustabl Enrich

• Enables the Enrich capability and delegates execution to the Trustabl Enrich pipeline.

src/client/src/lib/platform/connectors/scanner/trustabl/adapter.ts

enrich.tsRun the finding-to-diff pipeline +338/-0

Run the finding-to-diff pipeline

• Scans a temporary copy, enriches one finding with an isolated provider credential, optionally re-checks it, and returns a diff or structured failure. Handles retries, cancellation, cleanup, and eligible CLI-declined fixes.

src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts

types.tsDefine Enrich adapter and run contracts +93/-0

Define Enrich adapter and run contracts

• Adds capability, request, progress, failure, and persisted-run types for scanner enrichment.

src/client/src/lib/platform/connectors/scanner/types.ts

Refactor (1) +8 / -28
jobs.tsShare serialized scanner metadata updates +8/-28

Share serialized scanner metadata updates

• Moves job persistence to the shared metadata updater so concurrent job and Enrich writes do not overwrite one another.

src/client/src/lib/platform/connectors/scanner/jobs.ts

Tests (28) +3824 / -0
crontabIsolate e2e cron changes +9/-0

Isolate e2e cron changes

• Provides a fake crontab that writes to the test state directory instead of the host crontab.

src/client/e2e/fixtures/bin/crontab

trustablSimulate Trustabl for browser tests +198/-0

Simulate Trustabl for browser tests

• Implements fixture-backed scan and configurable enrichment outcomes, including applied, declined, and provider-error cases.

src/client/e2e/fixtures/bin/trustabl

scan-help.txtFixture Trustabl scan help +80/-0

Fixture Trustabl scan help

• Records scan help output for the fake CLI and runtime capability checks.

src/client/e2e/fixtures/cli/scan-help.txt

version.txtFixture Trustabl version +3/-0

Fixture Trustabl version

• Supplies version output for the browser-test CLI.

src/client/e2e/fixtures/cli/version.txt

github.jsStub GitHub commit and archive APIs +33/-0

Stub GitHub commit and archive APIs

• Serves a fixed commit SHA and fixture repository tarball to browser tests.

src/client/e2e/fixtures/github.js

agent.pyProvide a scan target with findings +18/-0

Provide a scan target with findings

• Adds agent definitions that the fake CLI can scan and modify during Enrich tests.

src/client/e2e/fixtures/repo/research-agent/research_agent/agent.py

prepare.jsPrepare isolated browser-test databases +43/-0

Prepare isolated browser-test databases

• Recreates test state and SQLite data, and optionally resets a dedicated ClickHouse database for Vault-backed tests.

src/client/e2e/prepare.js

scanner-enrich.spec.tsExercise the finding-to-diff workflow +173/-0

Exercise the finding-to-diff workflow

• Uses Playwright to cover Copy, missing Vault keys, successful enrichment, failed re-checks, retry, and declined-apply fallback.

src/client/e2e/scanner-enrich.spec.ts

playwright.config.tsConfigure an isolated Enrich browser suite +81/-0

Configure an isolated Enrich browser suite

• Starts the app and GitHub stub with fixture CLI, isolated state, and optional ClickHouse-backed Vault configuration.

src/client/playwright.config.ts

enrich-route.test.tsTest Enrich route contracts +222/-0

Test Enrich route contracts

• Checks authentication, input validation, and route responses for the Enrich endpoints.

src/client/src/tests/app/api/scanners/enrich-route.test.ts

enrich.integration.test.tsTest the integrated Enrich API pipeline +333/-0

Test the integrated Enrich API pipeline

• Exercises routes, persistence, archive extraction, and the pipeline together with mocked external systems.

src/client/src/tests/app/api/scanners/enrich.integration.test.ts

scanner-enrich-dialog.test.tsxTest Enrich option selection +163/-0

Test Enrich option selection

• Covers dialog provider-key availability and configuration controls.

src/client/src/tests/components/scanner-enrich-dialog.test.tsx

scanner-enrich-panel.test.tsxTest run-progress and result views +221/-0

Test run-progress and result views

• Verifies presentation and actions for running, successful, failed, and cancelled Enrich runs.

src/client/src/tests/components/scanner-enrich-panel.test.tsx

scanner-finding-sheet.test.tsxTest finding-sheet Enrich actions +258/-0

Test finding-sheet Enrich actions

• Covers suggested-fix copying and the finding sheet's Enrich entry point and result integration.

src/client/src/tests/components/scanner-finding-sheet.test.tsx

agent.pyFixture vulnerable agent source +12/-0

Fixture vulnerable agent source

• Provides a file with a flagged Bash tool for pipeline tests.

src/client/src/tests/fixtures/trustabl-enrich/agent.py

enrich-applied.jsonFixture an applied CLI fix +31/-0

Fixture an applied CLI fix

• Records representative Trustabl enrichment output with a replacement and unified diff.

src/client/src/tests/fixtures/trustabl-enrich/enrich-applied.json

enrich-provider-error.jsonFixture an unsuccessful enrichment +83/-0

Fixture an unsuccessful enrichment

• Provides representative Trustabl findings when the provider does not produce an applied fix.

src/client/src/tests/fixtures/trustabl-enrich/enrich-provider-error.json

scan.jsonFixture a full scan report +336/-0

Fixture a full scan report

• Provides realistic Trustabl scan data for finding selection and re-check tests.

src/client/src/tests/fixtures/trustabl-enrich/scan.json

scanner-adapter.test.tsCover adapter Enrich capability +20/-0

Cover adapter Enrich capability

• Adds assertions for the scanner adapter's Enrich support and capability behavior.

src/client/src/tests/lib/platform/connectors/scanner-adapter.test.ts

scanner-enrich-crud.test.tsTest Enrich run management +275/-0

Test Enrich run management

• Covers connector and finding validation, project scope, concurrency, persistence, cancellation, and run removal.

src/client/src/tests/lib/platform/connectors/scanner-enrich-crud.test.ts

scanner-enrich-params.test.tsTest Enrich input validation +77/-0

Test Enrich input validation

• Checks provider, finding number, model, attempt, and ref parsing constraints.

src/client/src/tests/lib/platform/connectors/scanner-enrich-params.test.ts

scanner-enrich-pipeline.test.tsTest Trustabl Enrich execution +423/-0

Test Trustabl Enrich execution

• Covers success, retries, re-check failures, provider errors, cancellation, secret isolation, and the declined-apply fallback.

src/client/src/tests/lib/platform/connectors/scanner-enrich-pipeline.test.ts

scanner-enrich-providers.test.tsTest Vault-backed providers +64/-0

Test Vault-backed providers

• Checks provider model lists, key-presence lookup, and provider-key resolution.

src/client/src/tests/lib/platform/connectors/scanner-enrich-providers.test.ts

scanner-enrich-result.test.tsTest finding and diff helpers +211/-0

Test finding and diff helpers

• Exercises finding matching, CLI output parsing, replacement application, diff generation, and re-check comparison.

src/client/src/tests/lib/platform/connectors/scanner-enrich-result.test.ts

scanner-enrich-runs.test.tsTest stored run behavior +133/-0

Test stored run behavior

• Checks metadata run retention, size limits, removal, and stale-run reporting.

src/client/src/tests/lib/platform/connectors/scanner-enrich-runs.test.ts

scanner-enrich-workspace.test.tsTest guarded GitHub workspaces +194/-0

Test guarded GitHub workspaces

• Covers commit and archive downloads, size and ref restrictions, path containment, and cleanup.

src/client/src/tests/lib/platform/connectors/scanner-enrich-workspace.test.ts

scanner-metadata.test.tsTest serialized metadata writes +80/-0

Test serialized metadata writes

• Verifies that concurrent scanner metadata updates preserve jobs and Enrich runs.

src/client/src/tests/lib/platform/connectors/scanner-metadata.test.ts

scanner-process.test.tsTest abortable scanner processes +50/-0

Test abortable scanner processes

• Adds coverage for terminating a scanner child process through an abort signal.

src/client/src/tests/lib/platform/connectors/scanner-process.test.ts

Documentation (9) +733 / -2
docs.jsonList Enrich API pages +6/-1

List Enrich API pages

• Adds the new scanner Enrich endpoint pages to documentation navigation.

docs/docs.json

scanner.mdxDocument finding enrichment +42/-1

Document finding enrichment

• Explains Copy and Enrich, Vault key setup, provider data exposure, run limits, and review actions. Lists the new API operations.

docs/latest/openlit/connectors/scanner.mdx

enrich-cancel.mdxDocument run cancellation +8/-0

Document run cancellation

• Adds the cancel endpoint page and describes process termination and workspace cleanup.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/enrich-cancel.mdx

enrich-discard.mdxDocument run discard +8/-0

Document run discard

• Adds the endpoint page for removing a finished run and its diff.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/enrich-discard.mdx

enrich-providers.mdxDocument provider discovery +8/-0

Document provider discovery

• Describes the provider listing and Vault key-presence response without exposing key values.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/enrich-providers.mdx

enrich-run.mdxDocument run retrieval +10/-0

Document run retrieval

• Explains polling a run and looking up the latest run for a finding.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/enrich-run.mdx

enrich.mdxDocument starting Enrich +10/-0

Document starting Enrich

• Describes starting a background run, Vault credential handling, and run limits.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/enrich.mdx

scanners.ymlDefine Enrich reference operations +288/-0

Define Enrich reference operations

• Adds provider, start, lookup, cancel, and discard operations with request and run schemas to the scanner API reference.

docs/latest/openlit/developer-resources/api-reference/endpoint/scanners/scanners.yml

openapi.yamlPublish Enrich endpoints in OpenAPI +353/-0

Publish Enrich endpoints in OpenAPI

• Defines all Enrich operations, authentication, parameters, and provider, request, progress, and result schemas.

src/client/public/openapi.yaml

Other (4) +8 / -2
jest.config.jsKeep browser tests out of Jest +1/-0

Keep browser tests out of Jest

• Excludes the e2e directory from Jest test discovery.

src/client/jest.config.js

next.config.jsAllow an isolated e2e build directory +3/-0

Allow an isolated e2e build directory

• Makes the Next.js output directory configurable so the browser-test server does not share a development build.

src/client/next.config.js

package.jsonAdd Playwright test tooling +3/-1

Add Playwright test tooling

• Adds a browser-test script and the Playwright test dependency.

src/client/package.json

tsconfig.jsonInclude e2e Next.js generated types +1/-1

Include e2e Next.js generated types

• Adds the isolated browser-test build's generated types to TypeScript's included paths.

src/client/tsconfig.json

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (12) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Large repositories can fill server disk 🐞 Bug ⛨ Security
Description
createEnrichWorkspace limits downloaded archive bytes but runs tar without a limit on extracted
bytes or file count. A repository with highly compressible contents can pass the 200 MB download
check and exhaust the temporary filesystem or its inodes before extraction times out.
Code

src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[R136-139]

+		await execFileAsync(
+			"tar",
+			["-xzf", archive, "-C", repoDir, "--strip-components=1", "--no-same-owner"],
+			{ shell: false, signal: input.signal, timeout: EXTRACT_TIMEOUT_MS, windowsHide: true }
Evidence
The byte checks cover only the HTTP archive; extraction writes its expanded contents directly to
disk without an output quota.

src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[91-106]
src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[129-145]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The compressed archive limit does not bound disk or inode use during extraction.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[80-110]
- src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[129-145]
## Recommended Fix
Enforce limits on extracted bytes and entries while unpacking, stopping extraction before either limit is exceeded. Retain cleanup on every failure path.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. CE access type gains an enrich literal 📘 Rule violation ⚙ Maintainability
Description
The CE no-op fallback type ScannerAction in scanner-route.ts adds the feature-specific literal
"enrich", and the new enrich routes pass it to withScannerAccess. Enterprise overrides that
replace this module must now recognise "enrich" for the enrich routes' access check to be
meaningful, and any CE consumer that switches on ScannerAction gains a branch tied to this
feature.
Code

src/client/src/lib/access/scanner-route.ts[8]

+export type ScannerAction = "read" | "create" | "scan" | "install" | "enrich";
Evidence
The PR adds "enrich" to the CE ScannerAction union, and the new enrich routes call
withScannerAccess("enrich", ...). The CE withScannerAccess ignores _action and returns the
handler unchanged, so the literal only has meaning in an enterprise override.

src/client/src/lib/access/scanner-route.ts[1-21]
src/client/src/app/api/scanners/[id]/enrich/route.ts[55-57]
AGENTS.md: Keep Enterprise Implementation and Permissions Out of CE

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The CE fallback `ScannerAction` union in `src/client/src/lib/access/scanner-route.ts` gained the feature-specific literal `"enrich"`. CE fallback APIs should use feature-agnostic keys rather than permission literals, so Enrich-specific permission names belong in the enterprise override.

## Fix Focus Areas
- src/client/src/lib/access/scanner-route.ts[8-8]
- src/client/src/app/api/scanners/[id]/enrich/route.ts[55-57]
- src/client/src/app/api/scanners/[id]/enrich/providers/route.ts[16-16]
- src/client/src/app/api/scanners/[id]/enrich/[runId]/route.ts[36-37]
- src/client/src/app/api/scanners/[id]/enrich/[runId]/cancel/route.ts[23-23]

## Recommended Fix
Confirm with the enterprise override owners which action key they expect for Enrich. If the enterprise layer maps actions generically, keep the CE type feature-agnostic (for example a generic `"run"` or `"execute"`), or confirm the enterprise override already handles `"enrich"`. Then update the routes to pass that key and document it next to the CE fallback comment.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Two workers can enrich one connector 🐞 Bug ☼ Reliability
Description
startScannerEnrich checks and reserves a connector using module-local maps rather than a shared
claim. When two server processes receive starts for the same connector, each can pass the check and
launch a separate run.
Code

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[R84-87]

+		startingConnectors.has(row.id) ||
+		enrichRunsFromMetadata(row.metadata || "{}").some((run) => activeRuns.has(run.id))
+	) {
+		throw new Error(SCANNER_ENRICH_RUNNING);
Evidence
Both the pending-start reservation and active-run registry exist only in process memory; persistence
happens later without a conditional claim.

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[44-46]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[84-95]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[105-142]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The one-run check only coordinates requests handled by the same server process.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[44-46]
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[78-95]
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[139-146]
## Recommended Fix
Use an atomic database-backed connector claim or equivalent shared lock before launching a run, and release it on terminal completion or interruption.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Concurrent writes can erase scan data 🐞 Bug ☼ Reliability
Description
updateScannerMetadata serializes read-modify-write operations only through an in-process promise
queue. If a scan-job write and an Enrich progress write run in different processes, both can read
the same old metadata and the later full-object write can erase the other's jobs or runs.
Code

src/client/src/lib/platform/connectors/scanner/metadata.ts[R33-42]

+			const existing = await prisma.connectorInstance.findFirst({
+				where: { id: instanceId },
+				select: { metadata: true },
+			});
+			if (!existing) return null;
+			const metadata = update(parseJsonObject(existing.metadata || "{}"));
+			await prisma.connectorInstance.update({
+				where: { id: instanceId },
+				data: { metadata: JSON.stringify(metadata) },
+			});
Evidence
The queue is module-local, while both job and run updates rewrite the complete metadata value
obtained by a separate read.

src/client/src/lib/platform/connectors/scanner/metadata.ts[11-12]
src/client/src/lib/platform/connectors/scanner/metadata.ts[29-43]
src/client/src/lib/platform/connectors/scanner/jobs.ts[20-27]
src/client/src/lib/platform/connectors/scanner/enrich-runs.ts[24-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The process-local queue cannot prevent lost metadata updates across server processes.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/metadata.ts[11-12]
- src/client/src/lib/platform/connectors/scanner/metadata.ts[25-49]
## Recommended Fix
Use database-level serialization or compare-and-swap with retry for the metadata read-modify-write. Cover concurrent job and Enrich updates from separate processes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View review recommended (7)
5. Remote cancellation leaves Enrich running 🐞 Bug ☼ Reliability
Description
cancelScannerEnrich can abort a process only when its local activeRuns map holds that run's
controller. If another process handles the cancel request, it writes a cancelled status while the
owner keeps running and can later overwrite that status with its result.
Code

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[R219-222]

+	const controller = activeRuns.get(run.id);
+	if (controller) {
+		controller.abort();
+		return run;
Evidence
The controller exists only in the owner process, but a non-owner persists cancellation without
signaling that controller; the worker subsequently persists its own final result.

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[44-46]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[180-193]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[217-232]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A cancellation handled outside the owning process changes metadata without stopping the subprocess.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[217-232]
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[153-195]
## Recommended Fix
Introduce shared cancellation state or route cancellation to the run owner. Have the owner observe the request, abort its controller, and prevent subsequent progress or finalization from overwriting cancellation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Discarded runs can reappear 🐞 Bug ☼ Reliability
Description
The worker removes its activeRuns entry before awaiting the final run write, while
discardScannerEnrich uses that entry as its only active-run guard. A discard in that interval can
delete the stored run and return success before finalization upserts it again.
Code

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[R190-193]

+		} finally {
+			clearTimeout(timeout);
+			activeRuns.delete(run.id);
+			await upsertScannerEnrichRun(row.id, run).catch(() => undefined);
Evidence
Ownership is deleted immediately before an awaited upsert; discard checks ownership and performs a
separate metadata removal.

src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[190-193]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[235-239]
src/client/src/lib/platform/connectors/scanner/enrich-runs.ts[24-38]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The active-run guard is released before the final metadata write, allowing discard to race with finalization.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[190-194]
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[235-239]
## Recommended Fix
Keep the run claimed through final persistence and coordinate discard with that write using shared, atomic run state so deletion cannot be followed by a stale upsert.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Another finding can show the wrong run 🐞 Bug ≡ Correctness
Description
useScannerEnrich.start applies its POST response with setRun without checking whether the
selected finding has changed. Starting Enrich for one finding and selecting another before the
response arrives can show the first finding's run in the second finding's sheet; pending cancel and
discard responses have the same state race.
Code

src/client/src/components/(playground)/scanner/use-scanner-enrich.ts[R123-127]

+				const body = await requestJson<{ run: ScannerEnrichRun }>(base, messages.SCANNER_ENRICH_FAILED, {
+					method: "POST",
+					body: JSON.stringify({ jobId, alertNumber, ...params }),
+				});
+				setRun(body.run);
Evidence
The selection effect invalidates its initial-load request but does not invalidate action callbacks,
while the parent changes findings without remounting the sheet.

src/client/src/components/(playground)/scanner/use-scanner-enrich.ts[63-76]
src/client/src/components/(playground)/scanner/use-scanner-enrich.ts[119-155]
src/client/src/components/(playground)/scanner/scanner-page.tsx[570-596]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Action responses can update hook state after the sheet switches to another finding.
## Fix Focus Areas
- src/client/src/components/(playground)/scanner/use-scanner-enrich.ts[63-76]
- src/client/src/components/(playground)/scanner/use-scanner-enrich.ts[119-155]
## Recommended Fix
Track a selection generation or current connector/job/finding identity and apply start, cancel, and discard responses only if they still belong to the current selection.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Enrich opens for an unselected finding 🐞 Bug ≡ Correctness
Description
ScannerFindingSheet keeps enrichOpen when the sheet closes or its finding changes. Because the
parent reuses the mounted sheet, a later finding can satisfy the dialog render condition and display
Enrich immediately without its Enrich button being pressed.
Code

src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx[R280-283]

+				{enrichOpen && connectorId && alertNumber ? (
+					<ScannerEnrichDialog
+						open={enrichOpen}
+						connectorId={connectorId}
Evidence
Dialog state is not reset by selection changes, and its render condition uses the current finding
props on a sheet that remains mounted.

src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx[90-100]
src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx[280-293]
src/client/src/components/(playground)/scanner/scanner-page.tsx[570-596]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Dialog-open state survives closing the sheet or selecting a different finding.
## Fix Focus Areas
- src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx[90-100]
- src/client/src/components/(playground)/scanner/scanner-finding-sheet.tsx[280-293]
## Recommended Fix
Close the dialog when the sheet closes or the connector, job, or finding selection changes, and avoid carrying an open dialog into another finding.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Failed Enrich commands can pass review 🐞 Bug ≡ Correctness
Description
runTrustablEnrich parses the Enrich subprocess's JSON without checking result.exitCode, unlike
its scan subprocess. If Enrich exits with a failure code after emitting parseable applied-fix
output, the pipeline can recheck that output and return a succeeded run.
Code

src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[R254-256]

+			const result = await run(enrichArgv, enrichEnv, root);
+			for (const line of result.stderr.split("\n").filter((item) => item.trim())) log(line);
+			const output = parseEnrichOutput(result.stdout, result.stderr);
Evidence
The runner exposes numeric exit codes and the adjacent scan path rejects codes of at least two,
whereas the Enrich path bases success solely on parsed output and recheck.

src/client/src/lib/platform/connectors/scanner/process.ts[116-128]
src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[206-219]
src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[251-302]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A nonzero Enrich subprocess exit is ignored when stdout contains usable JSON.
## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[251-263]
- src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[272-302]
## Recommended Fix
Handle failure exit codes before accepting applied output, retaining sanitized diagnostics and the CLI's documented distinction, if any, between findings and command errors.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


10. Fallback fix can rewrite code outside the flagged lines 🐞 Bug ≡ Correctness
Description
declinedFixContent accepts a model-supplied lineStart..lineEnd whenever it overlaps the finding,
and applyEnrichReplacement splices the entire model-chosen range into the review copy. When that
range extends far beyond the finding, unrelated code is removed; the rule-scoped re-check can still
treat the finding as resolved if its key disappears, while disabling re-check lets the run be marked
succeeded without a check.
Code

src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[R121-124]

+	const findingStart = Number(row.start_line) || 0;
+	const findingEnd = Number(row.end_line) || findingStart;
+	if (!findingStart || lineStart > findingEnd || lineEnd < findingStart) return null;
+	return applyEnrichReplacement(original, lineStart, lineEnd, replacement);
Evidence
The guard lineStart > findingEnd || lineEnd < findingStart rejects only nonintersecting ranges, so
a finding at lines 10–12 accepts a model range of 10–400 parsed from CLI output.
applyEnrichReplacement replaces the full supplied in-file range, despite the commit message’s
“stays on the finding’s lines” wording and the UI egress note that “only those lines are edited.”
Re-check success depends on the original finding key being absent rather than on the extent of the
edit; when params.recheck is false, enrich.ts returns succeeded after the splice.

src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[113-125]
src/client/src/lib/platform/connectors/scanner/enrich-result.ts[162-188]
src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[264-289]
src/client/src/constants/messages/en.ts[2984-2985]
src/client/src/lib/platform/connectors/scanner/enrich-result.ts[111-121]
src/client/src/lib/platform/connectors/scanner/enrich-result.ts[162-187]
src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[264-270]
src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[296-302]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`declinedFixContent` accepts a model range that merely intersects the finding, allowing the OpenLIT fallback splice to replace unrelated lines in the review copy.

## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[113-125]
- src/client/src/lib/platform/connectors/scanner/enrich-result.ts[162-188]

## Recommended Fix
Require fallback replacements to stay within the finding range: `lineStart >= findingStart && lineEnd <= findingEnd`. If a trailing blank line needs accommodation, permit only a small fixed slack, such as `lineEnd <= findingEnd + 1`. Otherwise return `null` so the run is reported as `not-applied`. Test a model replacement that overlaps the finding but extends far beyond it.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. API-started Enrich works on the wrong branch 🐞 Bug ≡ Correctness
Description
launchScannerEnrich passes input.baseRef through unchanged, so createEnrichWorkspace uses
HEAD when it is omitted; the dialog instead defaults to job.ref, but neither path pins the
commit that produced the findings. API calls without baseRef can enrich the default branch rather
than the scanned branch, while moved refs can make even dialog runs use a later tree; an explicitly
requested scan ref is also unreliable because the scan records that ref but passes only the
repository URL to Trustabl.
Code

src/client/src/lib/platform/connectors/scanner/trustabl/enrich.ts[R175-180]

+		const workspace = await createEnrichWorkspace({
+			target: request.target,
+			ref: params.baseRef,
+			token: request.githubToken,
+			signal,
+		});
Evidence
Scan jobs store a ref from settings or a /tree/<ref> URL but no resolved commit SHA, and the scan
passes Trustabl the clone URL without the requested ref. The dialog defaults baseRef to job.ref,
while the server path passes input.baseRef through to createEnrichWorkspace, which uses
input.ref || "HEAD". Enrich therefore resolves a ref or HEAD at run time rather than retrieving a
recorded scan commit, despite the documentation saying that a run downloads the repository at the
scanned commit.

src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[113-133]
src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[114-126]
src/client/src/lib/platform/connectors/scanner/trustabl/adapter.ts[84-91]
src/client/src/components/(playground)/scanner/scanner-enrich-dialog.tsx[78-86]
docs/latest/openlit/connectors/scanner.mdx[113-115]
src/client/src/lib/platform/connectors/scanner/trustabl/adapter.ts[74-111]
src/client/src/lib/platform/connectors/scanner/enrich-params.ts[67-75]
src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[120-133]
src/client/src/components/(playground)/scanner/scanner-enrich-dialog.tsx[78-85]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Enrich can download a different tree from the one that produced the stored findings: an omitted API `baseRef` resolves to HEAD, and a stored branch ref does not identify an immutable scanned commit. The scan also records a requested ref without passing it to Trustabl.

## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-crud.ts[114-166]
- src/client/src/components/(playground)/scanner/scanner-enrich-dialog.tsx[78-85]
- src/client/src/lib/platform/connectors/scanner/enrich-workspace.ts[120-133]
- docs/latest/openlit/connectors/scanner.mdx[113-115]

## Recommended Fix
In `launchScannerEnrich`, use `input.baseRef || job.ref` for both the run's `baseRef` and `params.baseRef`. Ensure scanning uses a requested ref, then record its resolved commit SHA when available and use that SHA for Enrich so it checks out the scanned tree. If Enrich can only fall back to a current branch or HEAD, make that behavior explicit and update the docs and OpenAPI text rather than claiming it downloads the scanned commit.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

12. Diff view hides removed lines that start with dashes 🐞 Bug ≡ Correctness
Description
ScannerEnrichDiff filters out every line starting with ---  or +++  so it can drop the file
headers. A removed line whose content begins with --  (for example a SQL or Lua comment) or an
added line starting with ++  therefore disappears from the review and from the +/− counts.
diffStats has the same problem with any line starting --- or +++, so the stored
additions/deletions are also too low.
Code

src/client/src/components/(playground)/scanner/scanner-enrich-diff.tsx[R19-24]

+	const lines = diff
+		.split("\n")
+		.filter((line, index, all) => !(index === all.length - 1 && line === ""))
+		.filter((line) => !line.startsWith("--- ") && !line.startsWith("+++ "));
+	const additions = lines.filter((line) => line.startsWith("+")).length;
+	const deletions = lines.filter((line) => line.startsWith("-")).length;
Evidence
Unified diff body lines are a one-character prefix plus the content, so removing -- note produces
--- note, which the header filter drops. Headers only appear before the first @@, so filtering
should stop at the first hunk header.

src/client/src/components/(playground)/scanner/scanner-enrich-diff.tsx[17-24]
src/client/src/lib/platform/connectors/scanner/enrich-result.ts[226-235]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The header filter also removes body lines whose content starts with `-- ` or `++ `.

## Fix Focus Areas
- src/client/src/components/(playground)/scanner/scanner-enrich-diff.tsx[19-24]
- src/client/src/lib/platform/connectors/scanner/enrich-result.ts[226-235]

## Recommended Fix
Track whether a line starting with `@@` has been seen. Skip `--- `/`+++ ` lines only before the first hunk header, and count +/- only after it.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


13. Connector metadata can grow to megabytes 🐞 Bug ➹ Performance
Description
Each connector keeps up to 20 runs in ConnectorInstance.metadata, and each run holds a diff and a
partial diff of up to 200,000 characters each plus 200 log lines. updateScannerMetadata reads,
parses and rewrites the whole blob on every progress report, and the connector list and get calls
also parse all of it, even though enrichRuns is removed from responses.
Code

src/client/src/lib/platform/connectors/scanner/enrich-runs.ts[R6-8]

+export const MAX_ENRICH_RUNS = 20;
+const MAX_DIFF_CHARS = 200_000;
+const MAX_LOG_LINES = 200;
Evidence
The caps allow about 20 × (200K + 200K + log) ≈ 8MB of JSON per connector. That blob sits in the
same column as jobs, which every scanner read path parses.

src/client/src/lib/platform/connectors/scanner/enrich-runs.ts[6-32]
src/client/src/lib/platform/connectors/scanner/metadata.ts[25-51]
src/client/src/lib/platform/connectors/scanner/crud.ts[100-150]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Enrich runs held in connector metadata can push the metadata to several MB, and it is rewritten on every progress update.

## Fix Focus Areas
- src/client/src/lib/platform/connectors/scanner/enrich-runs.ts[6-32]

## Recommended Fix
Lower `MAX_ENRICH_RUNS` and `MAX_DIFF_CHARS` (for example 5 runs and 50K characters), and drop the log and partialDiff from finished runs other than the latest one per finding. Or move enrich runs into their own table.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: Auto: 🧠 Deep: Dense cross-cutting feature spans security, APIs, subprocesses, persistence, and UI.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

This branch was previously deployed

1 inactive deployment
release-notes — 9521503d Deployed Nov 20, 2026 by ericksondelacruz via Normalize / Conventional title #869
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant