Skip to content

Lab

Trees in Space · TreeBot

The bot and web portal for Trees in Space, a Halo Infinite player community on Xbox. It automates what used to be tracked by hand in a spreadsheet: it detects group records from real match data, computes per-player and per-role stats, and publishes them on a public website and in the group's GroupMe chat.

Version 1.0 · in production. What runs today: the bot was born in 2022 and modernized in November 2026. Google Sheets works as the database. This version is frozen in the v1.0.0 release.

Tech stack

LayerTechnology
LanguagePython (web bot on Render; automation scripts on Python 3.11)
Web / botFlask, Gunicorn, Jinja2 templates (HTML)
DataGoogle Sheets (via gspread + a Google Cloud service account)
External APIsHalo Infinite (unofficial API, SPNKr library), Xbox Live (auth through a Microsoft Entra ID / Azure app), GroupMe Bots API, GitHub REST API (workflow_dispatch)
AutomationGitHub Actions (cron, manual runs, API-triggered runs)
HostingRender (web service, Procfile + Gunicorn)
SecretsGitHub Secrets and Render environment variables

Service architecture

  • Web bot (Flask on Render): receives GroupMe messages through a webhook, answers commands (records, personal stats, menu, a random snakemagic.com video), and serves the public records and roles site plus JSON endpoints.
  • Data layer (sheets.py): a single Google Sheets access module with a 5‑minute in-memory cache, shared by the bot and the scripts.
  • GitHub Actions workers: scripts that query the Halo API (records updater, per-player stats, nightly “GGs” recap, member onboarding) and write to the sheet or to GroupMe.
  • Google Sheets: works as the database: records, members, roles, stats, and a cache of Xbox IDs (XUIDs).
flowchart TB
    accTitle: TreeBot architecture
    accDescr: Members post in GroupMe, which sends messages by webhook to the Flask bot on Render. The bot replies in GroupMe, reads Google Sheets, triggers GitHub Actions workflows and serves the public site. GitHub Actions uses SPNKr to query the Halo Infinite API, authenticates with Xbox Live through Entra ID, writes to Google Sheets and posts recaps to GroupMe.
    U[Members] -->|messages| GM[GroupMe]
    GM -->|webhook| BOT["Flask bot (Render)"]
    BOT -->|replies| GM
    BOT <-->|read| GS[(Google Sheets)]
    BOT -->|dispatch| GHA[GitHub Actions]
    GHA -->|SPNKr| HALO[Halo Infinite API]
    GHA -->|auth| XBL[Xbox Live / Entra ID]
    GHA -->|write| GS
    GHA -->|recaps| GM
    BOT --> WEB["Public site (records and roles)"]
    WEB --> U
Figure 1. TreeBot components and how they talk to each other.

Data flow

  1. Source: Halo Infinite matches automated A daily workflow authenticates with Xbox Live and uses SPNKr to pull each member's recent matchmaking games.
  2. Processing automated It keeps wins in Big Team Battle, Squad Battle and Heavies with at least 5 group members on the same team (a community rule). Each result is compared with the current record for that map and mode (fastest time, or largest Slayer margin). Lifetime service-record stats are computed per player in the same run.
  3. Storage automated New records are written to Google Sheets and the previous one moves to “Good Times”. Stats go to their own sheet, and XUIDs are cached so lookups aren't repeated.
  4. Manual input manual Members are added through a manual workflow (gamertag as input), and each player's roles (Roamer, Anchor, Objective, Driver) are set with checkboxes in the sheet.
  5. Publishing automated, on request The bot reads the sheet (cached) and shows it on the public site (records, plus a roles page with sortable tables), through JSON endpoints, and as replies to GroupMe commands.
  6. Nightly recap on demand When someone types ggs in the chat, the bot triggers a workflow that summarizes the last few hours of games (W‑L score, match list and per-game leaders) and posts it to GroupMe in about a minute.

CI/CD with GitHub Actions

flowchart TD
    accTitle: GitHub Actions workflows
    accDescr: Update Halo records runs on a daily cron or manually; it runs records_updater.py and then player_stats_updater.py, both write to Google Sheets and the first can announce in GroupMe. GGs summary is triggered by the bot when someone types ggs, or run manually, and posts to GroupMe. Add member is run manually with a gamertag and writes to Google Sheets.
    CRON[Daily cron] --> UR[Update Halo records]
    MAN1[Manual] --> UR
    UR --> S1[records_updater.py]
    S1 --> S2[player_stats_updater.py]
    S1 --> SH[(Google Sheets)]
    S2 --> SH
    S1 -. optional .-> GM[GroupMe]

    CHAT[ggs in GroupMe] --> BOT[Render bot]
    BOT -->|API dispatch| GG[GGs summary]
    MAN2[Manual] --> GG
    GG --> GM

    MAN3[Manual + gamertag] --> AM[Add member]
    AM --> SH
Figure 2. Triggers and outputs of the three workflows.
Repository workflows
WorkflowTriggerWhat it doesOutput
Update Halo records schedule (daily cron, 00:17 Mexico City time) and workflow_dispatch with a dry run option Step 1: finds new group records. Step 2 (runs even if step 1 fails): computes per-player stats and sorts the roles sheet by last match played. Updated records, “Player Stats” and “Roles” sheets; optional GroupMe announcement.
GGs summary workflow_dispatch: triggered by the bot via the GitHub API, or run manually (look-back hours, dry run) Collects recent games with 2+ members on the same team and builds the recap. GroupMe message. Uses concurrency to avoid overlapping runs, and the bot enforces a 5‑min cooldown.
Add member workflow_dispatch (gamertag input) Validates the gamertag against Xbox and adds the member. New row in the members sheet.

All workflows use ubuntu-latest, Python 3.11, pinned dependencies, and credentials from GitHub Secrets. The bot's deployment doesn't go through Actions: Render auto-deploys it from the master branch. There is no automated test workflow.

Challenges and technical decisions

  • Two Python runtimes

    The Render service runs an older Python than SPNKr requires (3.11+). Instead of a risky full migration, the heavy logic moved to GitHub Actions with its own dependency file, and the bot only triggers it through the GitHub API. The result is a lightweight web bot plus serverless workers.

  • Halo API rate limits (HTTP 429)

    Gamertag lookups were easily throttled. The fix added retry-with-backoff for 429 and 5xx responses, plus a shared XUID cache sheet so each player is looked up only once.

  • Data integrity

    The “record counts only with 5+ members” rule is enforced in code and is configurable. Heavies is classified by map and variant, and map names are normalized. A locale bug was also fixed: the sheet uses decimal commas, so 10,577 was being read as 10577; values are now read unformatted.

  • Secrets management

    Credentials were removed from the repository (explicit .gitignore), the service-account key was rotated, and everything is injected from GitHub Secrets and Render environment variables.

  • Hands-off operations

    Every workflow has a dry run mode and timeouts, and the stats step runs even if the records step fails. Daily upkeep needs no one, and changes can be tested without touching real data.

What it demonstrates

  • Automation and orchestration: scheduled and on-demand GitHub Actions pipelines, including runs triggered from an external app via workflow_dispatch.
  • API integration: four external services with different auth schemes (Microsoft/Xbox OAuth, Google service account, bot token, GitHub token).
  • Small-system design: separation of web service, data layer and workers; caching; rate-limit handling; idempotency and dry runs.
  • Pipeline-as-code and configuration management: versioned workflows, per-environment variables and centralized secrets.
  • Legacy refactoring: the bot started in 2022 and was reorganized into modules in 2026 (sheets.py, roles.py), with pinned dependencies and new features.
  • AI-assisted development: the 2026 modernization was designed and built in pair with Claude (Anthropic) as a coding agent, covering diagnosis, refactoring, new features and production debugging.
  • Real users: used daily by a community of about 30 players.

Version 2.0 · in development (since November 2026). This tab describes the design and the plan; it is updated as each phase ships. Phases marked “delivered” are complete; the rest are still planned.

Goals

  • Stability: no command gets lost even when the free server is asleep, and failures are caught before the group notices.
  • History: store every match once in a database instead of querying the Halo API again on every command.
  • Presentation: nightly awards in the chat and a page per player with trends, best duos and strongest maps.
  • Advice, not just data: a coach! command that turns each player's stats into three concrete recommendations.

Stack changes

Layerv1.0v2.0
LanguageTwo Python runtimes (legacy bot and 3.11 workers)Python 3.11 across the system
DataGoogle Sheets for everythingServerless PostgreSQL (Neon) for matches and history; Google Sheets for hand-edited data (members and roles)
AINoneClaude API (Haiku model) for the coach! command
ObservabilityManual checks/health endpoint, external uptime monitor and alerts to a private Discord channel
QualityNo automated testspytest tests and CI on every pull request
HostingRender (free plan)Render, evaluating a move to Google Cloud Run

Target architecture

flowchart TB
    accTitle: TreeBot 2.0 target architecture
    accDescr: Members write in GroupMe, which sends messages to the Flask bot on Render. The bot queries Postgres on Neon for matches and history, Google Sheets for members and roles, and the Claude API for the coach command. GitHub Actions queries the Halo API with SPNKr, stores new matches in Postgres and posts the nightly awards to GroupMe. An external monitor checks the bot health endpoint and failures are reported to a private Discord channel.
    U[Members] -->|messages| GM[GroupMe]
    GM -->|webhook| BOT["Flask bot (Render, Python 3.11)"]
    BOT -->|replies| GM
    BOT <-->|matches and history| PG[("Postgres (Neon)")]
    BOT <-->|members and roles| GS[(Google Sheets)]
    BOT -->|coach| LLM["Claude API (Haiku)"]
    GHA[GitHub Actions] -->|SPNKr| HALO[Halo Infinite API]
    GHA -->|new matches| PG
    GHA -->|nightly awards| GM
    MON[External monitor] -->|health| BOT
    BOT -. alerts .-> DC[Private Discord]
    GHA -. alerts .-> DC
    BOT --> WEB["Public site: records, roles and player"]
Figure 3. Planned components for version 2.0.

Phased plan

  1. Assessment delivered Map of the current data flow and a list of weak points ranked by risk. Key findings: the Halo token expired without being renewed, the daily job started 8 to 12 hours late, and the webhook processed every message before responding.
  2. Stability delivered A single runtime (Python 3.11), immediate webhook response with background processing, health endpoint with an external monitor, retries with backoff, Discord alerts and 37 tests in CI. The Halo token now renews itself on every run, and the bot starts the daily job on time (GitHub's cron is the backup).
  3. Database planned PostgreSQL schema with versioned migrations, idempotent match ingestion and a one-time migration from Google Sheets.
  4. Awards and player page planned Nightly MVP, most improved and best duo; a page with a 30-day trend, player synergy and strong and weak maps.
  5. AI coach planned coach! command with daily cache, cooldown and a non-AI fallback if the API is down.

Design decisions

  • Sheets for people, Postgres for machines

    The sheet stays as the control panel for what the group edits by hand. What the scripts generate (matches, dated stats, XUID cache) moves to tables, with history and fast queries.

  • The AI interprets, it does not calculate

    Python computes the comparisons (against the player's own average, the group's and by mode) and the model only turns them into advice. It cannot invent stats, and every recommendation is tied to a verifiable number.

  • Near-zero cost

    A free database plan that scales to zero, a small AI model with a per-player daily cache (fractions of a cent per request) and free monitoring services.

  • Negatives stay private

    Only shout-outs are posted in the group chat; areas to improve appear only when each player asks for their own stats.

What it will demonstrate

  • Reliability on free infrastructure: designing for servers that sleep, plus monitoring and alerts.
  • Data modeling: relational schema, versioned migrations and idempotent ingestion.
  • Applied AI with cost control: a language model integrated into a real product, with deterministically computed data.
  • Phased delivery: one branch and one pull request per phase, with automated tests.

Links