Skip to content

fix(muse): keep typed quota stops classified as rate_limit - #195095

Closed
licheer-zte wants to merge 1 commit into
openclaw:mainfrom
licheer-zte:fix/muse-typed-quota-signal
Closed

licheer-zte wants to merge 1 commit into
openclaw:mainfrom
licheer-zte:fix/muse-typed-quota-signal

Conversation

@licheer-zte

Copy link
Copy Markdown
Contributor

What Problem

Muse turns that stop on a quota ran out fall back to the configured fallback model only when Muse's free-text message happens to look like a rate limit. MSP marks the stop structurally and the schema tells clients to branch on quota presence, never on message:

quota?: QuotaDetail: "present iff the stopping failure was the quota class. Clients branch on presence, never by parsing message."

extensions/muse/harness.ts dropped that field twice — once when the terminal === "failed" branch converted turnError to a plain Error, and again when the diagnostic wrapper built new Error(failureMessage) — so the host classified the failure from the wording alone. Tier limit reached for this window. classifies as null, and no fallback runs.

Repro (classifier probe on main, fictional wording):

"Muse Code: You have reached your usage limit. It resets at 10:00 AM." => {"kind":"reason","reason":"rate_limit"}
"Muse Code: quota exhausted"                                          => null
"Muse Code: Tier limit reached for this window."                      => null

Why This Change Was Made

Keep the typed fact instead of re-deriving it from text:

  • The terminal === "failed" conversion now keeps turnError as the Error cause.
  • museTurnFailure rebuilds a typed wrapper only when MSP attached quota detail (found through the cause chain), carrying status: 429. The host already maps a bare 429 status to rate_limit (classifyFailoverSignal), so fallback works for any wording and no new classifier pattern is needed.
  • Terminal failures without quota detail keep exactly their previous identity — no invented failover class.
  • agentHarnessAttemptTerminal.setFailure keeps the typed error when one is present instead of flattening it to its message.

Fix shape is the one ClawSweeper named: "Translate typed Muse quota failures into the existing structured rate-limit signal and preserve it through the diagnostic wrapper."

User Impact

A Muse quota stop now fails over to the configured fallback model regardless of Muse's wording, instead of surfacing "Agent couldn't generate a response" and ending the turn. Error text shown to users and the Gateway log are unchanged.

Evidence

Classifier probe on this branch's host code (real classifyFailoverSignal):

$ node scripts/run-vitest.mjs src/agents/failover/zz-probe.test.ts --maxWorkers=1
A_REASON={"kind":"reason","reason":"rate_limit"}   # {message: "Muse Code: Request stopped for this account.", code: "muse_code_quota", status: 429}
B_REASON={"kind":"reason","reason":"server_error"} # {message: "Request stopped", status: 503}  (control: status still wins)

CODE muse_code_quota_current_tier -> null
CODE insufficient_quota -> null
CODE quota_exceeded -> null
CODE rate_limit_exceeded -> {"kind":"reason","reason":"rate_limit"}
CODE rate_limit -> {"kind":"reason","reason":"rate_limit"}
STATUS429 -> {"kind":"reason","reason":"rate_limit"}

Extension boundary lint (production imports unchanged):

$ pnpm lint:extensions:no-src-outside-plugin-sdk
Rule: production bundled plugins must not import src/** outside src/plugin-sdk/**
No extension plugin-sdk boundary violations found.

New regression: extensions/muse/harness.test.ts drives the real harness against fake-muse.mjs, which now emits a structurally typed MSP quota terminal (quota: { limitKind: "tierLimit", ... }, neutral message Request stopped for this account.) and asserts the attempt terminal carries status: 429; a second test pins that an untyped Muse failure does not gain a failover status.

Limitation (explicit): extensions/muse could not be executed in this environment — the @muse-code/[email protected] workspace link is not installed (the pnpm install is blocked by the host's offline metadata mirror / Node patch floor), so extensions/muse/harness.test.ts fails at import (Cannot find package '@muse-code/sdk') before any test runs. No CI replacement is claimed here; PR CI runs the extension lane. The host-side link of the chain is executed above: the status/code the new wrapper produces classifies as rate_limit.

[AI-assisted]

MSP reports a quota stop only through the structured `TurnError.quota`
field and tells clients never to parse `message`. The Muse harness dropped
that field when it converted the terminal failure to a plain Error, and the
diagnostic wrapper created a second plain Error, so the host classified the
failure by Muse's free-text wording. Neutral wording such as "Tier limit
reached for this window." classified as null and the configured fallback
model never ran.

Keep the terminal error as the cause and rebuild a typed wrapper carrying
status 429 when MSP attached quota detail; the host's existing status
classification then yields rate_limit without reading the wording. Failures
without quota detail keep their previous identity.

Refs openclaw#195072
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added plugin: muse size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 8, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR maps typed Muse quota failures to HTTP 429 so host error handling can recognize them independently of message wording.

Example: Muse returns quota detail with the message “Request stopped for this account.”

  • Before: The harness discards quota identity, preventing reliable quota guidance.
  • After: The intended result is visible quota guidance; this patch currently throws a ReferenceError on the failure path.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful repair direction, but the final failure conversion is broken and the changed behavior has no executed proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A typed Muse quota stop can yield no reply instead of visible quota guidance.
Reason: Preserving provider error identity repairs an existing host contract without adding policy or configuration; automatic fallback is not the demonstrated user benefit.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this PR addresses a source-confirmed Muse quota-reporting bug, but introduces an undefined class reference and still discards the structured quota error at the final wrapper.

Priority: P2
Reviewed head: a01b8bc1709a0c07b3e1e4ddcb07e6b8ccf2fc42

Before merge

  • Add real behavior proof - The supplied classifier probe exercises a fabricated error rather than the changed Muse harness, whose new regression reportedly never ran; provide redacted CLI output showing a neutral-wording typed quota terminal reaches visible quota guidance on the repaired head, keeping IPs, keys, phone numbers, and non-public endpoints private. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Remove the unresolved FailoverError reference (P1) - FailoverError is neither imported nor declared in this module. Every attempt with a failureMessage evaluates this expression outside the surrounding try/catch, so quota stops, authentication failures, crashes, and approval failures now reject with ReferenceError instead of returning their canonical attempt terminal. Remove the class check and preserve the failure through the existing wrapper contract.
  • Preserve the quota error through the diagnostic wrapper (P2) - Even after resolving the missing identifier, museTurnFailure returns an ordinary Error carrying status 429, not a FailoverError. A neutral-wording quota terminal therefore takes the new Error(failureMessage) branch, which has neither status nor cause, leaving the original classification bug intact. Keep the diagnostic message and attach the typed failure as its cause so the host’s existing cause traversal can recover 429.

Findings

  • [P1] Remove the unresolved FailoverError reference — extensions/muse/harness.ts:619
  • [P2] Preserve the quota error through the diagnostic wrapper — extensions/muse/harness.ts:619

Tests

  • Missing end-to-end proof: Show the repaired Muse quota path through the shipped CLI returning visible quota guidance, plus the focused regression failing on base and passing on head.
Agent review details

How this fits together

The Muse plugin translates MSP turn outcomes into OpenClaw attempt terminals, which feed shared provider-error classification and user-facing replies.

flowchart LR
  A[Muse CLI] --> B[Muse SDK]
  B --> C[Muse harness]
  C --> D[Attempt terminal]
  D --> E[Host failure classification]
  E --> F[User reply]
Loading

Technical review

Best possible solution:

Map MSP quota presence to status 429 and retain that error as the diagnostic wrapper’s cause, preserving existing native replay safety.

Do we have a high-confidence way to reproduce the issue?

Source establishes both quota-identity loss on main and the introduced unresolved identifier; the linked reporter describes a controlled CLI reproduction, but this review executed no target code.

Is this the best way to solve the issue?

Structural quota mapping is the right boundary, but the final wrapper must preserve its cause; the PR’s fallback claim conflicts with the reporter’s corrected reproduction and existing native replay policy.

Full review comments:

  • [P1] Remove the unresolved FailoverError reference — extensions/muse/harness.ts:619
    FailoverError is neither imported nor declared in this module. Every attempt with a failureMessage evaluates this expression outside the surrounding try/catch, so quota stops, authentication failures, crashes, and approval failures now reject with ReferenceError instead of returning their canonical attempt terminal. Remove the class check and preserve the failure through the existing wrapper contract.
    Confidence: 1
  • [P2] Preserve the quota error through the diagnostic wrapper — extensions/muse/harness.ts:619
    Even after resolving the missing identifier, museTurnFailure returns an ordinary Error carrying status 429, not a FailoverError. A neutral-wording quota terminal therefore takes the new Error(failureMessage) branch, which has neither status nor cause, leaving the original classification bug intact. Keep the diagnostic message and attach the typed failure as its cause so the host’s existing cause traversal can recover 429.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b595ee78e015.

Provenance checked

  • Muse terminal failure and diagnostic conversion keeps the original intent (1c147d4: The original Muse integration specialized sign-in failures and retained actionable diagnostics with stderr in Gateway logs.)
  • Muse subprocess fixture keeps the original intent (test(providers, cli): remove low-value tests (batch d580) #184015: Earlier fixture consolidation removed duplicate examples while preserving distinct transport and failure contracts; the new quota case exercises a distinct structured terminal.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • node scripts/run-vitest.mjs extensions/muse/harness.test.ts extensions/muse/src/events.test.ts extensions/muse/src/runtime.test.ts --maxWorkers=1
  • node scripts/run-vitest.mjs src/agents/failover-error.test.ts src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts --maxWorkers=1
  • pnpm tsgo:extensions
  • Verify the typed-quota regression fails on base and passes on the repaired head while ordinary failure terminals retain their diagnostics.
  • Inspect contributor-supplied shipped-CLI output for a neutral-wording quota stop producing visible guidance without changing unsafe-native-turn replay policy.

What I checked:

  • Pinned patch introduces an unresolved identifier: The introduced diff references FailoverError at the final failure conversion, but the complete module contains no import or declaration for it; any truthy failure reaches this expression. (extensions/muse/harness.ts:619, a01b8bc1709a)
  • Quota error cannot satisfy the preservation check: museTurnFailure constructs an ordinary Error with status 429 and code muse_code_quota; it does not construct a FailoverError, so resolving the missing identifier alone would leave the final wrapper stripping its status and cause. (extensions/muse/harness.ts:73, a01b8bc1709a)
  • Current main retains both lossy conversions: Current main creates a plain Error from the failed MSP terminal and another plain Error from failureMessage, confirming the repair remains necessary. (extensions/muse/harness.ts:518, b595ee78e015)
  • Authoritative imported protocol contract: The harness imports @muse-code/sdk and its package pins 1.4.14, establishing the dependency boundary; TurnError.quota identifies quota failures by presence and explicitly prohibits branching on message wording. (schema/msp/msp.d.ts:3308, a45cb67cd2e2)
  • Reporter corrected the user-visible impact: In Muse quota failures drop MSP's typed quota signal, so the user gets no reply #195072 (comment), saariuslystoned reports a controlled MSP peer through the shipped CLI: main returned payloads:[], while preserving 429 produced quota guidance; native replay safety intentionally prevented fallback.
  • Existing host contract supports the narrow repair: Shared error normalization traverses causes, and existing reply coverage requires generic HTTP 429 failures to produce quota guidance. (src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts:141, a01b8bc1709a)

Likely related people:

  • Ayaan Zaidi: Raw commit 1c147d4 adds extensions/muse/harness.ts:370 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c147d4bca0d; files: extensions/muse/harness.ts)

PR surface

Source +36, Tests +26, Other +2. Total +64 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 43 7 +36
Tests 2 26 0 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 71 7 +64

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The quota-reporting defect and introduced failure-path regression are confined to the optional Muse runtime and admit a focused repair.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 8, 2026, 2:38 AM ET / 07:38 UTC.

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the work here. We're closing this: it doesn't show a real user-facing problem (no report from an affected user and no natural reproduction), and it follows a pattern of small, speculative or duplicate changes split across many PRs. Please open an issue with a reproduction of real harm first; a fix can follow once the problem is confirmed.

@obviyus obviyus closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. plugin: muse rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants