Repository navigation
feat(discovery): remove stale process descriptors and detect reused PIDs - #114
Merged
Merged
Conversation
akijakya
added a commit
to agntcy/dir
that referenced
this pull request
Oct 15, 2026
…ime#114 Signed-off-by: András Jáky <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟡 Changes recommended
Cleanup can delete a concurrently replaced live descriptor, making an active workload undiscoverable.
3 open findings
What changed in this PR
Updates process discovery to clean up stale descriptors and detect reused PIDs, supporting accurate running-workload registration.
Changes:
- Removes stale discoverable descriptors unless
keep_staleis enabled. - Adds optional
started_atchecks on Linux and macOS. - Documents the behavior and adds cleanup and PID-reuse tests.
| File | Description |
|---|---|
| docs/dir-component-runtime-discovery.md | Documents timestamps, cleanup, and configuration. |
| discovery/runtime/process/start_other.go | Provides unsupported-platform fallback. |
| discovery/runtime/process/start_linux.go | Reads process start times from /proc. |
| discovery/runtime/process/start_darwin.go | Reads process start times through sysctl. |
| discovery/runtime/process/descriptor.go | Adds optional started_at. |
| discovery/runtime/process/config.go | Defines KeepStale. |
| discovery/runtime/process/adapter.go | Checks process identity and removes stale descriptors. |
| discovery/runtime/process/adapter_test.go | Tests cleanup, retention, and PID reuse. |
| discovery/go.mod | Makes golang.org/x/sys a direct dependency. |
| discovery/config/config.go | Defaults keep_stale to false. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
akijakya
added a commit
that referenced
this pull request
Oct 15, 2026
Address review on #114: removal now checks that the descriptor on disk is still the file the scan read, so an atomic replacement written since is left alone; a failed removal stays in the invalid-file cache and is logged once per file version; and the Linux start time divides before multiplying, so it doesn't overflow for processes started ~1,068 days after boot. Signed-off-by: András Jáky <[email protected]>
akijakya
added a commit
to agntcy/dir
that referenced
this pull request
Oct 15, 2026
…w fixes Signed-off-by: András Jáky <[email protected]>
The process adapter skipped a descriptor whose PID was gone but left the file, so descriptors of killed processes piled up, and once the PID was reused (after a reboot, or when PIDs wrap) the stale descriptor was listed as a live workload again. A discoverable descriptor whose process is gone is now removed (keep_stale leaves it in place), and an optional started_at lets the adapter tell a reused PID from the original process on Linux and macOS. Fixes #113 Signed-off-by: András Jáky <[email protected]>
Signed-off-by: András Jáky <[email protected]>
Address review on #114: removal now checks that the descriptor on disk is still the file the scan read, so an atomic replacement written since is left alone; a failed removal stays in the invalid-file cache and is logged once per file version; and the Linux start time divides before multiplying, so it doesn't overflow for processes started ~1,068 days after boot. Signed-off-by: András Jáky <[email protected]>
akijakya
force-pushed
the
feat/113-stale-descriptors
branch
from
October 19, 2026 12:49
ffdeec2 to
2528b92
Compare
lgecse
approved these changes
Oct 20, 2026
ramizpolic
approved these changes
Oct 20, 2026
akijakya
added a commit
to agntcy/dir
that referenced
this pull request
Oct 20, 2026
dir-runtime v1.5.0 includes agntcy/dir-runtime#114. It requires dir api, client and utils v1.8.0; those are replaced by the local modules. Signed-off-by: András Jáky <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


The process adapter skipped a descriptor whose PID was gone but left the file in place. Descriptors piled up whenever a process couldn't remove its own (SIGKILL, a crash, a sandbox killing its children), and once the PID was reused, after a reboot or when PIDs wrap, a stale descriptor was listed again as a live workload.
Changes
keep_stale(DISCOVERY_RUNTIME_PROCESS_KEEP_STALE, defaultfalse) leaves stale descriptors in place, for a directory discovery may only read.started_at(optional, RFC 3339): when the descriptor was written. A process holding the PID that started later than that (with a second of slack) reused the PID, so the descriptor is stale. The process start time comes from/proc/<pid>/statand/proc/staton Linux andsysctl kern.proc.pidon macOS; elsewhere, or when it can't be read, only the PID is checked.This reverses the earlier rule that discovery never modifies descriptors (
TestWatchEventsProcessExitnow asserts removal).Testing
go test ./config/ ./runtime/process/andgolangci-lint run ./...indiscoverypass;GOOS=linux go vetandGOOS=windows go buildtoo. New tests: a stale discoverable descriptor is removed and a non-discoverable one kept,keep_stalekeeps it, astarted_atolder than the PID's process is stale while a current one is listed, andisRunningwithoutstarted_at.Fixes #113. Part of #105.
🤖 Generated with Claude Code