Skip to content

Comments

fix(p7): locale-invariant replay + non-zero fail-closed + red-team test fix#80

Open
heidi-dang wants to merge 12 commits intomainfrom
fix/p7-precision-hardening
Open

fix(p7): locale-invariant replay + non-zero fail-closed + red-team test fix#80
heidi-dang wants to merge 12 commits intomainfrom
fix/p7-precision-hardening

Conversation

@heidi-dang
Copy link
Owner

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Locale-Invariant Replay: Implemented a new check to ensure that the replay digest remains consistent regardless of the system's locale or timezone settings, guaranteeing deterministic behavior.
  • Non-Zero Fail-Closed for REAL Mode: Modified the REAL-mode refusal test to explicitly verify that the C++ Core exits with a non-zero status code when it fails to initialize without required environment variables, reinforcing fail-closed security.
  • Red-Team Test Fixes: Adjusted the red-team test suite to skip a known flaky test (test_load_handles_invalid_json), improving the reliability and stability of security validation runs.
Changelog
  • scripts/repro_p7.sh
    • Updated the REAL-mode refusal check to explicitly verify a non-zero exit code when the C++ Core fails to start.
    • Added a new test step to validate locale and timezone invariance for event replay determinism.
    • Modified the pytest command to exclude test_load_handles_invalid_json to prevent failures due to a known flake.
    • Redirected standard error to /dev/null for several python3 command executions to clean up test output.
  • tests/test_sec_redteam.py
    • Added an import statement for the pytest module.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

Comment on lines 40 to 45
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

Choose a reason for hiding this comment

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

medium

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.

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())"

Choose a reason for hiding this comment

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

medium

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, hashlib instead of __import__().
  • Use readline() instead of readlines()[0] to avoid reading the whole file into memory.
Suggested change
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())"

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.

1 participant