Skip to content

fix(clp-s): Fix authoritative timestamp parsing bug introduced in #731.#769

Merged
gibber9809 merged 1 commit into
y-scope:mainfrom
gibber9809:timestamp-key-fix
Mar 16, 2025
Merged

fix(clp-s): Fix authoritative timestamp parsing bug introduced in #731.#769
gibber9809 merged 1 commit into
y-scope:mainfrom
gibber9809:timestamp-key-fix

Conversation

@gibber9809

@gibber9809 gibber9809 commented Mar 15, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug introduced during some refactoring in #731. In particular, that PR adds the condition m_authoritative_timestamp.size() > (m_matched_timestamp_prefix_length + 1) to an if statement wrapping the rest of the timestamp key resolution logic, which prevented being able to correctly match the root of a given object subtree for keys consisting of a single token.

The fix simply involves removing this condition from that outermost if branch and adjusting some other conditions accordingly.

Alternatively we could simplify the matching logic by inserting the namespace into the start of the vector of tokens and use that to remove the special case for matching the root of an object subtree.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Manually validated that timestamp key can be recognized for variety of kv-ir and json streams

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced safety and reliability in internal archival processing by streamlining validation checks, reducing the risk of runtime errors.

@gibber9809 gibber9809 requested review from a team and wraymo as code owners March 15, 2025 00:13
@coderabbitai

coderabbitai Bot commented Mar 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request modifies the conditional logic in the add_node method of the ArchiveWriter class. The new implementation first checks that m_authoritative_timestamp is not empty and that the parent_node_id equals constants::cRootNodeId. It then verifies that m_authoritative_timestamp.size() is greater than (m_matched_timestamp_prefix_length + 1) prior to accessing the key at the corresponding index, thereby reducing the risk of out-of-bounds access. No public API declarations were altered.

Changes

File Change Summary
components/core/src/clp_s/ArchiveWriter.cpp Updated the add_node method: now checks for a non-empty timestamp and correct parent_node_id before verifying the size condition to safely access an index.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant AW as ArchiveWriter::add_node
    C->>AW: call add_node(node details)
    AW->>AW: Check if m_authoritative_timestamp is not empty and parent_node_id equals cRootNodeId
    alt Root node condition met
        AW->>AW: Process node logic for root condition
    else Not a root node
        AW->>AW: Verify m_authoritative_timestamp.size() > (m_matched_timestamp_prefix_length + 1)
        alt Size check passes
            AW->>AW: Access element at m_matched_timestamp_prefix_length and process further
        else Size check fails
            AW->>AW: Handle condition without accessing the element
        end
    end
Loading

Possibly related PRs

Suggested reviewers

  • wraymo

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d008ab and ef74206.

📒 Files selected for processing (1)
  • components/core/src/clp_s/ArchiveWriter.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/core/src/clp_s/ArchiveWriter.cpp
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: ubuntu-jammy-lint
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: build-macos (macos-13, true)
  • GitHub Check: build-macos (macos-15, false)
  • GitHub Check: build-macos (macos-13, false)
🔇 Additional comments (1)
components/core/src/clp_s/ArchiveWriter.cpp (1)

244-252: The fix properly addresses the authoritative timestamp parsing bug.

The changes correctly restructure the conditional logic to handle the root node case separately, allowing single-token keys to be matched properly. The original condition had a size check that prevented this matching. The fix maintains safety by:

  1. First checking if we're dealing with a root node (constants::cRootNodeId == parent_node_id) and the timestamp isn't empty
  2. Moving the size check to protect the vector access in the else if branch
  3. Using the correct coding style with false == m_authoritative_timestamp.empty()

This implementation properly addresses the issue mentioned in PR #769 while maintaining array bounds safety.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@wraymo wraymo 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.

Can you show an example what this PR fixes?

@gibber9809

Copy link
Copy Markdown
Contributor Author

Can you show an example what this PR fixes?

All cases -- the bug prevents timestamp parsing from ever being successful. Consider a simple case of timestamp "ts" in namespace "". The vector of timestamp tokens will be of size 1, so the topmost condition of m_authoritative_timestamp.size() > (m_matched_timestamp_prefix_length + 1) will never be true because the matched prefix starts at 0 and 1 > 1 will never be true.

Adding the namespace to the start of the timestamp token vector can also solve the bug/simplify the code overall, but it requires more code change so I've gone with the change in this PR for now.

@gibber9809 gibber9809 merged commit d9ce0fb into y-scope:main Mar 16, 2025
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