Repository navigation
Feat/tool integration v2 - #86
Amazing-Stardom wants to merge 23 commits into
Conversation
Implement Third-Party Tool IntegrationOverviewThis 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
Impact
|
| 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) | ||
| } |
There was a problem hiding this comment.
Severity: critical
GetEnabledToolsForOrg err -> enabledTools nil; loop line 72 crashes.
Suggestions:
- 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) | ||
| } |
There was a problem hiding this comment.
Severity: critical
ParseToolRuleConfigs err -> toolRuleConfigs nil; access line 74 crashes.
Suggestions:
- 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 { |
There was a problem hiding this comment.
Severity: critical
Credits deducted upfront for all tools. Partial queue failure (line 115) loses credits without dispatch. Billing bug.
Suggestions:
- 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 { |
There was a problem hiding this comment.
Severity: critical
DeductCredits not idempotent; retry or re-entry double-deducts credits.
Suggestions:
- 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) |
There was a problem hiding this comment.
Severity: warning
Log says 'Proceeding with AI review only' but returns error. Misleading.
Suggestions:
- 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) |
There was a problem hiding this comment.
Severity: warning
Logging tool.LambdaARN exposes internal infrastructure details.
Suggestions:
- Remove LambdaARN from log message, or log only a truncated/sanitized version.
| continue | ||
| } | ||
|
|
||
| if _, execErr := jq.db.ExecContext(ctx, ` |
There was a problem hiding this comment.
Severity: critical
Credit deduction, event insert, metadata update not in single transaction. Crash after deduction leaves inconsistent state.
Suggestions:
- 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 { |
There was a problem hiding this comment.
Severity: warning
resource leak: realDB not closed if NewDB succeeds but NewJobQueue fails
Suggestions:
- Restructure createTestJobQueue to defer realDB.Close() immediately after successful Open, or wrap in a cleanup helper
- 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 { |
There was a problem hiding this comment.
Severity: info
hardcoded args[0] for dispatched count; fragile if query parameter order changes
Suggestions:
- Match on specific named parameter instead of ordinal order
- Use a dedicated mock for the reviews update
| sql.Register("tooldispatcher-mock", &testMockDriver) | ||
| } | ||
|
|
||
| func setupMockDB(t *testing.T) (*sql.DB, *mockDBState) { |
There was a problem hiding this comment.
Severity: warning
potential deadlock if tests run in parallel: testMockDriverMu and driver.mu both held
Suggestions:
- Restructure mock to use a single mutex or use sync.Map
- Add t.Parallel() protection and ensure setupMockDB is serialized
There was a problem hiding this comment.
❌ 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%)
🔍 LiveReview
⚙️ Customize risk-based approval policy for this repository or your organization.
LiveReview auto-approval decisions