Skip to content

fix(codex): persist hook verification status - #28

Merged
LRainner merged 1 commit into
masterfrom
codex/fix-hook-verification-status
Jul 30, 2026
Merged

fix(codex): persist hook verification status#28
LRainner merged 1 commit into
masterfrom
codex/fix-hook-verification-status

Conversation

@LRainner

@LRainner LRainner commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • keep installed Hooks pending until a real Codex event verifies the integration
  • persist verification by Hook fingerprint while keeping the latest event scoped to the current app run
  • isolate Agent Cat handlers in mixed Hook groups and share install lifecycle across UI and CLI paths
  • keep local probes from changing verification state and retain an in-memory fallback when persistence fails
  • update Playwright Hook runtime mocks without committing regenerated README screenshots

Validation

  • npm test (43 passed)
  • npm run build
  • cargo test --manifest-path src-tauri/Cargo.toml (39 passed)
  • cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
  • cargo fmt --manifest-path src-tauri/Cargo.toml -- --check
  • npm run test:e2e (5 passed)
  • npm run screenshots (1 passed)

Summary by CodeRabbit

  • New Features

    • Added persistent verification tracking for Codex hook integrations.
    • The Settings page now distinguishes verified connections from pending or paused states.
    • Hook status displays the latest real Codex event and verification time.
    • Settings refresh automatically when a Codex event is received.
    • Installation changes and uninstallation now reset outdated verification status.
  • Bug Fixes

    • Prevented test or probe events from being mistaken for real Codex activity.
    • Improved status messaging for connection and local hook testing flows.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds deterministic hook-definition fingerprints and persistent verification state, records verification only from real Codex events, clears state when hooks change or are removed, and updates the settings UI, styling, and test mocks to use the new runtime status fields.

Changes

Hook verification integration

Layer / File(s) Summary
Fingerprint and persisted verification state
src-tauri/src/hook_installer.rs, src-tauri/src/hook_verification.rs
Agent Cat hook definitions receive stable v1-... fingerprints, while runtime and persisted verification state expose matching timestamps and cleared states.
Installation lifecycle integration
src-tauri/src/lib.rs
Shared install and uninstall helpers compare fingerprints and clear verification state when hooks change or are removed; CLI paths use the shared helpers.
Real event runtime tracking
src-tauri/src/hook_server.rs
Runtime status reports verification and last-real-event fields, and only genuine Codex events update verification and the real-event cache.
Settings status and test updates
src/settings.ts, src/styles.css, e2e/*.ts
The settings UI renders connected and pending verification states, refreshes on Codex events, updates messaging and styling, and aligns mocked status payloads with the new fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CodexHook
  participant HookServer
  participant HookVerification
  participant SettingsWindow
  CodexHook->>HookServer: emit_event(event)
  HookServer->>HookServer: classify real Codex event
  HookServer->>HookVerification: record(timestamp)
  HookServer->>SettingsWindow: emit codex-event
  SettingsWindow->>HookServer: refreshHookStatus()
Loading

Possibly related PRs

  • LRainner/AgentCat#25: Updates the README screenshot test’s mocked hook_runtime_status handling, which overlaps with this PR’s runtime-status payload changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: persisting Codex hook verification status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src-tauri/src/hook_server.rs`:
- Around line 283-292: Update the HookRuntimeStatus construction in the status
function to call latest_real_event() unconditionally instead of gating it
through hook_verification::verified_at(). Keep verified_at assigned solely to
the verified_at field, while last_real_event_at and last_real_event continue
deriving from the independently retrieved latest real event.

In `@src-tauri/src/hook_verification.rs`:
- Around line 75-105: Update record so a matching persisted
VerificationState.verified_at is reused when initializing or updating
RuntimeVerification memory, instead of retaining the incoming timestamp. Keep
last_real_event as the per-run activity marker, and ensure runtime and persisted
verification timestamps remain consistent across restarts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f9f8f502-460d-4c7c-89e4-9afc76fdde30

📥 Commits

Reviewing files that changed from the base of the PR and between 94898cd and 8618f56.

📒 Files selected for processing (8)
  • e2e/readme-screenshots.screenshot.ts
  • e2e/settings.e2e.ts
  • src-tauri/src/hook_installer.rs
  • src-tauri/src/hook_server.rs
  • src-tauri/src/hook_verification.rs
  • src-tauri/src/lib.rs
  • src/settings.ts
  • src/styles.css

Comment on lines +283 to +292
let verified_at = crate::hook_verification::verified_at();
let latest_real = verified_at.and_then(|_| latest_real_event());
HookRuntimeStatus {
receiver_running: RECEIVER_RUNNING.load(Ordering::Acquire),
socket_path: socket_path()
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_default(),
last_event_at: latest.as_ref().map(|event| event.timestamp),
last_event: latest.as_ref().map(|event| event.event.clone()),
last_event_is_test: latest
.as_ref()
.map(|event| {
event.session_id.starts_with("agent-cat-test")
|| event.session_id.starts_with("agent-cat-probe")
})
.unwrap_or(false),
verified_at,
last_real_event_at: latest_real.as_ref().map(|event| event.timestamp),
last_real_event: latest_real.as_ref().map(|event| event.event.clone()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep current-run real-event state independent from verification.

Line 284 suppresses lastRealEvent* whenever verified_at() is None. A received real event can then render as “尚未收到” even though LATEST_REAL_EVENT has it. Return latest_real_event() unconditionally; retain verifiedAt only for the verification state.

Proposed fix
-    let latest_real = verified_at.and_then(|_| latest_real_event());
+    let latest_real = latest_real_event();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let verified_at = crate::hook_verification::verified_at();
let latest_real = verified_at.and_then(|_| latest_real_event());
HookRuntimeStatus {
receiver_running: RECEIVER_RUNNING.load(Ordering::Acquire),
socket_path: socket_path()
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_default(),
last_event_at: latest.as_ref().map(|event| event.timestamp),
last_event: latest.as_ref().map(|event| event.event.clone()),
last_event_is_test: latest
.as_ref()
.map(|event| {
event.session_id.starts_with("agent-cat-test")
|| event.session_id.starts_with("agent-cat-probe")
})
.unwrap_or(false),
verified_at,
last_real_event_at: latest_real.as_ref().map(|event| event.timestamp),
last_real_event: latest_real.as_ref().map(|event| event.event.clone()),
let verified_at = crate::hook_verification::verified_at();
let latest_real = latest_real_event();
HookRuntimeStatus {
receiver_running: RECEIVER_RUNNING.load(Ordering::Acquire),
socket_path: socket_path()
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_default(),
verified_at,
last_real_event_at: latest_real.as_ref().map(|event| event.timestamp),
last_real_event: latest_real.as_ref().map(|event| event.event.clone()),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src-tauri/src/hook_server.rs` around lines 283 - 292, Update the
HookRuntimeStatus construction in the status function to call
latest_real_event() unconditionally instead of gating it through
hook_verification::verified_at(). Keep verified_at assigned solely to the
verified_at field, while last_real_event_at and last_real_event continue
deriving from the independently retrieved latest real event.

Comment on lines +75 to +105
pub fn record(timestamp: u64) -> Result<(), String> {
let Some(fingerprint) = hook_installer::verification_fingerprint()? else {
return Ok(());
};
let verified_at = RUNTIME_VERIFICATION
.get_or_init(|| Mutex::new(RuntimeVerification::Uninitialized))
.lock()
.map(|mut state| {
let verified_at = match &*state {
RuntimeVerification::Verified(memory) if memory.fingerprint == fingerprint => {
memory.verified_at
}
_ => timestamp,
};
*state = RuntimeVerification::Verified(MemoryVerification {
fingerprint: fingerprint.clone(),
verified_at,
});
verified_at
})
.unwrap_or(timestamp);
let existing = load().unwrap_or_default();
if existing.fingerprint.as_deref() == Some(fingerprint.as_str())
&& existing.verified_at.is_some()
{
return Ok(());
}
save(&VerificationState {
fingerprint: Some(fingerprint),
verified_at: Some(verified_at),
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep verified_at consistent with persisted verification.

Line 96 finds an existing matching timestamp, but Lines 79-95 have already cached the incoming event timestamp. After restart, the first new event changes verified_at only until the next restart, when it reverts to the old persisted value. Reuse the matching persisted timestamp when initializing runtime memory (or persist the new one consistently); last_real_event already represents per-run activity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src-tauri/src/hook_verification.rs` around lines 75 - 105, Update record so a
matching persisted VerificationState.verified_at is reused when initializing or
updating RuntimeVerification memory, instead of retaining the incoming
timestamp. Keep last_real_event as the per-run activity marker, and ensure
runtime and persisted verification timestamps remain consistent across restarts.

@LRainner
LRainner merged commit c8eded8 into master Jul 30, 2026
8 checks passed
@LRainner
LRainner deleted the codex/fix-hook-verification-status branch July 30, 2026 07:51
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