Skip to content

[Patch] perform a postmortem analysis if remove_ids fails#1799

Open
tdavidcl wants to merge 6 commits intoShamrock-code:mainfrom
tdavidcl:postmortem-remove-ids
Open

[Patch] perform a postmortem analysis if remove_ids fails#1799
tdavidcl wants to merge 6 commits intoShamrock-code:mainfrom
tdavidcl:postmortem-remove-ids

Conversation

@tdavidcl
Copy link
Copy Markdown
Member

@tdavidcl tdavidcl commented May 8, 2026

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances error reporting in the remove_ids method of PatchDataField by adding a post-mortem analysis block that provides diagnostic information, such as duplicate ID detection and flag sums, when an unexpected number of elements remain. The review feedback focuses on improving the robustness and idiomatic nature of this new logic, specifically by including missing standard headers, restricting the analysis to the relevant data range, utilizing standard algorithms like std::adjacent_find for duplicate detection, and ensuring type correctness in std::accumulate to avoid potential overflows.

Comment on lines 37 to +38
#include <memory>
#include <vector>
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.

high

The code uses std::sort, std::accumulate, std::vector, and potentially smart pointers. The headers <algorithm>, <numeric>, <vector>, and <memory> should be included explicitly to ensure the code compiles across different environments.

#include <algorithm>
#include <memory>
#include <numeric>
#include <vector>


// post mortem analysis

std::vector<u32> ids_to_rem_vec = ids_to_rem.copy_to_stdvec();
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.

medium

The remove_ids function processes only the first len elements of the ids_to_rem buffer. The postmortem analysis should be consistent with this by only analyzing those len elements. Using copy_to_stdvec() copies the entire buffer, which might contain extra data not relevant to the operation and could lead to false positives in the duplicate check.

        std::vector<u32> ids_to_rem_vec = ids_to_rem.copy_to_stdvec_idx_range(0, len);

Comment on lines +341 to +346
// Adgacent elements in ids_to_rem_vec should be different
for (size_t i = 1; i < ids_to_rem_vec.size(); i++) {
if (ids_to_rem_vec[i] == ids_to_rem_vec[i - 1]) {
has_duplicates = true;
}
}
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.

medium

The duplicate check can be simplified and made more readable by using std::adjacent_find instead of a manual loop. This also fixes the typo in the comment ("Adgacent" -> "Adjacent").

        // Adjacent elements in ids_to_rem_vec should be different
        has_duplicates = std::adjacent_find(ids_to_rem_vec.begin(), ids_to_rem_vec.end()) != ids_to_rem_vec.end();
References
  1. Refactor logic into standard algorithms or helper functions to improve readability and maintainability.

std::vector<u32> keep_flags_vec = keep_flag.copy_to_stdvec();

// compute keep flags sum
u32 keep_flags_sum = std::accumulate(keep_flags_vec.begin(), keep_flags_vec.end(), 0);
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.

medium

The third argument to std::accumulate determines the type of the accumulator. Using 0 (a signed int) can lead to overflow if the sum of keep_flags_vec exceeds INT_MAX. Since the elements and the result are u32, the accumulator should be u32(0) or 0u to avoid signed/unsigned mismatch and ensure the accumulator type matches the data range.

        u32 keep_flags_sum = std::accumulate(keep_flags_vec.begin(), keep_flags_vec.end(), u32(0));
References
  1. When performing a scan or accumulation, if the total sum fits within a specific integer type, there is no need to use a wider type for the accumulator, as intermediate sums will not overflow.

tdavidcl added 5 commits May 10, 2026 20:02
…simple commands

Copies shamenv_do from env/helpers into the build folder after setup,
providing a convenience wrapper that sources activate and runs commands
without manual sourcing.

Assisted-by: claude-code
@github-actions
Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit d2239be
Commiter email is timothee.davidcleris@proton.me

Pre-commit check report

Some failures were detected in base source checks checks.
Check the On PR / Linting / Base source checks (pull_request) job in the tests for more detailed output

❌ trailing-whitespace

Fixing AGENTS.md

❌ check-shebang-scripts-are-executable

env/helpers/shamenv_do: has a shebang but is not marked executable!
  If it is supposed to be executable, try: `chmod +x env/helpers/shamenv_do`
  If on Windows, you may also need to: `git add --chmod=+x env/helpers/shamenv_do`
  If it is not supposed to be executable, double-check its shebang is wanted.

Suggested changes

Detailed changes :
diff --git a/AGENTS.md b/AGENTS.md
index f8987f9f..02aba013 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -45,7 +45,7 @@ This shows the flags specific to that machine — they can vary widely.
 ```bash
 cd build
 ./shamenv_do shamconfigure # alias to the correct cmake command
-./shamenv_do shammake      # alias to ninja build (or make if ninja is unavailable) 
+./shamenv_do shammake      # alias to ninja build (or make if ninja is unavailable)

Always use something line && echo DONE after the build command to avoid confusion since ninja sometime can do a succesfull build without showing 100% in the steps.


</details>

<!-- thollander/actions-comment-pull-request "workflow_report" -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant