Repository navigation
ADFA-7302 SQLite debugger P2-7: .read with Pebble SQL templates rendered in Code on the Go - #2329
Draft
davidschachterADFA wants to merge 20 commits into
Draft
davidschachterADFA wants to merge 20 commits into
davidschachterADFA wants to merge 20 commits into
Conversation
A read-only tool that returns in one call what a SQL template can use without reading the app's rows: - app and device fields; - per database: pragmas, tables, columns, indexes, foreign keys, views, triggers, FTS tables and Room's master-table identity hash; - a library database recognised by file name. The lists are read through pragma_table_list and the other pragma table functions, paged to 20,000 rows. A database that fails is listed in errors, and the others still come. The JNI test runs the same SQL through the read-only authorizer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
…ings ProjectTemplatePebble in :common holds the delimiters, StringLoader and strict variables that ZipRecipeExecutor built inline. The SQL templates in the next commits use the same builder, so the two cannot drift. No behaviour change: ZipRecipeExecutor builds the same engine. The DELIM_ constants had no other users and are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
…mplates What it does: - AI-Agent-MCP passes a template's path in the open project, the variables it fetched from the app and the functions that read the app's data, and gets back the SQL. - The engine is the project templates' (ProjectTemplatePebble), with autoescaping off. - sql_ident and sql_literal quote what a template splices in. - A Supplier variable is read only when the template uses it, and once. - A function runs only when called. - The render runs on its own thread, under one time limit. - listTemplates lists the *.sql.peb files. - getRoomSchemas reads Room's exported schemas, with indices, foreignKeys and views present where Room left them out. Access: gated on debugger.endpoints, the permission a plugin already needs to reach the debugger; refused on the main thread. A template path must stay inside the project once links are resolved. API records: the plugin-api.api dump is updated by hand from the compiled descriptors. Run apiDump to confirm. Also updated: the changelog, plugin-api.md, PLUGIN_AUTHORING.md and the permission's description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
ktlint wraps and Eclipse member sorting on the new plugin-api, plugin-manager and sqlite-debugger files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Pebble never checks the interrupt flag, so a busy template such as an empty loop over range(1, 2000000000) kept a core after the time limit passed (the size cap never trips as nothing is written), one more per retry. Its range also builds the whole boxed list first, so range(1, 9999999999) exhausted the app's memory. In the SQL engine only (SqlExtension; the project templates keep Pebble's own): a for tag whose loop checks the interrupt on every pass, and a range that fails past 100,000 values, with Pebble's arguments and steps otherwise. An extension's tag and function replace the core ones of the same name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ase it did not read After the time limit passed, the databases left were in neither databases nor errors, so a client could not tell a short answer from a whole one; each is now in errors with a 'not read' message (documented in the tool description and README). Any exception other than an McpToolError from one database (a ClassCastException from a row, say) failed the whole call; it is now that database's entry in errors, and an Error or an interrupt still propagates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
own_tables listed every table whose name starts with room_, so an app's room_booking table was reported as Room's. Room 2.8.4's runtime creates room_master_table and room_table_modification_log (read from the room-runtime-android 2.8.4 classes: the only room_ table names there, besides the room_table_modification_trigger_ and room_fts_content_sync_ trigger prefixes); the list is now those two names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… the list truncated rows() returned what it had, without truncated, when a page came back empty with hasMore set, so a short list looked whole. FakeDebugEngine gets rawPage to hand back a page as given, since its paging rule cannot make an empty page with hasMore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…d a function's supplier
sql_literal wrote -5 as -5, so 1-${{ x | sql_literal }} became 1--5, a SQL comment; negative numbers are now in parentheses. A call such as fn(a=1) reached the function as an argument keyed "a" while the renderer read positions, so the function silently got null; named arguments now fail the render. A function that returned a Supplier had its toString written, as only the elements of a returned list or map were resolved; the result is now read once, as a variable's is. The Javadoc and changelog line formatting from the previous commit's blank Javadoc line is fixed by spotlessApply here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…keep path errors in the documented types The size check used length(), which is 0 for a FIFO named x.peb, and readText() then blocked forever, outside the time limit and not interruptible; and length() then readText() raced. The template is now read from the path that passed the containment check, only if it is a regular file (NOFOLLOW_LINKS), taking at most the size cap plus one byte whatever the file system reports. A NUL in the template path (or the project folder) made canonicalFile throw an undeclared IOException; the path is rejected up front and a failure resolving the project folder is an IllegalStateException. A swap of a folder on the path between check and read needs write access to the project and is noted in the KDoc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… disabled or unloaded SqlTemplateServiceImpl had no closed state, so a disabled or unloaded plugin that kept a reference could still read the project and render. It now has close() and reopen() like DebuggerEndpointServiceImpl, and starts closed for a plugin saved as disabled; PluginManager closes it where it closes that service (a failed load, unload, markDisabled, and the unload that races an enable) and reopens it on enable. Calls then throw CancellationException, also when the plugin is closed while a render runs (the render itself is not stopped: it ends at its time limit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…0-entry cut is sorted and logged A deeply nested schema file could overflow the stack in the recursive JSON conversion and fail getRoomSchemas for every file; JSON nested past 64 levels (Room's nest about six) is now not a schema, and a StackOverflowError or other exception in one file skips only that file. Note the runtime Gson (nesting limit 255 from 2.11) already refuses very deep files at parse time; the bound makes the behaviour independent of its version. The walk stopped silently at 2,000 matches in its own order and sorted afterwards, so which entries survived depended on the folder order: it now collects candidates (up to 50,000), sorts, then keeps the first 2,000, and the service logs a warning when a list reaches the limit. Documented in the Javadoc and changelog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…unction that ignores the interrupt keeps running
{@code }}}, {@code %}} and {@code #}} close at the first brace and rendered as stray braces; they are now written with } entities. After a time-out a function that ignores the interrupt keeps running on the render thread, which the approved time-limit behaviour allows; the SqlTemplateService Javadoc, the renderer KDoc and the changelog now say so. The changelog entry is rewrapped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The tests for close() and a service that starts closed were left out of the previous F04 commit (a staging slip: the file was committed without them). They pass against it; their revert proof (close() a no-op) failed as expected, in proofs.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The two tests for the previous commit's depth bound and sorted cut were left out of it (a staging slip). They pass against it; their revert proofs (depth check off; walk cut back to 2,000) failed as expected, in proofs.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7302 Brings in the 2026-11-26 review fixes of #2311 and #2323. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7302 Brings in the #2311 review fix through #2319 and #2323. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review of #2329 at 2760274706. Stacked on #2323 (P2-6); checked at this head.
IMPORTANT
- plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/sqltemplate/ProjectSqlFiles.kt:84 - readNBytes(int) is API 33; minSdk 28 and the desugaring rewrite covers only org.eclipse.jgit, so render/getRoomSchemas fail with NoSuchMethodError on Android 9-12
- plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/sqltemplate/SqlPebbleParts.kt:23 - exponential recursive macro is never interrupted; the render thread spins after the time limit, contrary to the PR body and Javadoc
Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.
Generated by Claude Code
…PI 33 readBounded called InputStream.readNBytes(int), which Android added in API 33; minSdk is 28. Desugaring does not backport it for this package (app/build.gradle.kts gives JavaIOReplacements org.eclipse.jgit only), so on Android 9 to 12 render() and getRoomSchemas() would throw NoSuchMethodError, an Error that no catch there handles (review of #2329, ADFA-7131 comment 41657). The dex of a debug APK built before this has "invoke-virtual Ljava/io/InputStream;.readNBytes:(I)[B" in ProjectSqlFiles, the only API-33 InputStream call in the app; one built with it has none. It now reads in a loop, at most MAX_FILE_BYTES + 1 bytes as before. Lint does not flag the call here and the JVM tests run on a JDK that has it, so a new test looks for readNBytes and skipNBytes in the template package's classes. Before the fix it fails with "ProjectSqlFiles.class: readNBytes". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…e limit Only for and range checked for an interrupt, so a macro that calls itself twice per level, f(40), kept the render thread busy after render() threw its time-limit error: about 2^40 calls that write nothing, so neither the output cap nor the stack ends it (review of #2329, ADFA-7131 comment 41657). A template that includes itself does the same: a template is its own text (StringLoader), so it can. A node visitor now puts an interrupt check at the start of every body of every template the engine compiles, included ones too. Besides for, a template repeats work only by rendering a body again, so this covers macros and includes (tested) and block(), whose block body the visitor also reaches (read, not tested). Both new tests time out as before but, before the fix, find the render thread still alive 5 s later. The Javadoc, the KDoc and the plugin API changelog say macros and includes stop too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…more The guard from 39daeac searched the template package's class files for the names readNBytes and skipNBytes. It now reads each class file's constant pool and refuses a call to readAllBytes, readNBytes, skipNBytes or transferTo whose owner is an InputStream class, so the older Files.readAllBytes and FileChannel.transferTo cannot trip it. It also checks SqlTemplateServiceImpl and ProjectTemplatePebble with their nested classes (follow-up from the re-check, ADFA-7131 comment 41663; David). It moves to MinSdkCallsTest. With 2760274's ProjectSqlFiles.kt it fails with "ProjectSqlFiles.class: java/io/InputStream.readNBytes". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Collaborator
Author
|
@hal-eisen-adfa A new commit since you were asked to review: c1df230, test-only, a follow-up from the cloud agent's re-check (ADFA-7131 comment 41663).
With the old |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADFA-7302
Phase 2, P2-7 of the SQLite debugger (ADFA-7131):
.readwith Pebble templates that Code on the Go renders, with variables the debugger supplies. Draft, stacked on #2323 (P2-6). The template functions use P2-6'ssuggest_indexesandlint_foreign_keys. The client is addonssqlite-debugger/ADFA-7302(AI-Agent-MCP 3.0.0), a separate draft on addons #178.What it adds
get_template_variables(subprojects/sqlite-debugger, read-only,readOnlyHint) returns, in one call:sqlite_sequence;room: identity hash, Room's own tables (room_master_table,room_table_modification_log) and its FTS sync triggers;library, recognised by file name.Lists are paged to 20,000 rows, with
truncated. A database that fails, or that the call's time limit leaves unread, goes inerrors.ProjectTemplatePebble(:common): the project templates' delimiters,StringLoaderand strict variables, now in one place.ZipRecipeExecutoruses it. A review compared every engine setting before and after and found no change for new projects.Plugin API
SqlTemplateService(render,listTemplates,getRoomSchemas), withSqlTemplateFunction,SqlTemplateExceptionandRoomSchema. It's implemented in plugin-manager (SqlTemplateServiceImpl,sqltemplate/).ProjectTemplatePebblewith autoescaping off, a 4 Mi output cap, and thesql_identandsql_literalfilters.sql_literalwrites a negative number in parentheses.Suppliervalue is read only when used, and once. Functions run only when called, with positional arguments; named arguments fail.forchecks on every pass, andrangeis capped at 100,000 values. A stopped render therefore ends instead of using a core until the app restarts..pebinside the project. It is read by its resolved path, without following links, and with at most the size cap read.debugger.endpointspermission and are refused on the main thread.DebuggerEndpointServiceis.<class>/<n>.json. It skipsbuild/and hidden folders, reads a missingindices,foreignKeysorviewsas empty, and skips a bad file.plugin-api.api(apiCheckpasses), the changelog (26.48),plugin-api.mdandPLUGIN_AUTHORING.md.Decisions (David, ADFA-7302 comment 41626):
debugger.endpointsreused;build_type(AGP 8 generates noBuildConfigby default);Commits
ProjectTemplatePebble;spotlessApplyonly.forand cappedrange;errors, and one database's failure kept to it;EventDecoderrefuses a row count its bytes cannot hold). Its diff is exactly 2d674ec's.readBoundedreads in a loop instead ofInputStream.readNBytes(int), which is API 33 (minSdk 28) and not desugared for this package. The dex of a debug APK built before it has that call inProjectSqlFiles, the app's only API-33InputStreamcall; the APK built with it has none. A new test looks forreadNBytesandskipNBytesin the template classes, since lint does not flag them here.f(40)kept the render thread busy after the error).block()gets the same check (read, not tested).MinSdkCallsTest, reads each class file's method references and refusesreadAllBytes,readNBytes,skipNBytesortransferToon anInputStreamclass, so the olderFiles.readAllBytesandFileChannel.transferTopass. It also coversSqlTemplateServiceImplandProjectTemplatePebble.Tests
test.sh0 failures (ASan+UBSan 21286 checks, TSan 21272, JNI 374);:plugin-manager:testV8DebugUnitTest,:plugin-api:testDebugUnitTest(251),:subprojects:sqlite-debugger:testDebugUnitTest(161) and:templates-impl:testV8DebugUnitTest(14);:plugin-api:apiCheck,spotlessCheckandassembleV8Debugpass.MinSdkCallsTest1,ProjectSqlFilesTest8,SqlTemplateRendererTest22) andspotlessCheckpass. With 2760274'sProjectSqlFiles.kt,MinSdkCallsTestfails with "ProjectSqlFiles.class: java/io/InputStream.readNBytes".:plugin-manager:testV8DebugUnitTest(323),:plugin-api:testDebugUnitTest(251),:plugin-api:apiCheckandassembleV8Debugpass.ProjectSqlFilesTestandspotlessCheckpassed again after a line wrap in the new test and the changelog edit. Revert proofs: with the oldreadBounded, the new test fails with "ProjectSqlFiles.class: readNBytes"; without the visitor, both new render tests find the render thread alive 5 s after the time limit. On the J7 (Android 9, API 28),app_processrunning each APK's ownProjectSqlFiles.readBounded: before the fix,NoSuchMethodErrorforInputStream.readNBytes(I); with it, the file is read. The full plugin path can't run there (AI-Agent-MCP needs Android 13).:subprojects:sqlite-debugger:testDebugUnitTest(165 tests) andspotlessCheckpass.:subprojects:sqlite-debugger:testDebugUnitTest(164 tests) andspotlessCheckpass.spotlessApplychanges nothing.fortag, the render thread is still alive 5 s after the limit;rangecap, the test JVM runs out of memory;Not done here:
exportSchemaon,schema_matchesboth ways, and no call beyondget_template_variablesfor a template that calls no function.Merging:
libs/refresh.No screens added or changed.
🤖 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.