Skip to content

fix: stop unwrapping activity attributes once they are no longer a string - #4980

Merged
themarolt merged 2 commits into
mainfrom
fix/issue-814-unwrap-attributes-loop
Oct 15, 2026
Merged

themarolt merged 2 commits into
mainfrom
fix/issue-814-unwrap-attributes-loop

Conversation

@themarolt

Copy link
Copy Markdown
Contributor

Summary

tryToUnwrapAttributes parsed activity attributes until it got an object. Attributes that arrive as a JSON-encoded number or boolean ("5", "true") parse to a value that is never an object, so the loop ran forever and hung the data sink worker. It now stops once the value is no longer a string, and anything that doesn't unwrap to an object is stored as empty attributes.

Changes

  • tryToUnwrapAttributes keeps parsing only while the value is a string and returns {} for any non-object result. Objects and JSON-encoded objects (also double-encoded) unwrap as before, JSON null still ends up as {}, and a string that isn't valid JSON still throws, as before.
  • Exported for its tests, which cover objects, single and double encoding, and "5", "true", "null" and a JSON-encoded string.
  • Protected path: the data-access layer.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Performance improvement
  • Chore / dependency update
  • Documentation

Related issue

Closes linuxfoundation/lfx-cdp-insights-ops#814

…ring

Attributes that are a JSON-encoded number or boolean made the unwrap loop
parse the same value forever and hang the data sink worker. Any value that
doesn't unwrap to an object is now stored as empty attributes.

Refs linuxfoundation/lfx-cdp-insights-ops#814

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:52
@cursor

cursor Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Targeted bug fix on the activity insert path; scalar/malformed unwrap cases now yield empty attributes instead of hanging, with no change to successful object unwrap behavior.

Overview
Fixes an infinite loop in tryToUnwrapAttributes when activity attributes are JSON strings that parse to scalars (e.g. "5", "true"). The old while (true) kept calling JSON.parse because the result was never an object, which could hang the data sink worker.

The loop now runs only while the value is still a string, then returns the object unchanged or {} if the final value is not a non-null object (including null and primitives). Normal object / single- and double-encoded JSON objects behave as before; invalid JSON still throws from JSON.parse.

The helper is exported and covered by new unit tests for objects, nested JSON encoding, and scalar encodings.

Reviewed by Cursor Bugbot for commit e9eede9. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI 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.

🔵 Needs a closer look

The protected shared data-access-layer change requires code-owner review.

0 open findings

What changed in this PR

Fixes an infinite loop in activity attribute decoding that could hang the data sink worker.

Changes:

  • Parses attributes only while they remain strings, returning {} for non-object results.
  • Adds regression tests for objects, nested encoding, and encoded scalar values.
File Description
services/​libs/​data-access-layer/​src/​activities/​insert.ts Bounds decoding by value type and normalizes non-object results.
services/​libs/​data-access-layer/​src/​activities/​insert.test.ts Adds attribute-decoding regression coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…attributes-loop

Signed-off-by: Uroš Marolt <uros@marolt.me>

# Conflicts:
#	services/libs/data-access-layer/src/activities/insert.test.ts
#	services/libs/data-access-layer/src/activities/insert.ts
Copilot AI balanced review requested due to automatic review settings October 15, 2026 21:19

Copilot AI 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.

🟢 Approval recommended

The focused fix resolves the infinite loop, preserves invalid-JSON errors, and includes regression coverage with no unresolved findings.

0 open findings

🧠 Review effort: Balanced

@themarolt
themarolt merged commit f7a7582 into main Oct 15, 2026
14 checks passed
@themarolt
themarolt deleted the fix/issue-814-unwrap-attributes-loop branch October 15, 2026 21:25
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.

2 participants