Skip to content

feat: add native PL/SQL routine debugging - #26

Open
lejyfps wants to merge 7 commits into
TabularisDB:mainfrom
lejyfps:feat/1411-routine-debugger
Open

lejyfps wants to merge 7 commits into
TabularisDB:mainfrom
lejyfps:feat/1411-routine-debugger

Conversation

@lejyfps

@lejyfps lejyfps commented Nov 9, 2026 •

Copy link
Copy Markdown

Behaviour

Adds native PL/SQL routine debugging for TabularisDB/tabularis#1411 through the optional routine_debug: 1 driver contract. Preview reads the selected standalone routine and bound inputs; explicit start stops at its entry. Dedicated target/controller sessions support continue, step into/over/out, native breakpoints, stack reads, scalar watches, and OUT/return values.

Companion host PR: TabularisDB/tabularis#1460.

The debugger never grants privileges, recompiles routines or creates persistent helpers. Starts are deduplicated before connection setup. Stop, cancellation, EOF and an abandoned-session lease interrupt execution and clean up both connections. Execution, overall transaction outcome and resource release are independent; COMMIT, DDL, autonomous transactions and external effects cannot be undone by the debugger. Remaining uncommitted work is rolled back and overall transaction outcome stays conservatively unknown.

Scope

  • First implementation: Oracle installations with DBMS_DEBUG available, valid precompiled standalone procedures/functions, and scalar numeric/character parameters. Packaged overloads, composite/date types, variable assignment and expression evaluation are explicitly unsupported.
  • Oracle deprecates DBMS_DEBUG. Required privileges/debug information must already exist; unsupported environments explain the failure rather than enabling permissions.
  • Ordinary RPC/query calls retain sequential processing and their existing cache; only isolated debugger calls use workers so stop remains responsive.
  • Stop also accepts an unused native preview ID, discards its saved state idempotently and prevents that preview from starting. This releases preview capacity when the host closes, expires or disconnects the workspace.
  • Older hosts ignore the capability. This PR needs the companion host change to expose the workspace.

Validation

  • Local: 55 plugin unit tests, two doctests, formatting and cargo clippy --all-targets -- -D warnings pass. Regression tests inject failed breakpoint removals/additions, verify retained handles remain removable and prevent duplicate installations, and check idempotent disposal of unused previews; the live test also replaces an existing breakpoint with a duplicated request.
  • tests/live_debugger.rs adds real stdio integration tests to the existing Oracle Free CI job: breakpoints, all step modes, stack/watches, OUT/return values, exception, duplicate start, concurrent stop, EOF, source changes, missing privileges/debug info, unsupported types, rollback and absence of leaked target/controller sessions. Oracle/Instant Client versions are logged.
  • Real Oracle integration passed on head 30219da86070ce40750a192811aef6bd6254d847: live Oracle job, Oracle AI Database 26ai Free 23.26.3.0.0 / Instant Client 23.26.2.0.0. ORACLE_TEST_HOST was set, so the native test ran rather than skipping. It confirmed unused preview disposal without execution, an entry stop before the routine's INSERT, breakpoint replacement/deduplication, step/variable inspection, numeric OUT/function return values, exception, cancellation, EOF, rollback and release of target/controller sessions.
  • The same fork CI run also passed unit tests, manifest validation, EXPLAIN validation, Markdown lint and security audit. Upstream fork-workflow execution still requires maintainer approval. Local runs skip live cases without ORACLE_TEST_HOST; other Oracle versions have not been validated.
  • GitNexus staged analysis: high risk (100 symbols / 14 flows), including the new debugger and RPC entry. Existing plugin tests and the live stdio cases cover that boundary.

Maintainer action: please apply the existing prerelease:alpha label required by the version-suggestion job. The fork author cannot assign upstream labels.

Comment thread src/debugger/session.rs Outdated
.ok_or_else(|| invalid("Debugger resources released"))?;
let mut failures = vec![];
let mut retained = vec![];
for (id, bp) in control.breakpoints.drain(..) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Breakpoint tracking is lost if a native call fails mid-update

control.breakpoints.drain(..) removes every entry from the tracked list up front, but the loop body can return early through ? (the connection.execute(...)? and bind_value(...)? calls). When that happens, the remaining drained entries are dropped and control.breakpoints is never reassigned from retained. The native breakpoints stay set in the Oracle session, but the plugin no longer tracks them, so they can't be deleted by a later set_breakpoints and the reported breakpoints snapshot no longer matches the native state.

A failed delete also keeps the old breakpoint in retained, and the loop below then re-adds the same line, which can create a duplicate native breakpoint on that line.

Suggestion: iterate over a copy (std::mem::take into a local and restore on error) or collect errors instead of using ? inside the loop, and skip re-adding lines that are already retained.

@kilo-code-bot

kilo-code-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

No changes since the previously reviewed commit, and the earlier review found no issues. I did not run the tests.

Files Reviewed (0 files in incremental diff)
  • No incremental changes
Previous Review Summaries (5 snapshots, latest commit 05341d1)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 05341d1)

Status: No Issues Found | Recommendation: Merge

The incremental changes since 838903c make the debugger more robust. I checked the following and found no logic, race or error-handling problems. I did not run the tests.

  • Entry breakpoint: a native breakpoint is installed in the routine at the first wrapper stop, so execution can't run past its entry unobserved.
  • Lease: a session paused at a stop now gets a 30-minute lease instead of 120 seconds.
  • Cancellation: only start, continue and step requests interrupt the target when cancelled.
  • Preview and session identity: a preview can be used to start only once, and old session-identity reservations are pruned.
  • DEBUG privilege: the metadata read now checks the DEBUG privilege up front.
  • Request queue: ordinary requests are queued to one worker, so Stop and cancel stay responsive.
Files Reviewed (8 files in incremental diff)
  • src/debugger/metadata.rs
  • src/debugger/mod.rs
  • src/debugger/session.rs
  • src/main.rs
  • src/debugger/tests.rs
  • tests/live_debugger.rs
  • CHANGELOG.md
  • README.md

Previous review (commit 838903c)

Status: No Issues Found | Recommendation: Merge

The incremental changes add handling for stop and cancel requests that arrive while a start is still preparing. A pending-start flag now makes the start abandon and release its resources. src/main.rs also accepts the host's cancel notification as well as $/cancelRequest, without replying. I found no logic, race or error-handling problems in the changed code. I did not run the tests.

Files Reviewed (5 files in incremental diff)
  • src/debugger/mod.rs
  • src/debugger/tests.rs
  • src/main.rs
  • tests/protocol.rs

Previous review (commit 30219da)

Status: No Issues Found | Recommendation: Merge

The incremental changes add a discard path for never-started previews. stop on a preview ID now removes the preview and returns an idempotent "cancelled / released" session. A later start for that preview fails with "preview expired or not found". Unit and live tests cover this. No new issues found.

Files Reviewed (3 files in incremental diff)
  • src/debugger/mod.rs
  • src/debugger/tests.rs
  • tests/live_debugger.rs

Previous review (commit 0ff9536)

Status: No Issues Found | Recommendation: Merge

The previous warning (breakpoint tracking lost on native call failure in set_breakpoints) is resolved: replace_breakpoints now retains every handle until removal is confirmed, skips duplicate re-adds, and reports partial state. Unit tests and a live test cover the new behavior.

Files Reviewed (3 files in incremental diff)
  • src/debugger/session.rs
  • src/debugger/tests.rs
  • tests/live_debugger.rs

Previous review (commit b3d37a8)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/debugger/session.rs 486 set_breakpoints drains control.breakpoints and then uses ? inside the loop; on a native call failure the remaining entries are dropped from tracking while the native breakpoints stay set. Failed deletions can also be re-added, producing duplicate native breakpoints.
Files Reviewed (11 files)
  • .github/workflows/ci.yml
  • .tabularium
  • README.md
  • src/debugger/metadata.rs
  • src/debugger/mod.rs
  • src/debugger/session.rs - 1 issue
  • src/debugger/tests.rs
  • src/lib.rs
  • src/main.rs
  • src/rpc.rs
  • tests/live_debugger.rs

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5.5 · Input: 250 · Output: 786 · Cached: 164.8K

@debba

debba commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This is a solid foundation: isolated target/controller sessions, bound inputs, and conservative transaction reporting are good choices. The host-side support has already landed in TabularisDB/tabularis#1460.

I reviewed head 30219da86070ce40750a192811aef6bd6254d847. I found two issues that should be fixed before merging:

  1. [P1] Handle the cancellation notification actually sent by Tabularis. In src/main.rs:48, the plugin recognizes $/cancelRequest, but the host's cancel_notification_line sends {"jsonrpc":"2.0","method":"cancel","params":{"id":123}}. I sent that notification to the PR binary: it returned -32601: method 'cancel' is not supported by this plugin with id: null, rather than invoking cancellation. This means host cancellation/timeout does not interrupt the in-flight debugger request through this path. Please handle the canonical cancel method, optionally accepting $/cancelRequest as an alias, and add a stdio regression test using the host's actual notification. A notification should not produce a response.

  2. [P1] Preserve Stop requests received while a session is being prepared. In src/debugger/mod.rs:224–254, start reserves the session ID in started, releases the registry lock, and calls Session::prepare before registering the session. A concurrent stop during that interval sees an already-started ID without a registered session and returns Native debug session not found. It does not cancel the pending start, so preparation can complete and activate the session after Stop. This also affects the host's workspace/disconnect cleanup, which sends Stop for starts already in flight. I reproduced the intermediate registry state with a focused unit test: Stop failed with -32602: Native debug session not found. Please make pending starts cancellable, record Stop against the reservation, and check that state before activation. A regression test should hold preparation behind a barrier, send Stop, then release preparation and verify that execution is not activated and resources are released.

Validation: the existing 55 unit tests and two doctests passed locally. The live Oracle tests were skipped locally because ORACLE_TEST_HOST was unset; I have not independently rerun the real Oracle integration. The successful fork integration run documented in the PR is useful evidence, while upstream CI is still awaiting maintainer approval.

Once these two cancellation cases are covered, I would be comfortable moving this forward as an alpha release.

Handle the host `cancel` notification (with `$/cancelRequest` as an
alias) without emitting a response, and record Stop against a reserved
start so preparation cannot activate after cancellation.
@lejyfps

lejyfps commented Nov 13, 2026

Copy link
Copy Markdown
Author

Addressed both P1s from review of 30219da:

  1. The stdio loop now handles the host cancel notification ({"jsonrpc":"2.0","method":"cancel","params":{"id":…}}) and keeps $/cancelRequest as an alias. Notifications produce no response. tests/protocol.rs sends the host payload against the real binary.
  2. Start reservations are pending-cancellable. Stop during Session::prepare is recorded on the reservation, preparation is not activated, and resources are released. A unit test holds preparation behind a barrier, sends Stop, then releases; another covers the reserved-but-unregistered Stop that previously returned -32602: Native debug session not found.

cargo test (58 unit tests + protocol stdio test + two doctests) and cargo clippy --all-targets -- -D warnings pass locally. Live Oracle tests were not rerun (ORACLE_TEST_HOST unset).

@debba debba added the prerelease:alpha Release channel for the version suggestion label Nov 17, 2026

@debba debba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. I re-reviewed 838903c: CI is green upstream (except the version-suggestion label, which I've now added), and I ran the binary end to end against Oracle Free 26ai with a least-privileged user. Both earlier P1s are fixed: the host cancel notification interrupts in-flight requests without replying, and Stop during preparation prevents activation and releases both connections. Breakpoints, all step modes, frame-scoped variables, OUT/return values, rollback, EOF cleanup and identifier/bind safety all behaved correctly.

Two new issues need fixing before merge:

  1. [P1] Ordinary requests block Stop. In src/main.rs:69-73, non-debugger requests still run on the stdin thread. When a paused target holds a row lock (normal mid-debug) and the user runs UPDATE on that row from the editor, execute_query waits on the lock, and the plugin stops reading stdin. In my run, Stop was answered only after 119 s, when the abandoned-session lease aborted the target. The host's 5 s stop timeout and its cancel notifications can't get through. Please read stdin on its own thread, dispatch cancel and routine_debug immediately, and queue ordinary requests to a single sequential worker so their ordering is preserved. A live regression test (pause after an UPDATE, send a conflicting execute_query, then Stop) should return within a few seconds.

  2. [P1] Without the object DEBUG privilege, Start runs the routine to completion. A user with EXECUTE but no DEBUG on another schema's routine gets no native stop, so reach_entry (src/debugger/session.rs:189-215) lets the call finish. Against a routine that INSERTs and COMMITs, Start returned execution: completed and the row was committed. That contradicts "stop at entry" in the protocol and README. Please check DEBUG access during preview/start (owner, object DEBUG, or DEBUG ANY PROCEDURE) and fail with a clear message. As a backstop, at the first wrapper stop, install a native breakpoint in the target and abort execution if that fails or the next stop isn't in the target. Please add a live test with a non-owner account.

Non-blocking, happy to take these as follow-ups:

  • The fixed 3 s call timeout and 1 s DBMS_DEBUG wait make cold or slow databases flaky: 2 of my first 4 live runs failed (DPI-1067 on start, and continue returning running at tests/live_debugger.rs:316). Consider configurable or longer timeouts, and have the test poll status.
  • Stop during preparation replies resources: released while a connection is still open.
  • Cancelling a read-only request (status/read_stack) stops the whole session.
  • The 120 s idle lease ends a session while a user is just reading code at a breakpoint.
  • started is capped at 1024 and never pruned.
  • A preview can be started again under a new session ID.
  • Missing or invalid routines surface as "no data found".
  • Please add a CHANGELOG [Unreleased] entry, and either note that only 23ai/26ai was validated or soften the "19c+" claim.

- Read stdin on its own thread: cancel and routine_debug dispatch
  immediately, ordinary requests run in order on one worker, so a query
  blocked on a paused target's row lock no longer delays Stop.
- Preview checks DEBUG access (owner, object DEBUG or DEBUG ANY
  PROCEDURE). As a backstop, the first wrapper stop arms a native
  breakpoint in the target and aborts if that fails or the next stop is
  elsewhere, so Start can never run the routine to completion.
- Review follow-ups: longer call/event timeouts and status polling in
  live tests, honest resources state for Stop during preparation,
  cancelling read-only requests no longer stops the session, 30-minute
  lease while paused, pruned start reservations, single-use previews,
  clear message for missing/invalid routines, CHANGELOG entry and
  23ai/26ai validation note.
- Live tests: Stop with a conflicting execute_query, non-owner with and
  without DEBUG.
@lejyfps
lejyfps force-pushed the feat/1411-routine-debugger branch from 05341d1 to a444c7a Compare November 17, 2026 22:50
@lejyfps

lejyfps commented Nov 17, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough re-review! Both P1s and the non-blocking follow-ups are addressed in a444c7a.

P1: Ordinary requests block Stop

  • stdin is read on the main thread; cancel and routine_debug are dispatched immediately. Ordinary requests go to a single sequential worker, so their ordering is preserved.
  • On EOF, debug sessions are released first so a queued query blocked on their locks can finish, then the worker is drained.
  • New live test: pause after an UPDATE, send a conflicting execute_query, then Stop. It asserts Stop answers within 5 s and that the queued query completes afterwards.

P1: Start without object DEBUG runs the routine to completion

  • Preview now checks DEBUG access (owner, object DEBUG incl. via PUBLIC/session roles, or DEBUG ANY PROCEDURE) and fails with a clear message before anything executes.
  • Backstop: at the first wrapper stop, a native breakpoint is armed on the first executable line of the target. If that fails, or the next stop is not in the target, execution is aborted.
  • New live test with a non-owner account: EXECUTE only → preview refused and nothing committed; after GRANT DEBUG → stops at entry, and Stop leaves nothing committed.

Follow-ups

  • Timeouts: call timeout 3 s → 15 s, DBMS_DEBUG wait 1 s → 2 s; live tests poll status after continue instead of asserting on the first reply.
  • Stop during preparation now reports resources: unknown; status afterwards reports released.
  • Cancelling a read-only request (status, read_stack, …) no longer stops the session; only start/continue/step interrupt.
  • Lease: 120 s while running, 30 min while paused at a stop.
  • started reservations are pruned after an hour once their session is gone.
  • A preview is single-use and can't be started again under a new session ID.
  • Missing/invalid routines now say so instead of "no data found".
  • CHANGELOG [Unreleased] entry added; README and preview warning now say validated on 23ai/26ai, 19c untested.

The new live tests are only exercised in CI (no local Oracle instance on my side), so I'll keep an eye on the live-db-integration job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease:alpha Release channel for the version suggestion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants