Skip to content

fix(graph-query): sync CIClient.cypher params parity + document workspace binding#29

Merged
colombod merged 1 commit into
mainfrom
fix/graph-query-sync-params-and-docs
Jun 4, 2026
Merged

fix(graph-query): sync CIClient.cypher params parity + document workspace binding#29
colombod merged 1 commit into
mainfrom
fix/graph-query-sync-params-and-docs

Conversation

@colombod

@colombod colombod commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Delivered — merged to main. Related: #30 (dtu test collection-safety fix split out from this work).

Summary

  • Sync/async parity: CIClient.cypher() (synchronous) now accepts an optional params: dict[str, Any] | None = None and forwards it in the /cypher POST body (previously hardcoded to {}). The async client and the graph_query tool already did this on main; this closes the remaining gap so parameterized Cypher works through the sync client too. Additive and backward-compatible (defaults to {}).
  • Docs accuracy: the graph_query tool's params input-schema description now documents the server's actual workspace handling — the effective workspace is bound into the query as the $workspace parameter; a specific (non-*) workspace overrides any workspace key supplied inside params, while * (all workspaces) passes a caller-supplied workspace key through unchanged.

Background

This was discovered while reviewing an out-of-tree fork's PR. The core params end-to-end work already landed on main for the async path, but the synchronous CIClient.cypher() still dropped params. The workspace-precedence note was verified directly against the server handler (context_intelligence_server/main.py:214-216): params = dict(body.params); if body.workspace is not None and body.workspace != "*": params["workspace"] = body.workspace then session.run(body.query, params).

Test Plan

  • New tests: 2 sync-client (test_cypher_forwards_params, test_cypher_default_params_is_empty_dict)
  • tests/test_client.py: 52 passed
  • Full top-level suite: 656 passed (the only collection error is an unrelated environment permission issue under tests/dtu/, not touched by this change)
  • modules/tool-graph-query suite: 29 passed
  • ruff lint + format clean on all changed files

…pace binding

The async AsyncCIClient.cypher() and the graph_query tool already forward `params` on main, but the SYNCHRONOUS CIClient.cypher() still hardcoded `params: {}` and did not accept a params argument. This brings the sync client to parity (accepts `params: dict[str, Any] | None = None`, forwards `params if params is not None else {}`), matching the async implementation exactly.

Documents verified server behavior in the graph_query tool's `params` input-schema description: the effective workspace is bound into the query as the $workspace parameter; a specific (non-"*") workspace overrides any `workspace` key supplied in params, while "*" (all-workspaces) leaves a caller-supplied `workspace` key untouched. (Verified against the server handler at context_intelligence_server/main.py:214-216 in microsoft/amplifier-context-intelligence.)

Adds 2 sync-client regression tests (params forwarding + backward-compat empty-dict default).
@colombod colombod merged commit 6815cb5 into main Jun 4, 2026
9 checks passed
@colombod colombod deleted the fix/graph-query-sync-params-and-docs branch June 4, 2026 14:27
colombod added a commit that referenced this pull request Jun 29, 2026
Process-level singleton AzureCliCredential with lock-free in-memory cache
keyed by scope. Cache strategy:
- Single TokenCredential per process (no repeated az subprocess overhead)
- Dict read on cache hit (~0.002 ms), threading.Lock only on refresh
- Fail-loud on token refresh; reset() seam for test/switch scenarios
- AMPLIFIER_CONTEXT_INTELLIGENCE_TOKEN_REFRESH_MARGIN_S env var for TTL tuning

Eliminates ~487-913 ms-per-request az subprocess cost on hot path.
Measured on real EntraTokenAuth against live az:
  - mount / build_auth_strategy(entra) x8: first 63.9 ms, rest 0.0015 ms
  - headers() hot path: first 914 ms (real az), cached 0.0017 ms (~500,000x)
  - 8 in-process subsessions sharing singleton: ONE az spawn (437 ms) + 7
    cached (~0.0009 ms each) = 437 ms total (~9x over isolated, grows with N)
  - cached bearer token still validates (HTTP 202 from server)

Council-approved conditional GO; implements all five conditions:
  - Threading.Lock (loop-agnostic, not asyncio.Lock per COE)
  - Scope + tenant keying (TB)
  - Fail-loud on refresh (ROB + TB + UA)
  - reset() seam + fake-credential injection (UA)
  - Re-measured against real az (ROB's merge gate, GREEN)

Stale 'SDK refreshes' comment replaced with justification: measurement
proves the reversal necessary, and future engineers have evidence.

Relates to 146c8ea (dual auth design), b0f82e4 (entra wiring),
fc964eb (PR #29 server validation)

Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
colombod added a commit that referenced this pull request Jun 29, 2026
Process-level singleton AzureCliCredential with lock-free in-memory cache
keyed by scope. Cache strategy:
- Single TokenCredential per process (no repeated az subprocess overhead)
- Dict read on cache hit (~0.002 ms), threading.Lock only on refresh
- Fail-loud on token refresh; reset() seam for test/switch scenarios
- AMPLIFIER_CONTEXT_INTELLIGENCE_TOKEN_REFRESH_MARGIN_S env var for TTL tuning

Eliminates ~487-913 ms-per-request az subprocess cost on hot path.
Measured on real EntraTokenAuth against live az:
  - mount / build_auth_strategy(entra) x8: first 63.9 ms, rest 0.0015 ms
  - headers() hot path: first 914 ms (real az), cached 0.0017 ms (~500,000x)
  - 8 in-process subsessions sharing singleton: ONE az spawn (437 ms) + 7
    cached (~0.0009 ms each) = 437 ms total (~9x over isolated, grows with N)
  - cached bearer token still validates (HTTP 202 from server)

Council-approved conditional GO; implements all five conditions:
  - Threading.Lock (loop-agnostic, not asyncio.Lock per COE)
  - Scope + tenant keying (TB)
  - Fail-loud on refresh (ROB + TB + UA)
  - reset() seam + fake-credential injection (UA)
  - Re-measured against real az (ROB's merge gate, GREEN)

Stale 'SDK refreshes' comment replaced with justification: measurement
proves the reversal necessary, and future engineers have evidence.

Relates to 146c8ea (dual auth design), b0f82e4 (entra wiring),
fc964eb (PR #29 server validation)

Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
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.

1 participant