Repository navigation
Closed
Copy link
Labels
agent:guardClaimed by Agent: GuardClaimed by Agent: Guardarea:crawlersbugSomething isn't workingSomething isn't workingpo:antigravityDispatched by the Antigravity Product OwnerDispatched by the Antigravity Product Ownerstatus:doneTask completed and verifiedTask completed and verified
Description
Goal
Prevent malformed numeric rows, prototype-property keys, and lone UTF-16 surrogates from bypassing the monthly AI USD spend cap, throwing runtime RangeError/URIError exceptions, or mutating Object.prototype keys in @repo/crawlers review jobs and helpers.
Requirements
monthSpendUsdNaN spend-cap bypass (apps/importer/src/shopee/jobs/review-ai-points.ts, around lines 822 and 1124):- Summing
Number(b.cost_usd ?? b.reserved_usd ?? 0)without aNumber.isFinitecheck lets a single malformed string (e.g."NaN") taintmonthSpendUsd = NaN, causingresult.monthSpendUsd + result.reservedUsd > capto evaluatefalseand bypass the monthly spend cap. - Coerce non-finite or negative row amounts safely so malformed rows cannot poison
monthSpendUsd(or fail closed when a batch row carries a non-finite positive reservation/cost).
- Summing
- Prototype-key guards (
apps/importer/src/shopee/jobs/review-ai-points.ts:800andapps/importer/src/shopee/product-points-ai-prompt.ts:327-329):- Replace
if (key in total)ontotalwithObject.hasOwn(total, key)instoreAiRows. - Use
Object.create(null)orMapforbyCriterioninproduct-points-ai-prompt.tsso untrusted keys like__proto__,constructor, ortoStringnever hitObject.prototype.
- Replace
- Finite cost & rating bounds (
apps/importer/src/shopee/review-ai-prompt.ts:370andapps/importer/src/shopee/jobs/review-values.ts:402):- Tighten
batchCostUsdvalidation inreview-ai-prompt.tsfromtypeof v === "number" && v > 0totypeof v === "number" && Number.isFinite(v) && v > 0(rejectingInfinity). - Tighten
expectedMasterRatingsinreview-values.tsfromtypeof value !== "number" || value < 1 || value > 5to also reject!Number.isFinite(value)soNaNcannot reachtoUnits(NaN, V_UNIT)and throwRangeError: The number NaN cannot be converted to a BigInt.
- Tighten
- UTF-16 surrogate safety (
apps/importer/src/shopee/jobs/review-ai-points.ts:332,343,353,373andapps/importer/src/shopee/logger.ts:143,161):- Call
.toWellFormed()beforeencodeURIComponent(...)on external batch/file IDs inreview-ai-points.tsto preventURIError: URI malformed. - Ensure
sanitizeAiGeneratedTexttruncation atsafeMaxLeninlogger.tsdoes not split a surrogate pair and leave a trailing lone high surrogate (e.g. slice cleanly at code-point boundary or normalize with.toWellFormed()without exceedingsafeMaxLen).
- Call
Approach
Apply minimal, surgical guards in the five importer files above and add targeted unit regression tests covering "NaN" / Infinity batch cost rows, NaN expected master ratings, __proto__ / toString keys, lone-surrogate batch IDs, and surrogate-pair boundary truncation in sanitizeAiGeneratedText.
Acceptance
- A malformed
"NaN"orInfinitycost/reservation value cannot makemonthSpendUsdNaNor bypassAI_MONTHLY_CAP_USD. expectedMasterRatingsignoresNaN/Infinityratings instead of throwingRangeErrorinBigInt.- Prototype keys (
__proto__,constructor,toString) do not match or mutateObject.prototypeinstoreAiRowsorbyCriterion. - Lone surrogates in batch/file IDs do not throw
URIError, andsanitizeAiGeneratedTextnever emits a trailing lone surrogate when truncating atmaxLen. - Unit tests in
apps/importerand full monorepotypecheck,lint,test, andbuildpass.
Files
apps/importer/src/shopee/jobs/review-ai-points.tsapps/importer/src/shopee/review-ai-prompt.tsapps/importer/src/shopee/product-points-ai-prompt.tsapps/importer/src/shopee/jobs/review-values.tsapps/importer/src/shopee/logger.tsapps/importer/src/shopee/__tests__/review-ai-points.test.tsapps/importer/src/shopee/__tests__/review-values.test.ts
Metadata
Metadata
Assignees
Labels
agent:guardClaimed by Agent: GuardClaimed by Agent: Guardarea:crawlersbugSomething isn't workingSomething isn't workingpo:antigravityDispatched by the Antigravity Product OwnerDispatched by the Antigravity Product Ownerstatus:doneTask completed and verifiedTask completed and verified
Activity
JOY commentedon Nov 22, 2026
🔒 [Agent: Guard] Claim lock
refs/claims/1853taken by claimantantigravity:93ebb889-4915-4c9f-bb0b-53a96791ec91(Status: in-progress).JOY commentedon Nov 22, 2026
[Agent: Guard] Claimed this issue on branch
fix/1853-review-jobs-hardening(Status: Ready -> In Progress).JOY commentedon Nov 22, 2026
[Agent: Guard] Checkpoint: opened PR #1857 into
devat9682b308. Local verification passed (pnpm --filter @repo/crawlers test,pnpm --filter @repo/crawlers test:dist,pnpm typecheck,pnpm lint,pnpm build). Next step: complete 2 independent fresh-context subagent reviews and wait for GitHub CI checks on PR #1857 before PO acceptance gate.JOY commentedon Nov 22, 2026
🔓 [Agent: Guard] Claim lock
refs/claims/1853of antigravity:93ebb889-4915-4c9f-bb0b-53a96791ec91 (Agent Guard) since 2026-11-22T09:47:39Z released by claimantantigravity:def296a6-5f67-48da-bb74-ee3ede4b7061because #1853 is closed (Status: done).