Skip to content

fix(usage): read gateway OBO from inbound ctx, not persisted sessionCtx (ENG-19115) - #185

Merged
insomnius merged 1 commit into
boonfrom
ariefrahman/log-obo-mapping-getreplyrun
Sep 3, 2026
Merged

insomnius merged 1 commit into
boonfrom
ariefrahman/log-obo-mapping-getreplyrun

Conversation

@insomnius

@insomnius insomnius commented Sep 3, 2026 •

Copy link
Copy Markdown

Root cause of the tier-1 OBO meter-skip never firing

The signed gateway-audience OBO (ENG-19112/19115/19117) was never reaching the gateway — every an internal-test org request logged no OBO header on request and fell back to the spoofable tier-2 @getboon.ai signal.

get-reply-run reads the OBO from sessionCtx — the reconstructed/persisted session context:

oboToken: normalizeOptionalString(sessionCtx.OboToken),

But the gateway-audience OBO is a fresh per-turn token (boon-core mints it with a 5-min TTL on every /boon-chat inbound). It rides the inbound ctx, not the persisted session. So sessionCtx.OboToken is empty on every persisted-session turn → oboToken empty → withBoonUsageHeaders emits no x-boon-gateway-obo-token → the gateway fail-closes to tier-2.

SenderId survived the same path only because it's a stable identity carried on the persisted sessionCtx — the seam OboToken was assumed to mirror, but a per-turn token can't be.

Fix

Read the inbound ctx first, fall back to sessionCtx — mirroring channelContext on the very next line:

oboToken: normalizeOptionalString(ctx.OboToken ?? sessionCtx.OboToken),

Evidence (live, an internal-test org)

  • boon-core mints + attaches the token (prod log: add_gateway_obo_token minted+attached account=<internal-test org> internal_test=true).
  • The box receives it — anychat-boon-web gatewayOboPresent: true (an internal-test org, ×16/hr) after v0.0.38 rolled.
  • Yet the gateway logged no OBO header on request every turn (its ENG-19230 logging) → the token was dropped between inbound receipt and the emitted header. This is the drop.

Confirmation after deploy

The gateway's existing logging is the regression check: post-deploy, an internal-test org requests flip from no OBO header on request → obo verified (tier-1).

Test

tsgo:core clean; existing get-reply-run + attempt.model-diagnostic-events (header-emit) tests pass. One-line context-source change mirroring the adjacent channelContext read.


Summary by cubic

Fixes the tier-1 OBO meter-skip never firing by sourcing the gateway-audience OBO from the inbound ctx instead of the persisted sessionCtx.

  • The token is a fresh per-turn token minted on every /boon-chat inbound, so it lives on ctx, not the reconstructed sessionCtx; reading only sessionCtx.OboToken left it empty and suppressed the x-boon-gateway-obo-token header, so the gateway fell back to tier-2 metering.
  • Now reads ctx.OboToken with a sessionCtx fallback, mirroring the adjacent channelContext read; post-deploy, an internal-test org requests flip from no OBO header on request to obo verified.

Written for commit 8764155. Summary will update on new commits.

Review in cubic

…tx (ENG-19115)

The gateway-audience OBO is a FRESH per-turn token -- boon-core mints it
with a 5-min TTL on every /boon-chat inbound. get-reply-run read it from
`sessionCtx` (the reconstructed/persisted session context), where it is
absent on every persisted-session turn -> `oboToken` was empty ->
withBoonUsageHeaders emitted no x-boon-gateway-obo-token -> the gateway
fell back to tier-2 (@getboon.ai) for internal-test metering.

SenderId survived only because it is a stable identity carried on the
persisted sessionCtx. Read OboToken from the inbound `ctx` first (fallback
to sessionCtx), mirroring `channelContext` on the next line.

Verified live: the box receives the token (anychat gatewayOboPresent=true
for org 99) yet the gateway logged "no OBO header on request" every turn.
@claude

claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@gandalfboon gandalfboon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving — the diagnosis is right and the fix is minimal.

Correctness check:

  • MsgContext.OboToken is declared on both ctx and sessionCtx (same type), so ctx.OboToken ?? sessionCtx.OboToken type-checks cleanly.
  • The comment nails the invariant: fresh per-turn 5-min-TTL token has to ride the inbound ctx, not the reconstructed session. The parallel with channelContext: ctx.ChannelContext ?? sessionCtx.ChannelContext on the very next line makes the pattern obvious to the next reader.
  • SenderId staying sessionCtx-only is the right call — it's stable-per-session identity, not per-turn.

Follow-up (not a merge-blocker):

  • Please add a regression test at the get-reply-run layer (get-reply-run.media-only.test.ts already stubs runPreparedReply — extend it or spin a sibling .obo-token.test.ts) that pins:

    1. ctx.OboToken set + sessionCtx.OboToken empty → run.oboToken = ctx value
    2. Both empty → run.oboToken undefined
    3. Both set → ctx wins (precedence)

    The existing attempt.model-diagnostic-events.test.ts proves the header flows when oboToken is truthy, but nothing at the get-reply-run layer pins where it's read from — which is exactly the regression that just shipped. A three-case test would make the same bug impossible to reintroduce silently.

Merge when CI settles.

@insomnius
insomnius merged commit f549f8e into boon Sep 3, 2026
144 of 146 checks passed
@insomnius
insomnius deleted the ariefrahman/log-obo-mapping-getreplyrun branch September 3, 2026 09:51
insomnius added a commit that referenced this pull request Sep 3, 2026
…186)

Cut the boon.34 fork release. Carries ENG-19115 fix (#185): read the
gateway-audience OBO from the inbound ctx, not the persisted sessionCtx
-- the per-turn token was being dropped, so the tier-1 internal-test
meter-skip never fired. Plus #182 (sentry-monitor correlation ids).

release:prep synced the lockstep extension versions + regenerated
release artifacts (plugin inventory/reference docs, shrinkwraps,
plugin-sdk API baseline, bundled-channel-config metadata).
insomnius added a commit that referenced this pull request Sep 3, 2026
#186 bumped the version but omitted the CHANGELOG.md section, so the
boon-release.yml prepack (scripts/package-changelog.mjs) hard-fails with
"CHANGELOG.md does not contain a release section for 2026.6.11-boon.34"
and no fleet tarball is built. Add the boon.34 section (covers #185
ENG-19115 OBO ctx fix, #182, #181) to unblock the release.
insomnius added a commit that referenced this pull request Sep 3, 2026
…15) (#190)

The gateway-audience OBO never reached the model call even after #185.
get-reply-run correctly sets run.oboToken from the inbound ctx, but
followup-runner builds RunEmbeddedPiAgentParams from an explicit field
list off the run block and never forwarded oboToken. FollowupRun.run did
not declare the field either, so no hop could legally reference it: the
value rode the untyped literal to that hop and was silently dropped,
params.oboToken was undefined in attempt.ts, and x-boon-gateway-obo-token
was never emitted. The gateway fell back to tier-2 email, or fully
metered internal-test senders whose identity is not @getboon.ai —
confirmed on org 543 (arief-openclaw-test) running boon.34, where the
gateway logged neither tier for the turn.

Declare oboToken on FollowupRun.run and forward it alongside
senderId/channelContext. Regression tests cover both directions:
forwarded when present, undefined when absent (omit-when-absent kept).
insomnius added a commit that referenced this pull request Sep 4, 2026
…the attempt (ENG-19115) (#198)

Local end-to-end run (boon-core -> anychat-boon-web -> openclaw -> local
boon-llm-gateway) on boon.36 reproduced the production failure: boon-core
minted the gateway-audience OBO, the plugin set MsgContext.OboToken, and
x-boon-gateway-obo-token still never reached the gateway. Presence-only
tracing at each hop showed the token alive through get-reply-run (#185)
and into agent-runner-execution, then gone at withBoonUsageHeaders. Two
more explicit-field-list hops dropped it:

- agent-runner-utils buildTemplateSenderContext built the primary-turn
  sender identity from the persisted sessionCtx only. The OBO is a fresh
  per-turn token that lives on run.oboToken, never on sessionCtx, so the
  first turn never carried it. (#190 fixed followup-runner, which only
  serves queued mid-turn followups.)
- embedded-agent-runner/run.ts copies RunEmbeddedAgentParams into the
  attempt params field by field and never copied oboToken, so attempt.ts's
  params.oboToken was undefined on every turn. #173 declared the field on
  the outer type and read it on the inner one without threading run.ts.

Both are required: with the builder fixed alone the wire log still read
obo=absent; with run.ts fixed as well the header attached and the local
gateway fetched the org's signing key from boon-core (200) for the first
time.

Also adds a names-only debug log of the Boon headers attached to each
model call (never values) - this hop had no observability, which is how
three fixes shipped without moving the gateway.

Regression tests: buildEmbeddedRunExecutionParams carries run.oboToken
(red before the builder edit) and never sources it from sessionCtx;
runEmbeddedAgent forwards oboToken into the embedded attempt (red before
the run.ts edit) and leaves it undefined when absent. Compaction-recovery
attempts intentionally untouched: compaction carries no identity today
(separate follow-up). .design/ records the trace and red->green ledger.
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