Skip to content

fix(session_metrics): guard VIBEGUARD_LOG_FILE against KeyError (#103)#105

Open
majiayu000 wants to merge 2 commits intomainfrom
feat/fix-vibeguard-log-file-guard
Open

fix(session_metrics): guard VIBEGUARD_LOG_FILE against KeyError (#103)#105
majiayu000 wants to merge 2 commits intomainfrom
feat/fix-vibeguard-log-file-guard

Conversation

@majiayu000
Copy link
Copy Markdown
Owner

Summary

  • Replace bare os.environ["VIBEGUARD_LOG_FILE"] at line 35 of hooks/_lib/session_metrics.py with .get() + sys.exit(0) guard, matching the pattern used for VIBEGUARD_SESSION_ID and VIBEGUARD_PROJECT_LOG_DIR added in PR fix(session_metrics): guard env vars against silent KeyError crash #93
  • Add two new test cases to tests/unit/test_session_metrics_env_guard.sh covering exit-0 and no-metrics-file-written behaviour when VIBEGUARD_LOG_FILE is unset (6/6 pass)

Closes #103

Test plan

  • bash tests/unit/test_session_metrics_env_guard.sh — all 6 tests pass (4 existing + 2 new)
  • Manually invoke python3 hooks/_lib/session_metrics.py without VIBEGUARD_LOG_FILE set → exits 0 with no traceback

Signed-off-by: majiayu000 1835304752@qq.com

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Hook Latency (P95)

Details
Benchmark suite Current: 9bec1ad Previous: 075c3ed Ratio
pre-edit-guard (P95) 184 ms 188 ms 0.98
pre-write-guard (P95) 221 ms 213 ms 1.04
pre-bash-guard (P95) 259 ms 255 ms 1.02
post-edit-guard (100) (P95) 296 ms 298 ms 0.99
post-write-guard (100) (P95) 209 ms 208 ms 1.00
post-edit-guard (5000) (P95) 315 ms 314 ms 1.00
post-write-guard (5000) (P95) 207 ms 209 ms 0.99
stop-guard (5000) (P95) 132 ms 132 ms 1
learn-evaluator (5000) (P95) 131 ms 132 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

…ssing env var

Replace bare os.environ["VIBEGUARD_LOG_FILE"] with .get() + early sys.exit(0)
so invocations without the variable exit silently instead of crashing with a
KeyError traceback, matching the existing guards for VIBEGUARD_SESSION_ID and
VIBEGUARD_PROJECT_LOG_DIR added in PR #93.

Add two test cases to test_session_metrics_env_guard.sh covering exit-0 and
no-metrics-file-written behaviour when VIBEGUARD_LOG_FILE is unset.

Signed-off-by: majiayu000 <1835304752@qq.com>
Assert that the missing VIBEGUARD_LOG_FILE guard exits silently, and reset the vg-helper session-metrics test temp dirs so repeated runs do not accumulate stale JSONL state.

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000 majiayu000 force-pushed the feat/fix-vibeguard-log-file-guard branch from 8677a28 to 9bec1ad Compare April 21, 2026 21:23
@majiayu000
Copy link
Copy Markdown
Owner Author

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

[P1] U-17: VIBEGUARD_LOG_FILE unguarded in session_metrics.py — incomplete fix from #93

1 participant