Skip to content

feat: Add Enterprise 1000-user scaling, SSE quota accounting, and bulk provisioning - #33

Merged
rekurt merged 1 commit into
masterfrom
feat/enterprise-1000-users
Oct 25, 2026
Merged

rekurt merged 1 commit into
masterfrom
feat/enterprise-1000-users

Conversation

@rekurt

@rekurt rekurt commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Summary

Transforms CortexForge v2.0.0 on Hermes Agent into an Enterprise Production-Ready platform capable of onboarding, operating, monitoring, and enforcing quotas across 1,000 concurrent users.

Type of Change

  • ✨ New feature
  • 🔒 Security fix
  • 📚 Documentation
  • 🚀 Performance

Changes

  • Quota-Proxy Enterprise (quota-proxy/proxy.py):
    • Added streaming token accounting (SSEUsageParser) for text/event-stream responses (Anthropic message_start/message_delta and OpenAI usage chunks) with 64 KB line-buffer protection against OOM.
    • Added dynamic key management without restart (POST /quota/register-key, POST /quota/reload-keys) backed by SQLite quota_keys.
    • Added hierarchical department quotas (POST /quota/set-department-limit) and pagination/filtering on GET /quota/report (department, status, limit, offset).
    • Switched to ThreadingHTTPServer with SQLite WAL mode (busy_timeout=10000, synchronous=NORMAL) and bounded RateLimiter bucket eviction.
  • Message Broker Enterprise (broker/broker.py):
    • Added dynamic key registration (POST /admin/register-key, POST /admin/reload-keys), message priorities (low/normal/high/urgent), custom ttl_sec, and POST /broadcast (including "*" for all registered agents).
    • Added pagination and non-destructive peek=1 on GET /inbox and GET /inbox/all, plus throttled background TTL expiry purging.
  • Fleet Provisioning & Ops at 1000-User Scale (scripts/bulk-users.py, scripts/sync-instances.sh, service-agent/server.py, resource-monitor/monitor.py):
    • Added scripts/bulk-users.py (import, export, status) with Docker Compose shard profiles (shard-0..shard-9), isolated shard bridge networks (corp-shard-<N> to avoid Linux bridge 1024-port exhaustion), atomic .env updates, and symlink protection.
    • Updated scripts/sync-instances.sh to inspect all containers in a single docker ps -a call and restart stopped containers in batches of 50.
    • Added per-caller rate limiting (SKILL_RATE_LIMIT) and configurable concurrency (MAX_CONCURRENT_SKILLS) in service-agent/server.py, and parallel container stats polling (ThreadPoolExecutor(max_workers=32)) + pagination in resource-monitor/monitor.py.
  • 1000-User Load Benchmark & Docs (scripts/benchmark-1000-users.py, docs/ENTERPRISE_1000_USERS.md, tests/):
    • Added scripts/benchmark-1000-users.py (make benchmark-1k) and 32 new enterprise/scale unit tests (164/164 total tests passing; 5,020 benchmark ops across 1,000 concurrent users at ~355 RPS with 0 errors).

Testing

  • Ran python3 -m unittest discover tests/ -v — 164/164 tests pass
  • Ran python3 scripts/benchmark-1000-users.py — 5,020 ops across 1,000 users, 0 errors
  • Ran python3 .github/scripts/ai_security_check.py — no findings
  • Ran shellcheck scripts/*.sh — 0 warnings / 0 errors

Documentation

  • README updated (README.md, README.ru.md, CLAUDE.md)
  • Relevant doc in docs/ updated (docs/ENTERPRISE_1000_USERS.md)
  • CHANGELOG.md entry added (or release-please will handle it)

Security

  • No secrets, tokens or credentials added to code or .env.example
  • No new subprocess.run() calls without input validation
  • No new network endpoints without auth

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-10-25T14:55:07.259325Z 464b314 PR opened
🔒 Security Review ✅ Completed 2026-10-25T14:58:51.100824Z 464b314 PR opened
ℹ️ 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.

Comment thread tests/test_scale_1000_users.py Outdated

tmpdir = tempfile.mkdtemp(prefix="ent1k_broker_1000_")
db_path = os.path.join(tmpdir, "broker_1000.db")
admin_key = "adm-broker-1000-secret"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Gitleaks has detected a secret with rule-id generic-api-key in commit 464b314.
If this secret is a true positive, please rotate the secret ASAP.

If this secret is a false positive, you can add the fingerprint below to your .gitleaksignore file and commit the change to this branch.

echo 464b314e742db81e4a206d15416ca3f789361295:tests/test_scale_1000_users.py:generic-api-key:389 >> .gitleaksignore

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5506f65: replaced test token literal in tests/test_scale_1000_users.py and amended commit so Gitleaks scans clean.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Security Check Results

Check Result
🔑 Secrets ✅ success
🐍 SAST Python ✅ success
🤖 AI Security ✅ success
🐳 Docker ✅ success
🐚 ShellCheck ✅ success
📦 Dependencies ✅ success

Все проверки пройдены.

@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: 464b314e74

ℹ️ 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 quota-proxy/proxy.py
print(f" Max body: {MAX_BODY_BYTES//1024}KB", flush=True)

server = HTTPServer(("0.0.0.0", PORT), Handler)
server = ThreadingHTTPServer(("0.0.0.0", PORT), Handler)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make quota admission safe before enabling concurrent requests

With the threaded server, simultaneous requests for the same instance can all pass _check_quota() before any upstream response records usage. The database locks protect individual operations, not the admission/accounting interval, so the quota no longer bounds concurrent spending. Using the existing mock upstream with a barrier, eight requests against a 30-token limit all returned 200 and accumulated 240 tokens; the previous serial server admitted only the first. Add per-instance admission synchronization or outstanding-token reservations, and account for shared department limits as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5506f65: added per-instance and per-department admission locks (_admission_guard) across the check-to-accounting window in quota-proxy/proxy.py, plus regression test test_concurrent_same_instance_quota_admission_barrier in tests/test_quota_enterprise.py.

Comment thread scripts/bulk-users.py
broker_key = secrets.token_urlsafe(32)
quota_key = f"quota-{spec.name}-" + secrets.token_urlsafe(24)
gateway_token = secrets.token_urlsafe(32)
name_upper = spec.name.upper().replace("-", "_")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject collisions between normalized environment variable names

Importing the valid, distinct names user-1 and user_1 succeeds, but both normalize to USER_1. The importer consequently writes duplicate broker/quota variables, and both generated services reference the same variables. Once the environment is loaded, one user's credentials overwrite the other's, collapsing their broker identity and quota accounting. Validate normalized names against both the batch and existing fleet before creating files, or use an unambiguous encoding.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5506f65: added normalized ENV_SUFFIX collision detection across both the import batch and existing fleet in scripts/bulk-users.py and scripts/add-user.sh, covered by unit tests in tests/test_bulk_provisioning.py.

Comment thread broker/broker.py Outdated
name = k[len("BROKER_KEY_"):].lower()
keys[hashlib.sha256(v.strip().encode()).hexdigest()] = name
return keys
name = k[len("BROKER_KEY_"):].lower().strip().replace("_", "-")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve underscore-containing broker instance identities

For an existing supported instance named team_one, BROKER_KEY_TEAM_ONE previously authenticated as team_one, but this replacement now authenticates it as team-one. Requests addressed to team_one consequently return Unknown recipient, and the original inbox is no longer accessible through that key. Both provisioning scripts still accept underscores, so this affects valid instances even without a naming collision. Preserve the original identity through explicit metadata or provide a compatible migration rather than unconditionally converting underscores.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5506f65: preserved underscore-containing instance identities in broker/broker.py via _resolve_env_instance_name() and alias resolution (_instance_aliases), covered by test_underscore_and_hyphen_env_identities_preserved in tests/test_broker_enterprise.py.

Comment thread scripts/bulk-users.py
Comment on lines +534 to +539
env_lines_to_append.extend(
[
f"BROKER_KEY_{name_upper}={broker_key}",
f"QUOTA_KEY_{name_upper}={quota_key}",
f"QUOTA_LIMIT_{name_upper}={spec.quota_limit}",
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist imported departments in the quota proxy's input

When a manifest assigns a user to engineering, the importer stores that department only in an instance comment and Compose label; the root environment entries omit QUOTA_DEPT_<NAME>, and the importer never registers the department through the quota API. The proxy reads department membership only from those environment variables or quota_keys, so even after recreating the proxy, imported users belong to default and bypass any configured engineering quota. Persist the department alongside the generated quota key or register it explicitly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5506f65: persisted QUOTA_DEPT_<ENV_SUFFIX>=<department> to the root .env in scripts/bulk-users.py and verified in tests/test_bulk_provisioning.py.

…k provisioning

- quota-proxy: add SSEUsageParser for text/event-stream token accounting (Anthropic & OpenAI) with 64KB line cap, dynamic key registration (/quota/register-key, /quota/reload-keys), department limits (/quota/set-department-limit), paginated /quota/report, ThreadingHTTPServer, and SQLite WAL tuning
- broker: add dynamic key registration (/admin/register-key, /admin/reload-keys), message priorities, custom TTL, admin /broadcast, paginated /inbox (limit, offset, since_id, peek) and /inbox/all, and throttled expiry purge
- fleet & ops: add scripts/bulk-users.py (import, export, status) with Compose shard profiles and isolated shard networks, batch self-healing in scripts/sync-instances.sh, per-caller rate limits in service-agent, and parallel container stats polling in resource-monitor
- benchmark & tests: add scripts/benchmark-1000-users.py, docs/ENTERPRISE_1000_USERS.md, and comprehensive enterprise & 1000-user scale test suites (164 total tests passing)
@rekurt
rekurt force-pushed the feat/enterprise-1000-users branch from 464b314 to 5506f65 Compare October 25, 2026 15:06
@rekurt
rekurt merged commit 02997fb into master Oct 25, 2026
12 checks passed
@rekurt
rekurt deleted the feat/enterprise-1000-users branch October 25, 2026 15:07
rekurt pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](v0.6.0...v1.0.0)
(2026-10-26)


### ⚠ BREAKING CHANGES

* Migrate to Hermes Agent (v2.0.0)
([#31](#31))

### Features

* Add Enterprise 1000-user scaling, SSE quota accounting, and bulk
provisioning ([#33](#33))
([02997fb](02997fb))
* Migrate to Hermes Agent (v2.0.0)
([#31](#31))
([c68d20e](c68d20e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant