Skip to content

fix(lab-ops-hub): validate the container crawler response shape before archiving or binding (#7018) - #7023

Merged
dezren39 merged 1 commit into
mainfrom
creator-b/7018-labops-crawl-shape
Nov 8, 2026
Merged

dezren39 merged 1 commit into
mainfrom
creator-b/7018-labops-crawl-shape

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #7018

crawlWithContainer returned res.json() under a type cast, and the /api/crawl route archived the spread result to R2 and bound its fields into the crawls INSERT unvalidated. Verified pre-fix with the real index.ts (probe ~/git/fleet/probe-labops-crawl, md5-checked copy, only the two platform imports stubbed):

  • container JSON null → 500 raw TypeError on result.title, after the R2 archive was already written (orphan archive, no crawls row)
  • container JSON string → 200 ok:true, crawls row with all fields null, archive body spread by character index ({"0":"h",…})
  • links as an object → 500 raw D1 bind TypeError, again after the archive write
  • wrong-typed scalars (title: 123, links: "3", status_code: "200") → bound as-is
  • in every case the designed Worker fallback never ran, because nothing threw until the damage was done (or at all)

Fix: parseCrawlResult in src/lib.ts validates the cross-service response (plain non-null/non-array object; title/excerpt/text strings and links/status_code finite numbers when present) and crawlWithContainer throws on a malformed result, so the route's existing catch falls back to the Worker crawler with container_error set — the same treatment as any other container failure. No side effects happen before validation.

Verification (laptop):

  • TS suite node --test "test/**/*.test.ts": 106/106 on the branch (3 new parseCrawlResult tests); the new tests fail against pre-fix lib.ts
  • Probe replay post-fix: control (well-formed container result) unchanged; null / string / object-field / wrong-typed cases all fall back to source: "worker-fallback" with a shape-naming container_error and sane binds
  • Python suite: 2 import errors (idna module missing in that env), identical on clean main — pre-existing baseline
  • tsc --noEmit not run: npm ci in the worktree hung with no output for ~9 min and was killed; the suite above executes the real TS via type stripping. CI will typecheck per repo policy if configured.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…e archiving or binding (#7018)

crawlWithContainer returned res.json() under a cast; the crawl route
archived the spread result to R2 and bound its fields into the crawls
INSERT unvalidated. A JSON null body 500d after the archive write, a
JSON string stored an all-null row reported as success, and
wrong-typed fields bound as-is — and the designed Worker fallback
never triggered, because nothing threw until the damage was done.

parseCrawlResult in lib.ts now validates the cross-service response
(plain object; string title/excerpt/text, finite-number
links/status_code when present). A malformed result throws in
crawlWithContainer, so the route falls back to the Worker crawler
with container_error set, like any other container failure.

Tests: 3 new lib.test.ts cases (well-formed passthrough, non-object
bodies, wrong-typed fields); TS suite 106/106 on the branch; the new
tests fail against pre-fix lib.ts. Probe replay
(~/git/fleet/probe-labops-crawl, real index.ts): control unchanged,
all malformed shapes now fall back with sane binds. (Python suite:
2 import errors from a missing idna module, identical on clean
main — pre-existing baseline.)
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 01:12
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4bc82cb9-7f82-4f69-8bf8-0471555e08e1
Commits

Reviewing files that changed from the base of the PR and between ab35bef and 7307ab5.

Files selected for processing: 3

  • pkgs/lab-ops-hub/src/index.ts
  • pkgs/lab-ops-hub/src/lib.ts
  • pkgs/lab-ops-hub/test/lib.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T01:13:28.498635Z 7307ab5 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.

@dezren39 dezren39 added kind/bug Something isn't working (prefixed form of the classic bug label) app/lab-ops-hub Package/app: lab-ops-hub (pkgs/ or apps/ in this repo) source/creator Filed by the new-issue-creator job labels Nov 8, 2026
@dezren39
dezren39 merged commit 08dd577 into main Nov 8, 2026
2 of 4 checks passed
@dezren39
dezren39 deleted the creator-b/7018-labops-crawl-shape branch November 8, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app/lab-ops-hub Package/app: lab-ops-hub (pkgs/ or apps/ in this repo) kind/bug Something isn't working (prefixed form of the classic bug label) source/creator Filed by the new-issue-creator job

Projects

None yet

1 participant