Skip to content

Fix daemon audit evidence polarity and trigger scope - #11626

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/pr1-review-fixes
Jul 31, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/pr1-review-fixes

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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:

  1. Linux /proc/<pid>/stat ENOENT could override a simultaneously occupied or permission-denied PID and produce a false gone; contradictory evidence now stays unknown.
  2. Windows named-pipe ENOENT could override a matching CIM CreationDate and produce a false gone; a matching process now keeps the classification unknown.
  3. The Windows contradiction path reported the endpoint as present even though the triggering connect error proved the pipe missing; the observation now preserves both facts.
  4. Endpoint identity replacement invoked the classifier as an undocumented fourth trigger; identity change remains an isolated observable event without process probing.
  5. Exact-identity pidfile reads ran synchronously from the reconnect path reachable by spawn; the initial record is cached at adapter construction and refresh reads run asynchronously only on audit failure triggers.
  6. The adapter-to-pidfile Linux tick/boot-id seam lacked integration coverage; a regression test now verifies the persisted identity reaches audit observations.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Executed with the repository-pinned Node 24:

  • Full typecheck across node, CLI, and web TypeScript configs
  • Normal and type-aware Oxlint on all changed files
  • pnpm run check:max-lines-ratchet equivalent under Node 24
  • Touched Vitest suites with --config config/vitest.config.ts --maxWorkers=2: 11 files, 347 tests passed
  • Adjacent daemon lifecycle, client, server, spawner, provider, and health suites: 12 files, 148 tests passed
  • Adjacent managed-hook identity suites: 2 files, 20 tests passed
  • Non-vacuity mutation run: reverting seven load-bearing production behaviors produced seven expected failures across five suites; all five suites passed after restoration
  • git diff --check

AI Review Report

Three complete review rounds covered the full merged 26-file diff plus these fixes. Round 1 found the two false-gone contradictions, 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 /proc access; 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:

This PR must not change daemon lifecycle behavior.

unknown always preserves the adapter and blocks destructive decisions.

A signal-0 permission error proves only that some process occupies the pid — the incarnation classification stays unknown unless command line, start time, or nonce independently match.

Classification runs event-driven — adapter transport close, observed authenticated disconnect plus token ENOENT, and lazily on inventory failure — never on a timer alone.

Run the classifier without removing adapters or shutting down daemons.

CommandLine is corroborating-only and never a negative signal.

Named pipes vanish with their process: pipe presence is positive liveness evidence, pipe absence is an independent second gone proof.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

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

  • Polarity fixes: Linux /proc/<pid>/stat ENOENT when signal-0 still sees the PID, and Windows named-pipe ENOENT when CIM confirms process presence, both now yield unknown instead of a false gone.
  • Scope fixes: endpoint_identity_changed is removed as a classifier trigger (identity change now only notifies listeners), and the Windows contradiction path correctly records endpointState: 'missing' while preserving state: 'unknown'.
  • Async pidfile reads: The synchronous readFileSync on the reconnect path is replaced with an async read; the initial record is cached at adapter construction and the refresh runs only on audit failure triggers.

Confidence Score: 5/5

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

Important Files Changed

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

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Daemon 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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes to daemon audit evidence handling and trigger scope.
Description check ✅ Passed The description covers the required sections, explains behavior and security impacts, and documents extensive testing, though checklist markings are partly inconsistent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/main/daemon/daemon-incarnation-evidence.ts (1)

68-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Merge duplicate missing/unavailable branches.

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 win

Duplicated identity-match predicate.

readMatchingPidRecord and exactDaemonIncarnationForPidRecord each re-implement the same pid/startedAtMs/launchNonce equality 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 readMatchingPidRecord and exactDaemonIncarnationForPidRecord.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d73c613 and bbc976a.

📒 Files selected for processing (6)
  • src/main/daemon/daemon-audit-classifier.ts
  • src/main/daemon/daemon-incarnation-evidence.test.ts
  • src/main/daemon/daemon-incarnation-evidence.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/shared/daemon-audit-eligibility.ts
💤 Files with no reviewable changes (1)
  • src/shared/daemon-audit-eligibility.ts

@brennanb2025
brennanb2025 merged commit 90692ba into main Jul 31, 2026
49 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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