Skip to content

fix(xtcp2): nsid_assigned — tell the kernel's first nsid (0) apart from none - #322

Merged
randomizedcoder merged 5 commits into
mainfrom
fix/nsid-assigned
Nov 24, 2026
Merged

randomizedcoder merged 5 commits into
mainfrom
fix/nsid-assigned

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

The kernel's first nsid is 0, and nsid also read 0 when a namespace had no id (or -populateNsid was off), so the two couldn't be told apart. This adds a presence column. Done test-first.

Fix

  • New bool nsid_assigned = 33 (a free slot, schema epoch stays 2), set wherever nsid is stamped; recycleRecord clears it
  • Parquet row, ClickHouse _v0/_v2/Kafka DDL, and an idempotent migration sql/migrations/nsid-assigned.sql (applied twice on clickhouse-local)
  • CSV/TSV default column order: one new column after nsid (CHANGELOG)
  • goldenrec: new Assigned class. nsid moves from Volatile to Ordinal, numbered when nsid_assigned is true (0 included) and - when false; Check validates the pairing
  • goldenrec: tcp_info_busy_time and tcp_info_rcv_rtt are now Volatile. Back-to-back captures differed on these alone: busy_time is in jiffies (tcp_get_info_chrono_stats), and rcv_rtt needs a window of received data, so on one-exchange connections both are 0 or not by chance
  • pkg/xtcp/testdata/golden/7_3_1 recaptured

Tests

  • TestApplyEnrichmentNsid (+ 0-alloc guard, benchmark), TestNormalizeNsid, TestDiffNsid, TestCheck assigned rows
  • TestClickHouseDDLMatchesProto: every proto field has a column in the Kafka table and _v2. Nothing checked this before (the AccECN columns went missing that way)
  • Golden VM capture asserts nsid against the kernel (link-netnsid of each container's veth): all PASS, with one container on id 0
  • Two captures: xtcp2-golden diff exit 0

Red (tests commit, before the fix)

pkg/goldenrec/classes_test.go:43:48: undefined: Assigned
pkg/xtcp/enrich_nsid_test.go:60:31: r.NsidAssigned undefined (type *xtcp_flat_record.XtcpFlatRecord has no field or method NsidAssigned)
FAIL	github.com/randomizedcoder/xtcp2/pkg/xtcp [build failed]
FAIL	github.com/randomizedcoder/xtcp2/pkg/goldenrec [build failed]

Green

ROW container_assigned positive PASS golden-1: 0 rows without nsid_assigned, link-netnsid 0
ROW matches_link_netnsid positive PASS golden-1: nsid 0, link-netnsid 0
ROW matches_link_netnsid positive PASS golden-ns: nsid none, ip netns list none
ROW no_stray negative PASS 0 rows with an nsid but no nsid_assigned
ROW zero_present boundary PASS 1 container namespaces with kernel id 0
ROW host_unassigned corner PASS 0 host rows with nsid_assigned (the root namespace has no id for itself)

go test ./... and the nix checks (gofmt, go-vet, nix-fmt, lint-baseline, golangci ×3, redteam-lint, golden-records, test-fuzz-all) pass.

🤖 Generated with Claude Code

randomizedcoder and others added 5 commits November 23, 2026 22:30
nsid 0 reads the same whether the kernel assigned id 0 or no id at all,
so the golden diff has to treat nsid as volatile. These tests pin the
fix (a nsid_assigned presence column) before it lands:

- TestApplyEnrichmentNsid (+ an allocation guard and a benchmark):
  stamping sets nsid_assigned with the id, 0 included, and a recycled
  record does not carry it to the next socket.
- TestClickHouseDDLMatchesProto: the Kafka table and _v2 have a column
  for every proto field. Green today; it turns red when the proto gains
  nsid_assigned without the DDL.
- TestNormalizeNsid and TestCheck's companion rows: goldenrec numbers an
  assigned nsid (0 included) through an Assigned-class companion column
  and writes "-" when unassigned.
- golden-capture.sh: ROW checks against each container veth's
  link-netnsid.

Red: pkg/xtcp and pkg/goldenrec do not build (NsidAssigned, Assigned
undefined).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom none

nsid 0 meant three things: the kernel's first id, no id for the
namespace, and -populateNsid off. Docker veths take ids 0,1,2… in
creation order, so one container in every capture had the ambiguous 0,
and the golden diff had to drop nsid as volatile.

- proto: bool nsid_assigned = 33, the free slot in the namespace block
  (no epoch bump). nsid is unchanged; read it only when nsid_assigned.
- applyEnrichment sets nsid_assigned with nsid; recycleRecord's Reset
  clears both.
- Parquet row and ClickHouse: the column in _v0 (so _v1), _v2 and the
  Kafka table; sql/migrations/nsid-assigned.sql adds it to existing
  deployments, idempotent, with the Kafka and MV blocks spliced verbatim
  from initdb.d.
- goldenrec: an Assigned class, a bool <ordinal>_assigned column. nsid
  is an Ordinal again, numbered when assigned (0 included) and "-" when
  not; Check validates the pairing; Diff reads "-" as unset.
- parquetColumnCount 181 -> 182.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…0.5 TODO

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two back-to-back captures differed on these alone. busy_time is counted
in jiffies, so a send shorter than a tick reads 0 or one tick, and
rcv_rtt is measured only once a receive window of data arrives: on the
fixture's one-exchange connections both are 0 or not by chance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two captures diff empty; every nsid check in the capture passes,
including the one namespace the kernel gave id 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder
randomizedcoder merged commit b812831 into main Nov 24, 2026
1 check passed
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