Skip to content

feat(plugin-sdk): expose the gateway live run count via gateway-activity-runtime - #202

Merged
holywend merged 5 commits into
boonfrom
wendy/gateway-activity-runtime
Sep 7, 2026
Merged

holywend merged 5 commits into
boonfrom
wendy/gateway-activity-runtime

Conversation

@holywend

@holywend holywend commented Sep 7, 2026 •

Copy link
Copy Markdown

What

Adds a narrow plugin-sdk read of the Gateway's live run count so a channel plugin can implement a drain guard — "is a customer turn in flight right now?" — without importing the broad gateway runtime barrel or reaching into gateway internals.

Three commits:

  1. feat(gateway) — new src/gateway/gateway-activity.ts. A process-local probe: setGatewayActiveRunCountProbe installs a counter, getGatewayActiveRunCount() reads it. server-runtime-state.ts installs the probe next to chatAbortControllers and clears it in releasePluginRouteRegistry (the gateway close path) and in the half-created-state catch, so a closed or failed runtime reports null instead of a stale count from an abandoned run map.
  2. feat(plugin-sdk) — new public subpath openclaw/plugin-sdk/gateway-activity-runtime re-exporting only getGatewayActiveRunCount. Registers the entrypoint, its doc-metadata category (runtime), the package.json export, the regenerated API baseline hash, and a row in docs/plugins/sdk-subpaths.md.
  3. chore(plugin-sdk) — the public surface ratchet in scripts/plugin-sdk-surface-report.mjs is pinned to the exact current counts, so one new entrypoint with one callable export trips all three budgets. Each is bumped by exactly one, keeping the ratchet tight.

Contract

getGatewayActiveRunCount(): number | null
  • number — count of registered chat/agent runs whose abort signal has not fired; these are the runs a restart would kill.
  • null — the count is unavailable: no gateway is running in this process, or the probe threw or returned a non-finite/negative value. Callers must treat null as unknown, never as idle. A drain guard that reads null must refuse to act rather than assume zero.

Why a probe rather than exporting the run map

Keeps the SDK surface to one function and one capability. The abort-controller map stays private to the gateway; plugins get the derived fact, and the lifecycle that owns the map owns installing and clearing the reader.

Testing

  • pnpm test src/gateway/gateway-activity.test.ts src/gateway/server-runtime-state.test.ts src/gateway/server.startup-websocket-race.test.ts — 8 files, 22 tests passed (new test written first, confirmed red on the missing module).
  • pnpm test src/plugins/contracts/plugin-sdk-subpaths.test.ts src/plugins/contracts/plugin-sdk-package-contract-guardrails.test.ts src/plugin-sdk/api-baseline.test.ts — 43 tests passed.
  • pnpm test test/scripts/plugin-sdk-surface-report.test.ts — 7 tests passed after the budget bump.
  • pnpm plugin-sdk:check-exports, pnpm plugin-sdk:api:check, pnpm build:plugin-sdk:strict-smoke, pnpm plugin-sdk:surface — clean.
  • pnpm lint:plugins:plugin-sdk-subpaths-exported, pnpm lint:scripts, oxlint on the changed files — clean.
  • pnpm format:check (oxfmt), pnpm format:docs:check, pnpm docs:check-mdx — clean for the changed files.
  • pnpm tsgo:core — clean.

Known-red on the base branch

check-test-types fails with two oboToken errors in src/agents/embedded-agent-runner/run.before-agent-reply-cron.test.ts. That file is unchanged by this branch and the same errors reproduce on origin/boon, so this is pre-existing and not caused by these commits.

pnpm check:changed delegates to the upstream Blacksmith Testbox runner, which is not reachable from this checkout; the lanes it selects were run individually as listed above.

No behaviour change for existing plugins: the new subpath is additive and nothing imports it yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6

holywend and others added 2 commits September 7, 2026 23:34
Adds a process-local probe so in-process plugins can read how many chat/agent
runs are live without reaching into gateway internals. The gateway runtime
state installs the probe alongside the abort-controller map and clears it on
release, so a closed or half-created runtime reports null rather than a stale
count.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6
Narrow public subpath exposing getGatewayActiveRunCount so a channel plugin can
implement a drain guard without importing the broad gateway runtime barrel.
Registers the entrypoint, its doc-metadata category, the package export, and the
regenerated API baseline hash.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6
@holywend
holywend requested a review from a team September 7, 2026 16:41
@claude

claude Bot commented Sep 7, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 11 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/gateway/server-runtime-state.ts Resolved
holywend and others added 2 commits September 7, 2026 23:58
The surface ratchet is pinned to the exact current counts, so adding
gateway-activity-runtime (one entrypoint, one callable export) trips all three
public budgets. Bump each by exactly one so the ratchet stays tight.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6
Review feedback. The probe lives in a single module-level slot, and release
cleared it with setGatewayActiveRunCountProbe(null) regardless of who owned it.
Runtime lifecycles can overlap — a replacement gateway creates its runtime
state, and its probe, before the outgoing one finishes releasing — so that late
release would drop the LIVE runtime's probe. Every later read then reports
"unknown" while runs are actually in flight.

Not dangerous on its own: readers are required to treat unknown as "do not
act", so the failure direction is a gateway that looks undrainable rather than
one that looks idle. But it silently disables the drain guard for the rest of
the process's life, which defeats the point of having one, and nothing surfaces
it.

Added clearGatewayActiveRunCountProbe(probe), which clears only when the given
probe is the one currently installed, and switched both release paths to it.
The creation-failure path in the catch needed the probe hoisted above the try —
it was reaching a const declared inside the try block, which does not compile —
so the installed probe is now tracked in a nullable declared alongside the other
pre-try state.

Both new tests were verified to fail with the identity check removed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6

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

Reviewed the diff end-to-end (203/-5, 12 files) — scope matches title, no blocking issues.

Design. Probe pattern keeps the abort-controller map private to the gateway; SDK surface is exactly one function on a new subpath (gateway-activity-runtime). Ratchets in plugin-sdk-surface-report.mjs bumped by exactly one across all three budgets, so any second export would trip them. null-as-unknown contract is documented on getGatewayActiveRunCount and enforced defensively (NaN/negative/throws → null).

Concurrency correctness. The identity-guarded clearGatewayActiveRunCountProbe(probe) is the right call — an outgoing runtime's late release can't nuke a probe a newer runtime already installed, and the new test covers exactly that race. Lifecycle is clean: probe hoisted above the try, cleared in both releasePluginRouteRegistry and the half-created catch, so no path leaks a stale reader.

Surface. Purely additive — nothing imports the new subpath yet, so no behaviour change for existing plugins.

CI. Every relevant lane green: checks-node-agentic-gateway-core (runs the new test file), checks-node-agentic-plugin-sdk, plugin-sdk subpath + package-contract lanes, check-guards, check-prod-types, all six Security High CodeQL shards, OpenGrep, dependency-guard. The one FAILURE (check-test-types, two oboToken TS2339 errors in run.before-agent-reply-cron.test.ts) reproduces identically on merged PRs #199, #200, #201 in a file this branch does not modify — pre-existing on boon, not caused here.

Cubic AI review also cleared. Ship it.

`check-test-types` has been red on the base branch since the OBO forwarding
landed, failing every open pull request:

    run.before-agent-reply-cron.test.ts(205,33): error TS2339:
      Property 'oboToken' does not exist on type '{ cleanupBundleMcpOnRunEnd?...
    run.before-agent-reply-cron.test.ts(213,33): error TS2339: (same)

Nothing is wrong with the production types. `run.ts` really does forward
`oboToken` to the attempt, and the attempt params carry `oboToken?: string`.
The gap is local to this test file: `firstAttemptParams()` describes the mocked
call with two hand-written inline type literals — its return type and the cast
over `mock.calls[0]` — and both list five fields without `oboToken`. Two tests
added alongside the forwarding assert on `.oboToken`, so they cannot compile.

Added the field to both literals. Verified by removing it again and watching
exactly those two errors return.

This is not related to the gateway activity probe in the rest of this branch;
it is carried here only because it blocks the branch from going green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CwCVkJ63nmYDQLDzcbmTS6
@holywend
holywend enabled auto-merge (squash) September 7, 2026 18:10
@holywend
holywend merged commit 4665ad5 into boon Sep 7, 2026
145 checks passed
@holywend
holywend deleted the wendy/gateway-activity-runtime branch September 7, 2026 18:18
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]>
convyusboy added a commit that referenced this pull request Sep 18, 2026
…ast-uri pin

CI on PR #140 caught two real regressions from the boon.34->45 merge
(a591cc5):

- checks-fast-contracts-plugins-a/b failed: the blanket `--ours` resolution
  used for ~206 pure version-string package.json/npm-shrinkwrap.json
  conflicts in that merge also silently dropped genuinely new content from
  root package.json that wasn't a version bump -- the `./plugin-sdk/
  gateway-activity-runtime` export (#202) and 11 `@opentelemetry/*` root
  dependencies plus the `!dist/extensions/diagnostics-otel/**` files
  exclusion removal (both from boon's `b78a1dd9da5`, "bundle diagnostics-otel
  by default"). Restored all three at our pinned OTel versions (0.220.0/
  2.9.0). This also means the earlier "pnpm-lock.yaml diagnostics-otel
  importer correction" documented in that merge commit was itself wrong --
  it deleted content that was actually correct; `pnpm install` restored it
  once package.json was fixed.
  extensions/diagnostics-otel/package.json now matches the bundled-by-default
  shape (private: true, no standalone install/release/clawhubSpec block,
  matching extensions/sentry-monitor's pattern) and its now-obsolete
  npm-shrinkwrap.json is removed, matching boon's own b78a1dd change.

- security-fast failed: our own deliberate fast-uri override (kept at 4.1.2
  during the boon.33 merge round, see ce336af) sits inside the
  GHSA-5jgf-p345-68v8/f65p-4m7j-42xc/fph4-wmhf-6fwf/jqff-g426-hqxp HIGH
  advisory range (>=4.0.0 <4.1.3). Bumped to 4.1.5 -- the newest 4.x release
  old enough to clear this repo's minimum-release-age install gate while
  staying on the 4.x line upstream's 6.34-era code targets. Regenerated
  root + extensions/acpx + extensions/lobster npm-shrinkwrap.json.

linux-docker and the 23 CodeQL "high" alerts on this PR are unrelated:
linux-docker smoke-tests the already-published openclaw@latest npm package's
install script against an unrelated Node/engines mismatch, and all 23 CodeQL
findings are pre-existing "cache poisoning via untrusted checkout" patterns
in 4 .github/workflows/.github/actions files this branch has never touched
(zero diff against ce336af) -- CodeQL's own note says this happens when
"the code changes were too large" for its baseline comparison.

Verified: pnpm-audit-prod (high) clean, all package/root npm-shrinkwrap.json
current, tsgo:core:test + tsgo:extensions:test clean, plugin-sdk-package-
contract-guardrails.test.ts + plugin-sdk-index.test.ts + extension-runtime-
dependencies.contract.test.ts + package-manifest.contract.test.ts +
diagnostics-otel/service.test.ts + pnpm-audit-prod.test.ts all passing.

Co-Authored-By: Claude Sonnet 5 <[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.

3 participants