Skip to content

ADFA-4059: capture debug info when SourceFileIndexer fails#1335

Merged
Daniel-ADFA merged 8 commits into
stagefrom
fix/ADFA-4059
May 26, 2026
Merged

ADFA-4059: capture debug info when SourceFileIndexer fails#1335
Daniel-ADFA merged 8 commits into
stagefrom
fix/ADFA-4059

Conversation

@itsaky-adfa
Copy link
Copy Markdown
Contributor

@itsaky-adfa itsaky-adfa commented May 25, 2026

See ADFA-4059 for more details.

Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
@itsaky-adfa itsaky-adfa requested review from a team and Daniel-ADFA May 25, 2026 19:44
@itsaky-adfa itsaky-adfa self-assigned this May 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f08a09e4-43aa-4f89-a1f0-0ca82a15e4cb

📥 Commits

Reviewing files that changed from the base of the PR and between 63a633a and cfa9a16.

📒 Files selected for processing (2)
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtLibraryModule.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtSourceModule.kt

📝 Walkthrough
  • Added Sentry dependency:

    • implementation(libs.sentry.android.core) (lsp/kotlin/build.gradle.kts)
  • Improved error capture in indexing:

    • SourceFileIndexer.analyzeDeclaration() wrapped declaration analysis in runCatching; on failure the exception is reported to Sentry with contextual extras (file path, declaration name, declaration debug text, parent debug text when available) and any KotlinExceptionWithAttachments payloads. The exception is suppressed and the function returns null instead of propagating.
  • Added diagnostic breadcrumbs for better traceability:

    • Build completion events in KotlinLanguageServer
    • Source refresh operations in CompilationEnvironment and KtSymbolIndex (breadcrumb data includes environment name and module counts)
    • Scope creation and invalidation in AbstractKtModule (moduleDescription property added; KtLibraryModule and KtSourceModule override it)
  • Module / search behavior and minor API changes:

    • ProjectStructureProvider.getModuleImpl() now uses a fresh visited set per search call (prevents state leakage across fast-path vs full-scan)
    • CompilationEnvironment now stores constructor name as val
    • Minor logging adjustment in KotlinCompletions: removed large element text from scope completion log messages

Risks and best-practice considerations:

  • ⚠️ Sentry initialization must be verified: many new Sentry.capture/addBreadcrumb calls were added; ensure Sentry is properly initialized (Sentry.init / SentryAndroid) where these code paths run to avoid silent drops or NPEs.
  • ⚠️ Exception-suppression semantics: SourceFileIndexer now captures exceptions and returns null instead of propagating, which prevents crashes but can hide upstream failures. Confirm callers handle nulls and consider surfaced telemetry or metrics for recurring failures.
  • ⚠️ Telemetry volume and performance: Breadcrumbs added at frequent/hot code paths may increase runtime overhead and Sentry event volume on large projects; consider sampling, rate-limiting, or aggregating breadcrumbs.
  • ⚠️ Sensitive data exposure: Sentry extras include file paths and declaration debug text; review for sensitive information (PII, secrets) before enabling in production.
  • ⚠️ Concurrency assumptions: The PR relies on existing project.write { } usages rather than introducing new locks. Confirm existing synchronization suffices to avoid race conditions when emitting breadcrumbs or updating module state.

Walkthrough

Adds Sentry dependency and instruments the Kotlin LSP: build completion, compilation environment refresh, symbol index refresh, and source-file analysis now emit Sentry breadcrumbs or report exceptions; module scope creation/invalidation includes breadcrumbs; moduleDescription overrides added; module virtual-file searches no longer share a visited set.

Changes

Sentry instrumentation and module lifecycle

Layer / File(s) Summary
Sentry dependency and build event tracking
lsp/kotlin/build.gradle.kts, lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/KotlinLanguageServer.kt
Add libs.sentry.android.core dependency and record breadcrumbs on build completion events.
Compilation environment instrumentation
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/CompilationEnvironment.kt
Store CompilationEnvironment.name as a property and wrap refreshSources() with breadcrumbs recording environment name and module count.
Index and source-file analysis instrumentation
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/KtSymbolIndex.kt, lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt
Emit breadcrumb on index refresh. Wrap declaration analysis in runCatching, capture exceptions to Sentry with file path, declaration name, debug text, and attach KotlinExceptionWithAttachments payloads; return null on failure.
Module scope and description tracking
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/AbstractKtModule.kt
Emit breadcrumbs during search-scope creation and invalidation including scope hash codes. Add moduleDescription property override returning module id, scope hash codes, and dependency ids.
Module type moduleDescription overrides
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtLibraryModule.kt, .../KtSourceModule.kt
Add @OptIn(KaExperimentalApi::class)-annotated overrides of moduleDescription delegating to upstream implementations.
Module search visited set optimization
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/services/ProjectStructureProvider.kt
Remove shared visited set across multiple module searches; each searchVirtualFileInModule call now receives a fresh mutableSetOf().
Completion logging tweak
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinCompletions.kt
Remove ktElement.text from an info log while preserving other context in the log call.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • dara-abijo-adfa
  • jatezzz

Poem

🐰 I hopped through logs at break of dawn,

Breadcrumbs laid where builds had gone.
Exceptions wrapped in gentle thread,
With tiny notes of file and thread.
A rabbit's hop keeps traces calm.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'ADFA-4059: capture debug info when SourceFileIndexer fails' accurately describes the main objective of this changeset, which adds Sentry-based debug info capture and exception reporting to SourceFileIndexer.
Description check ✅ Passed The description references the Jira issue ADFA-4059 which provides context for the changes, making it related to the changeset even though specific details are not included in the PR body.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ADFA-4059

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt`:
- Around line 123-134: The current Sentry.captureException block is adding full
attachment.encodedBytes into extras (inside the err is
KotlinExceptionWithAttachments branch) which can exceed Sentry limits and leak
data; modify the code that iterates err.attachments in the Sentry.scope.apply
lambda to stop calling setExtra with attachment.encodedBytes and instead record
only safe metadata (e.g., attachment.path, encoded byte length, and a
hash/checksum) and attach the actual binary via Sentry’s attachment mechanism
(or omit the payload entirely) so the extras remain small and non-sensitive;
look for the err.attachments.forEachIndexed loop and replace encodedBytes
setExtra with metadata fields and/or use Sentry attachment APIs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f9ccd07e-f7db-437b-b924-dbec93cdc793

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7fe53 and 4059800.

📒 Files selected for processing (8)
  • lsp/kotlin/build.gradle.kts
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/KotlinLanguageServer.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/CompilationEnvironment.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/KtSymbolIndex.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/AbstractKtModule.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/services/ProjectStructureProvider.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinCompletions.kt

Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtSourceModule.kt (1)

83-85: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Verify the delegation target for moduleDescription.

Same concern as in KtLibraryModule.kt: this override delegates to super<KaSourceModule>.moduleDescription (the interface) instead of super<AbstractKtModule>.moduleDescription. If the custom AbstractKtModule implementation contains Sentry instrumentation with debug context (module id, scope hashes, dependency ids), this delegation bypasses that information.

Please verify the delegation target is correct for capturing debug info as intended by the PR objective.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtSourceModule.kt`
around lines 83 - 85, The override of moduleDescription in KtSourceModule
currently delegates to super<KaSourceModule>.moduleDescription (the interface)
which may bypass AbstractKtModule's Sentry/debug instrumentation; change the
delegation target to super<AbstractKtModule>.moduleDescription so the
AbstractKtModule implementation (and its debug context like module id, scope
hashes, dependency ids) is executed—adjust the override in KtSourceModule.kt
(keeping the `@OptIn` annotation) to call
super<AbstractKtModule>.moduleDescription instead of
super<KaSourceModule>.moduleDescription.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtLibraryModule.kt`:
- Around line 117-119: KtLibraryModule.moduleDescription currently delegates to
super<KaLibraryModule>.moduleDescription which can lose the detailed debug
context built by AbstractKtModule; change the delegation to return
super<AbstractKtModule>.moduleDescription (or otherwise call the
AbstractKtModule implementation) so the id, _baseSearchScope/_contentScope hash
codes and dependency ids are preserved for Sentry/debugging; update the override
in KtLibraryModule to reference AbstractKtModule's moduleDescription
implementation instead of KaLibraryModule's.

---

Duplicate comments:
In
`@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtSourceModule.kt`:
- Around line 83-85: The override of moduleDescription in KtSourceModule
currently delegates to super<KaSourceModule>.moduleDescription (the interface)
which may bypass AbstractKtModule's Sentry/debug instrumentation; change the
delegation target to super<AbstractKtModule>.moduleDescription so the
AbstractKtModule implementation (and its debug context like module id, scope
hashes, dependency ids) is executed—adjust the override in KtSourceModule.kt
(keeping the `@OptIn` annotation) to call
super<AbstractKtModule>.moduleDescription instead of
super<KaSourceModule>.moduleDescription.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eda85cc5-ea20-4705-ab88-c347646ddb28

📥 Commits

Reviewing files that changed from the base of the PR and between 4059800 and 63a633a.

📒 Files selected for processing (3)
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtLibraryModule.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/modules/KtSourceModule.kt

Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
@Daniel-ADFA Daniel-ADFA merged commit 0ada33c into stage May 26, 2026
2 checks passed
@Daniel-ADFA Daniel-ADFA deleted the fix/ADFA-4059 branch May 26, 2026 16:44
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.

3 participants