Skip to content

Update Staging#1866

Merged
nedvedba merged 1 commit intostagingfrom
devel
Feb 23, 2026
Merged

Update Staging#1866
nedvedba merged 1 commit intostagingfrom
devel

Conversation

@nedvedba
Copy link
Collaborator

@nedvedba nedvedba commented Feb 23, 2026

Update Staging

Summary by Sourcery

Enhancements:

  • Convert received protobufjs messages to plain objects with defaults applied and scalar types normalized prior to callback processing.

#1861)

* fix: prevent defaults being set to undefined, and interpret numbers and enums as strings.

* chore: Auto-format JavaScript files with Prettier
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures incoming protobufjs messages are converted to plain JavaScript objects with default values and consistent scalar representations before invoking the message handler, with optional type resolution based on the active field.

Sequence diagram for protobufjs message handling and conversion

sequenceDiagram
    participant CoreServer
    participant g_core_sock
    participant MessageDispatcher
    participant ProtobufType
    participant Handler_f

    CoreServer->>g_core_sock: incoming_message
    g_core_sock->>MessageDispatcher: on_message(msg, msg_info, which_field, correlation_id)
    MessageDispatcher->>MessageDispatcher: set g_ctx_next = ctx
    alt msg is not null
        MessageDispatcher->>MessageDispatcher: resolve_type = msg_info.type
        alt which_field is set
            MessageDispatcher->>MessageDispatcher: actual_entry = find in g_msg_by_id by field_name
            alt actual_entry found
                MessageDispatcher->>MessageDispatcher: resolve_type = actual_entry.type
            end
        end
        alt resolve_type is set
            MessageDispatcher->>ProtobufType: toObject(msg, {defaults: true, longs: String, enums: String})
            ProtobufType-->>MessageDispatcher: msg_plain_object
        end
    end
    MessageDispatcher->>Handler_f: f(msg_plain_object_or_original)
    Handler_f-->>MessageDispatcher: handler_result
Loading

Flow diagram for protobufjs message to plain object conversion

flowchart TD
    A[start on_message callback] --> B{msg is not null}
    B -->|no| H[call f with original msg]
    B -->|yes| C[set resolve_type = msg_info.type]
    C --> D{which_field is set}
    D -->|no| G{resolve_type is set}
    D -->|yes| E[actual_entry = find in g_msg_by_id by field_name]
    E --> F{actual_entry found}
    F -->|no| G{resolve_type is set}
    F -->|yes| C2[set resolve_type = actual_entry.type]
    C2 --> G
    G -->|no| H[call f with original msg]
    G -->|yes| I["msg = resolve_type.toObject(msg, defaults true, longs String, enums String)"]
    I --> J[call f with converted plain object msg]
Loading

File-Level Changes

Change Details Files
Normalize protobufjs messages to plain objects with defaults and stringified scalars prior to handler invocation.
  • Determine the correct protobuf type from msg_info or by matching which_field against g_msg_by_id entries.
  • Use resolve_type.toObject to convert the protobufjs message into a plain object including default values.
  • Configure the conversion so that long integers and enums are represented as strings for consistency.
  • Guard the conversion logic so it runs only when a message instance and a resolvable type are available.
web/datafed-ws.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The new Object.values(g_msg_by_id).find(...) lookup on every message may introduce unnecessary overhead; consider caching a field_name → type map or storing type directly where which_field is determined.
  • Converting msg in-place from a protobufjs message to a plain object changes the type seen by f(msg); if any existing handlers rely on protobuf-specific methods/behavior, it may be safer to either gate this behavior behind a flag or pass a separate converted object instead of mutating msg.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `Object.values(g_msg_by_id).find(...)` lookup on every message may introduce unnecessary overhead; consider caching a `field_name → type` map or storing `type` directly where `which_field` is determined.
- Converting `msg` in-place from a protobufjs message to a plain object changes the type seen by `f(msg)`; if any existing handlers rely on protobuf-specific methods/behavior, it may be safer to either gate this behavior behind a flag or pass a separate converted object instead of mutating `msg`.

## Individual Comments

### Comment 1
<location path="web/datafed-ws.js" line_range="2468-2471" />
<code_context>
+                    if (actual_entry) resolve_type = actual_entry.type;
+                }
+                if (resolve_type) {
+                    msg = resolve_type.toObject(msg, {
+                        defaults: true,
+                        longs: String,
+                        enums: String,
+                    });
+                }
</code_context>
<issue_to_address>
**issue (bug_risk):** Double-check that converting longs/enums to strings here doesn’t break downstream expectations.

This changes `msg` from a protobuf Message into a plain object with `longs` and `enums` as strings. Any consumer relying on numeric enums, Long instances, or protobuf-specific methods may break subtly. Consider gating this conversion behind a feature flag/option, or verify all downstream consumers are updated to handle the new string-based shape.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +2468 to +2471
msg = resolve_type.toObject(msg, {
defaults: true,
longs: String,
enums: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Double-check that converting longs/enums to strings here doesn’t break downstream expectations.

This changes msg from a protobuf Message into a plain object with longs and enums as strings. Any consumer relying on numeric enums, Long instances, or protobuf-specific methods may break subtly. Consider gating this conversion behind a feature flag/option, or verify all downstream consumers are updated to handle the new string-based shape.

@nedvedba nedvedba merged commit 8e07d10 into staging Feb 23, 2026
13 of 14 checks passed
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