Repository navigation
Fix daemon audit evidence polarity and trigger scope - #11626
Conversation
Greptile SummaryThis PR applies six targeted correctness fixes to the daemon audit classifier following a retroactive review of #11606. All changes are audit-observation-only and do not touch daemon lifecycle, routing, retirement, or aggregate membership.
Confidence Score: 5/5Safe to merge; all six fixes are narrowly scoped to audit observation correctness and carry no risk to daemon lifecycle or routing decisions. Every changed code path produces at most a different audit observation label (unknown vs gone) with no side effects on adapters, sessions, or health state. The async pidfile enrichment is fire-and-forget with a stale-identity guard that prevents out-of-order cache writes. The two new polarity fixes convert false gone returns into unknown, which is always the safe direction per the stated contract. All six changes have targeted regression tests. Files Needing Attention: No files require special attention. daemon-pty-adapter.ts has the most structural change but the logic is straightforward and the integration test covers the key Linux identity seam.
|
| Filename | Overview |
|---|---|
| src/main/daemon/daemon-incarnation-evidence.ts | Fixes Linux procfs ENOENT polarity: stat.status === 'missing' now returns unknown (consistent with the existing unavailable branch) instead of a false gone, resolving the race where signal-0 and procfs disagree. |
| src/main/daemon/daemon-audit-classifier.ts | Fixes Windows named-pipe gone proof to block when CIM reports the process present, propagates observedEndpointState: 'missing' on the contradiction path, removes endpoint_identity_changed from reachabilityForTrigger, and consistently uses observedEndpointState across all return paths. |
| src/main/daemon/daemon-pty-adapter.ts | Removes the synchronous pidfile read from the reconnect path; caches the initial record at construction and introduces an async resolveExactDaemonIncarnation that enriches Linux incarnations only on audit failure triggers. Race-condition guard in cacheExactDaemonIncarnation correctly rejects stale updates when the daemon reconnects with a new identity before the async read completes. |
| src/main/daemon/daemon-incarnation-evidence.test.ts | Adds two regression tests: one for the Linux procfs ENOENT/signal-0 contradiction (inspection_failed unknown) and one for the Windows named-pipe/CIM contradiction (process present, endpoint missing, overall unknown). |
| src/main/daemon/daemon-pty-adapter.test.ts | Adds an integration test that writes a Linux pidfile before adapter construction and verifies linuxStartTicks/bootId flow end-to-end into the audit observation's exactIncarnation. |
| src/shared/daemon-audit-eligibility.ts | Removes endpoint_identity_changed from DAEMON_AUDIT_TRIGGER_VALUES and DAEMON_AUDIT_REASON_VALUES, enforcing the contract that identity change is an isolated observable event without a classifier invocation. |
Reviews (1): Last reviewed commit: "fix(daemon): preserve audit evidence pol..." | Re-trigger Greptile
📝 WalkthroughWalkthroughDaemon audit classification now treats missing Windows named pipes as gone only with configured proof, exact incarnation data, and absent process evidence. Linux process-stat inspection failures remain unknown when the PID is still observed. The adapter asynchronously loads PID records, derives and caches matching Linux incarnation data, and resolves it before audit classification. Tests cover contradictory Windows evidence, Linux inspection failures, and persisted birth identity after restart. The endpoint identity change trigger and reason were removed from shared eligibility values. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/daemon/daemon-incarnation-evidence.ts (1)
68-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMerge duplicate
missing/unavailablebranches.Both branches now return the exact same
unknown(...)call. Consolidating avoids the two staying in sync manually if evidence handling changes later.♻️ Proposed consolidation
- if (stat.status === 'missing') { - return unknown(signal === 'permission_denied' ? 'permission_denied' : 'inspection_failed', [ - 'linux_proc_stat', - 'process_signal' - ]) - } - if (stat.status === 'unavailable') { + if (stat.status === 'missing' || stat.status === 'unavailable') { return unknown(signal === 'permission_denied' ? 'permission_denied' : 'inspection_failed', [ 'linux_proc_stat', 'process_signal' ]) }src/main/daemon/daemon-pty-adapter.ts (1)
1688-1704: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated identity-match predicate.
readMatchingPidRecordandexactDaemonIncarnationForPidRecordeach re-implement the samepid/startedAtMs/launchNonceequality check independently. Extracting a shared predicate reduces the risk of the two drifting if match criteria ever change.♻️ Proposed extraction
+function pidRecordMatchesIdentity( + pidRecord: ParsedDaemonPid | null, + identity: DaemonEndpointIdentity +): pidRecord is ParsedDaemonPid { + return ( + pidRecord?.pid === identity.pid && + pidRecord.startedAtMs === identity.startedAtMs && + pidRecord.launchNonce === identity.launchNonce + ) +}Then use it in both
readMatchingPidRecordandexactDaemonIncarnationForPidRecord.Also applies to: 2340-2358
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 48480cf9-9765-4493-9d46-b96a582f825b
📒 Files selected for processing (6)
src/main/daemon/daemon-audit-classifier.tssrc/main/daemon/daemon-incarnation-evidence.test.tssrc/main/daemon/daemon-incarnation-evidence.tssrc/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/shared/daemon-audit-eligibility.ts
💤 Files with no reviewable changes (1)
- src/shared/daemon-audit-eligibility.ts
Summary
Follow-up fixes from the retroactive review of merged PR #11606. The classifier remains audit-only and does not change daemon lifecycle, routing, retirement, or aggregate membership.
Review findings fixed:
/proc/<pid>/statENOENTcould override a simultaneously occupied or permission-denied PID and produce a falsegone; contradictory evidence now staysunknown.ENOENTcould override a matching CIMCreationDateand produce a falsegone; a matching process now keeps the classificationunknown.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildExecuted with the repository-pinned Node 24:
pnpm run check:max-lines-ratchetequivalent under Node 24--config config/vitest.config.ts --maxWorkers=2: 11 files, 347 tests passedgit diff --checkAI Review Report
Three complete review rounds covered the full merged 26-file diff plus these fixes. Round 1 found the two false-
gonecontradictions, the extra classifier trigger, the reconnect-path synchronous pidfile read, and the missing adapter/pidfile integration assertion; round 2 found the contradictory Windows endpoint-state reporting; round 3 was clean.The review traced every new production call site and confirmed the result remains observation-only: no adapter removal, daemon shutdown, retirement change, routing decision, aggregate membership change, timer, or polling was added. Cross-platform review covered Linux raw ticks, boot identity, zombie and procfs failure polarity; macOS weak start-time mismatch handling; Windows CIM tolerance, null command-line handling, and named-pipe absence; platform-gated
/procaccess; and path handling. There is no renderer diff, so shortcut, label, and visual review is not applicable.Security Audit
The evidence probes accept only authenticated daemon identity and local pidfile data. Windows command interpolation remains limited to a validated positive safe-integer PID, process inspection uses fixed executables and arguments, telemetry excludes endpoint paths, profile paths, nonces, and command lines, and audit listener/telemetry failures remain isolated from daemon operations. No dependencies, secrets, new external inputs, destructive operations, or IPC authority changes were added.
Notes
Relevant contract lines: