Skip to content

Server management API: active queries, blocked sessions and lock waits #573

Backlog

Description

@MPCoreDeveloper

Summary

Operate needs to show live activity, but the server currently exposes only health and Prometheus metrics — not the actual active-query, blocked-session or lock-wait state.

Needed

  • Server endpoints/streams (gRPC + REST) that expose:
    • currently running queries (session, database, start time, elapsed, SQL preview),
    • blocked sessions and what they wait on,
    • lock waits / lock owners.
  • Respect RBAC (Admin-only) and avoid leaking SQL text of other users where inappropriate.

References

  • SharpCoreDB roadmap "Live connection monitor (active queries, blocked sessions, lock waits)".
  • SCDMS: docs/product-ui-roadmap.md §7 Operate, §13 Serverbeheer.

Activity

  1. added 2 commits that reference this issue on Dec 6, 2026
  2. MPCoreDeveloper commented on Dec 6, 2026

    @MPCoreDeveloper
    OwnerAuthor

    Shipped (first slice, master 6fc8b93 / PR #583)

    Verified against the code first: the server exposed health and metrics only — DatabaseController had no
    management route, SessionManager had no in-flight SQL, and nothing tracked a database's transaction holder. So the
    report was accurate; this is what now exists.

    ManagementActivityRegistry (SharpCoreDB.Server.Core.Observability) — bounded, in-memory, lossy:

    What Content
    active queries session, database, user, SQL preview (160 chars, flattened to one line), start + elapsed
    transaction conflicts the session that was refused BeginTransaction, the database, the user, the holder (when identifiable), the timestamp
    • An entry exists only while the call executes — the scope is disposed with the request, so an idle server reports
      nothing.
    • The conflict queue keeps the last 50; nothing is durable (that is Security audit event stream (RLS policy hits, failed auth attempts) #576).
    • blockedBySession is filled only when another session on the same database actually holds the transaction; it is
      left empty rather than guessed.

    Recorded on every server path: gRPC ExecuteQuery, gRPC ExecuteNonQuery, REST POST /api/v1/query, REST
    POST /api/v1/execute, and the BeginTransaction FailedPrecondition branch.

    Exposed as GET /api/v1/management/activity — admin only, because the payload names sessions, users and SQL text.
    Documented in docs/server/REST_API.md › Management: live activity (with the exact JSON), listed in
    docs/FEATURE_MATRIX.md, recorded in docs/CHANGELOG.md including the deliberate gaps.

    Tests: ManagementActivityTests — 6 cases (entry for the whole scope, truncation, single-line flattening, conflict
    with holder, bounded queue, empty-but-well-formed snapshot). Server suite 307/0; Sonar, coverage, codecov and the
    three platform builds green on the PR.

    What still keeps this open

    1. No gRPC RPC for the snapshot — it needs a proto message + method, the DatabaseService override, the client
      call, and an entry in GrpcCapabilityContract (which GrpcCapabilityContractTests would then enforce).
    2. No durable history and no retention/backpressure policy — that is the audit stream (Security audit event stream (RLS policy hits, failed auth attempts) #576); this registry is
      deliberately lossy.
    3. No per-query plan or lock introspection. The engine has exactly one storage transaction per database
      (Server transactions are stubs: Begin/Commit/Rollback accept the call but every statement autocommits #560), so a "lock wait" is a transaction conflict; there is no queue to report and this does not invent one. If
      per-session transactions land (Per-session transaction isolation: two sessions cannot hold independent transactions (storage is single-transaction) #564), this is the place that has to grow a real wait list.

    Where the docs changed with it

    docs/server/REST_API.md (new section + payload), docs/FEATURE_MATRIX.md (row), docs/CHANGELOG.md (Added +
    Not in this slice). No gRPC contract change was made, so
    docs/server/GRPC_CAPABILITY_MATRIX.md
    needed no edit — and that is stated in the REST section so nobody goes looking for an RPC that does not exist.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions