Skip to content

bug(code): rendered code evidence includes checked_at, so identical evidence renders differently on every prepare #2365

Closed

Description

@jasper-yl

Describe the bug

_render in src/powercontext/builtin/runtime/prepared_code.py:123 writes checked_at into each citation line of the prepared code context. checked_at is set to the current time on every code query (builtin/code/service.py:427). So when nothing in the repository has changed, two prepares of the same evidence still produce different text.

The text is included in prompts. A client that prepares and injects context on every model request, such as the Rust gateway proposed in #2307, therefore changes the prompt prefix on every request, and provider prompt caching stops working from the injection point onward. Hooks that inject once per user prompt are much less affected, because the injected text then stays fixed in the conversation history.

Steps to reproduce

  1. Configure code indexing for a scope and index a repository.
  2. Call POST /v1/context/prepare twice with the same query and include_code: true.
  3. Compare the two BEGIN_POWERCONTEXT_CODE_V1 blocks.

Expected behavior

The same evidence (same fingerprint, path, file hash, line range, and snippet hash) renders to identical bytes. Freshness can stay in the structured response, outside the prompt text.

Actual behavior

The blocks differ only in checked_at. We measured this with a gateway that injects code evidence on every Codex request on SWE-bench Pro: the prompt-cache hit rate dropped from about 85% to about 40%, and total cost went up. After removing checked_at from the rendered citation (keeping it in the structured candidate), the hit rate returned to the same level as without code injection.

Suggested fix: drop checked_at from the rendered citation. The fingerprint and hashes already identify the evidence exactly.

Related: #2040 (token and latency costs along the context chain).

Environment

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Activity

  1. moved this from Todo to In progress in PowerContexton Nov 1, 2026
  2. added a commit that references this issue on Nov 1, 2026
    ff0c6e4
  3. moved this from In progress to Done in PowerContexton Nov 2, 2026
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions