Skip to content

Improvements - #3

Merged
Psych0meter merged 6 commits into
mainfrom
improvements
Sep 22, 2026
Merged

Psych0meter merged 6 commits into
mainfrom
improvements

Conversation

@Psych0meter

Copy link
Copy Markdown
Owner

No description provided.

Claude added 6 commits September 22, 2026 11:44
/api/match and /api/generate accept arbitrary user-supplied patterns
and log text, with no bound on either size or how long matching can
take. Two independent mitigations:

- DebugRequest now caps pattern (5,000), custom_patterns (20,000) and
  log_text (200,000) length via pydantic Field(max_length=...).

- Both engine calls now run off the event loop through a small
  ThreadPoolExecutor with a wall-clock budget (MATCH_TIMEOUT_SECONDS,
  default 3s, env-overridable), via a new _run_with_timeout() helper.
  This bounds *response time*, not CPU usage - see the comment above
  MATCH_TIMEOUT_SECONDS for the full reasoning, including why pygrok's
  use of the third-party 'regex' package (one of its own dependencies)
  already mitigates some classic catastrophic-backtracking patterns
  before this timeout would ever need to fire.

Fixes a real bug this surfaces: pydantic's default validation-error
body is a list of error objects, which the frontend's
`this.errorMessage = data.detail || ...` can't render sensibly (it
would show "[object Object]"). Added a RequestValidationError handler
that flattens it to the same single-string {"detail": "..."} shape
HTTPException responses already use, so a validation failure (missing
field, oversized input, etc.) displays exactly like a 400 does.
The project had no tests at all. Adds:

- tests/test_grok_engine.py: unit tests for GrokDebuggerEngine -
  matching (grok fields, named regex groups, strict mode, custom
  pattern definitions), field-name validation, type detection,
  dict flattening/unflattening, and pattern auto-generation.
  Includes explicit regression tests for the find_partial_match
  tokenizer bug fixed earlier (both the simple named-group case and
  the harder nested-parens-inside-a-group case).

- tests/test_api.py: FastAPI TestClient tests for all four endpoints,
  including the new request size limits, the flattened validation-
  error shape, and the match timeout (mocked rather than relying on a
  genuinely catastrophic pattern, since pygrok's preference for the
  regex package over stdlib re makes wall-clock ReDoS timing
  environment-dependent - see the test's docstring).

- requirements-dev.txt and a [project.optional-dependencies] dev
  group in pyproject.toml (ruff, bandit, pytest, httpx).

- [tool.pytest.ini_options] in pyproject.toml so  resolves
  the app package correctly regardless of invocation style.
.github/workflows/ci.yml installs requirements-dev.txt and runs
'ruff check app/ tests/', 'bandit -r app/' and 'pytest -v' on every
push to main and every pull request, across Python 3.10-3.12.
- Project Structure now lists .devcontainer/, .github/workflows/,
  tests/, pyproject.toml and requirements-dev.txt.
- New Development section: how to install dev extras and run pytest,
  ruff and bandit, and a pointer to the CI workflow that runs them.
- New Request Limits & Timeouts section documenting the size caps and
  match timeout added earlier, with a pointer to the fuller reasoning
  in app/main.py.
- New Production Notes section flagging the two frontend CDN
  trade-offs (Tailwind's Play CDN, Alpine's floating version/missing
  SRI) with concrete steps to harden them - not applied automatically,
  since a wrong SRI hash would break the app outright.
- New License section - the repo is GPLv3 (LICENSE) but the README
  never said so.
Keep a Changelog style. 1.1.0-1.1.4 entries are reconstructed from git
history (this project didn't keep one before); 1.1.5 documents the
request limits/timeout, test suite, CI and README work from this
branch.
@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
grok-debugger Ready Ready Preview Sep 22, 2026 12:18pm UTC

@Psych0meter
Psych0meter merged commit 2e93200 into main Sep 22, 2026
5 checks passed
@Psych0meter
Psych0meter deleted the improvements branch September 22, 2026 12:21

This branch was successfully deployed

1 active deployment
Preview — 113b6a92 Deployed Sep 22, 2026 by vercel[bot]
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