Skip to content

fix(file source): preserve findable state on transient fingerprinting errors - #27315

Open
lukesteensen wants to merge 2 commits into
masterfrom
fix/file-source-transient-fingerprint-errors
Open

lukesteensen wants to merge 2 commits into
masterfrom
fix/file-source-transient-fingerprint-errors

Conversation

@lukesteensen

@lukesteensen lukesteensen commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes a bug where a transient I/O error during file discovery fingerprinting (such as EACCES or EIO) is treated identically to file deletion (!file_findable()).

Previously, FileServer::run cleared findable = false on all watched files before globbing, and Fingerprinter::fingerprint_or_emit returned None on any error. When a live watched file encountered a transient PermissionDenied or EIO error, findable remained false, causing FileWatcher::read_line on EOF to immediately flush any buffered partial line without a newline and mark the watcher dead (tearing the line in half and/or causing duplicate re-reads once the error cleared).

This PR adds FingerprintOutcome (Found, Skipped, TransientError) and Fingerprinter::fingerprint_or_emit_outcome, and keeps existing watchers at path marked findable on TransientError.

Review tip: Enable Hide whitespace (?w=1) in the Files changed view — replacing if let Some(file_id) = ... with an early-continue let file_id = match ... dedents the unchanged watcher-update block in file_server.rs by one level.

Vector configuration

N/A

How did you test this PR?

  • Added file_server::tests::transient_eacces_does_not_tear_partial_line (buffers a partial line, applies transient chmod 000 across glob cycles, restores chmod 644, appends the remainder + \n, and asserts the full line is emitted intact without tearing).
  • cargo clippy -p file-source-common -p file-source --all-targets -- -D warnings
  • cargo test -p file-source --lib transient_eacces_does_not_tear_partial_line

Does this PR include user facing changes?

  • Yes. Bug fix preventing torn lines / premature reaping on transient fingerprinting errors (changelog fragment to be added before marking ready for review).
  • No. A maintainer will apply the no-changelog label to this PR.

@lukesteensen
lukesteensen marked this pull request as ready for review November 25, 2026 02:37
@lukesteensen
lukesteensen requested a review from a team as a code owner November 25, 2026 02:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T02:40:02.502266Z da70328 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-official datadog-official Bot added the source:file Anything `file` source related label Nov 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da70328a03

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +735 to +737
// Inject transient EACCES across multiple glob cycles.
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o000)).unwrap();
tokio::time::sleep(Duration::from_millis(100)).await;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify that the test actually injects a fingerprinting error

When this test runs as root with permission-bypass capabilities, changing the file mode to 000 does not prevent Fingerprinter::fingerprint from reopening it. The emitter discards all errors, so nothing verifies that a fingerprinting failure occurred; the test then passes even with the original buggy discovery logic. Inject a deterministic fingerprinting failure, or verify that opening the file returns PermissionDenied and explicitly skip unsupported execution contexts, so a successful regression test demonstrates that the new branch was exercised.

Useful? React with 👍 / 👎.

Comment on lines +211 to +214
for watcher in fp_map.values_mut() {
if watcher.path == path {
watcher.set_file_findable(true);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Separate error preservation from successful fingerprint discovery

During rename-and-create rotation, if the replacement app.log is temporarily unreadable and is discovered before the readable app.log.1, this marks the old file's watcher as already found before its actual fingerprint is encountered at app.log.1. The subsequent was_found_this_cycle check therefore takes the duplicate-fingerprint branch instead of the rename branch. If the replacement has an equal or newer modification time, that branch never updates the watcher's path, so remaining records from the rotated file are emitted with the replacement's filename for the duration of the error. Preserve the watcher on transient errors without treating that preservation as a successful fingerprint match for rename detection.

Useful? React with 👍 / 👎.

@datadoghq-integration datadoghq-integration 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.

Bits Code Review: FAIL

Two distinct issues are flagged: a logic flaw at line 213 where marking a watcher as found during transient preservation can suppress correct rename detection (causing rotated lines to carry the wrong filename and risking premature deletion), and a test-reliability gap at line 736 where the regression test may silently pass on privileged runners because chmod(000) does not block fingerprinting and no assertion verifies that the permission-denied path was actually exercised.

Open Bits AI session

🤖 Bits Code Review · Commit da70328

// or reap the watcher as if the file were deleted.
for watcher in fp_map.values_mut() {
if watcher.path == path {
watcher.set_file_findable(true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Separate transient preservation from confirmed fingerprint sightings

If app.log rotates to app.log.1 and its replacement encounters a transient fingerprinting error first, this marks the old watcher findable before discovering its actual rotated path. The successful fingerprint of app.log.1 then enters duplicate-fingerprint handling instead of rename handling. When the replacement has a newer modification time, update_path is skipped, so unread lines from the rotated file receive filename app.log. Record transient paths separately and apply preservation after processing successful fingerprints so preservation cannot suppress confirmed rename detection.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

tokio::time::sleep(Duration::from_millis(60)).await;

// Inject transient EACCES across multiple glob cycles.
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o000)).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Verify that the regression test triggers a fingerprint error

When run as root with permission-bypass capabilities, chmod(000) leaves fingerprinting able to open the file. A focused filesystem reproduction confirmed that open succeeds under those conditions. Since NoopEmitter discards errors and the test never asserts a fingerprint failure occurred, the regression test can pass with the original buggy behavior. Use deterministic fault injection or unprivileged execution, and verify that the fingerprint-error path was exercised.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

source:file Anything `file` source related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant