Skip to content

ADFA-7139: Plugin API for the SQLite debugger endpoints - #2261

Open
davidschachterADFA wants to merge 49 commits into
sqlite-debugger/ADFA-7137from
sqlite-debugger/ADFA-7139
Open

davidschachterADFA wants to merge 49 commits into
sqlite-debugger/ADFA-7137from
sqlite-debugger/ADFA-7139

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7139

Plugin API for the SQLite debugger endpoints Code on the Go stores (ADFA-7137), so AI-Agent-MCP can connect without the user typing a port or token. The plugin side (AI-Agent-MCP) is appdevforall/addons#166.

Stack: on sqlite-debugger/ADFA-7137 (#2260). Merge order: #2259, then #2260, then this PR, then #2262. Stage, with #2244 (ADFA-7082) squash-merged as 5f3d76a, is merged up into this PR (0ece6a8); that merge left this PR's own diff unchanged. The one hand resolution was two adjacent lines in PluginManager.kt, this PR's loadedPlugin.debuggerEndpointService()?.close() and stage's cleanupPluginTemplates(...): both are kept. #2260's endpoint announce and slow-install pairing are merged up too (85ba2f4); the only conflicts were constructor calls, which keep both isInstalled and announce. #2260's session-keyed install pairing is merged up as well (e7223f3); its two conflicts were beside this PR's own edits: DebuggerEndpointRepository's companion (keeps this PR's isPackageInstalled, drops the removed 5-minute expiry constant) and the SQLite debugger README (keeps both the new pairing line and this PR's plugin-API line). #2260's brief-3 fixes (a throwing commit drops its note, a result with no package name pairs nothing, Quick Build doc text) are merged up (94e4620); the one conflict was adjacent lines in the SQLite debugger README, both kept. The head is 3406a95. CodeOnTheGo allows only squash merges and deletes the head branch on merge: once #2260 is squashed, this PR's base moves to stage while its branch still carries the original commits of #2259 and #2260. Then merge origin/stage into it, resolve to this PR's side only the conflicts that duplicate the squashed PRs, and prove nothing else changed (CLAUDE.md's squash recipe; no rebase). #2260, this PR and #2262 each delete a different line of the "Not done yet" list in subprojects/sqlite-debugger/README.md, so merging #2262 last will probably conflict there; resolve it by dropping all three items.

What it does

  • DebuggerEndpointService.getEndpoints() (plugin-api, beside ToolSourceRegistry): the open project's endpoints (application ID, port, token, updated at). New permission debugger.endpoints. SecurityException without it; IllegalStateException on a read failure, on the main thread, or when the app could not set up the endpoint source at startup; empty list when no project is open or no app has reported. API dump and docs/PLUGIN_API_CHANGELOG.md (26.48; 26.47 shipped without this stack) updated. If the stack misses 26.48, recheck the entry against the real release number (dc4c095 moved it from 26.47, which shipped on 2026-11-17).
  • plugin-manager implements it; the app supplies the rows from debugger_endpoint_table, looked up by the canonical project path, and leaves out apps that are no longer installed.

Tests: value class; service (permission, no project, other project, read failure, main thread, no source); the plugin system starting when the endpoint source can't be set up; an app that hasn't reported is dropped without the installed-app check; repository lookup through a non-canonical path (fails when the lookup uses the absolute path). :plugin-api:apiCheck passes. At da6a0e3: :app 1797, :plugin-manager 242, :plugin-api 251 and :subprojects:sqlite-debugger 84 tests pass, and :plugin-api:apiCheck passes (plugin-api changed only in Javadoc). The head 3406a95 adds only a line wrap in one test; that test and spotlessCheck pass there. CI runs only test-sqlite-debugger and the APK build.

Known: AI-Core asks for approval on every call of a contributed tool, so the SQLite debugger's read-only tools still prompt; the ticket's criteria 1 and 3 are amended for phase 1, and automatic approval is ADFA-7147.

Checked on a device (Galaxy Note 20, Android 13) with the whole stack, at an earlier head: the endpoint was stored after a cold start, every MCP tool answered, and the Agent answered a database question with 3 approval taps. The current head has not run on a device.

No screens added or changed.

After an independent review (Fable 5.2, review 5942657666):

  • getEndpoints() returns endpoints only while a project is open in the editor (the editor's provider is registered; the root comes from IProjectManager), and an empty list otherwise. Before, it used lastOpenedProject, which outlives a closed project. CogoProjectProvider itself is unchanged; ADFA-7192 covers it for the other services.
  • The endpoint source is a private field in PluginManager, which the app installs from Koin. Installing the same source again is a no-op, so a retried plugin-system start does not throw; a different source still throws and leaves the app's in place. The service is internal and keeps an unmodifiable copy of the plugin's permissions. The permission's description, the Javadoc, the changelog and PLUGIN_AUTHORING.md state the threat model: a plugin holding debugger.endpoints gets the token and can query the app's databases (read-only in phase 1). Plugins run in Code on the Go's process, so the permission declares intent; it cannot stop reflection. docs/plugin-api.md lists the service and DebuggerEndpoint.
  • getEndpoints() declares InterruptedException. It throws IllegalStateException on the main thread (deliberately: it reads a database), and CancellationException while the plugin is disabled (from the start, for a plugin saved as disabled), after it is unloaded, after any load failure once its context exists (including a step after a successful initialize), and after a failed activation. A disable whose deactivate() throws leaves the plugin enabled and the service open; enabling it reopens the service. It returns an unmodifiable list. A test pins CONTRACT_VERSION at 1. The unused private 3-argument createPluginContext overload is deleted (220 lines); it registered the service with startOpen = true.
  • New tests: registration through the real plugin-loading path, the closed-project case, installing the source (the same one again is a no-op, a different one throws), the disabled-plugin cases, a failed activation, two projects and a symlinked path, and the Koin wiring (no fail-open default for the installed-app check).
  • Known and out of scope: two public paths still give a plugin without the permission another plugin's permission-gated services: PluginManager.getInstance().getLoadedPlugin(id).context.services and PluginFragmentHelper.getServiceRegistry(pluginId). This affects every such service and is tracked in ADFA-7194; the Javadoc, the KDoc and the changelog name both paths. Commit d7a9b08 alone has one failing test, fixed in ad91c84.

After hal-eisen-adfa's review (4624864573 and 8 more threads): one commit per finding; each behaviour fix has a test that fails with only that fix reverted.

  • The service closes only once a disable has happened: a disable whose deactivate() throws leaves the plugin enabled and the service open (d1626c9). The terminal service still cancels its commands before deactivate(); that is stage code, left as is.
  • If the app can't set up the endpoint source, the plugin system starts anyway, the failure is logged and reported to Sentry, and getEndpoints() throws IllegalStateException instead of reporting no apps (7f717ef).
  • Every load failure after the plugin's context exists closes the service, including a step after a successful initialize() (6793181).
  • The source is asked by the canonical project path, as its KDoc says (4c98e4e).
  • The repository's KDoc names reportedEndpoints as the read that throws (33cdf50), and an app with no token or port is dropped before the installed-app binder call (da6a0e3).
  • One debuggerEndpointService() helper, and no redundant close for a plugin loaded as disabled (300bf93).
  • The service is now closed or reopened in 4 places instead of 7, each tied to a state change: disable, a failed load, enable and unload. hal's suggestion of one shared close/reopen mechanism for this service and the terminal service is ADFA-7219, since it changes the terminal service's stage behaviour and the loadPlugin lines ADFA-3570: Let plugins hear project open/close and file saves #2242 also changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn


Code Reviewer: Code Reviewer couldn't review this pull request
The pull request author does not have access to AI for the associated Atlassian organization.

@claude claude 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Stack review: this is the tip of #2259 -> #2260 -> #2261 (sqlite-debugger/ADFA-7135 -> ADFA-7137 -> ADFA-7139), nothing is based on it. Claims were checked against this PR's head 86b67f56 (it is the stack tip). No existing approvals and no earlier review comments to re-check. Repo rules: CLAUDE.md and REVIEW.md (including the section 13 plugin-API check); neither defines an approve/request-changes rule, so the default verdict table applied.

MINOR

  • DebuggerEndpointRepository.kt:127 - stored endpoints are never pruned, so a dead app's token/port is returned

NITPICK - 1 inline, not listed

Checked and found sound: permission is checked before anything else and the main-thread guard after it; a read failure is thrown and not turned into an empty list; the lookup uses the canonical path the pairing writes, and the test covers a non-canonical path; DebuggerEndpoint.toString leaves the token out; the service is registered on both plugin registration paths; the ABI dump, changelog, authoring doc and README are updated with the code.

Not verified (static review, no build or device): the :plugin-api:apiCheck claim, the tests, and the "26.43" release-week floor in the changelog.

Verdict: COMMENT. Only a MINOR and a NITPICK, which do not block under the default rule. The PR author is the authenticated account, so GitHub would refuse APPROVE regardless.

davidschachterADFA and others added 6 commits November 15, 2026 23:21
…ission

Plugins such as AI-Agent-MCP need to reach the SQLite debugger of the app
the user just built, without the user typing a port or token.

DebuggerEndpointService.getEndpoints() returns the open project's
endpoints as DebuggerEndpoint values (application ID, port, token,
updated at), behind the new permission debugger.endpoints. Contract:
SecurityException without the permission; IllegalStateException on a read
failure or when called on the main thread; an empty list when no project
is open or no app has reported.

The API dump and docs/PLUGIN_API_CHANGELOG.md (26.43) are updated, and
the plugin docs list the permission. A plugin that declares it needs
plugin.min_ide_version 26.43: an older Code on the Go rejects the unknown
permission at validation.

Tests: the DebuggerEndpoint value class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
PluginManager hands each plugin a DebuggerEndpointServiceImpl, which
checks the debugger.endpoints permission, refuses the main thread, and
maps a read failure to IllegalStateException so a plugin cannot mistake a
failure for "no app has reported".

Tests: permission refused, no project, endpoints of another project not
returned, read failure, main thread refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The app registers the service when it loads plugins, backed by
debugger_endpoint_table (ADFA-7137). The repository looks endpoints up by
the canonical project path, so a project opened through a symlink or a
non-normalised path still finds the rows stored under its real location.

Tests: repository lookup through a non-canonical path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…er README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…errupts

reportedEndpoints no longer returns the stored port and token of an app that is
no longer installed (injected check, PackageManager in the app). No
<queries> is needed: Code on the Go targets SDK 28, below the package
visibility filter of SDK 30. The
Javadoc says an endpoint can still be stale after the process dies and that
updatedAtMillis is when it last reported. DebuggerEndpointServiceImpl rethrows
InterruptedException (restoring the flag) and CancellationException unchanged
instead of wrapping them. Tests: an uninstalled app is left out, installed ones
are returned, the interrupt and the cancellation pass through; all three fail
with the fix removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
26.43 to 26.46 are released without it. The changelog entry moves to a new
26.47 section and the floor plugin.min_ide_version is 26.47.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA and others added 2 commits November 16, 2026 10:05

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-review of #2261 at 2007193 (medium effort). No new findings. Computed verdict: APPROVE (no findings above NITPICK); submitted as COMMENT because GitHub refuses APPROVE on a self-authored PR, and nothing was posted on a non-interactive run without --verdict.

NITPICK - none

Stack. Layer 3 of 4, a tip: below #2260 (ADFA-7137) and #2259 (ADFA-7135, on #2244). The other tip is #2262 (ADFA-7138, on #2259), which does not touch this layer's files. Claims were checked at this head, which is the tip that holds this code. Counterpart: addons#166 reads DebuggerEndpointService / DebuggerEndpoint from here.

Rules applied. REVIEW.md and CLAUDE.md at the head (REVIEW.md is "a coaching doc, not a gate"; no approve/request-changes rule, so the skill's default table applied). Plugin-API surface touched, so REVIEW.md section 13 applied: the new permission key is in the enum, the ABI dump, the three plugin docs, the changelog (26.47, after the 26.46 tag) and a test that pins the key; the service is permission-gated, main-thread-guarded, and registered in both of PluginManager's registration paths.

Prior threads (judged on the code at this head, not on the replies).

  • DebuggerEndpointRepository.kt:146 reportedEndpoints has no liveness bound: fixed as far as the finding asked. The repository drops apps that are no longer installed (isInstalled, wired in AppModule to PackageManager); the KDoc, DebuggerEndpoint Javadoc, changelog and README all say a dead process stays listed and updatedAtMillis is the last report, and that clients reconnect after a refusal. A row for a dead process is still returned by design, so the finding's residual risk is documented, not removed.
  • DebuggerEndpointServiceImpl.kt:56 interrupt rewrapped: fixed. InterruptedException restores the flag and is rethrown, CancellationException is rethrown, and both have tests.
    Both are fixed, so no thread needed a reply or an unresolve.

Merges and new commits. aa86aa1 (#2244 through #2260) and 2007193 (#2259's README corrections) are conflict-free merges. The README keeps this layer's paragraph on DebuggerEndpointService and no longer lists ADFA-7139 under "Not done yet". cbe541a moves the changelog entry to 26.47, consistent with the 26.46 tag.

Static review only: no build, no device. Leads from the built-in review that I discarded after reading the code: a dead process's token reaching another listener (the thread above, documented, and the token only goes to 127.0.0.1), the service passing an absolute rather than canonical path (the repository canonicalizes it, and the source's only implementation is that repository), Koin lookup and runBlocking without a timeout (a Room read; the plugin thread is not the main thread), permissions captured at registration (the pattern of every other service here; permissions are not revocable at runtime), the duplicated registration block (the pattern of the whole file), the global DebuggerEndpointSources (the same shape as the other *Impl.setX hooks), updatedAt ?: 0L (the DAO writes token, port and time together), the package-visibility assumption (a commented consequence of the hard TARGET_SDK=28 requirement in ARCHITECTURE.md), and the min_ide_version floor (documented in the changelog).

…e) up the stack

Brings 7135's three newer commits through 7137: the JNI layer refuses SQL
holding more than one statement, and a tool call's time limit starts when
the call begins. No conflicts; README.md auto-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 17, 2026
… QA only

Merges sqlite-debugger/ADFA-7138 (#2262, 9eb00a2) into
sqlite-debugger/ADFA-7139 (#2261, 7374a39) so CI builds one Code on the
Go with the whole stack, signed with the CI key, for an in-place install on
the QA phone. Not for review or merging; the branch is deleted after QA.

The only conflict was subprojects/sqlite-debugger/README.md: both sides'
new bullets are kept, and each side's "Not done yet" items that the other
side completes are dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ncation) up the stack

Brings 7135's two newer commits through 7137: the query backstop's
ROLLBACK gets past the server's authorizer and a failed one is reported,
and get_schema says when a CREATE statement was cut. No conflicts;
README.md auto-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 17, 2026
…ncation) into the integration build

Brings #2261's new head (e7be1a9), with 7135's two newer commits: the
query backstop's ROLLBACK gets past the server's authorizer and a failed
one is reported, and get_schema says when a CREATE statement was cut.
For the CI-signed device-QA build only. No conflicts; README.md
auto-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 17, 2026
…ncation) into the integration build

Brings #2262's new head (bc4889b). Its only new content is 7135's two
commits, which the merge of #2261 already brought, so the tree is
unchanged; this records the new head. For the CI-signed device-QA build
only. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… up the stack

Brings 7135's two newer commits through 7137: the query and
explain_query_plan descriptions say that functions the app adds to its
own connections, such as sqlite-js's stored JavaScript functions, are
missing on the SQLite debugger's connection, and get_schema's
description names both limits that can leave entries out. Text and
tests only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Independent review (Fable 5.2, fresh context) of this layer, sqlite-debugger/ADFA-7137...7d53ea7e4. Comment-only; findings are inline where they sit on a changed line.

No critical or high findings. :plugin-api:testDebugUnitTest, :plugin-api:apiCheck, and the *DebuggerEndpoint* tests in plugin-manager and app all pass. Both fixes claimed in the open threads hold, checked by reverting each one: the stale-row check, and interrupt and cancellation handling.

ID Severity Where Finding
R1 IMPORTANT DebuggerEndpointServiceImpl.kt:48 (inline) "The open project" is really the last opened project, so a closed project's endpoints are still returned
R2 IMPORTANT DebuggerEndpointServiceImpl.kt:21 (inline) The permission can be bypassed through the public DebuggerEndpointSources
R3 MINOR DebuggerEndpointService.java:35 (inline) InterruptedException is thrown but not declared
R4 MINOR PluginManager.kt:1588 (inline) The service's registration in PluginManager is untested
R5 MINOR AppModule.kt:70 (inline) The installed-app check defaults to { true } (fails open), and its wiring is untested
R6 MINOR PluginManager.kt:1150-1171, DebuggerEndpointServiceImpl.kt:39 A disabled plugin's service keeps returning endpoints. Services outlive disable, and only the terminal service is closed then. A worker thread the plugin left running keeps getting tokens. Fix: have the service check the plugin is enabled, or close it on disable as IdeTerminalServiceImpl is.
R7 MINOR docs/plugin-api.md:14 The list of service interfaces plugins call doesn't include DebuggerEndpointService, and the DebuggerEndpoint value type isn't named either. Only the permission line was updated.
R8 MINOR CredentialProtectedApplicationLoader.kt:413 (inline) GlobalContext.get() lookup, against ADR 0006
R9 MINOR DebuggerEndpointRepositoryTest.kt No repository test has two projects with endpoints, or a symlinked project path. Cross-project isolation is tested only against a fake source that filters by path, so a DAO change that returned every row would pass. A scratch test shows the real behavior is correct; promote those assertions.

Questions

  • Q1: The changelog says 26.47. Will this actually ship in a 26.47 build, given that 26.41-26.43 are still listed as unreleased? If it slips, the documented min_ide_version floor is wrong.
  • Q2: The threat model isn't stated. subprojects/sqlite-debugger/README.md:37 says the token holder can run SQL. Should the permission's description and the Javadoc say a plugin with it can read, and possibly write, the app's databases?
  • Q3: Throwing on the main thread is stricter than the sibling synchronous services (IdeLogService, IdeProjectService). Is that intended?
  • Q4: Should getEndpoints() say it returns an unmodifiable list?
  • Q5: CONTRACT_VERSION >= 1 in DebuggerEndpointTest pins nothing. Was == 1 intended?

Checked and found correct

  • DebuggerEndpoint is final and immutable, null-checks its fields, and its toString omits the token (tested).
  • No log line in this layer prints the token.
  • The lookup uses the canonical path: switching it to absolutePath fails the committed test.
  • A project switch mid-call can't tear the result: the root is read once.
  • A read failure surfaces as IllegalStateException with its cause.
  • An older IDE rejects the unknown permission key.
  • Module boundaries hold: plugin-manager doesn't touch Room, and persistence stays in Room per ADR 0001.
  • The source is installed before loadPlugins().

Base layer, not charged here: the Room entity DebuggerEndpoint in ADFA-7137 is a data class, so its toString includes the token. No log line prints it.

🤖 Generated with Claude Code

davidschachterADFA and others added 6 commits November 17, 2026 08:43
…get_schema paging advice) up the stack

Brings 7137's two newer commits: integrity_check's description and the README
say a full integrity_check fails when an index uses a function the app adds to
its own connections (quick_check does not), and get_schema's paging advice
gives ORDER BY name and says substr counts characters, not bytes.
Text and tests only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The plugin services setup resolved DebuggerEndpointRepository with
GlobalContext.get() inside the source lambda, against ADR 0006 and out of
reach of a test. coreModule now binds the DebuggerEndpointSource, built on
the repository by constructor, and CredentialProtectedApplicationLoader
resolves it as a KoinComponent, the pattern DeviceProtectedApplicationLoader
already uses. DebuggerEndpointBindingsTest resolves the binding from
coreModule over an in-memory database.

Review R8 on #2261.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
isInstalled defaulted to { true }, so a binding that dropped the argument
would serve an uninstalled app's stored port and token as live, and no test
would fail. The parameter has no default now; the tests pass it explicitly.
DebuggerEndpointBindingsTest resolves the repository from coreModule and
checks an app the package manager does not know is left out.

Review R5 on #2261.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Cross-project isolation was tested only against a fake source that filters
by path, so a DAO query that returned every row would have passed. This
promotes the review's scratch test: two projects each get only their own app,
a symlinked project path finds the canonical row, and an app moved to the
other project drops out of the first.

Review R9 on #2261.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
DebuggerEndpointService took its project from CogoProjectProvider, which
reads GeneralPreferences.lastOpenedProject. Nothing clears that on close, so
on the home screen a plugin still got the closed project's ports and tokens,
and "empty when no project is open" was false.

The service now takes the root from the editor: IProjectManager's project
path, but only while the editor activity has its provider registered, which
it does from onCreate to preDestroy. The project path alone is not enough:
ProjectManagerImpl.destroy() leaves it set too. CogoProjectProvider is
unchanged; the other services still use it.

PluginManagerDebuggerEndpointTest loads a plugin through PluginManager and
checks the open project's endpoints come back and a closed one's do not.

Review R1 on #2261.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The debugger.endpoints permission was checked only in getEndpoints(), while
DebuggerEndpointSources was a public object with a public current and
install. Plugin classes load through a child of the host class loader, so a
plugin without the permission could read any project's tokens through
current, or replace or blank the source for every plugin with install. The
permission set the service held was the mutable LinkedHashSet PluginManager
built, so a plugin could also add the permission to it by reflection.

- The public holder is gone. PluginManager keeps the source in a private
  field, and installDebuggerEndpointSource() installs it once: the app does
  so before plugins load, and a later call fails.
- DebuggerEndpointServiceImpl is internal and keeps its own unmodifiable
  copy of the permissions.
- The Javadoc, the permission's description, the changelog and
  PLUGIN_AUTHORING.md say plugins run in Code on the Go's process, so the
  permission declares intent and cannot stop reflection.

The review's scratch bypass tests, inverted: a second install fails and the
app's source stays (PluginManagerDebuggerEndpointTest), no public member
returns the source, and neither changing the set the service was built from
nor adding to the service's own set grants the permission
(DebuggerEndpointServiceImplTest).

Review R2 on #2261.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Round 6 review of f2aae36..6ed99d7 (the fixes for review 5942657666). Stack: #2261 is the tip, on sqlite-debugger/ADFA-7137. Claims were checked at 6ed99d7. Rules applied: CLAUDE.md and REVIEW.md. Self-authored, so COMMENT.

IMPORTANT (not blocking)

  • DebuggerEndpointServiceImpl.kt:28 - another plugin's service is reachable through the public getLoadedPlugin(id).context.services (extends ADFA-7194)

MINOR

  • PluginManager.kt:728 - the service stays open when initialize() fails, and during initialize() of a disabled plugin
  • PluginManager.kt:771 - activation-failure close is untested

Re-check of the previous threads, read at head and not from the replies:

  • R1 (4602747235): fixed. openProjectRoot() needs a registered editor provider and a non-empty projectDirPath. The test covers the home screen.
  • R2 (4602747217): the three reproduced bypasses are fixed (no public holder, one-shot private install, immutable permission copy, tested). One public path remains; see the first finding.
  • R3 (4602747248): fixed. throws InterruptedException, Javadoc, and a Java caller test.
  • R4 (4602747260): fixed. The test loads plugins through PluginManager.
  • R5 (4602747277): fixed. isInstalled has no default, and the Koin bindings test resolves it.
  • R8 (4602747290): fixed. The source is bound in coreModule and resolved as a KoinComponent.

Lifecycle paths closed for R6: disable, force-disable, unload, load-while-disabled, and activation failure; reopened on enable. closed is @Volatile, which is enough for a boolean flag. Not verified: nothing was built or run.

davidschachterADFA and others added 6 commits November 17, 2026 10:27
…rEndpointService

The KDoc, the Javadoc and the changelog claimed every path short of reflection was closed.
A plugin without the permission can still take another plugin's service from
PluginManager.getInstance().getLoadedPlugin(id).context.services and from
PluginFragmentHelper.getServiceRegistry. Name both, and point at ADFA-7194, which tracks them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…as disabled and after a failed initialize

The service started open, so a plugin saved as disabled could read tokens from its own initialize(),
and one whose initialize() threw or returned false kept an open service for any thread it started.
Create it closed when the saved state is disabled (enablePlugin reopens it) and close it when
initialize() fails. The activation-failure close, which a failed activate() already relies on, keeps working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…, no functional change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…he stack

Brings 7135's three newer commits: consumerProguardFiles registers consumer-rules.pro
so an app's R8 keeps NativeBridge (the AAR now has proguard.txt), a server connection
is refused for a path the app no longer has open, and a JSON-RPC batch is limited to
32 messages and 8 MiB of replies.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Round over 6ed99d7..61902dd: own commits a32d288, 24453ed, 14067c0, cff9d24, plus merges 5120581 and 61902dd. No new findings. Stack: #2261 is a tip, on #2260 (base sqlite-debugger/ADFA-7137) on #2259, with nothing above it; verification used its own head 61902dd. Rules read: CLAUDE.md, REVIEW.md. Self-authored PR, so COMMENT.

Merges (no code-review run on them):

  • 5120581: the diff against its first parent equals cee95ac..e1864d2 (#2259's bc76c14 and e1864d2), hunk headers aside; 3 files, nothing else.
  • 61902dd: the diff against its first parent equals e1864d2..e6d9171 (299266e, 8acd4bd, e6d9171) exactly.
  • Between #2259's head and this head, subprojects/sqlite-debugger/src differs only by #2260's own files (EndpointBroadcast, its test, DebuggerStartup, the manifest line), and no merge touches this layer's own files.

Re-check of earlier threads (judged on the code at head, not on the replies):

  • F141 (doc overstated the closed paths): fixed. The Javadoc, the KDoc and PLUGIN_API_CHANGELOG now name the two public entry points. Both exist and are public (PluginManager.getLoadedPlugin(id), which returns only enabled plugins, with LoadedPlugin.context.services; PluginFragmentHelper.getServiceRegistry) and point at ADFA-7194. No other file still claims "every path short of reflection".
  • F142 (service open for a plugin saved as disabled, and after a failed initialize): fixed. The service is built with startOpen = getPluginState(id) (default true), so a plugin saved as disabled is closed through its own initialize(); enablePlugin reopens it before activation, and activation failure closes it again. Both failure exits of initialize() close it. The tests pin all three and use a plugin thread as a real one would.
  • F143 (activation-failure close untested): fixed. FailingActivationPlugin makes activate() throw; the plugin ends disabled and the service throws CancellationException. It starts open (state defaults to enabled), so removing the close in activateLoadedPlugin's failure arm fails the test.

davidschachterADFA and others added 6 commits November 17, 2026 12:54
…limits, F170 closing connection check) up the stack
…2244 squash-merged) up the stack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…up the stack

Conflicts, all from the two ADFA-7137 commits:
- DebuggerEndpointRepository: keeps both required constructor arguments,
  isInstalled (ADFA-7139) and announce (ADFA-7137).
- AppModule: the repository binding passes both; the DebuggerEndpointSource
  binding is unchanged.
- DebuggerEndpointRepositoryTest, DebuggerEndpointReceiverTest: every
  constructor call passes both. The ADFA-7139-only pruning test also gets
  announce = {}, which it needs to compile.
- sqlite-debugger README: ADFA-7137's two rewritten bullets, then
  ADFA-7139's plugin bullet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
CredentialProtectedApplicationLoader.load clears _isLoaded when a step
after initializePluginSystem fails, and the retry after the user unlocks
runs initializePluginSystem again on the same PluginManager singleton with
the same Koin DebuggerEndpointSource. installDebuggerEndpointSource then
threw IllegalStateException; initializePluginSystem caught it, sent it to
Sentry, and skipped the rest of plugin setup, plugin loading included.

Installing the same source again is now a no-op. A different source, which
can only be a plugin's, still throws and leaves the app's source in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The private createPluginContext(pluginId, classLoader, permissions) had no
caller (plugins load through createPluginContextWithResources), and its
DebuggerEndpointService registration took startOpen's default of true, so
a plugin saved as disabled would have started with an open service had
anything ever called it. Every symbol it used is still used elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

davidschachterADFA and others added 2 commits November 17, 2026 22:37
…wide receiver) up the stack

Conflicts, both beside 7139's own edits: DebuggerEndpointRepository's companion
(kept 7139's isPackageInstalled, dropped the removed 5-minute expiry constant)
and the sqlite-debugger README (kept both the new pairing line and 7139's
plugin-API line). InstallationResultReceiverTest, new in ADFA-7137, passes
isInstalled = { true }, the constructor parameter 7139 added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Code on the Go 26.47 was released on 2026-11-17 without this stack, so the
plugin API changelog entry moves to the next unreleased version, 26.48, and
plugins floor plugin.min_ide_version at 26.48 (an IDE of 26.47 or older rejects
the debugger.endpoints permission). Recheck against the real release number if
the stack misses 26.48. No KDoc or Javadoc in #2259 to #2262 names a release
version for this stack. Documentation only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 18, 2026
…a package name, A4 Quick Build pairing text) up the stack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

# Conflicts:
#	subprojects/sqlite-debugger/README.md

@hal-eisen-adfa hal-eisen-adfa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nine findings on the endpoint service's lifecycle and the source contract. They are inline below.


private fun cleanupPluginContributions(loadedPlugin: LoadedPlugin) {
val pluginId = loadedPlugin.manifest.id
loadedPlugin.debuggerEndpointService()?.close()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IMPORTANT: disablePlugin calls cleanupPluginContributions (which now closes the endpoint service here) before loadedPlugin.plugin.deactivate(). If deactivate() throws, the catch returns false with isEnabled still true, but the service stays closed. From then on every getEndpoints() call fails requireOpen(), and tapping Enable does nothing, because enablePlugin returns early with "already enabled" and never reaches reopen() (line 1166). The plugin can't get endpoints again until it is unloaded or the process restarts.

Possible fix: close the service only once the disable has succeeded (after deactivate()), or reopen it in the catch.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in d1626c9. markDisabled now closes the service and clears isEnabled together, and disablePlugin calls it only after deactivate() returns. A disable whose deactivate() throws therefore leaves the plugin enabled with its service open. Force-disable and a failed activation, which always disable, call it too.

Test: a disable whose deactivate throws leaves the plugin enabled and its service open fails without the fix with CancellationException: Plugin reader is disabled or unloaded.

IdeTerminalServiceImpl has the same gap on this path: its cancelAll runs in cleanupPluginContributions before deactivate(). That code comes from stage, not this PR, so I left it as is.


Generated by Claude Code

setupBuildServiceProviders()
setupProjectManipulationProviders()
IdeLogServiceImpl.getInstance().setLogReader(LogsProvider::read)
manager.installDebuggerEndpointSource(get<DebuggerEndpointSource>())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IMPORTANT: this line runs unguarded inside setupPluginServices(), before setSessionLauncher, setupPluginInflationErrorHandler() and the GlobalScope loadPlugins(). If resolving DebuggerEndpointSource throws (a missing binding in some variant or test graph, or the repository/DAO failing to build), or if installDebuggerEndpointSource's check() fails (a different source after a Koin restart), initializePluginSystem's outer catch swallows it, and no plugin loads at all. An optional debugger source shouldn't be able to take down the whole plugin system.

Possible fix: wrap this call in its own runCatching that logs the failure, so that if it fails, plugins load and getEndpoints() returns an empty list.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7f717ef. The install now runs in its own runCatching, which logs the failure and reports it to Sentry. The terminal launcher, the inflation error handler and plugin loading still run.

One change from your suggestion: a plugin that then calls getEndpoints() gets IllegalStateException ("The SQLite debugger endpoints are unavailable: ...") rather than an empty list, because the contract says a failure must not read as "no apps".

Tests: PluginSystemStartTest runs the real initializePluginSystem twice, once with a source that can't be built and once with a different source already installed. Without the fix both cases fail at the first check, terminal session launcher, expected not to be: null. On the service side, DebuggerEndpointServiceImplTest without a source, as when the app could not set one up, a call fails clearly instead of reporting no apps fails without the fix with expected java.lang.IllegalStateException to be thrown, but nothing was thrown.


Generated by Claude Code

initializePlugin(plugin, pluginContext).getOrElse { e ->
logger.error("Plugin initialization threw exception for: ${manifest.id}", e)
// The plugin may have started threads of its own in initialize().
pluginContext.closeDebuggerEndpointService()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IMPORTANT: the two initialize() failure paths (here and line 721) close the endpoint service, but the outer catch (e: Throwable) (line 758) doesn't. If initialize() succeeds and something after it throws, such as PluginFragmentHelper.registerPluginContext / registerServiceRegistry (lines 729-731) or building LoadedPlugin, the service stays open. Threads the plugin started in initialize() can keep calling getEndpoints() and getting live tokens, for a plugin the IDE reports as failed to load.

Possible fix: close it in that catch too, or once in a finally for every failure path.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6793181. One finally in loadPlugin now closes the service of any plugin whose context was built but which never reached loadedPlugins, however the load ends. That finally replaces the two closes on the initialize() paths.

Test: a plugin that fails to load after its initialize succeeded is left with a service that refuses makes the step after initialize() throw. Without the fix it fails with expected java.util.concurrent.CancellationException to be thrown, but nothing was thrown.


Generated by Claude Code

val source = sourceProvider() ?: return emptyList()
val endpoints =
try {
source.endpointsFor(root.absolutePath)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MINOR: DebuggerEndpointSource.endpointsFor (line 19) says projectLocation is "as it appears in recent_project_table.location", which is the canonical path. This passes root.absolutePath, which isn't canonical. It works only because the app's implementation canonicalizes it again (reportedEndpoints -> canonicalProjectLocation()). A source written from the KDoc, such as a test double or a direct DAO lookup, would miss for a project opened through a symlinked or non-canonical path, and getEndpoints() would return an empty list.

Possible fix: pass root.canonicalPath here, or change the KDoc to say any path to the project root is fine.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 4c98e4e. The service now passes the canonical path, falling back to the absolute path as the app's canonicalProjectLocation does, and the KDoc says "its canonical path".

Test: asks the source by the canonical path, as recent_project_table stores it, for a root opened through a symlink fails without the fix: expected [DebuggerEndpoint{applicationId=com.example.demo, ...}] but was [].


Generated by Claude Code

* come back as live. An endpoint can still be stale when the app's process has died. Unlike the writes, a read failure is thrown: the plugin API reports it rather than
* answering "no apps".
*/
suspend fun reportedEndpoints(projectDir: File): List<PluginDebuggerEndpoint> =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MINOR: this method throws on a read failure, as its own KDoc says, but the class KDoc (line 20) still says "Nothing here throws except [CancellationException]". A future caller who trusts the class contract and calls this on the application scope, which has no handler, would crash the process on a database or IO failure.

Possible fix: change the class KDoc to name reportedEndpoints as the exception.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 33cdf50. The class KDoc now limits the no-throw rule to the writes, and names reportedEndpoints as the exception, to be called only where a failure is handled. KDoc only.


Generated by Claude Code

*/
suspend fun reportedEndpoints(projectDir: File): List<PluginDebuggerEndpoint> =
dao.getByProjectLocation(projectDir.canonicalProjectLocation()).mapNotNull { row ->
if (!isInstalled(row.applicationId)) return@mapNotNull null

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MINOR: isInstalled() makes a PackageManager.getPackageInfo binder call before the cheap token/port null checks. Every getEndpoints() call then costs one binder call per paired app, including apps that never reported and are dropped on the next line anyway. Checking token and port first gives the same result with fewer binder calls, on what a plugin may call repeatedly.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in da6a0e3. Token and port are now checked first, then isInstalled.

Test: an app that has not reported is dropped without asking whether it is installed, a binder call fails without the fix: unexpected (1): com.example.silent.


Generated by Claude Code


if (!isEnabled) {
// initialize() ran, so the plugin may already have threads of its own.
loadedPlugin.debuggerEndpointService()?.close()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NITPICK: this close is redundant. The service was created with startOpen = getPluginState(pluginId) (line 1633), which is the same value isEnabled was just read from, so it's already closed here. Two mechanisms enforce one rule, and a maintainer can't tell which one matters. Keeping one would do.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed in 300bf93. startOpen stays, because it also covers the plugin's own initialize(). Its comment now says it is the only close such a plugin needs. a plugin loaded while disabled gets a service that refuses still passes.


Generated by Claude Code

}.onFailure { logger.error("Failed to cleanup templates for: $pluginId", it) }
}

private fun PluginContext.closeDebuggerEndpointService() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NITPICK: PluginContext.closeDebuggerEndpointService() and LoadedPlugin.debuggerEndpointService() (line 1251) both do services.get(DebuggerEndpointService::class.java) as? DebuggerEndpointServiceImpl. One helper on PluginContext would cover both: callers with a LoadedPlugin can use loadedPlugin.context.debuggerEndpointService()?.close().

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 300bf93. There is now one PluginContext.debuggerEndpointService(), and callers that hold a LoadedPlugin use loadedPlugin.context.debuggerEndpointService().


Generated by Claude Code

// The services outlive a disable, which closed the terminal service.
// The services outlive a disable, which closed the terminal and SQLite debugger endpoint services.
(loadedPlugin.context.services.get(IdeTerminalService::class.java) as? IdeTerminalServiceImpl)?.reopen()
loadedPlugin.debuggerEndpointService()?.reopen()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MINOR (design): close and reopen for this one service are wired by hand into 7 lifecycle sites (lines 712, 721, 751, 794, 836, 1166, 1223), next to the terminal service's own reopen() / cancelAll() special cases. Every new stateful service will need adding at every site, and each missed site lets a disabled or failed plugin keep access. Two sites are already missed: the deactivate()-throws path on line 1223 and the catch (Throwable) path on line 758 (see those comments). A small shared close/reopen interface that PluginManager calls once per transition, over the plugin's ServiceRegistry, would remove the per-service special cases.

Found by code review; not yet reproduced on a device.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed: the hand wiring caused both misses. In this PR I narrowed it instead of generalising it. The SQLite debugger endpoint service is now closed or reopened in 4 places instead of 7, and each place is tied to a state change rather than a code path:

  • markDisabled closes it and clears isEnabled in one step. Disable, force-disable and a failed activation all call it.
  • One finally in loadPlugin covers every way a load fails.
  • enablePlugin reopens it.
  • unloadPlugin closes it.

I left the shared hook for a follow-up, ADFA-7219. Moving the terminal service onto the hook would change its behaviour on three paths where it stays open today: a failed initialize(), a plugin loaded as disabled, and a failed activation. Disable would also cancel its commands after deactivate() instead of before. Those changes are fixes, but they change stage code outside ADFA-7139, and they touch the loadPlugin lines that #2242 also changes. The shape I'd propose:

  • An internal close/reopen interface in plugin-manager. DebuggerEndpointServiceImpl and IdeTerminalServiceImpl implement it.
  • PluginManager keeps the list of these services when it builds each plugin's context. It doesn't read them back from the ServiceRegistry, because a plugin can register its own objects there.
  • markDisabled, enablePlugin, unloadPlugin and loadPlugin's finally call it once each. A plugin saved as disabled is closed when its context is built, which replaces startOpen.

Generated by Claude Code

davidschachterADFA and others added 8 commits November 18, 2026 22:47
…dy does

Review cleanups, no behaviour change (hal-eisen-adfa, PR #2261):

- PluginContext.closeDebuggerEndpointService() and
  LoadedPlugin.debuggerEndpointService() did the same lookup. One
  PluginContext.debuggerEndpointService() now serves both; callers with a
  LoadedPlugin go through its context.
- loadPlugin closed the service of a plugin loaded as disabled, but the
  service was created closed from the same saved state
  (startOpen = getPluginState), which isEnabled was just read from. Two
  mechanisms enforced one rule. startOpen stays, because it also covers the
  plugin's own initialize(); the comment there now says it is the only close
  such a plugin needs. "a plugin loaded while disabled gets a service that
  refuses" still passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
disablePlugin closed the SQLite debugger endpoint service in
cleanupPluginContributions, before deactivate(). When deactivate() threw,
the disable failed and the plugin stayed enabled, but its service stayed
closed. Enable then returned early ("already enabled") and never reopened
it, so the plugin could not get endpoints until it was unloaded or the
process restarted (hal-eisen-adfa, PR #2261).

markDisabled now closes the service and clears isEnabled in one step, and
disablePlugin calls it only after deactivate() returns. forceDisablePlugin
and a failed activation, which always disable, call it too, so the service
is closed exactly when a plugin stops being enabled, and the close no longer
sits in cleanupPluginContributions.

IdeTerminalServiceImpl has the same gap on this path (its cancelAll runs in
cleanupPluginContributions before deactivate()). That code comes from stage,
not this PR, and is left as is here.

Test: "a disable whose deactivate throws leaves the plugin enabled and its
service open" fails without this change with CancellationException: Plugin
reader is disabled or unloaded. "a plugin force-disabled after crashing gets
nothing, even when its deactivate throws" pins the force-disable side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
loadPlugin closed the SQLite debugger endpoint service on its two
initialize() failure paths, but not in the outer catch. When initialize()
succeeded and a later step threw (registering the resource context or the
service registry, building the LoadedPlugin), the service stayed open, and
threads the plugin started in initialize() kept getting live tokens for a
plugin the IDE reported as failed to load (hal-eisen-adfa, PR #2261).

One finally now closes the service of a plugin whose context exists but
which never reached loadedPlugins, whichever way loadPlugin leaves. It
replaces the two closes on the initialize() paths, and covers any early
return added later. Once loadedPlugins holds the plugin, disabling and
unloading close the service instead; closing it there for a plugin left
enabled would recreate the stuck state of the previous commit.

Test: "a plugin that fails to load after its initialize succeeded is left
with a service that refuses" makes the step right after initialize() throw,
through the test's logger. Without this change it fails with "expected
java.util.concurrent.CancellationException to be thrown, but nothing was
thrown". "a plugin whose initialize returns false or throws is left with a
service that refuses" still passes through the finally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
DebuggerEndpointSource.endpointsFor documents projectLocation as it appears
in recent_project_table.location, which is the canonical path, but
DebuggerEndpointServiceImpl passed root.absolutePath. It worked only because
the app's source canonicalizes again. A source written from the KDoc, such
as a test double or a direct DAO lookup, missed a project opened through a
symlink, and getEndpoints() returned an empty list (hal-eisen-adfa, PR
#2261).

The service now passes the canonical path, falling back to the absolute
path when canonicalPath throws, as the app's canonicalProjectLocation does
when it stores the pairing. The KDoc says "its canonical path". The two
test doubles that matched on absolutePath now match on canonicalPath.

Test: "asks the source by the canonical path, as recent_project_table stores
it, for a root opened through a symlink" fails without this change:
expected [DebuggerEndpoint{applicationId=com.example.demo, ...}] but was [].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…et up

setupPluginServices resolved and installed the DebuggerEndpointSource
unguarded, before setSessionLauncher, setupPluginInflationErrorHandler and
loadPlugins. When resolving it threw (a binding missing in some variant, the
repository or DAO failing to build) or installDebuggerEndpointSource's
check() failed (a different source already installed),
initializePluginSystem's catch swallowed it and no plugin loaded at all. An
optional SQLite debugger source must not take down the plugin system
(hal-eisen-adfa, PR #2261).

- The install now runs in its own runCatching, which reports the failure
  to the log and Sentry, and the rest of the start carries on.
- A plugin that then asks for endpoints gets IllegalStateException ("The
  SQLite debugger endpoints are unavailable: ...") instead of an empty list,
  which would read as "no apps". The service checks the source before the
  open project, so the failure shows on the home screen too.
- initializePluginSystem takes the context and the source resolver as
  parameters, defaulting to the application and Koin, so a test can run the
  real start without IDEApplication.
- DebuggerEndpointService's @throws, the changelog entry and the KDoc of
  installDebuggerEndpointSource and the service's sourceProvider say so.

Tests:
- PluginSystemStartTest runs initializePluginSystem with a source that
  cannot be built, and with a different source already installed. Both
  check that the terminal launcher and the inflation error handler are set
  and that a plugin loads; the first also checks that the plugin's
  getEndpoints() fails with the message above. Without the guard both fail
  at the first check: "terminal session launcher, expected not to be:
  null".
- DebuggerEndpointServiceImplTest "without a source, as when the app could
  not set one up, a call fails clearly instead of reporting no apps"
  replaces "is empty until the app installs a source". Without the service
  change it fails with "expected java.lang.IllegalStateException to be
  thrown, but nothing was thrown".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…rows

The class KDoc of DebuggerEndpointRepository still said nothing in it
throws except CancellationException, but reportedEndpoints, added for the
plugin API, throws on a read failure, as its own KDoc says. A caller who
trusted the class contract and called it on the application scope, which
has no handler, would crash the process on a database or IO failure
(hal-eisen-adfa, PR #2261).

The class KDoc now limits the no-throw rule to the writes, and names
reportedEndpoints as the exception, to be called where a failure is handled.
The method KDoc's overlong line is reflowed. KDoc only, no code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
reportedEndpoints asked isInstalled, a PackageManager.getPackageInfo
binder call, before the token and port null checks. Every getEndpoints()
call then cost one binder call per paired app, including apps that never
reported and were dropped on the next line anyway, on a call a plugin may
make repeatedly (hal-eisen-adfa, PR #2261).

The null checks now come first; the result is the same.

Test: "an app that has not reported is dropped without asking whether it
is installed, a binder call" fails without this change: isInstalled is asked
about com.example.silent as well ("unexpected (1): com.example.silent").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
ktlint max-line-length (140) flagged the sessionLauncherField line added
with the plugin-start test. Formatting only, no change to the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 19, 2026
…mporary branch)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
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.

2 participants