Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: document the class vs module-state convention (audit L3) - #576

Merged
ndycode merged 1 commit into
mainfrom
claude/audit-57-state-pattern-convention
Jun 11, 2026
Merged

ndycode merged 1 commit into
mainfrom
claude/audit-57-state-pattern-convention

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Closes out audit finding L3 ("Class vs module-function patterns mixed without documented rule — document the rule; no code change needed"). Adds one CONVENTIONS bullet to lib/AGENTS.md writing down the rule the codebase already follows:

  • Classes for state that needs multiple independent instances or dependency injection (AccountManager per pool, CircuitBreaker per account, SessionAffinityStore per proxy) and for the CodexError hierarchy.
  • Module-level state + plain functions only for genuinely process-global concerns (auth rate-limit trackers, the routing mutex, UI runtime options, the storage-meta cache), and always paired with a test reset helper (reset*ForTests / resetVolatileRuntimeState-style) so suites can isolate it.
  • Never module-level state for anything a caller might want two of.

Doc-only; no code paths touched. With this, the audit's L-tier items are either fixed (L1 partial via #517/#534 line), documented (L3 here), or roadmapped pending maintainer decisions (L2 rename, L4 postinstall, L5 pin rationale).

Validation

  • Markdown only.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB


Generated by Claude Code

note: greptile review for oc-chatgpt-multi-auth. cite files like lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.

Greptile Summary

doc-only change that closes audit finding L3 by writing down the class-vs-module-state convention the codebase already follows. no runtime code is touched.

  • adds a single bullet to the CONVENTIONS section of lib/AGENTS.md explaining when to use a class (multiple independent instances or DI) vs module-level state (genuinely process-global, always paired with a test reset helper)
  • explicitly bans module-level state for anything a caller might want two of, and requires a reset*ForTests/resetVolatileRuntimeState-style helper for any module that does carry global state

Confidence Score: 5/5

markdown-only edit to a dev-facing knowledge base file; no runtime code, no token handling, no filesystem paths altered.

the new bullet accurately captures the class-vs-module-state split already present in the codebase, includes concrete class names as examples, mandates the test-reset helper that existing module-level state already ships, and slots cleanly into the existing CONVENTIONS section without contradicting any prior rule.

no files require special attention

Important Files Changed

Filename Overview
lib/AGENTS.md adds one CONVENTIONS bullet documenting class-vs-module-state rule; no code changes, fits existing style

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    direction LR
    class AccountManager {
        +per pool instance
        +dependency-injected
    }
    class CircuitBreaker {
        +per account instance
        +dependency-injected
    }
    class SessionAffinityStore {
        +per proxy instance
        +dependency-injected
    }
    class CodexError {
        +hierarchy root
    }
    note for AccountManager "USE A CLASS\nwhen caller may want\nmultiple independent instances"

    class moduleRateLimits {
        <<module-level state>>
        +process-global
        +resetForTests()
    }
    class moduleRoutingMutex {
        <<module-level state>>
        +process-global
        +resetForTests()
    }
    class moduleUIRuntimeOptions {
        <<module-level state>>
        +process-global
        +resetVolatileRuntimeState()
    }
    note for moduleRateLimits "USE MODULE STATE\nonly when truly global\n+ must have reset helper"
Loading

Reviews (1): Last reviewed commit: "docs: document the class vs module-state..." | Re-trigger Greptile

Context used:

  • Context used - lib/AGENTS.md (source)

The audit's L3 finding asked for the implicit rule to be written down
rather than changed: classes for multi-instance/injectable state and
the error hierarchy; module-level state only for process-global
concerns, always paired with a test reset helper.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ndycode, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 39 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 17755b2c-e214-45ff-bdb8-ed06d1058e9e

📥 Commits

Reviewing files that changed from the base of the PR and between b566656 and 7311f91.

📒 Files selected for processing (1)
  • lib/AGENTS.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-57-state-pattern-convention
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-57-state-pattern-convention

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

ndycode pushed a commit that referenced this pull request Jun 10, 2026
CodeRabbit's description check flagged that the intro characterised every
table row as a unit-test suite while #576 is a convention doc and #577 a
version-drift fix; the prose now says so explicitly.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@ndycode
ndycode merged commit 76c80f0 into main Jun 11, 2026
1 of 2 checks passed
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