Skip to content

Feat/tool integration v2 - #86

Open
Amazing-Stardom wants to merge 23 commits into
masterfrom
feat/tool-integration-v2
Open

Amazing-Stardom wants to merge 23 commits into
masterfrom
feat/tool-integration-v2

Conversation

@Amazing-Stardom

@Amazing-Stardom Amazing-Stardom commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🔍 LiveReview

⚙️ Customize risk-based approval policy for this repository or your organization.



LiveReview auto-approval decisions

Review Time Decision Reason
#14010 14 Nov 2026, 14:27 UTC ❌ Not approved Author level 1 < required 2
#14007 14 Nov 2026, 13:16 UTC ❌ Not approved Author level 1 < required 2
#13951 12 Nov 2026, 15:53 UTC ❌ Not approved Author level 1 < required 2
#13948 12 Nov 2026, 15:28 UTC ❌ Not approved Author level 1 < required 2
#13937 12 Nov 2026, 14:02 UTC ❌ Not approved Author level 1 < required 2
#13903 11 Nov 2026, 18:50 UTC ❌ Not approved Author level 1 < required 2
#13831 9 Nov 2026, 16:20 UTC ❌ Not approved Author level 1 < required 2
#13783 5 Nov 2026, 21:25 UTC ❌ Not approved Author level 1 < required 2
#13774 5 Nov 2026, 17:54 UTC ❌ Not approved Author level 1 < required 2
#13732 4 Nov 2026, 20:33 UTC ❌ Not approved Author level 1 < required 2

@lovestaco
lovestaco marked this pull request as ready for review August 29, 2026 16:13
@LiveReview-Bot

Copy link
Copy Markdown

Implement Third-Party Tool Integration

Overview

This change introduces a new feature enabling third-party static analysis tools to run as Lambda-backed jobs during LiveReview code reviews. It establishes a comprehensive system including new database schemas, API endpoints, UI components, and job orchestration. The system aims to provide detailed tool findings and credit consumption within the review process.

Technical Highlights

  • db/migrations/*, db/schema.sql: Add available_tools, org_tools, org_tool_billing_state, and tool_credit_ledger tables.
  • internal/api/server.go, tools_handler.go: Implement new API endpoints for managing global and organization-specific tools.
  • internal/review_processor/events.go: Introduce SeverityCounts and ToolSummary structs for review event aggregation.
  • docs/tools/tools-integration-beta.md: Defines the tool_invocation River job for orchestrating Lambda-based tool execution.
  • ui/src/components/reviews/ToolAnalysisCard.tsx: New UI component displays detailed tool analysis results with filtering and pagination.
  • ui/src/pages/Reviews/ReviewDetail.tsx: Integrates ToolAnalysisCard and processes tool accounting data for display.
  • internal/api/diff_review.go: Gracefully handles decoding failures for reviews without AI comments.
  • ui/src/components/Dashboard/widgets/ToolsUsageWidget.tsx: Adds a new dashboard widget for tool usage overview.

Impact

  • Functionality: Users can now integrate, configure, and view results from third-party static analysis tools directly within code reviews. Review summaries include detailed tool findings and severity counts.
  • Risk: New database schemas require careful migration and data integrity checks. The hasNoReviewLayerData function in ReviewLayersData.tsx now always returns false, potentially affecting existing dashboard logic. Extensive mock data usage in ReviewDetail.tsx could mask real API issues during development.

Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread db/schema.sql Resolved
Comment thread docs/openapi.yaml Resolved
Comment thread docs/openapi.yaml Resolved
Comment thread docs/tools/tools-integration-beta.md Resolved
Comment thread docs/tools/tools-integration-beta.md Resolved
Comment thread docs/tools/tools-integration-beta.md Resolved
Comment thread docs/tools/tools-integration-beta.md Resolved
Comment thread internal/jobqueue/tool_dispatcher.go Outdated
enabledTools, err := toolsStore.GetEnabledToolsForOrg(ctx, p.OrgID)
if err != nil {
logMsg("[WARN] DispatchTools: Failed to fetch enabled tools for org %d: %v", p.OrgID, err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: critical

GetEnabledToolsForOrg err -> enabledTools nil; loop line 72 crashes.

Suggestions:

  1. Handle error from GetEnabledToolsForOrg: log error and return early, or initialize enabledTools to empty list.

toolRuleConfigs, parseErr = lrcconfig.ParseToolRuleConfigs(p.LRCBundle)
if parseErr != nil {
logMsg("[WARN] Failed to parse tool rule configs from .lrc bundle: %v", parseErr)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: critical

ParseToolRuleConfigs err -> toolRuleConfigs nil; access line 74 crashes.

Suggestions:

  1. Handle error from ParseToolRuleConfigs: log error and initialize toolRuleConfigs to empty map, or return early.

}

creditStore := storagetools.NewCreditStore(jq.db)
if err := creditStore.DeductCredits(ctx, p.OrgID, p.ReviewID, breakdown, planCode); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: critical

Credits deducted upfront for all tools. Partial queue failure (line 115) loses credits without dispatch. Billing bug.

Suggestions:

  1. Deduct credits individually per tool after successful queue, or implement rollback mechanism for undispatchable tools.

}

creditStore := storagetools.NewCreditStore(jq.db)
if err := creditStore.DeductCredits(ctx, p.OrgID, p.ReviewID, breakdown, planCode); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: critical

DeductCredits not idempotent; retry or re-entry double-deducts credits.

Suggestions:

  1. Ensure DeductCredits is idempotent (e.g., using review_id + tool_id as a dedup key) or wrap in a transaction with queue operation.


creditStore := storagetools.NewCreditStore(jq.db)
if err := creditStore.DeductCredits(ctx, p.OrgID, p.ReviewID, breakdown, planCode); err != nil {
logMsg("[WARN] Failed to deduct tool credits for review %d: %v. Proceeding with AI review only.", p.ReviewID, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: warning

Log says 'Proceeding with AI review only' but returns error. Misleading.

Suggestions:

  1. Fix log message to accurately reflect behavior, e.g., 'Static analysis skipped due to credit deduction failure'.

}

toolsDispatched++
logMsg("Enqueued tool job for %s (Lambda ARN: %s)", tool.Name, tool.LambdaARN)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: warning

Logging tool.LambdaARN exposes internal infrastructure details.

Suggestions:

  1. Remove LambdaARN from log message, or log only a truncated/sanitized version.

continue
}

if _, execErr := jq.db.ExecContext(ctx, `

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: critical

Credit deduction, event insert, metadata update not in single transaction. Crash after deduction leaves inconsistent state.

Suggestions:

  1. Wrap credit deduction, event inserts, and metadata update in a single database transaction to ensure atomicity.

return db, state
}

func createTestJobQueue(t *testing.T, mockDB *sql.DB) *JobQueue {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: warning

resource leak: realDB not closed if NewDB succeeds but NewJobQueue fails

Suggestions:

  1. Restructure createTestJobQueue to defer realDB.Close() immediately after successful Open, or wrap in a cleanup helper
  2. Return an error and let the caller decide how to handle the fallback

if state.failReviewsMetadata {
return nil, errors.New("failed to update reviews metadata")
}
if len(args) > 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

hardcoded args[0] for dispatched count; fragile if query parameter order changes

Suggestions:

  1. Match on specific named parameter instead of ordinal order
  2. Use a dedicated mock for the reviews update

sql.Register("tooldispatcher-mock", &testMockDriver)
}

func setupMockDB(t *testing.T) (*sql.DB, *mockDBState) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: warning

potential deadlock if tests run in parallel: testMockDriverMu and driver.mu both held

Suggestions:

  1. Restructure mock to use a single mutex or use sync.Map
  2. Add t.Parallel() protection and ensure setupMockDB is serialized

@livereview-agent livereview-agent 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.

❌ LiveReview policy: Not approved (blocked at Eligibility) · Review #14010

Stage Result Detail
Eligibility ❌ author level 1 < required 2
Static rules ⏭️ skipped (earlier stage blocked)
Risk score ⏭️ skipped (earlier stage blocked)
LLM classification ⏭️ skipped (earlier stage blocked)
Final decision ❌ eligibility: author level 1 < required 2

LiveReview Pre-Commit Check: ran (iter:2, coverage:17%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:5, coverage:96%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:5, coverage:89%)
LiveReview Pre-Commit Check: ran (iter:2, coverage:100%)
LiveReview Pre-Commit Check: ran (iter:2, coverage:97%)
LiveReview Pre-Commit Check: ran (iter:3, coverage:27%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:4, coverage:90%)
LiveReview Pre-Commit Check: ran (iter:2, coverage:98%)
LiveReview Pre-Commit Check: ran (iter:3, coverage:89%)
LiveReview Pre-Commit Check: ran (iter:2, coverage:78%)
LiveReview Pre-Commit Check: ran (iter:3, coverage:51%)
LiveReview Pre-Commit Check: ran (iter:4, coverage:97%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:2, coverage:51%)
LiveReview Pre-Commit Check: ran (iter:3, coverage:50%)
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.

4 participants