skill: treat unavailable subagent token usage as unknown, not zero (Codex)
Environment
- graphifyy
0.9.20 - Codex desktop collaboration host
- clean, large mixed code/docs repository refresh
Observed behavior
The semantic chunks correctly carry placeholder input_tokens: 0 and
output_tokens: 0, and the skill correctly asks the parent agent to replace
them with the Agent tool result's usage fields before merging.
In this Codex host, collaboration results expose completion text but not a
machine-readable token-usage payload. A six-chunk refresh therefore had real
semantic-agent work but no trustworthy per-chunk counts to write back. If we
followed the current merge literally, the committed GRAPH_REPORT.md and
cost.json would state 0 input / 0 output, which is false rather than
"unknown". We had to edit the report to say that token accounting was
unavailable.
This is adjacent to closed #658, but it is not the same omission: the skill now tells hosts that expose usage to preserve it. The remaining gap is a host that cannot expose usage at all.
Proposal
Make token accounting tri-state in the skill and generated report:
- When per-chunk usage is available, sum it as today and mark
token_accounting: measured. - When a host does not expose usage, persist
null/unavailable(not zero) with a short reason such ashost_usage_not_exposed. - Keep zero exclusively for a genuinely code-only/no-semantic run.
- Add one small regression fixture: semantic chunks plus missing host usage
must render
Token accounting: unavailable, never0 input · 0 output.
This is a reporting-only change: it neither adds an LLM call nor lengthens
update, CI, or release paths. It preserves Graphify's honesty promise for
agent hosts whose orchestration API intentionally hides usage.
Another angle on the same field: even on a host that can report usage, the number that lands in cost.json is agent-supplied, never measured.
Env: graphifyy 0.9.39, Claude Code host, 116-file corpus.
The chunk JSON ships input_tokens: 0 / output_tokens: 0 placeholders, and Step B3 asks the parent agent to write the real values back before merging. Nothing downstream validates them. In my run the semantic pass ran inline in the parent agent (no subagent dispatch, so no usage payload existed at all), and I wrote an estimate into the merged file. graphify-out/cost.json now reads:
{"runs": [{"date": "...", "input_tokens": 212000, "output_tokens": 14000, "files": 116}],
"total_input_tokens": 212000, "total_output_tokens": 14000}
and GRAPH_REPORT.md prints Token cost: 212,000 input · 14,000 output with no marker distinguishing it from a measured figure. A cumulative total_* across runs then compounds whatever each run happened to write.
This strengthens the tri-state proposal — the third state is not only "host cannot expose usage" but "value is self-reported and unverified". Concretely:
token_accounting: measured— read from a host usage payloadtoken_accounting: reported— written by the agent without a usage payload (today's silent default)token_accounting: unavailable— host exposes nothing, persistnulltoken_accounting: none— genuinely code-only run, where zero is correct
and have cost.json refuse to add anything but measured into the cumulative totals, or keep a separate total per state. Otherwise the all-time number is an average of guesses presented as an accounting record.
Opened #4772. It implements the tri-state you proposed. A chunk whose host gives no machine-readable usage gets null token counts, and null stays unknown from there: the B3 merge writes null totals, cost.json records the run and counts it under unmeasured_runs without adding it to the all-time totals, merge-chunks and build() carry it through, and GRAPH_REPORT.md says "Token cost: unavailable (the host did not report token usage)". Zero still means a run with no semantic work. The regression test runs the skill's own merge and cost snippets (codex, aider and devin variants) and fails on v8. This closes when #4772 merges.