Skip to content

feat(codex): opt-in profile + launcher (no dead-proxy lock-out), doctor, onboarding, shared insights - #440

Closed
OsherElhadad wants to merge 4 commits into
mainfrom
feat/codex-plugin-parity
Closed

OsherElhadad wants to merge 4 commits into
mainfrom
feat/codex-plugin-parity

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Part of #436 (Workstream C). Tested against the real Codex CLI 0.162.1 (npm @openai/codex), model azure/gpt-5.5 through the IBM gateway's Responses endpoint, proxy built from this branch on port 4125, isolated CODEX_HOME.

Problems and changes

  1. Dead proxy locked Codex out. Setup rewrote the top-level model_provider. Now setup writes only $CODEX_HOME/context-guru.config.toml (Codex >= 0.134 profile file; [profiles.x] in config.toml is rejected by 0.162) and a launcher context-guru-codex that health-checks the proxy, restarts its user service, runs codex --profile context-guru, and if the proxy cannot be brought up warns and runs plain codex. config.toml is never modified (byte-identical across setup and uninstall). A legacy install is migrated back on the next setup. A SessionStart hook cannot fix this (it runs after provider selection) so it is advisory only.
  2. Insights. The 128-line stub is replaced by the Claude plugin's engine: insights_core.py is a verbatim copy of context-guru-plugin/scripts/insights.py (the Codex marketplace is a sparse checkout, so it cannot import across directories); a test fails on drift. insights.py supplies the Codex port/options and rewrites fix commands to $context-guru-*.
  3. Hooks, onboarding, doctor. SessionStart hook (advisory), onboardingSkill, $context-guru-doctor skill and codex_plugin.py doctor.
  4. Gaps documented in the plugin README (no status line, hook trust, no MCP, etc.).
  5. Bug found live: a provider base_url ending in /v1 was passed as the proxy upstream, giving /v1/v1/responses -> 404 through the proxy. Now stripped.

Before (origin/main plugin, same gateway config)

$ cat config.toml          # after setup
model_provider = "context-guru"     <- default rewritten
...
$ codex exec "reply pong"   # proxy up, gateway base_url ends in /v1
ERROR: unexpected status 404 Not Found: ... http://127.0.0.1:8787/openai/v1/responses
$ <stop proxy>; codex exec "reply pong"
(no response within 120 s; every plain codex start is pointed at the dead proxy)

After

$ cat context-guru.config.toml     (token redacted)
# Managed by the context-guru Codex plugin.
model_provider = "context-guru"

[model_providers.context-guru]
name = "context-guru (local)"
base_url = "http://127.0.0.1:4125/openai/v1"
wire_api = "responses"
requires_openai_auth = false
experimental_bearer_token = "<redacted>"
$ context-guru-codex exec "reply with the single word pong"        # proxy up
codex
pong
tokens used
8,316
pong
proxy requests recorded: 1
[proxy killed: healthz unreachable]
$ codex exec "..."   # plain codex, proxy DEAD
pong
tokens used
11,772
pong

$ context-guru-codex exec "..."   # launcher, proxy DEAD but restartable
pong
tokens used
8,304
pong
healthz after launch: ok
proxy requests recorded: 2
$ context-guru-codex exec "..."   # proxy DEAD and NOT restartable
context-guru-codex: the proxy is not reachable and could not be restarted; starting Codex directly. This session is NOT routed through context-guru (log: ~/state/context-guru-codex/proxy.log).
Reading additional input from stdin...
OpenAI Codex v0.162.1
--------
workdir: /tmp
model: azure/gpt-5.5
provider: gw
approval: never

Also verified live: plugin installed through codex plugin marketplace add + codex plugin add; Codex loaded the skill from the plugin cache and ran $context-guru-doctor; the SessionStart hook executes (with --dangerously-bypass-hook-trust; otherwise it waits for /hooks review); insights.py all against the proxy after real routed traffic (125 lines, 5 requests, window/decl/keep-alive/component sections) vs the stub's 14 lines; uninstall removes the profile and stops the proxy (no process on 4125 afterwards).

Not verified

  • ChatGPT-login (non-API-key) Codex auth: not tested (no OpenAI login on this box).
  • Hook systemMessage rendering in the TUI; codex exec does not print it.
  • macOS LaunchAgent path (unchanged code).

Tests

cd codex-marketplace/plugins/context-guru/scripts && python3 -m unittest test_codex_plugin test_insights -> 41 tests OK (new: launcher routes / falls back, hook advisory, legacy migration, onboarding/doctor wiring, insights drift + Codex wording with a stub server).

…lt provider; doctor, onboarding, shared insights

A stopped proxy used to block Codex from starting because setup rewrote the default
model_provider. Setup now writes only a context-guru profile file and a launcher that
restarts the proxy or falls back to plain codex. Adds a SessionStart advisory hook,
doctor and onboarding skills, and replaces the 128-line insights stub with the Claude
plugin's insights engine (verbatim copy guarded by a drift test).

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Reviewer: approved. python3 -m unittest test_codex_plugin test_insights: 41 OK; CI all pass; config.toml is only touched by the legacy-migration path (profile file is marker-checked before unlink); launcher falls back to plain codex; insights_core.py is byte-identical to context-guru-plugin/scripts/insights.py. Heads-up (non-blocking): the verbatim copy means the upcoming feat/plugin-insights redesign of insights.py will fail the drift test until insights_core.py is refreshed with the cp command in the test; the Python tests are not run in CI, so nothing will flag it automatically. Also consider trimming 'IBM gateway' and the model name from the PR body.

@OsherElhadad OsherElhadad 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.

Review: REQUEST CHANGES at b6f35b4. (Posted as a comment: GitHub does not let the author account request changes.)

Verified:

  • On the PR head, the Codex plugin suite passes (41 tests) and CI is green. The commit is by Osher-Elhadad and signed off, with no AI attribution.
  • No lock-out. launch() runs codex --profile context-guru only when the proxy is routed and revive() succeeds; otherwise it warns and execs plain codex. With that condition forced true, test_launch_falls_back_to_plain_codex_when_proxy_cannot_start fails.
  • config.toml is untouched; the profile and proxy config are written 0600 through a temp file and os.replace.

Blocking: after merging current main, test_core_is_a_verbatim_copy_of_the_claude_insights fails. Main has since changed context-guru-plugin/scripts/insights.py (637204a and 7836726, the cache_aware_summarizer presets), so codex-marketplace/.../scripts/insights_core.py is stale. Merge main into the branch and copy insights.py over insights_core.py again. The suite should then pass on the merged tree.

@OsherElhadad OsherElhadad 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.

Re-check: APPROVE at 168867a. Main is merged in (075450f), and codex-marketplace/.../insights_core.py is again byte-identical to context-guru-plugin/scripts/insights.py, so the verbatim-copy test passes. CI is green (build-test, purego, trivy, DCO). 168867a is signed off. The merge commit 075450f has no sign-off, so squash-merge with an explicit subject and body. This approval covers 168867a.

Signed-off-by: Osher-Elhadad <[email protected]>

# Conflicts:
#	codex-marketplace/plugins/context-guru/hooks.json
#	codex-marketplace/plugins/context-guru/scripts/codex_plugin.py
#	codex-marketplace/plugins/context-guru/scripts/test_codex_plugin.py

@OsherElhadad OsherElhadad 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.

Re-review: APPROVE at 1df1aa6 (main merged; last approved 168867a).

  • Conflicts. git show --remerge-diff 1df1aa6d shows three, in the Codex plugin:
    • hooks.json. It parses as valid JSON. It keeps this PR's advisory session-start-hook (SessionStart, no matcher) alongside main's signal hooks: SessionStart with compact|resume|clear (async) and SessionEnd.
    • codex_plugin.py. It has the union of both command sets: setup, status, ensure, serve, signal, update, uninstall, configure, doctor, launch and session-start-hook. signal_hook still POSTs with Content-Type: application/json, as #520/#524 require.
    • The merged hook test. It asserts both halves: the first SessionStart hook is the advisory one, and every other hook is exactly codex_plugin.py" signal. That keeps main's guarantee that the proxy lifecycle never depends on a sandboxed hook, with this PR's advisory hook as the single named exception.
  • Copy and tests. insights_core.py is still byte-identical to the Claude plugin's insights.py, on this head and on a local merge with today's main. On that merge, the Codex unittests pass (42), and go vet and the plugin's Codex/Insights/Signal tests pass. CI is green, and the merge commit is signed off.

Non-blocking:

  • The advisory hook's command leaves ${PLUGIN_ROOT} unquoted, while the signal hooks quote it, so a plugin root with a space breaks only the advisory hook.
  • The advisory hook can call revive() from inside Codex's hook sandbox. That is harmless, since it is best effort and only prints a message.

This approval covers 1df1aa6.

@OsherElhadad OsherElhadad mentioned this pull request Oct 21, 2026
1 of 2 tasks
amiddavid added a commit that referenced this pull request Nov 26, 2026
…ad proxy cannot lock Codex out

Setup no longer rewrites the default model_provider. It writes a Codex
profile file and a launcher, context-guru-codex. The launcher checks
the proxy, restarts the owned service, and runs codex --profile
context-guru. If the proxy cannot start, it warns and runs plain codex.
A legacy install is migrated back on the next setup.

Adds a doctor command and skill, an advisory SessionStart hook and an
onboarding skill. Strips a trailing /v1 from the provider base_url so
the proxy upstream does not become /v1/v1/responses.

Based on #440 by Osher Elhadad, without its insights copy.

Refs #440
Assisted-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator

Closing: replaced by #1509.
#1509 takes the launcher, the profile, doctor, the hook and the /v1 fix from this PR, on current main. It leaves out the copy of the insights engine. That copy is stale, and savings figures now come from the accountant.

@amiddavid amiddavid closed this Nov 26, 2026
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 26, 2026
amiddavid added a commit that referenced this pull request Nov 26, 2026
…ests and a data-dependence row

- The SessionStart hook never fails and no longer checks or restarts the proxy.
  A sandboxed hook may not reach loopback, so a failed check proved nothing.
- Setup refuses to overwrite a profile file that is not managed (config_conflict).
- The launcher refuses a user --profile, and names a missing profile apart from a dead proxy.
- Uninstall removes the launcher. The doctor legacy fix points to context-guru-reset --yes.
- Quote PLUGIN_ROOT in the hook. Fix the setup skill's file name.
- Add tests for doctor, the hook, the profile guard and the launcher.
- Add the docs/data-dependence row for the Codex plugin.

Refs #440
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 26, 2026
… and the conflict path

- One write_record helper writes install.json atomically at 0600. All 7 write sites use it.
- The README says the hook warns only when the launcher did not start the session.
- A profile conflict prints the profile path, not the proxy.yaml path.

Refs #440
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 26, 2026
feat(codex): opt-in profile and launcher, doctor, onboarding, so a dead proxy cannot lock Codex out

Setup no longer rewrites the default model_provider. It writes a Codex
profile file and a launcher, context-guru-codex. The launcher checks
the proxy, restarts the owned service, and runs codex --profile
context-guru. If the proxy cannot start, it warns and runs plain codex.
A legacy install is migrated back on the next setup.

Adds a doctor command and skill, an advisory SessionStart hook and an
onboarding skill. Strips a trailing /v1 from the provider base_url so
the proxy upstream does not become /v1/v1/responses.

Based on #440 by Osher Elhadad, without its insights copy.

Refs #440

fix(codex): fail-open hook, refuse an unmanaged profile, add doctor tests and a data-dependence row

- The SessionStart hook never fails and no longer checks or restarts the proxy.
  A sandboxed hook may not reach loopback, so a failed check proved nothing.
- Setup refuses to overwrite a profile file that is not managed (config_conflict).
- The launcher refuses a user --profile, and names a missing profile apart from a dead proxy.
- Uninstall removes the launcher. The doctor legacy fix points to context-guru-reset --yes.
- Quote PLUGIN_ROOT in the hook. Fix the setup skill's file name.
- Add tests for doctor, the hook, the profile guard and the launcher.
- Add the docs/data-dependence row for the Codex plugin.

Refs #440

fix(codex): write install.json at mode 0600, fix the README hook text and the conflict path

- One write_record helper writes install.json atomically at 0600. All 7 write sites use it.
- The README says the hook warns only when the launcher did not start the session.
- A profile conflict prints the profile path, not the proxy.yaml path.

Refs #440

Behavior change (plain codex is no longer routed after setup; routing moves to the context-guru-codex launcher and an opt-in profile) approved by the owner in the integrator session: "1509 ok". Credential: the profile file and install.json hold the provider key at 0600 until #1512 moves it out; the owner accepted this.

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

Labels

ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants