fix(p7): locale-invariant replay + non-zero fail-closed + red-team test fix#80
fix(p7): locale-invariant replay + non-zero fail-closed + red-team test fix#80heidi-dang wants to merge 12 commits intomainfrom
Conversation
Summary of ChangesHello @heidi-dang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the system's robustness and security posture. It introduces checks to ensure that core functionalities, such as event replay, are deterministic across different locales and timezones. Furthermore, it strengthens the fail-closed mechanism for the C++ Core in REAL mode by verifying non-zero exit codes upon failure, and improves the reliability of red-team security tests by addressing known flakiness. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable hardening improvements, and a security audit confirmed no vulnerabilities were identified within the scope of the changes. Key improvements include strengthening the fail-closed mechanism by ensuring REAL mode fails with a non-zero exit code, adding a locale-invariance check for deterministic replays, and fixing a red-team test. My feedback focuses on enhancing the maintainability and debuggability of the test scripts, specifically by suggesting a refactoring of a complex one-liner and cautioning about the potential downsides of suppressing error streams in tests.
scripts/repro_p7.sh
Outdated
| if python3 -c "import heidi_cpp; c = heidi_cpp.Core(); c.start('real')" 2>/dev/null; then | ||
| error "REAL mode unexpectedly exited with 0" | ||
| exit 1 | ||
| else | ||
| log "PASSED: REAL mode refused start with non-zero exit code." | ||
| fi |
There was a problem hiding this comment.
Suppressing stderr with 2>/dev/null in this and subsequent tests (lines 49, 58) can make debugging difficult. While these tests correctly check for non-zero exit codes to verify expected failures, swallowing stderr means that if a script fails for an unexpected reason (e.g., a missing dependency, a different runtime error), the root cause is hidden. The test would still pass, but for the wrong reason. For more robust testing, consider redirecting stderr to a temporary file for inspection during debugging.
scripts/repro_p7.sh
Outdated
| log "4) locale/timezone invariance check" | ||
| get_head_hash() { | ||
| local locale=$1 | ||
| LC_ALL=$locale TZ=UTC python3 -c "import heidi_cpp; os=__import__('os'); os.environ['OUT_DIR']='$RUNTIME/tmp'; c = heidi_cpp.Core(); c.init(); c.start('collect'); c.tick(1); c.shutdown(); print(__import__('hashlib').sha256(open('$RUNTIME/tmp/verified/events.jsonl').readlines()[0].encode()).hexdigest())" |
There was a problem hiding this comment.
This Python one-liner is quite complex, which can impact readability and maintainability. It can be made more efficient and conventional by using standard imports and a more memory-efficient way to read the first line of a file.
Specifically:
- Use
import os, hashlibinstead of__import__(). - Use
readline()instead ofreadlines()[0]to avoid reading the whole file into memory.
| LC_ALL=$locale TZ=UTC python3 -c "import heidi_cpp; os=__import__('os'); os.environ['OUT_DIR']='$RUNTIME/tmp'; c = heidi_cpp.Core(); c.init(); c.start('collect'); c.tick(1); c.shutdown(); print(__import__('hashlib').sha256(open('$RUNTIME/tmp/verified/events.jsonl').readlines()[0].encode()).hexdigest())" | |
| LC_ALL=$locale TZ=UTC python3 -c "import heidi_cpp, os, hashlib; os.environ['OUT_DIR']='$RUNTIME/tmp'; c = heidi_cpp.Core(); c.init(); c.start('collect'); c.tick(1); c.shutdown(); print(hashlib.sha256(open('$RUNTIME/tmp/verified/events.jsonl').readline().encode()).hexdigest())" |
Precision hardening: replay digest no longer varies with locale/TZ, REAL mode fail-closed returns non-zero, and red-team tests are fixed. Includes local reproducibility gates.