Skip to content

fix(kpi): reject malformed JSON-looking compute evidence - #481

Merged
seonghobae merged 2 commits into
mainfrom
fix/compute-kpi-malformed-json-lines
Aug 23, 2026
Merged

fix(kpi): reject malformed JSON-looking compute evidence#481
seonghobae merged 2 commits into
mainfrom
fix/compute-kpi-malformed-json-lines

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Purpose

Test-first repair of direct KPI evidence integrity. scripts/compute-kpi.mjs intentionally tolerates plain Wrangler diagnostic noise, but its prior JSON parse catch also silently dropped malformed JSON-looking NDJSON. A truncated /exchange failure record could therefore disappear from request/failure/latency computation instead of failing closed.

RED → GREEN

  • protected/live base: 52e786e48cced049f8daf0505b87241d832c4fc7
  • RED head: 896b145574f05b0e3c5061fab1af032424b89594
  • RED evidence: application CI 32608870644, job 97118404115; the realistic malformed-JSON regression failed because compute-kpi exited 0 instead of 1
  • GREEN candidate: d2c6e659ca94c69b6a0ba558b1aee373ba51495a
  • production repair: when a line starts as structured JSON ({ or [ after whitespace) but cannot parse, fail closed with a line-specific diagnostic; ordinary Wrangler diagnostic noise remains tolerated
  • exact candidate diff: scripts/compute-kpi.mjs plus test/compute-kpi-input-integrity.test.ts only

Exact-head verification

On unchanged d2c6e659ca94c69b6a0ba558b1aee373ba51495a:

  • application CI 32609156503: terminal success
  • reviewer-ci 32609156610: terminal success
  • central Security Scan 32609156526: terminal success
  • review threads: none
  • merge-base/live base remains exactly 52e786e48cced049f8daf0505b87241d832c4fc7

Authority boundary

This hardens direct retained KPI computation only. It does not create a production 30-day KPI window, provenance, release, deployment, revenue, legal/IP or acquisition-ready evidence. No central .github or other dedicated-writer source is modified.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

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

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

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b207b7a7-3159-48ca-926f-817cd3f6c663

📥 Commits

Reviewing files that changed from the base of the PR and between 52e786e and d2c6e65.

📒 Files selected for processing (2)
  • scripts/compute-kpi.mjs
  • test/compute-kpi-input-integrity.test.ts

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

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae marked this pull request as ready for review August 23, 2026 00:59
@seonghobae
seonghobae merged commit f726c91 into main Aug 23, 2026
16 of 17 checks passed
@seonghobae
seonghobae deleted the fix/compute-kpi-malformed-json-lines branch August 23, 2026 01:00

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Open in Devin Review

Comment thread scripts/compute-kpi.mjs
Comment on lines +30 to +32
if (/^\s*[\[{]/.test(line)) {
console.error(`Malformed JSON in KPI log line ${index + 1}.`);
process.exit(1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Malformed-JSON diagnostic reports wrong line number

filter(Boolean) drops blank lines before the loop, so the iteration index no longer matches the file line. When a blank line precedes a malformed record, Malformed JSON in KPI log line ${index + 1} names the wrong line and sends an operator to the wrong place.

Prompt for agents
The malformed-JSON diagnostic in scripts/compute-kpi.mjs reports a line number derived from the index of the post-filter array. Line 20 builds `lines` as `text.split("\n").filter(Boolean)`, which removes empty lines, so `index` from `lines.entries()` (line 25) no longer corresponds to the actual line number in the source file. When blank lines appear before a malformed record, the number in `Malformed JSON in KPI log line ${index + 1}` (line 31) is off. Fix by tracking the true line number, e.g. iterate over the unfiltered `text.split("\n")` result with its index and skip empty lines inside the loop, so the reported line number matches the file.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread scripts/compute-kpi.mjs
Comment on lines +30 to +33
if (/^\s*[\[{]/.test(line)) {
console.error(`Malformed JSON in KPI log line ${index + 1}.`);
process.exit(1);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Bracket-prefixed Wrangler diagnostics can fail closed

The new guard treats any non-parseable line starting with { or [ as fatal. Wrangler tail can emit bracket-prefixed diagnostic lines like [wrangler:info] ...; such a line would now exit 1, contradicting the intent to tolerate diagnostic noise. Depends on the actual capture format — confirm the tail output never produces bracket-prefixed non-JSON lines.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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