Skip to content

fix(tui): stop file-watcher polling for a missing file with a throwing probe#799

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/file-watcher-non-throwing-probe
Draft

fix(tui): stop file-watcher polling for a missing file with a throwing probe#799
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/file-watcher-non-throwing-probe

Conversation

@posthog

@posthog posthog Bot commented Jul 3, 2026

Copy link
Copy Markdown

Problem

The TUI file-watcher spammed error tracking with expected ENOENT exceptions
while waiting for the agent to write .posthog-events.json.

startFileWatcher (src/ui/tui/hooks/file-watcher.ts) can't attach fs.watch
to a file that doesn't exist yet, so it falls back to a 1s retry setInterval
that probed for the file with fs.accessSync. That call throws ENOENT on
every tick
until the file appears. Because exception autocapture is enabled on
the analytics client, each throw surfaced as a spurious $exception
(Module.accessSync under Timeout._onTimeout), creating error-tracking noise.
LogViewer (src/ui/tui/primitives/LogViewer.tsx) used the identical
accessSync-in-retry pattern.

This is error-tracking noise, not a broken flow — the retry loop still works —
but a benign, expected filesystem state should never raise.

Changes

  • Replace the throwing fs.accessSync existence probe with a non-throwing
    fs.existsSync in both the file-watcher and LogViewer retry loops.
    existsSync returns a boolean without constructing an Error, so there is
    nothing for autocapture to pick up regardless of how the exception path is
    wired.
  • Attach the fs.watch before clearing the retry interval, so a file removed
    between the existence check and the watch just keeps the poll running for the
    next tick instead of dropping the watcher.
  • Add a regression test asserting the watcher never calls accessSync while the
    file is absent.

Test plan

  • pnpm build && pnpm test — 1157 tests pass, including the new
    never probes for the missing file with a throwing accessSync case.
  • pnpm lint — 0 errors (pre-existing warnings only; none in the changed files).

Created with PostHog Code from an inbox report.

…g probe

The file-watcher's attach-retry loop polled for a not-yet-created file with
`fs.accessSync`, which throws ENOENT on every tick while the file is absent.
With exception autocapture on, each throw surfaced as a spurious `$exception`,
polluting error tracking (~1/sec while the watcher waits for the agent to write
`.posthog-events.json`).

Swap the throwing `accessSync` existence probe for a non-throwing `fs.existsSync`
so the expected "file not there yet" state never raises. `existsSync` returns a
boolean without constructing an Error, so there is nothing to capture regardless
of how the exception path is wired. Apply the same fix to LogViewer, which uses
the identical accessSync-in-retry pattern. Attach the watch before clearing the
retry interval so a file removed mid-probe just keeps the poll running.

Generated-By: PostHog Code
Task-Id: 091f2350-ce0c-4767-bb84-ced895939554
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci error-tracking-upload-source-maps
  • /wizard-ci mcp-analytics
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci error-tracking-upload-source-maps/android
  • /wizard-ci error-tracking-upload-source-maps/cicd-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-nested-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-single-stage-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-gitlab-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-monorepo-pnpm-node-react
  • /wizard-ci error-tracking-upload-source-maps/cicd-monorepo-raw-node-react
  • /wizard-ci error-tracking-upload-source-maps/cicd-ssh-vps-node-raw
  • /wizard-ci error-tracking-upload-source-maps/flutter
  • /wizard-ci error-tracking-upload-source-maps/ios
  • /wizard-ci error-tracking-upload-source-maps/next
  • /wizard-ci error-tracking-upload-source-maps/next-no-posthog
  • /wizard-ci error-tracking-upload-source-maps/node-raw
  • /wizard-ci error-tracking-upload-source-maps/node-rollup
  • /wizard-ci error-tracking-upload-source-maps/node-rollup-typescript-plugin
  • /wizard-ci error-tracking-upload-source-maps/node-webpack
  • /wizard-ci error-tracking-upload-source-maps/nuxt-3-6
  • /wizard-ci error-tracking-upload-source-maps/nuxt-4-3
  • /wizard-ci error-tracking-upload-source-maps/react-native
  • /wizard-ci error-tracking-upload-source-maps/react-vite
  • /wizard-ci error-tracking-upload-source-maps/rust
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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.

0 participants