codex icon indicating copy to clipboard operation
codex copied to clipboard

Python SDK metadata includes the user-agent suffix in serverInfo.version

Open dovvnloading opened this issue 3 weeks ago • 1 comments

Summary

The Python SDK's public Codex.metadata.serverInfo.version includes the platform, terminal, and client suffix from the user-agent string rather than just the server version. Callers cannot reliably compare or parse that field as a version.

Reproduction

With the checkout's Python SDK dependencies installed, put sdk/python/src on PYTHONPATH and run this isolated test with codex on PATH. It starts only the local app server.

import os
from pathlib import Path
import shutil
import subprocess
import tempfile

from openai_codex import Codex, CodexConfig
from openai_codex._runtime_requirements import require_runtime_version

with tempfile.TemporaryDirectory(dir=os.getcwd()) as tmp:
    Path(tmp, 'config.toml').write_text('[features]\nplugins = false\n', encoding='utf8')
    cli = shutil.which('codex')
    assert cli
    expected = subprocess.check_output([cli, '--version'], text=True).strip().split()[-1]
    config = CodexConfig(codex_bin=cli, cwd=tmp,
                         env={'CODEX_HOME': tmp, 'CODEX_APP_SERVER_DISABLE_MANAGED_CONFIG': '1'})
    with Codex(config) as client:
        actual = client.metadata.serverInfo.version
        print('codex --version:', expected)
        print('metadata.serverInfo.version:', repr(actual))
        print('metadata.userAgent:', repr(client.metadata.userAgent))
        assert actual.startswith(expected + ' ')
        require_runtime_version(expected)
        try:
            require_runtime_version(actual)
        except ValueError:
            print('runtime version validation rejects metadata version')
        else:
            raise AssertionError('expected invalid metadata version')

On Windows with Python 3.14.0, SDK source at 392ced7d3a9160fd35d40c606359869215f50522, and codex-cli 0.167.0-alpha.4.1, the CLI reported 0.167.0-alpha.4.1, while metadata reported 0.167.0-alpha.4.1 (Windows 10.0.26200; x86_64) dumb (codex_python_sdk; 0.0.0-dev). The SDK's version validator accepted the former and rejected the latter. This was reproduced independently. The SDK's own initialization separately extracts the first token for its internal runtime version; this report concerns the public metadata field.

Expected behavior and possible fix

Populate serverInfo.version with the version token while retaining the complete userAgent. _split_user_agent currently takes everything after the first slash as the version. Parse the version token in the fallback path and preserve an explicitly supplied serverInfo. Add tests for a full user agent, an explicit server version, and sync/async metadata.

The relevant SDK source matches main at 1b7c0252586f3701493bb7c9331290c06346b842; testing used the installed CLI rather than a native build of that commit. Searches for Python SDK serverInfo.version and _split_user_agent found no equivalent report.

dovvnloading avatar Nov 12 '26 00:11 dovvnloading

Additional AI-assisted regression verification against the upstream source at 065e18b04021008e2e7d504db8dc50275f589f73 confirms that the fallback user-agent parser retains platform and terminal metadata in the server version.

An isolated six-case Python 3.13.5 test passed 3/6 cases with the upstream parsing behavior and 6/6 with the proposed version-token extraction.

The corresponding implementation is available for reference:

https://github.com/sanskarIN/codex/commit/459816b2639dfc0da294342542e6624f1b48e92d

These results are from reduced parser fixtures, not a full SDK integration test.

sanskarIN avatar Nov 28 '26 14:11 sanskarIN