fix(codex): declare the codex harness on every upstream request

AR
16h ago
+286-100

wally codex starts a Codex session and never tells the gateway it was Codex.

src/codex/server.rs sent the upstream request with a User-Agent and nothing else, because the comment said it could not do better:

/// The `User-Agent` sent upstream. The contract's `Harness` enum has no Codex
/// member, so there is no `X-RA-Harness` to declare; ...

The comment is out of date. console_contract.rs contains

    KCodex,
...
            Harness::KCodex => "codex",

added by 7f97280 ("contracts: sync the CLI contract from InferenceInfra staging (release 2's contract family and the codex harness)"). The comment was written in 4513e23, five days earlier. Nothing in CI compares a comment against the enum it describes, so it sat there.

Why it matters

inference.runanywhere.ai attributes each request to a harness (api/app/services/harness.py, detect()). It reads the declared header first, then falls back to a substring match over the User-Agent. That attribution feeds usage-by-tool and the ledger's harness column, and RA_REASONING_ALLOWANCE_HARNESS_ONLY gates the reasoning allowance on a recognised harness.

So a Codex session was leaning on a User-Agent substring match while every other surface declared itself. The Anthropic bridge declares claude_code and claude_desktop. The config writers declare opencode, openclaw and deepseek, each with a comment explaining that the tool's own User-Agent would not name it. Codex was the one path that got the contract wrong.

Fix

Send the header, next to the User-Agent.

headers: vec![
    (
        HARNESS_HEADER.to_string(),
        harness_header_value(DeclaredHarness::KCodex).to_string(),
    ),
    ("User-Agent".to_string(), upstream_user_agent()),
],

The spelling comes from the contract's own Harness::as_str, not a retyped literal, so a value the server cannot store cannot be sent. That is the rule stated at the top of declared_harness.rs, and this path was the one not following it.

The User-Agent stays. harness.py matches on it too, so a server whose detect() ignores the declaration still attributes the session correctly.

The stale comment is corrected rather than deleted, so the next reader can see the enum was checked.

Tests

a_streamed_turn_goes_through_end_to_end already inspects the upstream headers. It now asserts the declaration:

assert_eq!(header("X-RA-Harness").as_deref(), Some("codex"));

It fails without the fix. I reverted it to check:

assertion `left == right` failed
  left: None
 right: Some("codex")
test result: FAILED. 32 passed; 1 failed

Verified

$ cargo test --test test_wally_codex
test result: ok. 33 passed; 0 failed

$ cargo test             # whole suite
0 failed

$ cargo clippy --all-targets -- -D warnings
Finished `dev` profile, no warnings

Scope

One header, one corrected comment, one assertion. No change to translation, to the Responses endpoint, or to any other harness.

Worth a separate change: a case in declared_harness.rs's existing test that walks every Harness variant and fails when one is reachable from a wally command surface but never declared. That is the check that would have caught this without anyone reading the comment.


Summary by cubic

wally codex now sends the X-RA-Harness: codex header on every upstream request, so Codex sessions are attributed to the correct harness instead of relying on a User-Agent substring match. Previously the contract's Harness enum was assumed to lack a Codex member, but it has carried KCodex => "codex" since the release-2 contract sync.

This PR also fixes the build script's link-line filter, which passed bare include directories (e.g. the SDK's c++/v1) to the linker when -isystem and its operand were split apart, and moves the filter into build_link_args.rs so it can be tested.

Bug Fixes

  • Operand-taking flags like -isystem, -I, and -F now drop their values along with the flag; --sysroot=<dir> and -nostdinc are also filtered.
  • The existing end-to-end codex test now asserts the X-RA-Harness header, and a new test file covers the link-line filter cases.

Summary by CodeRabbit

  • Bug Fixes
    • Improved build handling of compiler-specific options, helping prevent linking issues across supported toolchains.
    • Codex requests now include harness identification alongside existing request metadata.