Repository navigation
feat(pi): route Pi's OpenAI provider through context-guru - #982
Merged
Merged
Conversation
amiddavid
commented
Nov 9, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 746b0be01ebf |
blocking |
Verdict: blocking
Findings
- pi-package/scripts/models_route.py:77 —
oursmatches URLs across providers, so another provider's route URL is treated as ours- What fails:
own_urls(pi_plugin.py:436) flattensbase_urlsinto one list, and_ourschecks that list for every provider. So the URL setup wrote foranthropic(http://127.0.0.1:<port>/anthropic) counts as "ours" foropenai. Whenproviders.openai.baseUrlholds that URL:conflictsreports no clash, setup overwrites it, andinstall(models_route.py:116) recordsprevious: None. Uninstall then deletes the key instead of putting back the user's value. A user-set baseUrl is lost from the routing record. - Proof:
models_route._ours(url, port, provider, ours)runsany(_same(url, mine) for mine in ours)with no provider filter onmine.pi_plugin.own_urlsreturns[url for url in urls.values()]— both providers' URLs, keyed by nothing. Trace: models.json{"providers": {"openai": {"baseUrl": "http://127.0.0.1:8800/anthropic"}}}, install record from an anthropic-only install (port 8800), routing record absent.setup→conflicts(models, 8801, ("anthropic", "openai"), ["http://127.0.0.1:8800/anthropic"])→{}(no clash).install→keys["openai"]["previous"] = None.restore→ the openaibaseUrlkey is deleted, the user's value is gone. - Severity: low. The trigger needs a user to point
openaiat the anthropic route URL, and that config cannot work anyway (the OpenAI SDK would POST/anthropic/responses, a 404). But the record is the only undo path, and the value it loses is real. - Fix: scope
oursper provider. Letown_urlsreturn thebase_urlsdict (or{provider: [urls]}), and have_ourscompare only the entry for that provider.
- What fails:
Non-blocking
- pi-package/extensions/context-guru.ts:120 — the new
before_provider_requestgating has no test. The conditions (provider, api, routed,payload.model === model.id,isUsingOAuth) are new behavior; only the pureforChatGPTSignIntransform is tested. The repo has no Pi runtime harness and the PR saystscpasses against Pi 1.5.0 types, so this is a coverage gap, not a known defect. - The Pi API surface (
before_provider_requestpayload-replacement return,ctx.modelRegistry.isUsingOAuth,model.api) is external to this repo. I could not verify it from the code. The PR'stscrun against Pi 1.5.0 types is the only check; the ChatGPT sign-in path is also untested against the real service, which the PR states under Open questions. - The classifier 404 (
/v1/decisions) and "one clash blocks both providers" are already open questions 3 and 4 in the PR. I agree they are acceptable to defer; both are disclosed in the README Limits.
What I checked
- The full diff (7 files) and the code around each change:
context-guru.ts,models_route.py,pi_plugin.py, both test files, README, package.json. - Proxy wiring for every README claim:
POST /openai/v1/responsesandPOST /openai/v1/chat/completionsexist (proxy/proxy.go:560-569);/v1/decisionsdoes not (404, as documented); the OpenAI upstream defaults tohttps://api.openai.com(cmd/context-guru-proxy/main.go:86). - Credential pass-through:
bearerKey("")returns nil (proxy/proxy.go:972), so a ChatGPT OAuthAuthorizationheader is forwarded unchanged. The keep-alive holds the request body the extension already stripped, so pings carry the stripped body too. - OpenAI keep-alive numbers: idle default 28 minutes (
modelinfo.OpenAIDefaultKeepAliveIdle, internal/modelinfo/cachefrac.go:12), the 240 skeepalive_idle_secondsis replaced for OpenAI (proxy/keepalive.go:491), the GPT-5.6+ gate stops pings on earlier models (keepalive/ping.go:112), andkeepalive_max_pings,keepalive_max_usd_per_ping(0.50),keepalive_min_prefix_tokens(80000) are enforced provider-agnostic (keepalive/keeper.go:329). The_1hkeys are Anthropic-only, as the comment says. - Config keys written by
render_configmatch the proxy's YAML keys (config/config.go). - The session header
x-context-guru-sessionis read on the chat routes (proxy/proxy.go:743) and/signalexists, so the extension's OpenAI coverage works. - Upgrade and port-move paths, traced by hand and covered by the new tests: anthropic-only install re-run adds openai and keeps the first
previous; a taken recorded port moves both routes; our own URL is never saved asprevious; restore undoes each provider by its own record. - The reset hatch (
reset.sh) and the refusal message that names it: the hatch is named only when it exists, and the tests cover both cases. - The PR body: data dependence stated (no change), behavior change named with the human-permission note, open questions listed.
amiddavid
commented
Nov 9, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 746b0be01ebf |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, and no broken fail-open path.
Non-blocking
pi-package/extensions/context-guru.ts:120— the ChatGPT field removal keys offctx.modeland requirespayload.model === ctx.model.id. A request Pi sends for a different model whilectx.modelis a routed OAuth model keeps the four fields, and a ChatGPT token rejects it. I could not build a case where Pi does this in normal chat use. The PR already lists Sign in with ChatGPT as untested (open question 1), so this rides that disclosure.pi-package/scripts/models_route.py:77—_oursmatches a recorded URL against every provider, not just the provider it was written for. A user would have to copy our Anthropic URL into the OpenAI key to hit this. The URL still points at our proxy, so the takeover changes no traffic path.pi-package/extensions/context-guru.ts:120— the handler's gate (provider, api, routed, payload model, OAuth) has no test. Only the pure helperforChatGPTSignInis tested. This matches the package's existing pattern of testing pure helpers only.- OpenAI classifier calls get a 404 on a routed provider. The PR discloses this in Limits and open question 3. I checked Pi 1.5.0: the Decisions classifier is used by permission extensions, so it is opt-in, not a default path.
What I checked
- The full diff (
18b60bc9..HEAD, 7 files, onlypi-package/) and the code around each change. - Proxy side of every README claim:
proxy/proxy.go:560-575servesPOST /openai/v1/chat/completionsandPOST /openai/v1/responses, so the/openai/v1base URL is right for Pi's SDK (it appends/responses).proxy/keepalive.go:490-495replaces the idle time withOpenAIIdle, default 28 minutes (internal/modelinfo/cachefrac.go:12).MaxPings,MaxUSDPerPing,MinPrefixTokenscome from the sharedcache:config block (cmd/context-guru-proxy/main.go:1192-1224), so the plugin's claim "same keys, idle replaced" is correct.keepalive/ping.go:112gates pings to GPT-5.6 and later.keepalive/keeper.go:329applies the 80,000-token prefix floor.proxy/proxy.go:743-748readsx-context-guru-sessionon every route, so the header works for OpenAI too.
- Pi 1.5.0 sources (pi-ai and pi-coding-agent, from the package the extension targets):
isChatGPTSignInrequiresbaseUrl === "https://api.openai.com/v1", so a routed model stops omitting the four fields. The extension's list matchesbuildParamsexactly.- The extension runner replaces the payload when a
before_provider_requesthandler returns a value, and leaves it when the handler returnsundefined.ctx.model,modelRegistry.isUsingOAuth, andpayload.model === model.idall exist and behave as the handler assumes. OpenAI model ids are bare, so the id comparison holds. - The OpenAI catalog defines no
promptCache, so "Pi warms no built-in OpenAI model" is true.
- Routing record logic, by hand-tracing: upgrade from Anthropic-only, port move with the old port taken, missing routing record, user-changed key on restore, and crash between the two atomic writes. All end in a safe state: refuse, or restore the user's own value.
previousis never set to our own URL. - Strategy parity: the
cachedicts are unchanged and still matchcontext-guru-plugin/scripts/settings.py(test_strategies_match_the_claude_code_plugincovers it). - Tests: I read all new Python and Node tests. I did not run them (live tests not approved).
- The PR description states data dependence (no change) and the behavior change, and names who must confirm it.
Collaborator
Author
Round 1: replies to both reviewsFixed in Reviewer 2, blocking
Non-blocking
|
amiddavid
commented
Nov 9, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 33633c05a7d0 |
approve |
Verdict: approve
Findings
None. The fix commit is correct and I found no new defect in it.
Earlier findings
- Reviewer 2, finding 1 (blocking):
_oursmatched URLs across providers. Fixed in33633c05.own_urls(pi_plugin.py:436) now returns{provider: url}, and_ours(models_route.py:77) compares onlyours.get(provider). I traced the broken case: models.jsonopenai.baseUrl= our Anthropic URL, install record from an Anthropic-only install.conflictsnow reports{"openai": ...}, so setup refuses and never touches the key.installcalled directly on that state records the URL as the user'sprevious, andrestoreputs it back. The new testtest_our_url_for_one_provider_is_not_ours_for_anothercovers all three steps. I checked every caller ofconflictsandinstall: onlypi_plugin.setupand the tests, all updated to the dict form in the same commit.reset.shuses onlyrestore, which did not change. Defaultours=Nonebecomes{}, and_same(url, None)is false, so old callers withoutourskeep the old behavior. - My non-blocking notes from round 1:
- Cross-provider
_oursmatch — fixed with the finding above. I add: reviewer 2's severity call was right and mine was wrong. I stopped at "the traffic path does not change" and missed thatprevious: Nonemakes uninstall delete the user's key. That is real data loss in the routing record. - The ChatGPT field removal keys off
ctx.model— not changed, rejected with a reason. I accept the reason. The check limits the change to the request the extension can match to a routed model, and the Sign in with ChatGPT path stays disclosed as untested (open question 1). - The
before_provider_requestgate has no test — not changed. The reason (no Pi runtime harness in this repo; the gate is type-checked against Pi 1.5.0) holds. - Classifier 404 and one clash blocking both providers — not changed, disclosed in Limits and Open questions. Accept.
- Cross-provider
Non-blocking
- None new.
What I checked
- Last review: round 1,
746b0be01ebfdf8d3fae3b4ee8d7dbb0a2b116b8, 2026-11-09T16:27:49Z. - New commits read: 1 —
33633c05"fix(pi): count a route URL as ours only for the provider it was written for". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- Reviewer 2's round-1 review (posted 3 minutes before mine, same head). I read it only now, per the round rules. Its blocking finding overlaps my non-blocking note; the fix commit addresses it.
- The author's reply comment (2026-11-09T16:29:07Z). It states what was fixed and what was rejected, with reasons. I checked each claim against the code above.
- The fix commit
33633c05. Full diff read:models_route.py(_ours,conflicts,installsignatures),pi_plugin.py(own_urls),test_pi_plugin.py(one new test, two updated). I verified the dict plumbing end to end and found no caller left on the old tuple form.
- I did not run the tests (live tests not approved). The author reports 30 Python and 7 Node tests pass.
amiddavid
commented
Nov 9, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 33633c05a7d0 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Mine, round 1, blocking:
oursmatched URLs across providers (models_route.py:77). Fixed in33633c05.own_urlsnow returns{provider: url}and_ourscompares onlyours.get(provider), so our Anthropic URL in the OpenAI key is a conflict, andinstallrecords it as the user'spreviousvalue. I re-traced the fixed code and the new test (test_our_url_for_one_provider_is_not_ours_for_another):conflictsreports the key,installkeeps the user's value,restoreputs it back. The port-move and no-record tests were moved to the dict form and still cover their original behaviors. All callers ofconflicts/install/own_urlsuse the new form; none passes the old tuple. - Mine, round 1, non-blocking: the
before_provider_requestgate has no test. Rejected by the author: no Pi runtime harness exists in this repo, the gate is type-checked against Pi 1.5.0, and the transform is tested. I accept the reason. Reviewer 1 also checked the Pi 1.5.0 sources and confirmed the handler's assumptions (return value replaces the payload,isUsingOAuth, bare OpenAI model ids), which closes my round-1 concern that the Pi API surface was unverified. - Reviewer 1, round 1, non-blocking: field removal keys off
ctx.model. Rejected by the author: the check is on purpose, so the extension changes only a request it can match to a routed model with a ChatGPT login. Reviewer 1 could not build a failing case, and neither could I in round 1. I accept. - Reviewer 1, round 1, non-blocking: classifier 404, one clash blocks both. Not changed; both stay disclosed in the README Limits and the PR's open questions. I agree with leaving them.
Non-blocking
- None new. The fix commit changes only the
oursscoping, its callers, and tests.
What I checked
- Last review: round 1, 746b0be, 2026-11-09T16:24:36Z.
- New commits read: 1 —
33633c05"fix(pi): count a route URL as ours only for the provider it was written for". I read the full diff (git diff 746b0be0..HEAD) and the changed files around each change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- Commit
33633c05— reviewed above; the fix is correct and tested. - Reviewer 1's round-1 review (16:27:49Z) — read in full. Their non-blocking
_oursnote is the same defect as my blocking finding, now fixed. Their Pi 1.5.0 source checks answer my round-1 note about the unverifiable Pi API. - The author's reply comment (16:29:07Z) — read in full. Each reply to a finding is checked above; I accept the two rejections.
- Commit
- Re-verified the fixed code paths by hand:
conflictsandinstallwithoursmissing a provider (ours.get(provider)isNone,_samereturnsFalse),own_urlsfiltering non-string values, andrestoreputting back a recordedprevious.
Setup now routes Pi's built-in `openai` provider (OpenAI Responses) as well as `anthropic`. It sets providers.openai.baseUrl in models.json to http://127.0.0.1:<port>/openai/v1. The proxy forwards it to api.openai.com. - One consent question names both providers and what spends quota on each. A re-run on an Anthropic-only install adds OpenAI and keeps the Anthropic record. - The cache strategy keys are unchanged: the proxy's OpenAI keep-alive reads the same keys and pings GPT-5.6 and later after 28 minutes. - For a routed `openai` model with a stored ChatGPT login, the extension removes the four request fields that Pi removes for ChatGPT tokens. - `openai-codex` is not routed: the proxy has no chatgpt.com route. - Fix: when another program holds the recorded port, setup moves the route to the new port. It no longer refuses because of its own old URL. The refusal names the reset command when one exists. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…en for The own-URL check took every URL the install record held, for every provider. A user who put our Anthropic URL into the OpenAI key had that key treated as ours: setup recorded no previous value, and uninstall deleted the key. Now each provider matches only its own recorded URL, so that key is a conflict and is never deleted. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
force-pushed
the
feat/pi-plugin-openai
branch
from
November 9, 2026 22:16
33633c0 to
95a72a7
Compare
Collaborator
Author
Rebase onto main
approval-still-valid
|
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacks on #977. Merge #977 first; this PR's base is
feat/pi-plugin-anthropic.The Pi package now routes Pi's built-in
openaiprovider through context-guru, as well asanthropic.openaiprovider (OpenAI Responses API) goes tohttp://127.0.0.1:<port>/openai/v1. The proxy forwards it toapi.openai.com.openai-codex(the legacy ChatGPT Plus/Pro login) is not routed. The proxy has no route forchatgpt.com/backend-api.pi-package/.Data dependence
No change. The package still sends the proxy only metadata: the session id header and the session end and compaction signals. The new request-field removal (see below) runs in Pi and stores nothing. The proxy stores what its preset and storage level say, as before. No row in
docs/data-dependence.mdchanges.Behavior change
Who it affects: Pi users of this package (new in #977, not yet released).
anthropic.anthropicandopenai. A user with an Anthropic-only install gets OpenAI after they run/context-guru setupagain and answer yes. Nothing changes until they do.auto,1-pingor2-ping, the proxy also pings OpenAI GPT-5.6+ sessions after 28 minutes idle. This uses the user's OpenAI quota. The consent question says so./context-guru cache-strategy nonestops all pings./context-guru uninstallremoves both routes.A human developer must confirm this before merge.
What changed
models_route.ROUTESgets"openai": "/openai/v1".pi_plugin.PROVIDERSis now("anthropic", "openai"). Pi's OpenAI SDK appends/responses, so requests reach the proxy'sPOST /openai/v1/responses.cache:keys as Anthropic (keepalive,keepalive_max_pings,keepalive_max_usd_per_ping,keepalive_min_prefix_tokens). It replaces the idle time with its OpenAI default of 28 minutes. The_1hkeys are Anthropic only. So the strategies stay equal to the Claude Code plugin's, and the test that checks this still passes.previousvalue. Restore undoes each provider by its own record: a provider the user changed after setup stays as it is.isRoutedworks frombase_urls, so the session header and the signals now cover OpenAI requests too. The cache-warming stop needs no change: Pi 1.5.0 warms no built-in OpenAI model (they have nopromptCachelifetime).openai. Pi removes 4 fields that ChatGPT tokens reject (prompt_cache_retention,prompt_cache_options,max_output_tokens,temperature). Pi does this only when the URL ishttps://api.openai.com/v1. A routed model has the proxy URL, so the extension removes the same 4 fields. It does this only for a routedopenaiResponses model with a stored OAuth login. API key requests are not changed.choose_portpicks a new one. Setup then saw its own old-port URL as foreign and refused withbase_url_already_set. Now a URL in the install record'sbase_urlscounts as ours, and install moves it to the new port. The routing record gets the new port, and eachpreviousstays the user's original value. Our own URL is never saved asprevious.base_url_already_setrefusal now names the reset command (~/.local/state/context-guru-pi/context-guru-reset) when it exists.How it was tested
python3 -I -W ignore -m unittest discover -s scripts— 29 tests pass (16 before). New tests:/openai/v1; both providers route and restore.models.json.models.json.node --test tests/*.test.ts— 7 tests pass (5 before). New: OpenAIisRouted, and the ChatGPT field removal.tscagainst Pi 1.5.0 types: no errors.none,auto,1-ping,2-ping): each loads,/healthzanswers,GET /openai/v1/responsesgives 405, a WebSocket upgrade gives 426,/signalgives 204.--openai-upstreamset to a local fake server on 8875: aPOST /openai/v1/responseswithAuthorization: Bearer sk-test-…andx-context-guru-session: pi-sess-1reached the fake as/v1/responseswith the sameAuthorization. The proxy log showsprovider=openai session=pi-sess-1.Open questions
openaiis not tested against the real service. The field removal copies Pi 1.5.0's own rule. It needs the extension: withpi --no-extensions, a ChatGPT login on a routedopenaimodel can fail. Is that acceptable, or should setup skipopenaiwhen Pi has a stored ChatGPT login?openai-codexis not routed. It needs a proxy route forchatgpt.com/backend-api(openai-codex-responses). Do we want that route in the proxy?openaiprovider also has a Decisions classifier (POST /v1/decisions). The proxy has no such route, so a classifier call on a routedopenaiprovider gets a 404. Should the proxy pass/openai/v1/decisionsthrough, or should we accept this?models.jsonalready sends OpenAI to a gateway, setup refuses for Anthropic too. Should setup route the providers with no clash and report the rest?🤖 Generated with Claude Code