Skip to content

llm: openai-cli backend — semantic extraction through the locally authenticated Codex CLI - #5

Merged
Azeem1985 merged 5 commits into
v8from
feat/openai-cli-backend
Aug 24, 2026
Merged

Azeem1985 merged 5 commits into
v8from
feat/openai-cli-backend

Conversation

@Azeem1985

Copy link
Copy Markdown

What

A new openai-cli backend (--backend openai-cli) that runs semantic extraction and community labeling through the locally authenticated OpenAI Codex CLI (codex exec) — i.e. on a ChatGPT OAuth subscription, not a metered OPENAI_API_KEY.

  • Default model gpt-5.6-sol (GRAPHIFY_OPENAI_CLI_MODEL overrides); reasoning effort default ultra (GRAPHIFY_OPENAI_CLI_EFFORT).
  • Zero pricing on purpose: subscription usage is not metered API spend.
  • Prompt via stdin — Linux MAX_ARG_STRLEN caps one argv entry at 128 KB and real chunks reach 240–306 KB.
  • --sandbox read-only: an agentic Codex must not be able to write to the corpus it reads.
  • Every configured MCP server is disabled per call via Codex's own per-server enabled override; a blanket -c mcp_servers={} deep-merges away and leaves the servers running (measured: four ~152 MB graph servers started per codex exec).
  • Usage from the last turn.completed JSONL event; cached input is not re-added (Codex input_tokens already includes it).
  • An empty-but-valid graph raises instead of feeding the hollow-response bisect — that exact failure mode once consumed 87% of an hourly backend quota.
  • Forced serial unless GRAPHIFY_OPENAI_CLI_PARALLEL=1, mirroring ollama/claude-cli.
  • The credential gate accepts a present codex CLI as the credential (OAuth), mirroring claude-cli.

Why

This ports a local patch that has been carrying production extraction on the TELB-COCKPIT box since 2026-08-19. The original patch comment states the stake plainly:

PATCHED FOR TELB-COCKPIT (2026-08-19). This explicit backend routes graph extraction through the owner's authenticated Codex CLI/ChatGPT subscription. If an upgrade removes it, the backend silently disappears and extraction can fall back to the metered OpenAI API — a spending regression.

With it merged, a reinstall from this repo no longer erases the free extraction route.

Tests

tests/test_openai_cli_backend.py — 15 offline tests (subprocess and shutil.which mocked): argv contract, MCP-disable per server, env overrides, missing binary, happy parse with usage accounting, non-zero exit / missing -o / empty -o raises carrying stderr and the JSONL stdout tail, empty-graph raise, and _openai_cli_turn_usage edge cases.

🤖 Generated with Claude Code

Azeem and others added 5 commits August 23, 2026 21:24
…ly authenticated Codex CLI

Sibling of the existing claude-cli backend, for operators whose OpenAI access is a ChatGPT
subscription (Codex CLI OAuth), not an API key. Ported from a field-proven implementation
(measured ~308 docs/hour at concurrency 6 on an 8 GB box): codex exec --skip-git-repo-check
--json --sandbox read-only, prompt via stdin (argv would hit Linux MAX_ARG_STRLEN), result
via -o file, empty-graph refusal to avoid hollow-bisect storms. Two per-call config pins:
mcp_servers={} (each exec otherwise spawns the user's configured MCP servers per call —
measured ~160-300 MB each, more than the extraction itself) and model_reasoning_effort
(GRAPHIFY_OPENAI_CLI_EFFORT, default ultra). Model via GRAPHIFY_OPENAI_CLI_MODEL (default
gpt-5.6-sol). Tests: argv contract, env overrides, missing-binary error.
…the credential (OAuth), mirroring claude-cli
…ket mcp_servers={} does not work

Codex merges config overrides into the table rather than replacing it, so `-c mcp_servers={}` leaves
every server enabled — verified with Codex's own reader: `codex mcp list -c mcp_servers={}` still
shows 'enabled', while `-c mcp_servers.<name>.enabled=false` shows 'disabled' (`enabled` is a real
field in `codex mcp get`). Measured cost of the ineffective pin during a live extraction: four MCP
servers spawned by one `codex exec`, ~152 MB each.

Now the backend asks Codex for its own server list (`codex mcp list --json`) and adds one
`-c mcp_servers.<name>.enabled=false` per server — no hardcoded names, best-effort (older Codex or no
config: extraction proceeds unchanged). Tests cover both servers disabled, the empty-config case, and
that the blanket form is gone.
# Conflicts:
#	graphify/cli.py
…etail, and turn-usage accounting; changelog

The argv-contract tests said what we send; these say what we accept back:
the -o JSON becomes the result dict with usage from the last turn.completed
JSONL event (cached input not double-counted), a non-zero exit or a missing/
empty -o file raises with stderr AND the JSONL stdout tail preserved (HTTP
errors surface only there), and an empty-but-valid graph raises instead of
feeding the hollow-response bisect.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Azeem1985
Azeem1985 merged commit 3788ca7 into v8 Aug 24, 2026
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