Skip to content

feat(pi): chain the proxy in front of an existing base URL - #1010

Merged
amiddavid merged 2 commits into
mainfrom
feat/pi-chain-mode
Nov 10, 2026
Merged

amiddavid merged 2 commits into
mainfrom
feat/pi-chain-mode

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Behavior change

  • Who it affects: only Pi users whose models.json already sets baseUrl for anthropic or openai (a company gateway, for example).
  • Old: /context-guru setup refuses with base_url_already_set. Nothing changes.
  • New: setup asks one question with three answers: chain (recommended), replace, or don't change anything. Print mode and a shell setup without --on-conflict still change nothing.
  • How to undo: /context-guru uninstall (or the reset command) puts the old baseUrl back.
  • Approved by the developer (David Amid) in session on 2026-11-10.

Summary

A user behind a gateway can now put the proxy in front of that gateway. The gateway still gets every request, on the same path, with the same headers and key.

What changed

  • Chain: Pi -> proxy -> the existing endpoint. The proxy starts with --anthropic-upstream / --openai-upstream set from the old baseUrl. The provider entry keeps headers, apiKey and every other field. Only baseUrl changes.
  • Replace: Pi -> proxy -> the public API. The question warns that this usually breaks the gateway's auth.
  • Per provider: only a provider with a foreign baseUrl needs the decision. The other one is routed as usual.
  • Plan output: setup --plan prints consent_question_chain + confirm_command_chain and consent_question_replace + confirm_command_replace. No plain consent_question on that path.
  • Refused cases: chain is not offered for a URL the proxy cannot reproduce. Setup then offers only replace or no change, and prints chain_refused=<provider>:<reason>:
    • an OpenAI baseUrl that does not end in /v1 (openai_path_not_v1)
    • a URL with a user name or password (credentials_in_url), a query (query_in_url), or not http(s) (not_an_http_url)
    • a URL that points at this proxy's own port (points_at_this_proxy)
  • Kept on re-render: the install record stores upstreams. configure, update and a new setup start the proxy with them. proxy.yaml names them in a comment line.
  • Status: prints routes=anthropic -> proxy -> https://gw...; openai -> proxy -> api.openai.com. The extension shows it.
  • Restore: uninstall and the reset command put back the gateway URL. A gateway the user set AFTER our route is now recorded again, so uninstall restores that value, not the older one.
  • Extension: /context-guru setup shows the choice with ctx.ui.select. The Sign in with ChatGPT field removal skips a chained openai provider, because Pi sent those fields to that endpoint before.
  • Review note from feat(pi): add a Pi package that routes Anthropic through context-guru #977 (our own URL on an old port): origin/main already treats it as ours through own_urls. This PR adds a test only.
  • README: new section "An existing baseUrl", and the Limits section.

How it was tested

  • python3 -m unittest discover -s scripts: 46 tests pass (16 new, in ChainMode). They cover the paired plan lines, chain, replace, abort, refusal without the flag, a one-provider conflict, unchainable URLs, uninstall and the reset command restoring the gateway, and configure keeping the upstream.
  • node --test tests/*.test.ts: 9 tests pass (2 new, for conflictPrompt).
  • Live check in a sandbox HOME (Pi 1.5.0, proxy 0.7.1, fake keys, a local fake gateway that logs requests):
    • Anthropic baseUrl http://127.0.0.1:18931/corp/anthropic -> the gateway got POST /corp/anthropic/v1/messages with x-api-key and the custom x-corp-tenant header.
    • OpenAI baseUrl http://127.0.0.1:18931/corp/openai/v1 -> the gateway got POST /corp/openai/v1/responses with Authorization: Bearer ... and x-corp-tenant.
    • Uninstall restored models.json byte-for-byte equal as JSON.
    • The live check started the proxy as a child process, not as a launchd job, so it did not touch the real LaunchAgents.

Data dependence

None new. This is routing only: the proxy gets a different upstream URL. No row in docs/data-dependence.md changes.

Open questions

  • The proxy drops the request's query string on /anthropic/v1/messages (Pi sends ?beta=true). That is the same today for api.anthropic.com, so this PR does not change it. A gateway that needs the query would see a difference.
  • A baseUrl on one model (models.<id>.baseUrl) wins over the provider's. Setup does not read it, so that model goes direct, as before.

Technical notes

  • The proxy config YAML has no upstream key, and it refuses unknown keys. The upstream goes on the command line: --anthropic-upstream and --openai-upstream (cmd/context-guru-proxy/main.go).
  • Path join: the proxy sends upstream + "/v1/messages" and upstream + "/v1/responses" (proxy/proxy.go Mux, doUpstream). Pi's SDKs send baseUrl + "/v1/messages" (Anthropic) and baseUrl + "/responses" (OpenAI). So the Anthropic upstream is the baseUrl as it is, and the OpenAI upstream is the baseUrl without /v1.
  • Headers: copyHeaders forwards every client header except hop-by-hop headers, x-context-guru-* and Cookie. The service sets no ANTHROPIC_API_KEY / OPENAI_API_KEY, so the proxy injects no key of its own.
  • No Go code changed.

🤖 Generated with Claude Code

When Pi's models.json already sends anthropic or openai to another
endpoint (a company gateway), setup now asks one question: chain,
replace, or change nothing. It used to refuse.

- chain: Pi -> proxy -> the existing endpoint. The proxy gets the old
  baseUrl as --anthropic-upstream / --openai-upstream. An OpenAI baseUrl
  must end in /v1. Other URLs that the proxy cannot reproduce are refused.
- replace: Pi -> proxy -> the public API. The question warns that this
  usually breaks the endpoint's auth.
- setup --plan prints paired consent_question_* and confirm_command_*
  lines. setup without --on-conflict still refuses on a conflict.
- The install record keeps the upstreams, so configure, update and a new
  setup start the proxy with them. proxy.yaml names them in a comment.
- status prints the routes. Uninstall and the reset command restore the
  old baseUrl. A gateway set after our route is now what they restore.

Approved by the developer (David Amid) in session on 2026-11-10.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 76051d87d3c4 approve

Verdict: approve

Findings

None. I could not confirm a defect. Details of what I tried are under "What I checked".

Non-blocking

  • pi-package/extensions/context-guru.ts:81 — The dialog title shows existing_base_url as raw JSON, for example {"anthropic":"https://gw.example"}. A person reads JSON. Print the provider names and URLs in plain words instead.
  • pi-package/extensions/context-guru.ts:153 — The chained-OpenAI guard (install?.upstreams?.openai) has no test. The other request-shaping rule (forChatGPTSignIn) is a pure, tested helper. Extract the guard the same way, or state why not.
  • pi-package/scripts/pi_plugin.py:554 — When both providers clash and one URL is not chainable, chain is refused for both. The person cannot chain one and replace the other; replace then applies to both. A coarse choice, and the consent text does disclose it. Worth a README line.
  • A recorded chain persists while the provider's baseUrl in models.json holds our URL. If the user later deletes that key, setup asks nothing and the proxy keeps the --anthropic-upstream flag. Plan mode and /context-guru status do show the route. Uninstall is the only way out. Acceptable, but undocumented.
  • pi-package/scripts/pi_plugin.py:506 — The chain consent text says the keep-alive pings "use your own quota on each provider". With a chain, the quota spent is the gateway's. The pings are disclosed; only the wording is off.
  • pi-package/README.md (chain section) — "The proxy removes only its own x-context-guru-* headers, Cookie and hop-by-hop headers." The proxy also strips Accept-Encoding on the forward path (proxy/proxy.go:92, counttokens.go). Transport necessity; the word "only" is slightly too strong.

What I checked

  • The full diff of all six files, and the unchanged code around each change (pi_plugin.py, models_route.py, context-guru.ts, both test files, README.md).
  • Path arithmetic of chain mode. Pi appends /v1/messages (Anthropic) and /responses (OpenAI) to a baseUrl; the proxy appends /v1/messages, /v1/responses, /v1/chat/completions and /v1/messages/count_tokens to its upstream (proxy/proxy.go:560-591, counttokens.go:14). chain_upstream makes both sides equal, including the trailing-slash and /v1 cases the tests list. The OpenAI /v1 rule is the right refusal for a URL the proxy cannot reproduce.
  • The proxy flags exist and keep their meaning: --anthropic-upstream / --openai-upstream (cmd/context-guru-proxy/main.go:97-98). With no key configured, setUpstreamAuth only scrubs our token and the client's Authorization / x-api-key pass through (proxy/proxy.go:2702), so a gateway's key arrives. The README header claim matches copyHeaders (proxy/proxy.go:3116).
  • chain_upstream refusals: bad scheme, missing host, whitespace, userinfo, query, fragment, bad port (ValueError is caught), and the self-loop check against the chosen port. A loop through another host name would 404 (the proxy serves /anthropic/..., not /v1/messages), not cycle.
  • The models_route.install re-record rule against every prior test scenario: first install, re-run on a new port with ours, a key the user changed, an entry we created, and the new "gateway set after our route" case. The old keep-first-record behavior is preserved for URLs that are ours; only a foreign value re-records. Restore semantics stay consistent.
  • The setup decision flow: plan prints paired questions and no plain one; no choice refuses with a note; abort changes nothing; chain refuses unchainable URLs before any write; replace pops only the clashing providers. The record, proxy config comment, service command, configure, update, and a new setup all carry the upstreams, and the tests assert each.
  • The extension: conflictPrompt option/answer mapping (KEEP has no answer, so a KEEP or cancelled select changes nothing), the no-UI paths, and the chained-OpenAI skip of the ChatGPT field removal. The skip is correct: before setup Pi sent those fields to that endpoint and it accepted them.
  • Uninstall and the reset hatch restore the gateway baseUrl (both tested, including the real reset.sh run).
  • Tests read in full; the new Python and Node tests match the code they cover, and pi_test.go runs both suites in CI. I did not run them (live tests not approved).
  • Repo rules: fail-open and reversibility are untouched (no library or proxy change); no component or data-dependence change, so docs/data-dependence.md needs no row.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 76051d87d3c4 blocking

Verdict: blocking

Findings

  1. pi-package/scripts/pi_plugin.py:583 — chain mode promises the cache strategy, but keep-alive pings cannot carry a gateway's custom auth header

    • What fails: a user chains a provider to a gateway that needs a header from models.json headers on every request (a tenant tag like x-corp-tenant, or an Azure-style api-key header — the PR's own test fixture and live check use exactly this shape). Every keep-alive ping lacks that header, so the gateway answers 401. After 3 failed pings the route breaker trips for one hour, then the cycle repeats. Keep-alive stays silently off. The chain consent question (pi_plugin.py:506-510) still promises "Cache strategy auto sends small keep-alive requests", and nothing tells the user it cannot work. A corporate gateway may also count the failed auth attempts.
    • Proof: a ping carries only the PingHeaders allow-list (keepalive/dispatch.go:6-15: Content-Type, Anthropic-Version, Anthropic-Beta, OpenAI-Organization, OpenAI-Project) plus the held credential, and heldAuth holds only the standard auth slots (proxy/credmask.go:78-89, authHeaders = Authorization, x-api-key, x-goog-api-key in proxy/tenancy.go:237). copyHeaders forwards custom headers on real requests (proxy/proxy.go:3116-3128), so requests work and only pings fail. The breaker trips at 3 failures (keepalive/breaker.go:19-28). The default strategy is auto, so pings are on. Fail open holds: requests are not affected.
    • Fix: smallest fix inside this PR — when a chained provider's entry has headers, say in the chain consent question (and the README) that keep-alive needs the gateway's auth in apiKey/Authorization, or it stops. Real fix, proxy-side and later: carry the request's non-secret custom headers on pings.
  2. pi-package/scripts/pi_plugin.py:384 — _systemd_quote does not escape %, and chain mode is the first user-supplied string on the service command line

    • What fails: on Linux, systemd expands %-specifiers inside a quoted ExecStart argument. A chained baseUrl whose path contains % followed by a specifier letter (for example https://gw.example/team%b) silently becomes a different upstream: %b turns into the boot ID, %h into the home directory, %m into the machine ID. The proxy then sends every request of that provider to the wrong URL and returns 502s. /context-guru status prints routes from the install record, so it still shows the original URL and the divergence stays invisible. macOS is not affected (launchd ProgramArguments is an array, no expansion).
    • Proof: proxy_command (pi_plugin.py:327-332) puts the chain upstream into the command; the systemd branch writes ExecStart= with _systemd_quote (pi_plugin.py:400-406), which escapes only \ and ". chain_upstream (pi_plugin.py:337-362) refuses whitespace, credentials, queries and non-http URLs, but accepts % in the path. Percent-encoded URLs are safe (a hex digit follows %), so this needs a raw % + letter — rare, but silent when it hits.
    • Fix: escape % as %% in _systemd_quote (and $ as $$, since systemd also expands $VAR there). Or refuse a % or $ in chain_upstream, like the other refusals.
  3. pi-package/extensions/context-guru.ts:153 — the chained-openai skip in before_provider_request has no test

    • What fails: new behavior, documented in the README ("A chained openai provider is not changed either"), but nothing tests it. A regression here would silently strip temperature, max_output_tokens, prompt_cache_retention and prompt_cache_options from requests to a chained gateway — a behavior change for users the PR promised not to touch.
    • Proof: tests/context-guru.test.ts covers only the pure helpers (forChatGPTSignIn, conflictPrompt, …); the skip lives inside the plugin closure, where the Node tests cannot reach it.
    • Fix: export the decision as a pure helper (like forChatGPTSignIn), for example keepsGatewayFields(install), and test it with and without upstreams.openai.

Non-blocking

  • The proxy drops the request's query string (doUpstream builds up.base + up.path only, proxy/proxy.go:2651). The PR names this as an open question and it matches today's behavior for api.anthropic.com. I agree: no change needed in this PR, but a chained gateway that keys on ?beta=true sees a difference from direct Pi traffic.
  • README says the proxy removes "only its own x-context-guru-* headers, Cookie and hop-by-hop headers". Accept-Encoding is also dropped (proxy/proxy.go:2662). A doc nit.
  • models_route.install re-records only when the new baseUrl is a non-None foreign value. A user who deletes baseUrl between setups keeps the old recorded previous, so uninstall brings back a value the user removed. This is the pre-PR behavior, and the alternative is ambiguous; noting it only.

What I checked

  • Read the full diff (6 files) and the surrounding code in all of them, plus CLAUDE.md and docs/design.md.
  • Verified every proxy-side claim of the PR against the Go code, unchanged by this PR: --anthropic-upstream/--openai-upstream exist (cmd/context-guru-proxy/main.go:97-98, present since the first context-guru release, so the 0.4.0 minimum is fine); the proxy sends upstream + /v1/messages and upstream + /v1/responses and /v1/chat/completions (proxy/proxy.go:560-587, doUpstream at 2646); count_tokens follows the Anthropic upstream (proxy/counttokens.go:113-122); headers are forwarded except hop-by-hop, x-context-guru-*, Cookie (copyHeaders); with no server key the caller's credential goes upstream untouched (setUpstreamAuth, bearerKey/headerKey).
  • Traced chain_upstream through its test cases and edge cases: trailing slashes, //v1, ports, localhost vs 127.0.0.1, IPv6, empty port, uppercase scheme, the same-port loop check, and the cross-provider URL case. All sound.
  • Traced the models_route.install re-record change through: first chain, chain re-run with a new gateway, gateway set after our route, old-port repoint, replace after chain, deleted key, created entry later filled by the user. Restore puts back the right value in each. The routing record is written before models.json, and earlier is read before the record changes, as before.
  • Traced setup in plan and run mode: paired answers, chain_refused, --on-conflict refusal without a choice, abort, one-provider conflicts, upstreams kept by configure/update/re-setup, record and proxy.yaml contents, systemd and launchd command construction.
  • Read all 16 new Python tests and 2 new Node tests; they match the code paths they name.
  • Checked the extension flow: conflictPrompt options and answers, KEEP as the no-answer, print mode, the needs_decision dialog as the consent, and the fresh install read after setup.
  • Checked the PR body: it names the behavior change at the top, with the old and new behavior, the undo path, and the approval. Data dependence is stated (none new; routing only) and I agree — the record stores a URL, not customer data.

amiddavid added a commit that referenced this pull request Nov 10, 2026
- README: name what is not tested live (a real answer, keep-alive
  pings, Sign in with ChatGPT), and cite Pi's engines field for 22.19.
- Comparison page: the two open-PR rows name #1010 and #1011.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
- The chain question warns when a chained provider sets headers in
  models.json: a keep-alive ping carries only Authorization / x-api-key,
  so the endpoint may refuse it and keep-alive may stop. It suggests
  /context-guru cache-strategy none. The README says the same.
- With a chain, the question says the pings spend quota at the endpoint
  they reach, not "your own quota on each provider".
- _systemd_quote writes % as %% and, on an Exec line, $ as $$. systemd
  expands both inside quotes, so a chained URL with %b or $X changed.
- The chained-openai guard is now a pure helper, stripsChatGPTFields,
  with a test. The dialog title shows conflicts as "provider: url".
- README: chain is offered for both providers or neither, a recorded
  chain stays until uninstall, and the proxy also drops Accept-Encoding.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 replies. All fixed in 91e7e8af, except the two notes that describe existing behavior.

Reviewer 1, blocking

  1. Keep-alive pings cannot carry a gateway's custom headers: fixed, in this PR, by telling the user. When a chained provider sets headers and the strategy sends pings, the chain question warns that a ping carries only the standard auth headers, so the endpoint may refuse it and keep-alive may stop for that provider. It suggests /context-guru cache-strategy none. The README says the same, and says that requests are not affected. Carrying custom headers on pings is a proxy change; it stays out of this PR.
  2. systemd % and $ expansion: fixed. _systemd_quote writes % as %% and, on ExecStart, $ as $$ (systemd.unit "Specifiers" and systemd.service "COMMAND LINES"). The log paths get %%. Two tests, one of them on the unit file that start_service writes.
  3. No test of the chained-openai skip: fixed. It is now the pure helper stripsChatGPTFields(install), with a Node test of 4 cases.

Reviewer 1, non-blocking

  • Query string dropped: not changed. Same behavior as direct Anthropic traffic today. Listed as an open question.
  • Accept-Encoding: fixed in the README.
  • Deleted baseUrl keeps the old previous: not changed. This is the behavior before this PR.

Reviewer 2, non-blocking

  • Raw JSON in the dialog title: fixed. conflictWords() prints anthropic: https://gw.example. Tested.
  • Untested chained-openai guard: fixed, see item 3 above.
  • One unchainable URL refuses chain for both providers: documented in the README.
  • A chain stays until uninstall: documented in the README.
  • Quota wording: fixed. With a chain, the question says the pings use quota at the endpoint the provider is chained to.
  • "Only" in the header sentence: fixed.

Tests: Python 49 pass, Node 11 pass.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 91e7e8af8e65 approve

Verdict: approve

Findings

None. I read the new commit in full and checked each fix against the code. I could not confirm a defect.

Earlier findings

  • Reviewer 1, finding 1 (pings cannot carry a gateway's custom headers): fixed by disclosure, and I checked the mechanism. PingHeaders copies only Content-Type, Anthropic-Version, Anthropic-Beta, OpenAI-Organization, OpenAI-Project (keepalive/dispatch.go:5-15), and the breaker trips a route after 3 failures for one hour (keepalive/breaker.go:10-13). So the warning text is accurate: a ping lacks the headers from models.json, the endpoint may refuse it, and keep-alive stops for that provider while requests keep working. The chain question now warns exactly this when a chained provider sets headers and the strategy spends, and suggests /context-guru cache-strategy none. The README says the same. Deferring the proxy-side fix (carry custom headers on pings) out of this PR is right: it is a proxy change.
  • Reviewer 1, finding 2 (systemd % and $ expansion): fixed. _systemd_quote now writes % as %% and, on an Exec line, $ as $$; the log paths keep $ literal and escape % only, which matches systemd (ExecStart expands specifiers and variables, StandardOutput= expands specifiers only). The warning covers the real failure: a raw % + specifier letter in a chained URL changed the upstream silently.
  • Reviewer 1, finding 3 (untested chained-openai skip): fixed. stripsChatGPTFields(install) is a pure helper used by the handler, with a Node test of four cases, including a chained anthropic only (removal still applies) and a chained openai (skip).
  • Reviewer 1, non-blocking (query string dropped, deleted baseUrl keeps the old previous): rejected by the author, and I accept both reasons. Each matches the behavior before this PR, and the query-string case is named as an open question.
  • My round-1 notes: all six fixed or documented — conflictWords() prints plain words, stripsChatGPTFields is tested, the README documents the one-answer-for-both rule and the chain-stays-until-uninstall rule, the quota wording names the endpoint, and "only" is gone from the header sentence.

Non-blocking

  • pi-package/scripts/pi_plugin.py:520 — In the replace question, a provider chained by an earlier setup (kept, not replaced) still triggers the chained quota wording and the headers warning for the whole question. The clashing provider's pings meanwhile go to the public API. Mixed wording only; both statements are true for their own provider.

What I checked

  • Last review: round 1, 76051d87d3c4d6a7f7347a1b39f6044d9da3ae3e, 2026-11-10T07:38:30Z.
  • New commits read: 1 — 91e7e8af "fix(pi): chain review round 1 - ping headers, systemd quoting, tests".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files; the inline list is empty).
  • New items since my last review: reviewer 1's round-1 review (3 blocking, 3 non-blocking findings — I checked each fix or rejection as listed above), the author's round-1 reply comment (all claims verified against the diff), and commit 91e7e8af (reviewed below).
  • The full new diff, and the code around each change:
    • _systemd_quote: traced the escaping order (\, ", %, then $ on Exec lines) against the two new tests, including the unit-file test that runs start_service on systemd with a URL containing %b and $x. The unit text carries the upstream literally.
    • has_headers + the consent-question warning: traced it in the chain question (clashing and kept chains), in the replace question (kept chains only), and with --cache-strategy none (no warning, because nothing spends). has_headers reads models.json safely: _load errors are caught.
    • The quota wording: chain questions say the pings spend quota at the endpoint they reach; non-chain questions keep the old text.
    • conflictWords and stripsChatGPTFields: read the helpers and their tests, and confirmed the handler now calls stripsChatGPTFields with the same meaning as the old inline guard.
    • README additions: each new sentence matches behavior I traced in round 1 or in this commit.
  • I did not run the tests (live tests not approved). The author reports Python 49 and Node 11 passing.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 91e7e8af8e65 approve

Verdict: approve

Findings

None. All three round-1 findings are fixed. I checked each fix against the code and the tests.

Earlier findings

Mine, round 1:

  1. Keep-alive pings cannot carry a gateway's custom auth header — fixed by telling the user. consent_question now warns when a chained provider sets headers and the strategy spends (pi_plugin.py:512-525): a ping carries only Authorization / x-api-key, the endpoint may refuse it, keep-alive may stop, run /context-guru cache-strategy none. The README says the same and that requests are not affected (README.md, "Keep-alive pings and custom headers"). The warning appears only when the strategy sends pings, and only for chained providers that set headers — I traced both gates. This is the fix my round-1 review proposed as the smallest one inside this PR. Carrying custom headers on pings stays a proxy change, correctly out of scope here. The ping wording also no longer says "your own quota on each provider" when a chain is in the question.
  2. _systemd_quote did not escape % — fixed. It now writes % as %% always, and $ as $$ on an Exec line only (pi_plugin.py:384-393). Both escapes match systemd's own rules (systemd.unit specifiers, systemd.service command lines). StandardOutput/StandardError keep $ literal, which is right: those settings expand specifiers but not variables. The order of the replaces cannot interact (\, ", %, $ are distinct characters). Two tests cover the function and the unit file start_service writes, including an upstream with %b and $x.
  3. No test for the chained-openai skip — fixed. The guard is now the exported pure helper stripsChatGPTFields (context-guru.ts:85-87), used by the handler at context-guru.ts:172, with a 4-case Node test (no install, no upstreams, anthropic-only chain, openai chain). The semantics match the old inline check.

My non-blocking notes: Accept-Encoding is now in the README sentence; the query-string and deleted-baseUrl notes were left as is, with the reasons ("same as direct traffic today" and "pre-PR behavior"). Both reasons are right.

Reviewer 2's non-blocking items: I checked each fix myself. conflictWords turns the raw JSON into provider: url words and falls back to the raw text on odd input (tested); the README now documents the one-answer-for-both rule, the chain-stays-until-uninstall rule, and the quota wording is chain-aware. All correct.

Non-blocking

  • pi_plugin.py:521-522 — when both chained providers set headers, the warning reads "Anthropic and OpenAI sets headers". The verb should be "set". Cosmetic.
  • context-guru.ts:76 — conflictWords joins with ", ", so a URL containing a comma makes the list ambiguous to read. Cosmetic.

What I checked

  • Last review: round 1, 76051d8, 2026-11-10T07:44:01Z
  • New commits read: 1 — 91e7e8af "fix(pi): chain review round 1 - ping headers, systemd quoting, tests" (5 files, all in pi-package)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files; the inline file is empty — the PR has no inline comments)
  • New items since my last review: the fix commit and the author's round-1 reply comment. I also read reviewer 2's round-1 review in full now, after my own was posted.
  • Verified the ping-header warning end to end: has_headers reads only the provider's own entry and fails closed to "no warning" on an unreadable models.json; the warning shows in the chain question, in a re-setup plan of an already-chained provider, and in the replace question for a provider that stays chained; it is absent with --cache-strategy none. The new Python test asserts each of these.
  • Verified the systemd escaping by hand: applied each replace to a URL with %b, $HOME, a quote and a backslash, and got the expected quoted string; checked the unit-file test asserts "--anthropic-upstream" "https://gw.example/team%%b$$x" in ExecStart. launchd is untouched (plist ProgramArguments is an array, no expansion).
  • Verified stripsChatGPTFields against the old inline check and read its test.
  • Read the two new README blocks ("One answer for both providers", "A chain stays until uninstall") against the code: both describe behavior I traced in round 1, unchanged by the fix commit.
  • Re-read the full new-commit diff and the final state of every changed region (consent_question, has_headers, _systemd_quote, start_service, conflictWords, conflictPrompt, the handler, all new tests).
  • Did not run the tests (live tests not approved). The author reports Python 49 and Node 11 passing.

@amiddavid
amiddavid merged commit e37d14c into main Nov 10, 2026
9 of 11 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 10, 2026
amiddavid added a commit that referenced this pull request Nov 10, 2026
Conflicts were additions on both sides; each resolution keeps both:
- pi-package/README.md: the chained-openai sentence from #1010 and the
  session-start bullet from this branch.
- pi-package/scripts/test_pi_plugin.py: the Restart and ChainMode test
  classes.
- pi-package/tests/context-guru.test.ts: one import list with the
  helpers of both changes, and both sets of tests.

Python 63 pass, Node 26 pass, tsc strict clean.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 10, 2026
…1014)

TestDashboardAddsNoRequestLatencyWithContentCapture failed on loaded
CI runners (on #930, #971, #996, #1010) because one pass of 40 paired
samples was too noisy for the 45 ms budget. It now measures the guard
in up to 3 rounds, and passes as soon as one round is in budget; a
real slowdown fails all 3. Closes #1013.

Behavior change: none. Test only (proxy/dash_test.go).
Data dependence: none.
Known limit (older than this PR): under heavy load, a 50 ms delay in
capture.finish does not fail the test; filed as its own issue.

Reviews: 2 offload reviews (GLM), round 2, both approve at 2fbb429.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 10, 2026
At each Pi session start, the Pi extension now checks the local
proxy with one GET /healthz (5-second limit). If the proxy does not
answer, it restarts the proxy's user service once and checks again.
If the proxy is still down, Pi shows one warning, not only a
connection error on every routed request.

Behavior change: Pi users who installed context-guru with
/context-guru setup, and only when a Pi model goes to the proxy. Old:
nothing checked the proxy, and a down proxy showed only connection
errors. New: the check, one restart, and one warning. No switch;
pi --no-extensions turns off the whole extension, and
/context-guru uninstall removes the install record and so the check.
Owner's yes, 2026-11-10, in the integrator session: "1011 behavior change approved".

Data dependence: metadata only. A bare GET /healthz to localhost with
no body. It reads the install record and the model URLs Pi knows. No
change to stored data.

Reviews: 2 offload reviews (GLM), round 3 (owner granted round 3), both approve at 655a6a9. Round 3 reviewed the merge of main after #1010, which changed the same 5 pi-package files.
Two later merges of main (1077d80 after #1012, d4124cd after #1014)
change no #1011 code: their remerge-diff outside
docs/data-dependence.md is 0 lines; the one doc conflict kept both
rows.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 10, 2026
…rged (#1046)

#1010 and #1011 are merged, so the two "(open PR)" rows on the Pi and
Claude Code comparison page now describe what main does.

Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 10, 2026
- restart reads the install record again after it takes the lock.
- setup and update write the config and the record under the restart lock.
- The lock wait has a 40 s limit. restart reports result=busy; configure,
  setup and update refuse with reason=busy and write nothing.
- With no fcntl (a state directory copied to Windows) there is no lock,
  and restart reports service=unsupported, not a traceback.
- The extension gives configure 60 s, as restart has. A restart stopped
  at the 60 s limit says so, not "the restart did not run".
- The headers warning says "set" for two providers, and the chained quota
  wording names the chained providers.
- conflictWords joins with "; ", because a URL can hold a comma.
- data-dependence: restart does not read the proxy URLs.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
The review notes left on #1010, #1011 and #1049, for the Pi package:
configure reads the install record again, conflictWords joins with
"; " (a URL can hold a comma), and the data-dependence row says
restart does not read the proxy URLs. Tests for the configure and
update busy paths, and for each finding.

Behavior change: none for users: the Pi package has no users yet
(owner decision on #1049).
Owner's yes, 2026-11-11, in the integrator session: "btw in the meantime 1058 is ready".

Data dependence: no change. Metadata only; the docs row states it
more exactly.

Reviews: 2 offload reviews (GLM), round 2, both approve at 4da5bb4.
The branch was then rewritten only to change the sign-off e-mail; the
patch is identical (patch-id 563da3ea9c58 before and after).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
…0.2.12, Pi 0.1.1)

Claude Code plugin 0.6.7 -> 0.7.2:
- #981, #989, #1018, #1035: subscription band and savings show saved tokens.
- #1038: insights drop the finding that credits a user's own removal.
- #1039, #1040: dash and keep-alive fixes that touch the plugin files.

Codex plugin 0.2.11 -> 0.2.12:
- #1051: read the cache strategies and presets from the proxy.
- The vendored cg.py gets the same plugin changes.

Pi package 0.1.0 -> 0.1.1:
- #1010: chain the proxy in front of an existing base URL.
- #1011: check the proxy at session start and restart it once.
- #1049, #1058: write the cache strategy by name; review fixes.

OpenCode plugin (#483): new in v0.7.2, no version file, not changed.
Bob plugin 0.1.0: no change since v0.7.1, not changed.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
Bump the plugin versions for v0.7.2.

- Claude Code plugin 0.6.7 -> 0.7.2: #981, #989, #1018, #1035 (savings
  in tokens on a subscription), #1038, #1039, #1040, #1055 (cache
  strategies read from the proxy).
- Codex plugin 0.2.11 -> 0.2.12: #1051 (cache strategies and presets
  read from the proxy), plus the vendored cg.py changes.
- Pi package 0.1.0 -> 0.1.1: #1010, #1011, #1049, #1058, and the #1040
  README line.
- OpenCode plugin: new in v0.7.2 (#483), no version file. Its first
  start now downloads proxy v0.7.2 (was v0.7.1). Nothing compares
  against PINNED_VERSION; the floor stays "v0.7.1 or later". The README
  lines, the install guide and 3 tests follow.
- Bob plugin: 0.1.0, no change since v0.7.1.

Behavior change: the OpenCode plugin's first download is proxy v0.7.2,
not v0.7.1. Owner's yes, 2026-11-11, in the integrator session: "option1
it is"; the version bumps: "I approve the version bumps for the
plugins".

Data dependence: none.

Reviews: 3 offload review rounds (GLM; round 3 pre-approved by the
owner). Both reviewers approve at 3cf6176, which is the PR head.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant