Skip to content

fix(sensor): percent-encode the opencode database URI - #200

Open
rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/sensor-opencode-db-uri-escaping
Open

rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/sensor-opencode-db-uri-escaping

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 19, 2026 •

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related issue: N/A (found by reading the code; reproduced on main at 6b33dff)

What changed?
Build the URI with Path(db_path).resolve().as_uri() + "?mode=ro" (same as CodexParser), via a small _read_only_uri helper used in both places.

Why?
Sensor/adr_sensor/parsers/opencode_parser.py:163 and :227 open sqlite3.connect(f"file:{db_path}?mode=ro", uri=True) without escaping. If the data dir path (e.g. $XDG_DATA_HOME or home) contains '#', '?' or '%', SQLite reads another path: opencode history is never found (backend None, 0 events), and with '#' the ?mode=ro is cut off so SQLite creates an empty stray file (e.g. .../data next to .../data#1).

How did you test it?

  • Reproduction: scratchpad/oc_uri.py: main -> data#1 None 0 ['data', 'data#1'] and 100%data None 0; branch -> data#1 sqlite 1 ['data#1'], 100%data sqlite 1. New parametrized test test_reads_database_under_path_with_uri_special_characters (#, %, ?): main 3 failed; branch 3 passed.
  • Test suite: py3.14 611 passed; py3.9 611 passed.
  • Not tested: Windows paths (as_uri yields file:///C:/..., which SQLite accepts, but not run on Windows here).

Potential risks
The change only affects the input described above; other paths go through the same code as before, and the component's existing tests pass.

The opencode parser opened its database with f"file:{path}?mode=ro" and
uri=True without escaping the path. A data directory containing '#', '?'
or '%' made SQLite read a different path: the database was never found,
and with '#' the "?mode=ro" suffix was cut off so SQLite created an empty
stray file next to the real directory. Build the URI with Path.as_uri(),
as the Codex parser already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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