Skip to content

fix: hide Windows service console window and validate uploaded usage - #72

Open
tanqyry wants to merge 2 commits into
851-labs:mainfrom
tanqyry:fix/windows-hidden-service-and-usage-validation
Open

fix: hide Windows service console window and validate uploaded usage#72
tanqyry wants to merge 2 commits into
851-labs:mainfrom
tanqyry:fix/windows-hidden-service-and-usage-validation

Conversation

@tanqyry

@tanqyry tanqyry commented Sep 8, 2026

Copy link
Copy Markdown

What this does

Two fixes in one branch:

1. Windows service no longer flashes a console window

The Windows Task Scheduler task pointed /TR directly at the service-sync.cmd wrapper, so Task Scheduler launched it via cmd.exe in the interactive session and a blank console window flashed every five minutes.

  • The task now routes through a hidden wscript launcher (service-sync.vbs) that runs the wrapper with window style 0.
  • The launcher is written alongside the wrapper on install and removed on uninstall.
  • windowsTaskCreateArgs points /TR at wscript.exe "<launcher.vbs>" instead of the .cmd.

2. Server-side validation for uploaded usage (anti-forgery)

The server previously stored client-computed daily aggregates verbatim, so any authenticated client could report arbitrary spend, token counts, and model names and put itself at the top of the leaderboard.

Added sanitizeUsageDays in apps/api/src/usage/validation.ts, wired into writeStructuredUsage (covers both /usage/ingest and the legacy /usage/sync), which rejects:

  • non-finite or negative token counts and costUsd
  • per-row token totals above a 1B/day ceiling and costUsd above a $100k/day ceiling
  • malformed dates (must be YYYY-MM-DD)
  • empty, oversized, or control-character model/source names (and trims surrounding whitespace)

A new InvalidUsage error (HTTP 400) is declared on both usage endpoints and returned with a descriptive message.

Notes / follow-ups

  • These are conservative sanity ceilings, not a full server-side price table. Server-side pricing (dropping client costUsd entirely and computing from a trusted model → per-token price table) and a model allowlist would make the leaderboard impossible to forge; those need a model/price catalog that doesn't exist in the repo yet and are left as follow-ups.
  • Rate limiting sync frequency is also a worthwhile follow-up.

The Windows Task Scheduler task pointed /TR directly at the .cmd wrapper,
so Task Scheduler launched it via cmd.exe in the interactive session and a
console window flashed every five minutes. Route the task through a hidden
wscript launcher (.vbs) that runs the wrapper with window style 0 instead.
The server stored client-computed daily aggregates verbatim, so any
authenticated client could report arbitrary spend, token counts, and model
names. Add server-side sanity validation that rejects non-finite/negative
values, implausible per-day token and cost totals, malformed dates, and
empty/oversized/control-character model and source names.
@tanqyry

tanqyry commented Sep 8, 2026

Copy link
Copy Markdown
Author

this shit is incredibly vibecoded so just know 🙏

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