Skip to content

fix(agents): reject synchronous sessions_send self-targets, break down missing-cost entries, dedup usage merges - #108354

Merged
steipete merged 3 commits into
mainfrom
claude/codex-group7-reporting
Jul 15, 2026
Merged

steipete merged 3 commits into
mainfrom
claude/codex-group7-reporting

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Three Codex-adjacent reporting/behavior bugs:

  1. [Bug]: Codex sessions_send can self-target the active Feishu session, causing lane wait and “Done.” empty-reply fallback #107172 — A Codex-runtime session could call sessions_send with a target that resolved to its own active session key. The message enqueued on the sender's own lane (held by the in-flight turn), blocked until the lane timeout, and surfaced as a "Done." empty-reply fallback.
  2. [Bug]: Show token/provider breakdown for missingCostEntries, especially openai-codex/* #98348 — Zero-priced usage (Codex models deliberately ship cost: 0, which isModelPricingKnown treats as unknown) incremented an opaque missingCostEntries counter with no way to see which provider/model was unattributed.
  3. [Refactor] Consolidate duplicated telemetry reporting inside codex-synthetic-usage.ts #107497 — codex-synthetic-usage.ts repeated the same preferred-vs-secondary precedence ranking across three merge helpers.

Why This Change Was Made

  • Self-target guard: after canonical session-key resolution and before dispatch, a synchronous send (timeoutSeconds !== 0) whose resolved target equals the requester's key fails fast with "sessions_send cannot target the calling session; use your own reply instead". The legitimate self-send path is preserved: timeoutSeconds: 0 fire-and-forget channel-delivery/A2A flow is untouched, and cron/system-event delivery uses a separate mechanism.
  • Missing-cost breakdown: an optional missingCostByModel: Record<"provider/model", count> rides alongside the existing scalar (kept for compatibility), aggregated where raw provider attribution already exists, with a cache-version bump and clone/merge support; the status runtime line and gateway CLI cost line render it compactly (Missing cost: 3 (openai/gpt-5.6-sol 2, openai-codex/gpt-5.5 1)).
  • Merge dedup: one generic precedence helper feeds all three merges; identical ranking semantics, production file net −2 LOC, plus new billing-precedence coverage.

User Impact

  • No more mysterious lane-timeout "Done." replies from agent self-sends; the agent gets an actionable error immediately.
  • /status and openclaw gateway cost output attribute missing-cost turns to concrete provider/model pairs.

Evidence

  • Focused suites (all pass): session-cost-usage 43+ (new breakdown/aggregation/clone-merge cases), codex-synthetic-usage (precedence coverage added), sessions tool 46 (self-target rejected; distinct target unaffected; fire-and-forget preserved), status-text, gateway-cli coverage.
  • Live loopback proof during implementation showed the formatted breakdown line with JSON retaining scalar + map.
  • Autoreview (Codex gpt-5.6-sol, xhigh): clean on first pass (0.94).

Fixes #107172
Fixes #98348
Fixes #107497

…n missing-cost entries, dedup usage merges

- sessions_send fails fast with a clear error when a synchronous send resolves
  to the calling session's own key, instead of enqueueing behind the sender's
  own lane until timeout and falling back to an empty reply; fire-and-forget
  (timeoutSeconds: 0) self-delivery keeps working (#107172)
- missingCostEntries now carries a provider/model breakdown surfaced on the
  status runtime line and gateway CLI cost line, so zero-priced usage (e.g.
  openai-codex/*) is attributable instead of an opaque counter (#98348)
- codex-synthetic-usage merge helpers share one precedence helper; behavior
  unchanged, duplicate ranking logic deleted (#107497)
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 15, 2026
@steipete
steipete merged commit 65188a7 into main Jul 15, 2026
113 checks passed
@steipete
steipete deleted the claude/codex-group7-reporting branch July 15, 2026 15:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 16, 2026
…n missing-cost entries, dedup usage merges (openclaw#108354)

* fix(agents): reject synchronous sessions_send self-targets, break down missing-cost entries, dedup usage merges

- sessions_send fails fast with a clear error when a synchronous send resolves
  to the calling session's own key, instead of enqueueing behind the sender's
  own lane until timeout and falling back to an empty reply; fire-and-forget
  (timeoutSeconds: 0) self-delivery keeps working (openclaw#107172)
- missingCostEntries now carries a provider/model breakdown surfaced on the
  status runtime line and gateway CLI cost line, so zero-priced usage (e.g.
  openai-codex/*) is attributable instead of an opaque counter (openclaw#98348)
- codex-synthetic-usage merge helpers share one precedence helper; behavior
  unchanged, duplicate ranking logic deleted (openclaw#107497)

* test: use a valid billing type in synthetic-usage precedence case

* test: fix billing expectation to match valid type
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…n missing-cost entries, dedup usage merges (openclaw#108354)

* fix(agents): reject synchronous sessions_send self-targets, break down missing-cost entries, dedup usage merges

- sessions_send fails fast with a clear error when a synchronous send resolves
  to the calling session's own key, instead of enqueueing behind the sender's
  own lane until timeout and falling back to an empty reply; fire-and-forget
  (timeoutSeconds: 0) self-delivery keeps working (openclaw#107172)
- missingCostEntries now carries a provider/model breakdown surfaced on the
  status runtime line and gateway CLI cost line, so zero-priced usage (e.g.
  openai-codex/*) is attributable instead of an opaque counter (openclaw#98348)
- codex-synthetic-usage merge helpers share one precedence helper; behavior
  unchanged, duplicate ranking logic deleted (openclaw#107497)

* test: use a valid billing type in synthetic-usage precedence case

* test: fix billing expectation to match valid type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes maintainer Maintainer-authored PR size: M

Projects

None yet

1 participant