refactor(socketwatch): carry only the pid and port a socket event is for#45
Merged
Merged
Conversation
SocketEvent carried proto, remote_ip, remote_port and outbound "for the connection log later". Nothing ever read them, and the review found out why that never hurt: for all four, the NETWORK-layer packet the engine already holds is a strictly better source. The connection log takes the remote address, port, proto and direction straight off the packet, and the packet even distinguishes ICMP, which the SOCKET layer does not. The one thing a packet cannot tell us is the owning pid, and that is what the event still carries. Keeping them was not free. _ipv4() ran per event for nobody, and it decodes IPv4 ONLY (addr[0] as a 32-bit int) - so the first person to "just wire up the field we already have" would have shipped garbage for IPv6 into a user-visible column, in a tool whose traffic filters all cover v4 and v6. The dead field was a trap with a plausible-looking comment on it, which is the shape of drift this project keeps paying for. - SocketEvent is now "kind pid local_port"; _ipv4() and its test are gone - the octet finding from that test is preserved in CHANGELOG-INTERNAL.md: the spike proved WinDivert stores the IPv4 addr MSB-first, and the naive decode rendered 192.168.1.29 as 29.1.168.192. The code goes, the knowledge stays - event helpers updated in the three socketwatch test files - OPEN_PENDING is empty again, which is its healthy state (convention 44) - guard fix found BY this closing: test_no_stale_pending_markers now skips CHANGELOG*.md, because a changelog records what HAPPENED and stays true after the marker it announced is gone. Re-verified by mutation afterwards: a marker naming an unlisted stage in an ordinary .md still turns the test red, so the scan was narrowed rather than broken Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What and why
SocketEventcarriedproto,remote_ip,remote_portandoutbound"for the connection loglater". Nothing ever read them, and the review found out why that never hurt: for all four, the
NETWORK-layer packet the engine already holds is a strictly better source. The connection log
takes the remote address, port, proto and direction straight off the packet, and the packet even
distinguishes ICMP, which the SOCKET layer does not. The one thing a packet cannot tell us is the
owning pid - and that is exactly what the event still carries.
So the honest answer to "what do we gain by wiring these up" was: nothing. The Connections table
already shows all of it, from a better source.
Keeping them was not free either.
_ipv4()ran per event for nobody, and it decodes IPv4 only(
addr[0]read as a 32-bit int). The first person to "just wire up the field we already have"would have shipped garbage for IPv6 into a user-visible column, in a tool whose traffic filters all
cover v4 and v6. A dead field with a plausible-looking comment on it is a trap, which is the
shape of drift this project keeps paying for.
What a reviewer should know:
test_ipv4_decodes_high_byte_firstencoded a real measured finding from the 2026-07-22 spike: WinDivert stores the IPv4 address
MSB-first in
addr[0], and the naive low-byte-first decode rendered192.168.1.29as29.1.168.192. The decoder is gone, so the test goes with it - but the finding now lives inCHANGELOG-INTERNAL.md, with a note to extend it to IPv6 if remote addresses are ever wantedagain.
PENDINGmarker added in test(repo): guard prose that has an expiry date #44, soOPEN_PENDINGis empty again. Thecode says that empty is its healthy state, so nobody reads it as an unused mechanism.
repo's own
CHANGELOG-INTERNAL.md, which literally names the marker while announcing it. That isa false positive: a changelog records what HAPPENED and is dated by nature, so "added a marker
named X" stays true after X is gone. Fixed by skipping
CHANGELOG*.md, and the reasoning is inthe code next to the skip.
disable it, so after the fix a probe marker naming an unlisted stage in an ordinary
.mdwasconfirmed to still turn the test red, and green again once removed. The scan was narrowed, not
broken. Both probe files were deleted (
git status --untracked-files=allclean).test_hot_path.py(packet threads must never reach the OS) was runexplicitly and is green. Net effect on the code is -16 lines.
Checklist
python -m pytest testspasses locally. (660 tests, 0 failures - one fewer than before,which is precisely the deleted
_ipv4test; on an elevated shell, so the two knownnon-admin failures are absent rather than excused.
smoke_gui.py: OK.)tests/for the style). - no new behaviour: dead fields removedand the existing
test_socketwatch*.py/test_targeting_socketwatch.pysuites still coverthe map and its wiring through the trimmed event.
lang/en.jsonandlang/pl.jsonupdated. -n/a: no UI text.
CHANGELOG.md; technical ones and new tests inCHANGELOG-INTERNAL.md, under[Unreleased]. - internal only (convention 39): the fieldswere never read, so nothing a tester sees changes.
type(scope): summary).VERSION.txt.🤖 Generated with Claude Code