Skip to content

feat(management): expose bounded plugin quota metadata - #5323

Open
sussdorff wants to merge 12 commits into
router-for-me:devfrom
sussdorff:feat/cca-5h1.2/upstream-minimal-quota
Open

sussdorff wants to merge 12 commits into
router-for-me:devfrom
sussdorff:feat/cca-5h1.2/upstream-minimal-quota

Conversation

@sussdorff

@sussdorff sussdorff commented Aug 28, 2026

Copy link
Copy Markdown

Summary

Expose one explicitly public, bounded plugin_quota object on management auth-file entries so native plugins can publish subscription quota data without adding provider-specific host code or exposing their private metadata.

The host deliberately does not understand provider names, contract versions, quota windows, currencies, or freshness. Plugins and consumers own those semantics, so future subscription providers can use the same seam without another CLIProxyAPI patch.

Why this matters beyond one plugin

CLIProxyAPI's plugin system can add authentication and model providers, but subscription quota information currently has no safe path into management clients. A plugin author must otherwise choose between losing quota visibility, requesting a provider-specific host patch, or exposing a broader metadata channel.

This change creates a small provider-neutral capability:

  • any native plugin can publish a redacted quota contract under the reserved plugin_quota key;
  • management clients can opt into contracts they understand;
  • new contract versions and new subscription providers do not require host changes;
  • built-in quota behavior and credential availability remain authoritative and unchanged.

The accompanying CPA Manager Plus draft demonstrates an independent generic consumer, but the transport is not tied to that UI or to Cursor.

Scope

  • Read only Auth.Metadata["plugin_quota"].
  • Require a non-empty JSON object and cap its sanitized compact representation at 16 KiB.
  • Bound the input tree before encoding, detach it through JSON round-tripping with number preservation, and recursively apply the existing management-response string sanitizer.
  • Preserve JSON numbers specifically inside plugin_quota when dynamic-plugin auth responses are decoded, including when metadata is subsequently sent back through the plugin boundary; all existing numeric metadata retains its historical float64 representation.
  • Reject credential-shaped nested keys; the otherwise credential-shaped tokens, latest_tokens, and period_tokens names are accepted only for finite numeric counter values.
  • Emit only the sanitized top-level plugin_quota; sibling plugin metadata remains private.
  • Document the producer boundary in the existing plugin example README.

No route, refresh lifecycle, provider branch, plugin ABI, auth availability, built-in quota, or generic metadata projection is added.

Upstream sync

  • Synced additively with upstream dev at 5208aec7 on 2026-09-05.
  • The review surface remains six focused files and GitHub reports the branch mergeable without a history rewrite.

Review surface

  • Production: one existing file, +151 lines.
  • Plugin API decode boundary: one existing file, +40 lines.
  • RPC metadata sanitation: one existing file, +5 lines.
  • Documentation: one existing README, +12 lines.
  • Tests: two focused test files, +343 lines.

Verification

  • go test ./internal/api/handlers/management
  • go test ./...
  • go build -o <temporary-output> ./cmd/server
  • Formatting and diff checks.
  • Live three-component validation with two plugin-produced subscription accounts and a provider-neutral management client.

Security notes

The field is an explicit public namespace, not a general metadata escape hatch. Invalid, oversized, non-object, non-JSON, credential-shaped, or unsafe payloads are omitted without changing the auth entry's availability. The 16 KiB limit is enforced again after HTML sanitization, and token-counter exemptions are value-type aware. Rejection diagnostics contain the auth ID only and never include payload data.

Related

luispater and others added 5 commits August 28, 2026 17:57
…s omitted

- Ensure `message_delta` is emitted on tool call usage chunks and stream completion even if `finish_reason` is missing or null.
- Add `terminalOpenAIFinishReason` fallback to map missing finish reasons to standard stop reasons.
- Consolidate content block finalization into `finalizeOpenAIAnthropicContentBlocks` and delta emission into `emitAnthropicMessageDelta`.

Closes: router-for-me#5308
- Fall back to array index in tool calls accumulator when the `index` field is missing.
- Ensure parallel tool calls without explicit indices are accumulated properly during streaming.

Closes: router-for-me#5058
…sification (router-for-me#5313)

* feat(executor): measure effective TTFT with protocol-aware token classification

- Introduce protocol-aware streaming token classification under internal/runtime/executor/helps
- Implement responses_ttft_helpers.go for OpenAI Responses / Codex WebSocket & SSE streaming
- Filter out container metadata, rate limits, handshake headers, and tool execution outputs
- Implement dual-track firstPacketDuration fallback for abnormal / zero-token stream terminations
- Add TrackHTTPClientRoundTripOnly to bypass false TTFT triggers on first response body reads
- Optimize UsageReporter.ObserveTokenEvent hot path with fast-path RLock short-circuiting (0 B/op)
- Align terminal event completions across SSE, WebSocket streaming, and non-streaming executions
- Add EnsurePublished metric recording fallback for successful terminal turns lacking usage blocks
- Add stub helpers with comprehensive specifications for Chat, Claude, and Gemini protocols

* fix(executor): normalize SSE response.done and terminate incomplete WS streams

* fix(usage): capture first-packet fallback on initial body reads with TrackHTTPClientRoundTripOnly
- Inline local `$ref` pointers and strip `$defs` and `definitions` from tool parameter schemas for Moonshot compatibility.
- Ensure tool parameter root objects declare an explicit `type: "object"`.

Closes: router-for-me#5316
@github-actions
github-actions Bot changed the base branch from main to dev August 28, 2026 17:21
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@sussdorff
sussdorff marked this pull request as ready for review August 29, 2026 06:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T09:23:01.761849Z 225c586 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bbd8de32f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0fafc126e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f4068ca5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 076694fba0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/pluginhost/rpc_client.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 225c586908

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go
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