Skip to content

fix(hive): backfill the context gauge for Codex agents from their rollout log - #542

Open
MEKSI8 wants to merge 1 commit into
chaitanyagiri:mainfrom
MEKSI8:fix/codex-context-gauge
Open

MEKSI8 wants to merge 1 commit into
chaitanyagiri:mainfrom
MEKSI8:fix/codex-context-gauge

Conversation

@MEKSI8

@MEKSI8 MEKSI8 commented Sep 16, 2026

Copy link
Copy Markdown

What & why

Codex agent cards can remain without a context (ctx %) reading while a worker
is active. The root cause is a provider-coverage gap, not one shared telemetry
failure:

  • Claude can send an exact context reading through a status hook.
  • The renderer independently polls Claude transcripts every 15 seconds to
    backfill a missing reading (useHive.ts:565-590).
  • Fleet tokens/lastTool data comes from a separate OpenTelemetry input.
  • Codex rollout logs provide another provider-specific source through
    token_count events.

The shared Codex hook wiring was traced in the architecture, but hook delivery
was not empirically proven as part of this work. This fix does not depend on
that delivery path.

HiveManager now exposes the isolated worker CODEX_HOME at
<hive>/agents/<id>/.codex. The main-process poll reads that location rather
than the registry's project cwd, selects the newest nested rollout, and feeds
the latest valid last_token_usage.input_tokens / model_context_window
reading through HookServer.reportContext(). The renderer needs no change.

The 8-second poll no longer recursively walks all rollout history on every
tick. The selected path, mtime, size, and reading are cached; ordinary ticks
stat only the selected file, changed files are re-tailed, and discovery is
repeated after 60 seconds or immediately if the selected file disappears.

Fleet cost/activity telemetry remains out of scope and unchanged.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Build / CI

Evidence

Before

Before: readCodexContext(registryCwd) called on the pre-fix path returns null — the project worktree has no .codex, so a Codex agent's context gauge never populates

The pre-fix candidate was run against a read-only copy of one real worker
rollout. The registry project cwd returned no reading, while the agent
directory happened to work only because the old parser appended .codex
itself:

{"registryCwdReading":null,"agentDirectoryReading":{"tokens":204802,"limit":258400}}

The regression-first focused run against the pre-fix implementation exited 1:
9/15 tests succeeded and 6 failed, including the registry/HiveManager seam,
the exact tail-window boundary, and cache behavior.

After

After: readCodexContext(codexHome) called through HiveManager.codexHome(id) returns a real {tokens, limit} reading from a copy of an actual Codex rollout file

After: the running Munder Difflin office (candidate applied) — Dwight and Angela, the two Codex-provider agents, now show a populated context gauge under their agent cards, same as the Claude agents

The same copied rollout, placed under an agent-home-shaped temporary directory,
was read through the corrected CODEX_HOME contract without reading or modifying
the live session:

{"projectCwdReading":null,"codexHomeReading":{"tokens":204802,"limit":258400}}

The focused command node --test test/codex-context.test.cjs exited 0 with
15/15 tests. Its coverage includes the real HiveManager.registry() plus
HiveManager.codexHome() seam, a tail window beginning exactly after a newline,
cache refresh/discovery behavior, and deletion assertions for every test temp
directory.

The repository-wide test command still exits 1 because the base and candidate
both have the same 19 failing test names:

base bdf524e:      831 total / 804 succeeded / 19 failed / 8 skipped
candidate:         846 total / 819 succeeded / 19 failed / 8 skipped
failing-name diff: empty

Since this evidence was gathered, the office was restarted with this fix
applied. The third screenshot above is that running app: Dwight's and Angela's
(Codex) agent cards now carry the same context gauge Claude agents already had.

How I tested it

  • Windows 11, Node v24.15.0.
  • npm ci --ignore-scripts — exit 0; 870 packages installed. npm reported the
    existing audit state: 22 vulnerabilities (3 moderate, 18 high, 1 critical).
  • node --test test/codex-context.test.cjs — exit 0; 15/15.
  • npm run typecheck — exit 0 (node and web TypeScript projects).
  • node --test --test-reporter=tap test/*.test.cjs on detached base
    bdf524e — exit 1; 19 baseline failures.
  • The same full-suite command on the candidate — exit 1; the same 19 failure
    names, with 15 additional successful Codex-context tests.
  • npm run build — exit 0; Vite retained its existing dynamic/static import
    chunk warning.
  • git diff --check bdf524e..HEAD — exit 0.
  • Real-rollout copy reproduction above — exit 0; the temporary copy and
    detached base worktree were removed afterward.

Credit

Discord:

X:

Checklist

  • Before and after terminal evidence is recorded above.
  • npm run typecheck completed with exit 0.
  • npm run test:focused is not claimed: the repository-wide test command
    remains exit 1 with the same 19 baseline failures. The directly relevant
    Node test file completed 15/15 with exit 0.
  • npm run build completed with exit 0.
  • This PR is limited to the Codex context gauge and supporting tests.
  • No debug output, unrelated formatting churn, or live data mutation is
    included.
  • N/A — no new UI.
  • N/A — no new art.

…lout log

Codex agent cards can remain without a context (`ctx %`) reading while a
worker is active. The root cause is a provider-coverage gap, not one shared
telemetry failure: Claude can send an exact reading through a status hook and
the renderer independently backfills from Claude transcripts every 15 seconds
(`useHive.ts:565-590`), while fleet `tokens`/`lastTool` come from a separate
OpenTelemetry input. Codex supplies none of those, but its rollout logs carry
`token_count` events with the same accounting.

`HiveManager` now exposes the isolated worker `CODEX_HOME` at
`<hive>/agents/<id>/.codex`. The main-process poll reads that location rather
than the registry's project `cwd`, selects the newest nested rollout, and feeds
the latest valid `last_token_usage.input_tokens` / `model_context_window`
reading through `HookServer.reportContext()`. The renderer needs no change.

The 8-second poll does not walk all rollout history on every tick: the selected
path, mtime, size and reading are cached, ordinary ticks stat only the selected
file, and discovery repeats after 60 seconds or as soon as the selected file
disappears.

Codex hook delivery was traced through the shared shim architecture but was not
empirically proven here; this fix does not depend on that path. Fleet
cost/activity telemetry stays out of scope.

Tests: 15 new cases in test/codex-context.test.cjs, including the
registry/HiveManager seam and the tail-boundary case. The repository's full
`node --test test/*.test.cjs` exits 1 on this platform both before and after
this change with the same 19 pre-existing failures.
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Evidence received. Before and after are both attached. Thanks — this is what makes a PR reviewable in one pass.

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