Skip to content

Add an OpenAI Codex adapter that lets Codex call common.ai toolsets - #76000

Merged
Lee-W merged 17 commits into
apache:mainfrom
astronomer:common-ai-openai-codex
Nov 19, 2026
Merged

Lee-W merged 17 commits into
apache:mainfrom
astronomer:common-ai-openai-codex

Conversation

@Lee-W

@Lee-W Lee-W commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Why

Codex runs as a separate harness process, so it can only reach Airflow tools through an MCP server. This adds an adapter that serves the common.ai toolsets to it, like the existing Strands, ADK, Anthropic, OpenAI Agents and Claude Agent SDK adapters. The adapter is experimental: tool calls through MCP, removal of the built-in shell tool, deny_all approval and apply_patch under the read-only sandbox have not been run against a model, and the guide lists the manual checks.

What

  • AirflowTools (tools/openai_codex.py) serves toolsets to Codex from a loopback MCP server guarded by a per-run bearer token.
  • Isolation: Codex starts with empty CODEX_HOME, HOME and cwd, its shell tool is turned off, and the thread defaults to deny_all approval with a read_only sandbox. A system-level config under /etc is still read. Known limits are in the guide.
  • Failures: a correctable tool failure returns to the model as an isError result. Any other failure interrupts the turn and run() raises ToolCallError.
  • MCPToolset is rejected with MCPToolsetNotSupportedError, and the message points to Codex's mcp_servers config.
  • The new openai-codex extra and the dev group floor mcp at 2.2.0. The workspace resolves one mcp for every provider, and the lowest-direct resolution installed 2.0.0, which broke the Databricks Unity MCP tests that check an error message 2.2.0 added.
  • Adds a guide (docs/frameworks/openai_codex.rst), an example Dag, and the openai_codex value for the framework tag of common_ai.tool_calls.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@kaxil

kaxil commented Nov 5, 2026

Copy link
Copy Markdown
Member

@Lee-W #76495 (review)

@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch 7 times, most recently from 21f647b to e2b436b Compare November 13, 2026 06:08
@Lee-W
Lee-W marked this pull request as ready for review November 13, 2026 06:46
@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from 08cbad1 to 4815f4a Compare November 16, 2026 03:09
@Lee-W

Lee-W commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

@Lee-W #76495 (review)

The Codex adapter now passes an MCP hint to _collect_tools that points to Codex's mcp_servers config, and a test covers the MCPToolsetNotSupportedError message.

@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from 4815f4a to c4739a8 Compare November 17, 2026 07:58
@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from c4739a8 to 51f6ab3 Compare November 18, 2026 02:04
@kaxil

kaxil commented Nov 18, 2026

Copy link
Copy Markdown
Member

@Lee-W Would appreciate screenshots/gif/demo of a working dag

@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch 2 times, most recently from 0594d06 to 18573c4 Compare November 18, 2026 06:26
@github-actions

Copy link
Copy Markdown
Contributor

uv.lock on main just moved via #73926 ("Include tables when DocumentLoaderOperator parses DOCX files"), commit eca7ad4 and this PR currently conflicts.

Quickest fix:

git fetch upstream main && git rebase upstream/main
rm uv.lock && uv lock
git add uv.lock && git rebase --continue
git push --force-with-lease

Automated nudge — ignore if you're not ready to rebase. This comment is updated in place on future uv.lock bumps.

@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from 18573c4 to cb493a4 Compare November 18, 2026 23:59
@Lee-W

Lee-W commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

This is the log from example_openai_codex, showing Codex calling the SQL tools and returning the table counts: 3 customers and 5 orders.

Screenshot 2026-11-19 at 10 53 36 AM

@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from cb493a4 to 94bdbc8 Compare November 19, 2026 02:32
Lee-W added 17 commits November 19, 2026 19:19
Codex runs as a separate harness process, so it can only reach Airflow
tools through an MCP server. The adapter serves the tools from a
loopback MCP server guarded by a per-run bearer token and starts Codex
against an empty home and working directory, so it reads none of the
worker's user-level Codex settings. A system-level config under /etc
is still read.

The adapter is experimental. Tool calls through MCP, removal of the
built-in shell tool, the `deny_all` approval mode and `apply_patch`
under the read-only sandbox have not been run against a model;
the guide lists the manual checks for them.
…adapter

- Pass an MCP hint to _collect_tools so the error names Codex's mcp_servers config
- Add a test that an MCPToolset raises MCPToolsetNotSupportedError with that hint
The workspace resolves one mcp for every provider, so the lowest-direct
resolution installed mcp 2.0.0 and broke the Databricks Unity MCP tests,
which check a client error message mcp 2.2.0 added. The openai-codex extra
and the dev group now floor mcp at 2.2.0.
Cancelling run(), for example with asyncio.wait_for, now interrupts the turn before the stream is closed.
The interrupt is skipped if the turn already completed or a tool-failure interrupt was already sent.
The interrupt log message no longer says it follows a tool failure.
The tests' HTTP client relied on httpx2's default 5 second timeout. On the
Compat 3.2.2 / Python 3.11 CI job,
TestRealMcpServer::test_a_successful_tool_result_is_not_marked_isError hit
a ReadTimeout after 5.39 seconds. The cause is not established; it is likely
a stall on the shared event loop under load. The client now uses an explicit
60 second timeout. Only the test changes.
The in-process MCP server built its uvicorn.Config without log_config,
so uvicorn applied its default logging dictConfig, which disables the
task process's existing log handlers. The config now passes
log_config=None, as the API server command does. A test pins the value.
The Codex example imported SQLToolset at module level, but it needs the
sql extra, which is optional. Dag parsing would fail wherever that extra
is not installed. The import now sits in the task next to AirflowTools,
as in the Claude Agent SDK example, and the comment covers both extras.
The docs said the task log shows framework=openai_codex. The log shows
a Tool call group, and the common_ai.tool_calls metric carries the tag.
They also said hook calls run one at a time anyway. The adapter queues
only sequential tools, so other tools rely on
supports_parallel_tool_calls=false. The retry budget text now says that
Codex sends calls one after another, so failed calls in one response
each count, here and in the code comment. Only text changes.
…uarantees

The retry budget counts failures of calls that run at the same time as one
and calls one after another separately. The adapter asks Codex to send calls
one at a time, but whether Codex honours that is not confirmed, so the
comments and the guide now say "normally" instead of promising it.

The comment on supports_parallel_tool_calls no longer cites the docs, and
the uvicorn comment says what the default logging config does: it removes
and closes the task process's log handlers. The example now tells users to
install the sql extra too, since its task uses SQLToolset.
The supports_parallel_tool_calls row now says the flag asks Codex not to
send calls in parallel, matching the note that Codex's compliance is not
yet confirmed. The uvicorn log_config comment is wrapped to fit the line
length limit.
The docs spelling check rejects "honours", which failed the documentation build. The same sentence in the adapter comment is changed to match.
…is passed

build_thread_options() now rewrites a nested config["mcp_servers"] table into
dotted mcp_servers.<name>.<key> keys. Codex replaces a nested table as a whole
at thread level, so the adapter's own server and its required=true were dropped
and the thread started without any Airflow tools. The same-name check now also
covers dotted keys, and a server or setting name that cannot be written as a
dotted key raises ValueError.
AirflowTools.run() now marks the run ended before it waits up to 10 s for
the Codex turn interrupt on cancellation. A tool call that arrives in that
window is answered with a "Not run" result instead of executing its hook.

Cover both outcomes of a failing stream close: it propagates after a
completed turn, and it is logged while the tool failure is raised.
The Codex guide said the adapter is tested with openai-codex 0.163.0 but
did not say that Airflow's lock, and so CI, resolves 0.167.0. Say it was
first tested with 0.163.0 and that the lock and CI have 0.167.0, as the
guide already does for mcp.

Set execution_timeout on the example task, as the guide advises, so the
example cannot loop on model responses without limit.

Move the note on draining connections from the start timeout to
_SERVER_SHUTDOWN_TIMEOUT_SEC, which is what it describes.
The Codex docs no longer say which Codex version or environment the
adapter was tested on, and the installation section no longer cites the
versions Airflow's lock resolves to. The note on MCP server names keeps
the fact that Codex rejects a quoted key segment.

The example task now allows 30 minutes instead of 10. Ten minutes equals
the adapter's default tool timeout, so one tool call that ran to its
timeout would use up the whole task budget.
@Lee-W
Lee-W force-pushed the common-ai-openai-codex branch from cd6a559 to b8a7b7d Compare November 19, 2026 10:19
@Lee-W
Lee-W enabled auto-merge (squash) November 19, 2026 11:00
@Lee-W
Lee-W merged commit 36193e1 into apache:main Nov 19, 2026
92 checks passed
@Lee-W
Lee-W deleted the common-ai-openai-codex branch November 19, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants