Skip to content

fix(usage): carry the gateway OBO through the primary-turn params to the attempt (ENG-19115) - #198

Merged
insomnius merged 1 commit into
boonfrom
ariefrahman/eng-19115-obo-primary-turn-attempt-params
Sep 4, 2026
Merged

insomnius merged 1 commit into
boonfrom
ariefrahman/eng-19115-obo-primary-turn-attempt-params

Conversation

@insomnius

@insomnius insomnius commented Sep 4, 2026 •

Copy link
Copy Markdown

Verified locally end to end this time — RED → GREEN

Full local stack: boon-core (:3000) → anychat-boon-web-clone (dist rebuilt) → openclaw pnpm dev gateway (:18789) → local boon-llm-gateway (:8080) → back to boon-core. Turns driven with boon agent send.

RED (boon.36, i.e. #185 + #190 in): mint ✓ (minted + attached: account=2 internal_test=true), plugin ✓ (gatewayOboPresent:true), but the gateway never fetched the org's signing key (GET boon-core's per-org signing-key endpoint — zero all day) and flushed tokens_consumed for org 2 → the internal-test turn was metered. Exactly prod.

Bisection (presence-only trace logs, since removed): token present at dispatchInboundMessage, at get-reply-run (ctx and sessionCtx), and at agent-runner-execution (candidateRun.oboToken=present) — absent at withBoonUsageHeaders. Two more explicit-field-list hops:

  1. agent-runner-utils.ts buildTemplateSenderContext — built the primary-turn identity from persisted sessionCtx only. The OBO is per-turn and lives on run.oboToken, never on sessionCtx. (fix(usage): forward run.oboToken into embedded runner params (ENG-19115) #190 fixed followup-runner, which only serves queued mid-turn followups; the first turn goes through agent-runner-execution → this builder.)
  2. embedded-agent-runner/run.ts — copies RunEmbeddedAgentParams into the attempt params field by field (senderId, senderName, …) and never copied oboToken → attempt.ts's params.oboToken was always undefined. feat(usage): forward gateway-audience OBO as x-boon-gateway-obo-token (ENG-19115) #173 declared the field on the outer type and read it on the inner one; run.ts was never threaded.

Both required: builder fix alone → wire log still obo=absent. Builder + run.ts → boon usage headers attached: […, x-boon-gateway-obo-token] obo=present and the local gateway did GET …/openclaw_signing_key → 200 (first ever), i.e. it received and verified the OBO.

Changes (5 files + .design/ trace)

  • agent-runner-utils.ts: buildTemplateSenderContext(sessionCtx, run) adds oboToken: run.oboToken.
  • run.ts: attempt params include oboToken: params.oboToken (main attempt).
  • attempt.model-diagnostic-events.ts: names-only debug log of attached Boon headers + obo=present|absent (never values). This hop had zero observability — how three fixes shipped blind.
  • Tests: builder carries run.oboToken (red before) / never from sessionCtx; runEmbeddedAgent forwards oboToken into the attempt (red before) / undefined when absent. Touched suites 123/123; oxlint + oxfmt clean.
  • .design/: requirement, flow, nodes, gate + acceptance ledgers with the red/green evidence.

Not in this PR

Compaction model calls (compact.ts, and run.ts's timeout/overflow-recovery compaction sites) carry no identity today (no senderId either) — pre-existing gap, separate follow-up.

Refs #173, #185, #190, ENG-19115/19116/19117.


Summary by cubic

Carries the gateway-audience OBO token through the primary-turn runner params so internal-test turns reach the LLM gateway with the x-boon-gateway-obo-token header. Previously the token was dropped in two places — buildTemplateSenderContext built sender identity from the persisted session context only (the OBO is a fresh per-turn token on run.oboToken), and run.ts copied attempt params field by field without oboToken — so the header never reached the gateway and internal-test turns were metered against the customer's agent token budget.

  • Both fixes are required; either one alone still leaves the header absent.
  • run.ts forwards oboToken only into the main attempt; compaction-recovery attempts are untouched because compaction carries no identity today (separate follow-up).
  • Adds a names-only debug log of attached Boon headers at withBoonUsageHeaders, never values, to give this previously unobservable hop visibility.
  • Regression tests cover buildEmbeddedRunExecutionParams carrying run.oboToken and never sourcing it from sessionCtx, plus runEmbeddedAgent forwarding it into the attempt and leaving it undefined when absent.

Addresses ENG-19115.

Written for commit 15df086. Summary will update on new commits.

Review in cubic


Actual local results (verbatim, secrets-free)

Stack: boon-core :3000 (puma + sidekiq on the dispatch queue) · anychat-boon-web-clone v0.0.39 (dist rebuilt) · openclaw pnpm dev gateway :18789 · boon-llm-gateway :8080 with BOON_CORE_URL=http://localhost:3000 · turns driven by boon agent thread create / send / poll as the org-2 internal-test user. Harness: scripts/boon/obo-e2e-local.sh (this PR). Nothing below is a token, key, or personal identifier.

Manual RED — boon.36 (#185 + #190 in), before any change here

boon-core development.log, turn window:

[Openclaw::Client#add_gateway_obo_token] minted + attached: account=2 internal_test=true
Started GET  "boon-core's key-verification endpoint"                              ← gateway resolved org 2 (no org-0 trap locally)
Started POST "boon-core's request-log endpoint"  ×2
Started POST "boon-core's usage-flush endpoint"        ← tokens_consumed posted for org 2: the internal-test turn was METERED
(no GET boon-core's per-org signing-key endpoint — zero all day)   ← gateway never received an OBO header

openclaw stdout: "gatewayOboPresent":true · message dispatch completed … sessionKey=2:thread-124 … outcome=completed

Bisection (presence-only trace logs, since removed) — builder fix in, run.ts fix not yet

dispatchInboundMessage      ctx.OboToken=present  oboKeys=OboToken
get-reply-run               ctx.OboToken=present  sessionCtx.OboToken=present  ctxIsSessionCtx=false
agent-runner-execution      followupRun.run.oboToken=present  candidateRun.oboToken=present
                            runKeys=senderId,oboToken,senderName,senderSource,senderUsername,senderE164,senderIsOwner
boon usage headers attached: [x-boon-session-id, x-boon-user-id, x-boon-user-name, x-boon-thread-id] obo=absent   ×3

→ alive into agent-runner-execution, dead at the wire → the run.ts attempt-params copy was the last drop.

Harness RED — scripts/boon/obo-e2e-local.sh 2 with agent-runner-utils.ts + run.ts at their origin/boon versions

== assertions
  PASS  A2 boon-core minted + attached (account=2 internal_test=true)
  PASS  A3 plugin: gatewayOboPresent:true
  FAIL  WIRE openclaw built headers WITHOUT the OBO: boon usage headers attached: [x-boon-session-id, x-boon-user-id, x-boon-user-name, x-boon-thread-id] obo=absent
  SKIP  A4 inconclusive: org 2 signing key was fetched <5 min ago and is cached  — rely on WIRE, or rerun after 5 min
  PASS  A5 gateway → boon-core llm_request_logs internal_test=true
== result: 10 passed, 1 failed        exit=1

Harness GREEN — this branch (fresh gateway process, cache cold)

== fire one turn (org 2)
  PASS  turn completed (thread 135, reply: PONG)
== assertions
  PASS  A2 boon-core minted + attached (account=2 internal_test=true)
  PASS  A3 plugin: gatewayOboPresent:true
  PASS  WIRE openclaw attached x-boon-gateway-obo-token (obo=present)
  PASS  A4 gateway fetched org 2 signing key from boon-core → 200 (OBO arrived + verified)
  PASS  A5 gateway → boon-core llm_request_logs internal_test=true
== result: 12 passed, 0 failed

boon-core log for that turn: Started GET "boon-core's per-org signing-key endpoint" … Completed 200 OK in 21ms — the first signing-key fetch the local gateway has ever made, i.e. it received the OBO and verified it.

Not observable from these logs

The gateway's [usage] … "source" field (signed OBO vs getboon_email) is only on the gateway's own stdout. Locally the test user is @getboon.ai, so tier-2 also sets internal_test=true — the tier-1 discriminator above is the signing-key fetch (only the OBO path performs it). To confirm source end-to-end, read the gateway terminal for the turn.

Unit gate (red before / green after each edit)

  • agent-runner-utils.test.ts "carries run.oboToken into the primary-turn sender context": red expected undefined to be 'obo-signed-token' → green
  • run.before-agent-reply-cron.test.ts "forwards the gateway-audience OBO into the embedded attempt": red expected undefined to be 'obo-signed-token' → green
  • touched suites 123/123 · oxlint + oxfmt clean

…the attempt (ENG-19115)

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.
@insomnius
insomnius requested a review from a team September 4, 2026 13:32
@insomnius
insomnius enabled auto-merge (squash) September 4, 2026 13:33
@claude

claude Bot commented Sep 4, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@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.

Approved.

Trace holds: #185 fixed the read (ctx.OboToken → run.oboToken), #190 fixed the QUEUED-followup hop, but the PRIMARY turn goes through buildTemplateSenderContext (identity from sessionCtx only, no per-turn token) then run.ts's explicit field-by-field attempt-params copy (no oboToken line). Either fix alone leaves obo=absent at the wire — confirmed by the trace's turn #4 (B1 green, wire absent) vs turn #5 (both fixes, wire present ×2 + gateway fetches org-2 signing key for the first time).

Points I looked at hard:

  • The B2 test 'leaves oboToken undefined … when sessionCtx has one' is the right invariant guard. Persisted OBO would be stale (5-min TTL); sourcing from sessionCtx here would silently look right and be wrong.
  • Names-only debug log is genuinely names-only: 'attached' only ever gets header names, obo is boolean-coerced to present/absent, raw JWT never touches the log line, level is debug. Closes the observability gap that let three fixes ship blind.
  • Compaction-recovery attempt sites (timeout/overflow) intentionally skipped — compaction carries no identity today, correct as a separate follow-up.
  • Two regression tests are red-before / green-after for the two distinct hops, not one test that could pass for the wrong reason.

Auto-merge armed with SQUASH; the two directly-relevant CI shards (checks-node-auto-reply-reply-agent-runner, checks-node-agentic-agents-embedded) gate the merge.

@insomnius
insomnius merged commit 5e9a1c9 into boon Sep 4, 2026
144 of 146 checks passed
@insomnius
insomnius deleted the ariefrahman/eng-19115-obo-primary-turn-attempt-params branch September 4, 2026 13:38
insomnius added a commit that referenced this pull request Sep 4, 2026
…200)

Ships #198 (ENG-19115) — the gateway-audience OBO finally reaches the wire:
agent-runner-utils builds the primary-turn sender context from run.oboToken
and run.ts copies it into the attempt params, verified end to end on a local
stack (gateway fetched the org signing key and verified the token). Also
#197 browser-handoff recheck, #194 sentry-monitor tenant tag + hook
allow-list, #195/#196 CI dependency-audit hardening. Lockstep bump via
release:prep; CHANGELOG.md gains the 2026.6.11-boon.37 section the prepack
requires.
orswn added a commit that referenced this pull request Sep 8, 2026
…206)

## Release 2026.6.11-boon.38

Ships channel-owned sub-agent completion replies for Boon web chat.

### Contents (merged onto `boon` since boon.37)
- **#205 (ENG-19421)** — a plugin can register a completion owner for its channel; the announce flow hands the sub-agent completion to the owner and falls back to the existing delivery path when none is registered, so other channels are unchanged. `sessions_yield` runs its tool batch sequentially so a `message` send in the same turn is no longer aborted. Carries upstream openclaw#97657 and openclaw#98835 (`reply session initialization conflicted`). Smoke-tested on a local stack; evidence in #205.
- **#202** — plugin-sdk read of the gateway live run count.
- **#201** — internal identifiers removed from the public tree.

### Release prep
- Root version boon.37 → boon.38; `pnpm release:prep` regenerated the lockstep set (211 files) → `[release-preflight] OK`.
- `CHANGELOG.md` `## 2026.6.11-boon.38` section added; `scripts/package-changelog.mjs` extractor returns 2496 packaged bytes.

### After merge
Tag `v2026.6.11-boon.38` → `boon-release.yml`. The fleet is pinned to `boon.36`, so the roll also picks up boon.37 (#189, #194–#198). Gateway roll first (gated `fleet-roll`), then the anychat-boon-web release that pins this tarball.
william-antoline-boon added a commit that referenced this pull request Sep 9, 2026
…211)

## Release 2026.6.11-boon.39

Surfaces a swallowed before_tool_call hook failure to Sentry + the durable
audit trace so the ENG-19492 incident class is diagnosable after the fact.

### Contents (merged onto `boon` since boon.38)
- **#209 (ENG-19492)** — emit a `before_tool_call_hook_failed` observability
  hook (genuine handler exception only, never a policy veto), paged by
  sentry-monitor, and thread the real error text into boon-core's audit_trace
  as an optional `detail` field. Requires boon-core companion getboon/boon#14629
  (merged + live) which accepts the new field. Non-hook pipeline failures are
  classified separately.
- **#208** — derive legacy tool counts from surfaced failures.

### Release prep
- Root version boon.38 -> boon.39; lockstep regenerated (211 files:
  135 plugin package.json + 70 npm-shrinkwrap.json + SDK/config baselines).
  All release-preflight --check steps pass.
- CHANGELOG.md `## 2026.6.11-boon.39` section added.

### After merge
Tag `v2026.6.11-boon.39` -> `boon-release.yml`. Fleet is pinned to boon.36, so
a roll also picks up boon.37 (#194-#198) and boon.38 (#201, #202, #205).


Claude-Session: https://claude.ai/code/session_01AMjtZJAWLVBwa5Dtc4oNog

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

2 participants