Commit Graph

6 Commits

Author SHA1 Message Date
briandevans
1c362700b3 fix(codex): stop double-counting cached input in app-server usage
_record_codex_app_server_usage fed inputTokens — which the app-server protocol
reports INCLUSIVE of cachedInputTokens — into CanonicalUsage.input_tokens while
also recording cachedInputTokens as cache_read. CanonicalUsage.prompt_tokens sums
both buckets, so cached tokens were counted twice: inputTokens=80,
cachedInputTokens=20 produced prompt_tokens=100 instead of 80. The inflated value
reached session accounting, cost estimation and context_compressor.last_prompt_tokens
(premature compaction) on every cache-hit turn (#105412, #63654, #48801).

Subtract cache_read from the reported input to get the uncached remainder,
mirroring normalize_usage's codex_responses branch so both Codex transports yield
identical accounting. The transport exposes no cache-write, so only cache_read is
subtracted. totalTokens stays the provider passthrough. The existing integration
test asserted the wrong totals; it now pins prompt=80, uncached=60, cached=20.

Ported from PR #63654 onto the current adapter shape.

Fixes #105412
2026-09-19 09:42:18 -07:00
teknium1
4b8bac1a5a test: trim codex_bin coverage to two invariants; tighten docs
Keep the two behaviours that matter for #61360 — the /codex-runtime binary
check and the app-server session spawn both receive model.codex_bin — and
drop the helper unit tests, the Popen argv test (the transport already
passes codex_bin as one argv element) and the migration capture test, whose
path is covered by the same helper. Docs name the exact failure the key
fixes and its default.
2026-09-19 09:30:56 -07:00
embwl0x
267ddabb2a feat(codex): configure app-server binary 2026-09-19 09:30:56 -07:00
teknium1
d7e405ef79 fix(agent): codex app-server quota and rate-limit failures fail over to fallback_providers
The codex_app_server dispatch returned the turn result unconditionally, so a
billing/usage-limit/rate-limit error carried as result["error"] text never reached
the classify_api_error -> _try_activate_fallback chain every other runtime uses.
Classify that text after the codex turn; on a fallback-eligible verdict activate
the configured fallback and continue the same user turn on the generic loop,
keeping the projected codex rows and the failed API call in the accounting.

Re-port of PR #71642 (@kingrubic) onto the _LoopState loop shape; the invariant
test drives the real activate -> retry path against a local fake OpenAI server.

Fixes #71633
2026-09-19 09:29:49 -07:00
teknium1
c2e5c94cd7 fix(tui): tolerate agents without session_cwd in _register_session_cwd; adapt stubs to the cwd kwarg
Workspace moves stamp agent.session_cwd so a lazily started Codex thread
starts in the moved-to directory. Agents that never had the attribute
(test doubles, slotted objects) must keep working, so stamp only when the
attribute exists. Test stubs of _set_session_context mirror the new cwd
kwarg, and the Codex gateway test asserts the contract (no pinned session
cwd) instead of the attribute's absence.
2026-09-15 22:30:11 -07:00
teknium1
d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00