Skip to content

Context7 response cache and topic cache keys raise UnicodeEncodeError for a library id or query with a lone surrogate #756

Open

Description

@antonwolfy

Two more cache keys hash text with .encode(): Context7Client.get_library_docs (dokimi/dokimi/mcp/context7.py:137, f"{library_id}:{query}:{max_tokens}") and RagasSeedExtractor.extract_topics (dokimi/dokimi/questions/ragas_seed.py:100, f"{library_id}:{max_topics}:{max_tokens}"). The library id comes from --context7-id or, for a local: doc source, from the path; the query is a question text. Repro, with a cache directory set: Context7Client(cache_dir=d).get_library_docs('org/n\udcff', 'q') and get_library_docs('org/x', json.loads('"n\\ud800"')) raise UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position N: surrogates not allowed at context7.py:137; RagasSeedExtractor(mcp_client=..., cache_dir=d).extract_topics(library_id='local:n\udcff', library_name='n', max_topics=3) raises at ragas_seed.py:100. The second one also stops EvaluationPipeline._generate_questions end to end for a local: doc source whose directory name has a non-UTF-8 byte, after the pipeline's own topics-cache key (#716) is fixed. Fix: os.fsencode(...) for the library id (a path or argv value) and .encode('utf-8', 'surrogatepass') for the query (question text from JSON), which keeps every key that encodes today unchanged.

Found while fixing #716. The fix's PR is #761.

Activity

  1. self-assigned this
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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