Skip to content

telemetry: public /api/stats endpoint (Tier B showcase) - #1

Merged
IgnazioDS merged 1 commit into
mainfrom
telemetry-public-stats
Apr 27, 2026
Merged

telemetry: public /api/stats endpoint (Tier B showcase)#1
IgnazioDS merged 1 commit into
mainfrom
telemetry-public-stats

Conversation

@IgnazioDS

Copy link
Copy Markdown
Owner

Summary

  • Adds a stdlib-only Vercel Python serverless function at api/stats.py exposing the public Tier-B telemetry contract
  • Returns honest GitHub-derived metrics (commits_30d, commits_total, last_commit_at, primary_language, repo_stars, lines_of_code) with mode: "showcase" flagged so the homepage widget renders this tile as a deployed scaffold rather than a live workload system
  • Promotes the static-only Vercel deploy to hybrid static + Python serverless

Why showcase mode (mode: "showcase")

Per the schema at https://github.com/IgnazioDS/IgnazioDS/blob/main/TELEMETRY_SCHEMA.md, this repo is currently a static landing page with a CLI scaffold (no DB, no queues, no runbook executions). Reporting fabricated runbooks_active_now / approvals_pending counters would violate the credibility constraint of the homepage telemetry panel. The endpoint instead reports real signals about the codebase. When the system is promoted to production workload, the implementation upgrades to Tier A and mode flips to live.

Implementation

  • api/stats.pyBaseHTTPRequestHandler Vercel function, sub-200ms cold start, no third-party deps
  • 5-min module-scope cache stays well under GitHub's 60-req/hr unauth rate limit even across many warm invocations
  • SAFETY_CAPS clamps every counter to prevent runaway exposure
  • Never returns HTTP 5xx: GitHub failures degrade to status: "degraded" with last-good-cache or zeroed metrics, contract stays valid
  • CORS headers (* origin) set both at vercel.json edge and inside the Python handler
  • scripts/compute_telemetry_static.py regenerates api/_telemetry_static.json (the LOC artifact) before each deploy

Verification (preview deploy)

$ curl https://agent-runbook-orchestrator-k8ohm6r4v-ignaziods-projects.vercel.app/api/stats
{
  "system": "runbook-orchestrator",
  "mode": "showcase",
  "status": "operational",
  "last_deployed_at": "2026-04-27T18:37:45Z",
  "last_commit_at": "2026-04-01T18:28:15Z",
  "metrics": {
    "commits_30d": 1,
    "commits_total": 4,
    "primary_language": "Python",
    "repo_stars": 0,
    "lines_of_code": 1390
  },
  "schema_version": 1,
  "generated_at": "2026-04-27T18:40:13Z"
}

Headers: Content-Type: application/json, Access-Control-Allow-Origin: *, Access-Control-Allow-Methods: GET, OPTIONS, Cache-Control: public, max-age=30.

Test plan

  • Local: python3 -m unittest tests.test_stats — 6/6 pass (happy path, degraded path, stale-cache fallback, safety caps, handler 200, OPTIONS 204)
  • Live preview: curl /api/stats returns HTTP 200 with the documented shape
  • Browser CORS preflight from https://eleventh.dev console (verify before merge)
  • Production verification after merge: curl https://agent-runbook-orchestrator.vercel.app/api/stats

Adds a stdlib-only Vercel Python serverless function at api/stats.py
that exposes honest, GitHub-derived metrics about the codebase. The
endpoint is consumed by the Production Telemetry panel on
https://eleventh.dev.

Per the schema at
https://github.com/IgnazioDS/IgnazioDS/blob/main/TELEMETRY_SCHEMA.md
this system runs in showcase mode (Tier B): the Vercel deploy is a
public landing page, not a system serving production workload. Rather
than fabricate `runbooks_active_now` / `approvals_pending` counters
that would have nothing to count, the endpoint reports real signals:

- commits_30d, commits_total      via GitHub Link header pagination
- primary_language, repo_stars    via GET /repos/:owner/:repo
- last_commit_at                  via GET /repos/.../commits?per_page=1
- lines_of_code                   via committed api/_telemetry_static.json
                                  (regenerated by scripts/compute_telemetry_static.py)
- mode = "showcase"               explicit Tier-B signal for the widget

Implementation:
- BaseHTTPRequestHandler entrypoint, no third-party deps; sub-200ms
  cold start on Vercel.
- Module-scope 5-min cache keeps us well under GitHub's 60-req/hr
  unauth rate limit even across many warm invocations.
- All counters clamped by SAFETY_CAPS to prevent runaway exposure.
- Never returns HTTP 5xx: GitHub failures degrade to status="degraded"
  with last-good-cache or zeroed metrics, contract stays valid.
- CORS headers (* origin) set both at vercel.json edge and inside the
  Python handler — belt-and-suspenders so the homepage widget can poll
  the endpoint cross-origin.

Tests (tests/test_stats.py, stdlib unittest):
- happy path: response shape matches Tier B contract
- degraded path: GitHub unreachable -> 200 with status="degraded"
- stale-cache fallback: last good response served on subsequent failure
- safety caps: oversize values clamped
- handler always returns 200, never 5xx
- OPTIONS returns 204 with CORS headers

To refresh lines_of_code before deploying:
  python3 scripts/compute_telemetry_static.py
  git add api/_telemetry_static.json
@vercel

vercel Bot commented Apr 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-runbook-orchestrator Ready Ready Preview, Comment Apr 27, 2026 6:41pm

@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: 993d5543a6

ℹ️ 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 api/stats.py
Comment on lines +220 to +223
def do_GET(self) -> None: # noqa: N802 (interface contract)
try:
payload = _build_response()
except Exception: # noqa: BLE001 (last-resort: contract forbids 5xx)

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 Implement HEAD without returning 5xx

This handler defines do_GET and do_OPTIONS only, so HEAD /api/stats falls through to BaseHTTPRequestHandler's default unsupported-method path and returns 501, which is a 5xx. That violates the endpoint’s documented “never returns HTTP 5xx” behavior and can surface in environments where proxies, uptime checks, or bots probe with HEAD; add do_HEAD (or equivalent method handling) so HEAD returns a non-5xx response with the same headers as GET.

Useful? React with 👍 / 👎.

@IgnazioDS
IgnazioDS merged commit 031cbdb into main Apr 27, 2026
3 checks passed
@IgnazioDS
IgnazioDS deleted the telemetry-public-stats branch April 27, 2026 19:05
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