Skip to content

fix(quota): preserve recovery across concurrent sessions - #176602

Merged
steipete merged 2 commits into
mainfrom
fix/quota-concurrent-recovery
Oct 18, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/quota-concurrent-recovery

Conversation

@steipete

@steipete steipete commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent Codex sessions could fail quota recovery because a pending write to one session binding denied reads of another binding. Separately, an older exhausted WHAM response could re-block a credential after a newer successful request.

User Impact

Independent session bindings remain readable during non-evicting sibling writes, and a newer successful request keeps its recovered quota state when an older failure probe finally replies. Relevant pending writes and uncertain outcomes still deny effect guards.

Why This Change Was Made

#171458 replaced repeated binding/revocation reads with owner-published facts and correctly denied queued or unknown writes. Its database-wide pending guard also rejected unrelated bindings. The same publication owner now records each known write scope: a non-evicting keyed write denies that key, an eviction-capable write denies its namespace, and unscoped native/compound writes retain database-wide denial. Unknown settlement remains denied for the database identity until restart. Receipt publication, rollback, expiry, and final lifecycle checks stay with their existing owners.

#174632 removed broad WHAM health fingerprints and explicitly accepted late quota observations superseding newer health. The existing Gateway regression demonstrates a real failure in that accepted edge. The failure reducer now compares the probe's start timestamp with the current persisted lastProbeAt, which successful use advances for shared, inherited, and personal credentials. This preserves ordering without restoring whole-store fingerprints, extra reads, or a new generation counter. lastUsed remains selection-owned and is intentionally unchanged by inherited success.

The fixes have separate commits and share the quota-reset concurrency proof. No schema, storage format, retention, dependency, configuration, or service lifecycle changes.

Evidence

On baseline main 5e8ac91fbf6 with only the new tests added, the independent-binding regression fails with Plugin state authority is unavailable (1 failed, 1 eviction control passed). All three quota ownership regressions fail because the held exhausted response reinstalls a block over newer successful health.

On exact head bb06a1b1e4124f83879121982f87feb6d05f49a3:

  • Six focused owner suites: 100 tests passed. Type-aware lint for all touched TypeScript files, core typecheck, formatting, and diff checks pass. Both independent Codex autoreviews are scoped-clean at P0–P2.
  • Original failing Gateway file: OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/quota-reset.e2e.test.ts --maxWorkers=1 — 9 passed, wrapper and remote command exit 0, Node 24.19 on Blacksmith Testbox. A fresh clone's full head and hashes of every changed file plus the target test were verified before execution. This is the external Testbox command result; lease cleanup may cancel the hosting workflow.
  • ClickClack production service/state boundary: 5 passed in service-state-persistence.test.ts, using real SQLite owners and stubbed external channel calls. Unchanged published authority reaches updateChannel; revoked/replaced authority rejects before it and asserts no update call. Pending/unknown settlement denies session targets, and stale reverse indexes reject previous routes. These complement the deterministic sibling-write scope regression; no live ClickClack server is claimed.

PR CI run 39175283306 is green on this head. Its changed-test selection does not include the original Gateway file, which is covered by the explicit Node proof above. No inherited-failure exception is needed.

Keep independent bindings readable during non-evicting sibling writes while retaining key, namespace, and unknown-outcome denial at the publication owner. Reproduce the race with a real pending SQLite worker write.
Compare the failed WHAM observation start with the current persisted success timestamp so delayed exhaustion cannot restore a cleared block. Cover shared, inherited, and personal credential owners.
@clawsweeper

clawsweeper Bot commented Oct 18, 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 docs Improvements or additions to documentation agents Agent runtime and tooling plugin: file-transfer size: M labels Oct 18, 2026
@steipete
steipete marked this pull request as ready for review October 18, 2026 23:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T23:13:07.351667Z bb06a1b Draft marked ready
ℹ️ 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.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: bb06a1b1e4124f83879121982f87feb6d05f49a3
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/usage-reduction.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/usage.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR scopes pending binding-write denial and prevents delayed WHAM failures from overwriting newer successful quota recovery.

Example: A WHAM check for openai:primary starts at 12:00:00, a request succeeds at 12:00:01, and the older check reports one hour of exhaustion at 12:00:02.

  • Before: The delayed response reinstates the exhaustion block.
  • After: The reducer preserves the newer successful health state.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-consistent, with meaningful regression coverage; final-effect authority evidence remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent sessions can lose access to independent bindings, and a recovered credential can become exhausted again when an older quota response arrives.
Reason: The maintainer-authored repair addresses demonstrated owner-boundary failures without adding configuration, schemas, or competing implementations.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit 662bfffab1e6 by Peter Steinberger; no PR verified.

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR: it addresses two current concurrency failures through existing owners, and no definite introduced code defect was found.

Priority: P2
Reviewed head: bb06a1b1e4124f83879121982f87feb6d05f49a3

Before merge

  • Add real behavior proof - Authority-chain proof required: scoped publication changes the binding facts consumed before ClickClack channel I/O; supplied real-SQLite prepared-read tests cover affected-key and eviction denial, but no current-head production-path output demonstrates an allowed effect and rejection of a revoked or reassigned binding before I/O. Supply a redacted trace through those owners, excluding keys, IPs, phone numbers, and non-public endpoints. 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.
  • Resolve security review attention item - No concrete authorization bypass, credential exposure, or supply-chain regression was found.
  • Resolve merge risk - Before merge, establish that narrowing pending-write denial still rejects revoked or reassigned bindings before final channel I/O.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show allowed and revoked or reassigned bindings reaching the final channel-effect boundary under scoped pending writes.
Agent review details

How this fits together

Plugin-state publication supplies committed binding facts to effect guards, while auth-profile reducers combine provider observations with persisted credential health.

flowchart TD
  A[Concurrent sessions] --> B[Plugin state worker]
  B --> C[Scoped publication owner]
  C --> D[Binding effect guards]
  A --> E[WHAM observation]
  E --> F[Auth usage reducer]
  F --> G[Persisted profile health]
Loading

Technical review

Best possible solution:

Keep the scoped guard in the existing publication owner and reject stale quota observations in the shared persisted-health reducer.

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

Current-main source exposes both failure paths, and the supplied regressions target them through real storage owners; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The implementation uses existing publication and health owners, preserves namespace-wide eviction and database-wide uncertainty denial, and avoids restoring broad quota fingerprints or introducing a new counter.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify scoped denial at channel I/O (recommended)
    Supply a production-path trace showing an allowed binding proceeding during an unrelated keyed write, and a revoked or reassigned binding being rejected before channel I/O.

Provenance checked

  • Binding publication denial changes intended behavior with a stated reason (ad76238: Replace repeated authority reads with owner-published facts while denying pending mutations and uncertain settlement.)
  • WHAM observation ordering changes intended behavior with a stated reason (87c1f1c: Remove historical health fingerprints and accept best-effort late observations; this PR explains the resulting recovery failure and uses the existing lastProbeAt field instead.)
  • Inherited credential health ownership keeps the original intent (1e7b255: Persist inherited health in the credential owner's store while preserving child-local health and selection ownership.)

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete authorization bypass, credential exposure, or supply-chain regression was found.

Evidence

What I checked:

Likely related people:

  • ryanngit: Raw commit 0b3d31c adds src/agents/auth-profiles/usage.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0b3d31c0ce8e; files: src/agents/auth-profiles/usage.ts)
  • Ayaan Zaidi: Raw commit 2e4391a adds src/agents/auth-profiles/usage.ts:143 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 2e4391ac95ae; files: src/agents/auth-profiles/usage.ts)

PR surface

Source +80, Tests +122, Docs +5. Total +207 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 109 29 +80
Tests 3 123 1 +122
Docs 2 6 1 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 238 31 +207

Labels

Label changes:

  • add P2: The repair addresses concurrency-dependent binding availability and quota recovery failures with a focused scope.
  • add merge-risk: 🚨 compatibility: Public prepared-read availability changes from database-wide to scope-based denial; the maintainer-authored direction accepts that narrowing while preserving signatures and stored formats.
  • add merge-risk: 🚨 security-boundary: The diff narrows a pending-write guard consumed immediately before channel effects.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The repair addresses concurrency-dependent binding availability and quota recovery failures with a focused scope.
  • merge-risk: 🚨 security-boundary: The diff narrows a pending-write guard consumed immediately before channel effects.
  • merge-risk: 🚨 compatibility: Public prepared-read availability changes from database-wide to scope-based denial; the maintainer-authored direction accepts that narrowing while preserving signatures and stored formats.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof showing unrelated writes permit an authorized binding while revocation or reassignment prevents channel I/O.

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 October 18, 2026, 7:25 PM ET / 23:25 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Current-head proof is complete for bb06a1b1e4124f83879121982f87feb6d05f49a3; the PR body now records the results and limits.

The original Gateway quota-reset file passes all 9 scenarios under Node 24.19 on an exact-head Blacksmith Testbox clone, with verified source hashes and wrapper/remote exit 0. The five targeted ClickClack production-service cases also pass with real SQLite state: unchanged authority reaches the channel update, revoked/replaced authority rejects before it with zero update calls, pending/unknown settlement denies session targets, and stale reverse indexes reject old routes. External channel calls are stubbed; this is production-path in-process proof rather than a live-server claim. The independent sibling-write regression supplies the concurrent scope proof at the same publication owner.

Broad PR CI is green, both isolated reviews are clean at P0–P2, and no inherited-failure exception is needed. No concrete code/security finding was reported; the requested effect-boundary evidence is now supplied.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@steipete
steipete merged commit 11e96b0 into main Oct 18, 2026
244 of 247 checks passed
@steipete
steipete deleted the fix/quota-concurrent-recovery branch October 18, 2026 23:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…6602)

* fix(plugin-state): scope publication settlement to the read binding

Keep independent bindings readable during non-evicting sibling writes while retaining key, namespace, and unknown-outcome denial at the publication owner. Reproduce the race with a real pending SQLite worker write.

* fix(quota): keep newer success over stale exhaustion

Compare the failed WHAM observation start with the current persisted success timestamp so delayed exhaustion cannot restore a cleared block. Cover shared, inherited, and personal credential owners.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. plugin: file-transfer rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant