Skip to content

fix(server): do not return database errors from the skill endpoints - #494

Merged
BaaRai merged 6 commits into
BaaRai:mainfrom
Coff0xc:fix/skill-db-error
Nov 26, 2026
Merged

BaaRai merged 6 commits into
BaaRai:mainfrom
Coff0xc:fix/skill-db-error

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Skill usage and missing-skill stats returned the database driver error to the client. Those failures are logged on the server and the client receives a fixed message. The server package compiles. Rebased onto current main; the only merge conflict was CHANGELOG.md.

Recent skill calls and missing-skill stats put pgx text in the HTTP body.
The server now logs that error and returns a fixed message.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:43

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

kolli-karthik-accenture pushed a commit to kolli-karthik-accenture/bounded that referenced this pull request Nov 22, 2026
kubernetes-client/python#2786 - fix(stream): handle tuple _request_timeout
  - 3 files, score: 77/100, 2 critical issues

kubernetes-client/python#2762 - Regenerate Python clients with shared legacy
  - 30 files, score: 77/100, 13 critical issues

kubernetes-client/python#2698 - Support _request_timeout in dynamic client
  - 2 files, score: 66/100, clean code

BaaRai/ARTEX#494 - fix(server): do not return database errors
  - 2 files, score: 68/100, 1 security issue

torvalds/GuitarPedal#60 - WebMIDI: keep queued BLE writes
  - 2 files, score: 77/100, clean code

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

PR #494 — fix(server): do not return database errors from the skill endpoints

  • Head checked: 068a4630 (068a463), detached worktree, matches GitHub.
  • Base: main @ 94757c5d (merge base = 94757c5). GitHub: MERGEABLE, 2 files, +5/-2.
  • Verdict: request changes. The two handlers the PR touches are fixed, but the PR title covers "the skill endpoints", and two of them still return driver text (finding 1).

What the PR changes

server/server_mgmt.go fsSkillUsage and fsMissingSkills: a DB error is now
logged with log.Printf("... %v", err) and the client gets a fixed string
(failed to load skill usage / failed to load missing skills).

Path trace (every path the new code adds)

  • GET /api/skills/{name}/usage -> fsSkillUsage -> pg.RecentSkillCalls
    (db/skill_usage.go:164). Errors come back raw from d.Query / rows.Scan /
    rows.Err (no %w, no wrapping at all). Response: fixed string. Log: driver text.
  • GET /api/skills/missing -> fsMissingSkills -> pg.MissingSkillStats
    (db/skill_usage.go:106), which also calls archivedTaskAggregates
    (db/task_archive_aggregate_stats.go:21): a json.Unmarshal error from an archived
    row can also reach the log. Response: fixed string.
  • What the log line can contain: pgx PgError.Error() is ERROR: <msg> (SQLSTATE x);
    it does not print the query text, the DSN, or Detail (row values). A connect
    failure prints failed to connect to `user=... database=...` host:port; no password.
    A json.Unmarshal error prints the offending type/offset, not the row.
  • name in the log line is gated by validSkillName ([a-z0-9-] plus Unicode
    letters/digits, max 64 runes), so no log-line injection through the path value.
  • s.pg(w) nil path (503) is unchanged and returns a fixed message.

Findings

  1. blocking for the stated scope — same leak remains on the other DB-backed skill endpoints; this is why I am not approving.
    server/server_mgmt.go:2034 (pgSkillVisibility, GET skill visibility) and
    server/server_mgmt.go:2055 (pgToggleSkillVisibility) still do
    writeErr(w, 500, err.Error()). Scenario: PG pool closed or a query fails ->
    the client receives the driver string. The PR title says "the skill endpoints";
    either extend the fix to these two or narrow the title/CHANGELOG line.
    Reproduced: throwaway test with a closed pool returned
    {"error":"sql: database is closed"} for pgSkillVisibility, while the two fixed
    handlers returned the fixed strings.
  2. should — no regression test. A test that drives both handlers with a failing
    DB (closed pool is enough) and asserts the body is the fixed string would keep
    this from coming back. Read only.
  3. nit — the pattern writeErr(w, 500, err.Error()) is used ~50 more times in
    server_mgmt.go (non-skill handlers). Out of scope here; worth a tracked follow-up
    if the goal is "no driver text in responses". Read only.
  4. nit — the server log still carries full driver text (including DB user and
    database name on connect failures). That is the intended place for it; noting only
    so log shipping is considered. Read only.

Tests run (throwaway review Postgres container, ARTEX_PG_DSN set)

Command Exit
go test -count=1 -run TestZZReview494SkillErrors -v ./server/ (throwaway test, deleted after) 0
go test -count=1 -run TestSkillUsageLedger -v ./db/ 0 (PASS, not skipped)
go test -count=1 -run Skill ./server/ 0
go vet ./server/ 0
gofmt -l server/server_mgmt.go 0, no output

Throwaway test output (abridged):

  • usage: 500 {"error":"failed to load skill usage"}
  • missing: 500 {"error":"failed to load missing skills"}
  • visibility (not in PR): 500 {"error":"sql: database is closed"}
  • server log: [skills] recent calls for zz: sql: database is closed,
    [skills] missing skills: sql: database is closed

Note: a first run failed with "connection refused" because the review DB container
had stopped; it was started again and the run above is the clean one.

Not verified

  • A real PostgreSQL error (e.g. missing table, constraint) through these handlers;
    only the closed-pool error was exercised. pgx error formatting was read, not run.
  • Full ./server/ and ./db/ suites were not run, only the targeted tests.
  • Web UI handling of the new fixed messages (no web change in this PR).

Skill usage and missing-skill stats already returned a fixed message. Skill
visibility and its toggle still sent err.Error() to the client. Those two
now log the driver text and return a fixed message. A closed pool test
covers all four handlers.
@Coff0xc

Coff0xc commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing and reopening to retrigger CI. The review commits did not start a workflow run.

@Coff0xc Coff0xc closed this Nov 23, 2026
@Coff0xc Coff0xc reopened this Nov 23, 2026
@5P34R

5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review notes

Looks good to merge. It's correct for the 4 skill endpoints it touches, and the test covers it.

There are still about 250 writeErr(w, 500, err.Error()) sites elsewhere in server/. Worth a follow-up issue if the goal is to stop leaking DB errors everywhere.

BaaRai added a commit to nirlep1204/ARTEX that referenced this pull request Nov 26, 2026
BaaRai added a commit to nirlep1204/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/skill-db-error branch from 83ad4bc to 3fb3ac5 Compare November 26, 2026 22:24
BaaRai added a commit to nirlep1204/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/skill-db-error branch from 3fb3ac5 to d844841 Compare November 26, 2026 22:40
BaaRai added a commit to nirlep1204/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/skill-db-error branch from d844841 to 6863948 Compare November 26, 2026 22:56
BaaRai added a commit to nirlep1204/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/skill-db-error branch from 6863948 to 0d66d6f Compare November 26, 2026 23:13
@BaaRai
BaaRai merged commit 6aa60cf into BaaRai:main Nov 26, 2026
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.

4 participants