Skip to content

fix: 7 critical bugs in cdm.js and server.js#196

Merged
k-rister merged 7 commits into
masterfrom
fix-cdm-critical-bugs
Jun 29, 2026
Merged

fix: 7 critical bugs in cdm.js and server.js#196
k-rister merged 7 commits into
masterfrom
fix-cdm-critical-bugs

Conversation

@k-rister

Copy link
Copy Markdown
Contributor

Summary

Seven critical bugs in the CDM query engine, each as a separate commit:

  • Missing await on 4 esJsonArrRequest() calls.forEach() on a Promise silently fails, tag/param filters in getIters() produce no results
  • JSON.stringify(obj.null, 2) wrong arg order — logs undefined instead of the object that failed source resolution
  • retMag typo — error message assigned to throwaway variable, caller gets empty ret-msg
  • addRuns checked instead of addIterations--add-iterations only works when --add-runs is also non-empty
  • Detailed error immediately overwritten — response/request count mismatch error replaced by unrelated generic message
  • != 'undefined' string comparison — compares against literal string instead of using isDefined(), causes TypeError when breakout is actually undefined
  • Implicit global metric_data in server.js — missing var creates race condition on concurrent /api/v1/metric-data requests

Closes #194

Test plan

  • Syntax verified: node --check passes on both files
  • Review each commit individually for correctness
  • Run CDM query server and verify metric-data endpoint returns correct results

🤖 Generated with Claude Code

k-rister and others added 7 commits June 27, 2026 10:03
Four calls to the async esJsonArrRequest() were missing await,
causing .forEach() to be called on a Promise (silently failing).
Two of these also used the obsolete sync-request .getBody()
pattern which is incompatible with the async version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
JSON.stringify(obj.null, 2) accessed obj.null (undefined) and
passed 2 as the replacer. Should be JSON.stringify(obj, null, 2)
to pretty-print the object with 2-space indentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
retMag (typo) was assigned instead of retMsg, so the error
message was lost and retMsg remained empty on return.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy-paste error: the addIterations block checked addRuns != []
instead of addIterations != [], so addIterations was only
processed when addRuns was also non-empty.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The detailed mismatch error (response count vs request count)
was immediately overwritten by an unrelated generic error about
missing period-id/run-id. Remove the erroneous overwrite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comparing sets[i].breakout != 'undefined' checks against the
literal string, not the undefined type. When breakout is actually
undefined, the comparison is true (different types), causing
.length to be called on undefined (TypeError). Use the existing
isDefined() helper which does typeof correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
metric_data was assigned without var/let/const, creating an
implicit global variable. Concurrent requests to
/api/v1/metric-data could overwrite each other's data, returning
wrong results. Add var to make it function-scoped.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@k-rister k-rister self-assigned this Jun 27, 2026
@k-rister k-rister requested a review from a team June 27, 2026 15:07
@project-crucible-tracking project-crucible-tracking Bot moved this to In Progress in Crucible Tracking Jun 27, 2026
@k-rister

Copy link
Copy Markdown
Contributor Author

@atheurer Can you take a close look at these AI identified bugs and the associated fixes since this is more your area?

@atheurer atheurer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All 7 fixes are correct — reviewed each individually:

  1. JSON.stringify arg orderobj.nullobj, null, 2
  2. Missing await on esJsonArrRequest — 4 calls were silently getting Promises instead of results ✓
  3. addRuns → addIterations — wrong variable name ✓
  4. Error message overwrite — preserved the specific diagnostic ✓
  5. retMag typo — → retMsg
  6. String comparison for undefined!= 'undefined'isDefined()
  7. Implicit global metric_data — race condition on concurrent requests ✓

Minor note: fix #3's addIterations != [] is still always-true (JS reference comparison), but that's pre-existing.

@k-rister k-rister merged commit e746315 into master Jun 29, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Crucible Tracking Jun 29, 2026
@k-rister k-rister deleted the fix-cdm-critical-bugs branch June 29, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: cdm.js missing await, wrong JSON.stringify, lost error messages

2 participants