bug: Source capture accepts Unicode and space-containing IDs that exact read rejects
Describe the bug
POST /v1/sources/content accepts Source IDs containing Chinese characters or spaces, returns HTTP 202 with the exact Source reference and a journal position, and persists the Source. However, GET /v1/scopes/{scope_id}/sources/content/{source_id} rejects those same IDs with HTTP 422, including when the path is correctly percent-encoded.
This breaks exact readback of an accepted Source through the public HTTP API. It reproduces with both real SQLite and real OceanBase, and survives a Server restart.
Reconfirmed on the original regression commit bcdac7322aa2cfadb10c3da3ac1c353ca91ffbef and upstream master at 40bd8481809dedd2ad34c877496dbe89f679c6f6 on October 16, 2026.
Steps to reproduce
-
From a checkout, install the locked dependencies and start a fresh local SQLite Server. No model provider or API key is needed:
uv sync --locked --group notebooks POWERCONTEXT_HOME=/tmp/pc-source-repro-home \ POWERCONTEXT_SERVER_DATABASE_KIND=sqlite \ POWERCONTEXT_SERVER_DATABASE_URL=sqlite+aiosqlite:////tmp/pc-source-repro.sqlite \ uv run --locked --no-sync powercontext server run --no-env-file --host 127.0.0.1 --port 8765 -
In another terminal, run:
from urllib.parse import quote from uuid import uuid4 import httpx with httpx.Client(base_url="http://127.0.0.1:8765", trust_env=False) as client: scope = client.post("/v1/scopes", json={ "title": "Source identity regression", "summary": "Synthetic test data", "idempotency_key": uuid4().hex, }) scope.raise_for_status() scope_id = scope.json()["scope_id"] for source_id in [ "ascii-source-731", "中文来源-731", "folder/source-731", "source with space-731", ]: capture = client.post("/v1/sources/content", json={ "scope_id": scope_id, "source_id": source_id, "content": "Synthetic Source identity round-trip regression evidence.", }) capture.raise_for_status() saved = client.get( f"/v1/scopes/{scope_id}/sources/content/{quote(source_id, safe='')}" ) print(repr(source_id), capture.status_code, saved.status_code) if saved.is_error: print(saved.json())
Expected behavior
A Source identity accepted by capture must be usable through its supported exact read path. If Unicode and spaces are supported, exact GET should return the captured content. If some identities are intentionally unsupported, capture should reject them before accepting or persisting a Source.
The write/read contract should agree across OpenAPI, HTTP validation, and the client. A fix should also define readback compatibility for already accepted records.
Actual behavior
The following results were identical on both tested commits and both actual database backends:
| Source ID | Capture | Exact GET | Exact GET after Server restart |
|---|---|---|---|
ascii-source-731 |
202 | 200 | 200 |
中文来源-731 |
202 | 422 | 422 |
folder/source-731 |
202 | 200 | 200 |
source with space-731 |
202 | 422 | 422 |
For the Chinese ID, capture returns:
{"status":"accepted","source":{"name":"content","source_id":"中文来源-731"},"position":2}
Exact GET returns:
{"error":{"code":"invalid_request","message":"The request violates the API contract.","details":{"errors":[{"type":"string_pattern_mismatch","loc":["path","source_id"],"msg":"String should match pattern '^[\\x21-\\x7E]+$'"}]}}}
Direct inspection of the fresh SQLite pc_sources table confirmed that all four synthetic IDs were stored with journal positions 1–4. ASCII and slash-containing controls return their original content through HTTP, including after restart. Percent-encoding does not resolve the Unicode/space cases.
The contract mismatch is visible in the current source:
- CaptureContentSourceRequest limits
source_idlength without an ASCII-only pattern. - Exact Source GET requires
^[\x21-\x7E]+$; the Server applies this restriction to the decoded path parameter.
Environment
- PowerContext baseline:
1.3.1.dev61+gbcdac7322/bcdac7322aa2cfadb10c3da3ac1c353ca91ffbef. - Also executed the Server from an isolated checkout of upstream
40bd8481809dedd2ad34c877496dbe89f679c6f6, using itssrconPYTHONPATH.pyproject.tomlanduv.lockare identical between these commits. - Linux x86_64; Python 3.12.14; SQLite 3.53.1; OceanBase CE 4.3.5.4 (MySQL mode).
- FastAPI 0.139.2, Pydantic 2.13.4, HTTPX 0.28.1.
- Real loopback TCP HTTP servers and isolated databases; no mocks, ASGI test transport, or LLM calls. Test-owned OceanBase databases were dropped after execution.
could i try it?