code wiki / (root) / nx_logtail.nx

nx_logtail.nx

buildroot/runtime/nx_logtail.nx

7519 B112 linesdepth 2pulls 2 transitivereach 88 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_logtail.nx -- THE shared HONEST TAIL READER for append-only logs and journals. ONE copy, so the corpus stops re-deriving a bounded read that silently keeps the WRONG END of the file. ***A BOUNDED READ OF AN APPEND-ONLY LOG THAT KEEPS THE HEAD IS NOT A SMALLER TRUTH, IT IS THE OPPOSITE ONE.*** Freshness, last-state and terminal-closure all live at the TAIL, so a reader that bounds its read from offset 0 reports THE PAST AS THE PRESENT -- and because the dropped fraction grows with the file, IT FAILS TOWARD FALSE VERDICTS ON THE MOST ACTIVE LOGS FIRST, which are exactly the ones anyone cares about. Filed as a class with 4 instances in debt 1786054115. LIFTED, NEVER COPIED (2026-08-06, ws=resume-surface-rearm). This body is not new code: it is the reader already proven GREEN 12/12 inside nx_ws_kickoff_sync.nx, including a neg-control tooth that FORCES truncation through a deliberately tiny window and asserts newest-kept AND oldest-dropped. It is lifted here verbatim so the second and third consumers inherit the proof instead of re-earning it. MEASURED cost of NOT having this: nx_ws_kickoff_sync read 262140 of a 1364805-byte journal (19.2%) from offset 0 and never compared the count to the file size, which did not merely hide rows -- it FABRICATED, because the closure and last-activity predicates test WITHIN the buffer, so lanes closed past the cap read IN-FLIGHT FOREVER and every age was a false staleness age. Two seats then acted on those numbers. nx_cron_watch had the same geometry in a different organ (head served as tail) and produced a false 12.5-day dead-beat alarm that a second seat propagated. IMPORT COST IS DELIBERATELY THE MINIMUM POSSIBLE -- nx_syscalls.nx and nothing else -- per the law in nx_itoa_lib.nx: WHEN A CORRECT PRIMITIVE IS RETYPED, MEASURE ITS IMPORT COST BEFORE BLAMING DISCOVERABILITY, because people do not retype what is CHEAP to reach. That is also why this lib does NOT format the envelope: every consumer already owns a catn (ks_catn, cw_catn, st_catn) and each emits a different shape (text vs JSON), so formatting here would either force a format or drag in an emitter and price the lib out of the very sites it exists to serve. The numbers are handed back as data. ENV CONTRACT -- caller passes a *i64 with at least LT_ENV_SLOTS slots (>=32 bytes): env[0] = file_bytes EXACT total size, because the whole file is streamed. This is strictly more than nx_fs can report: nx_fs honestly declares FILE-EXCEEDS-SCAN-WINDOW but cannot say BY HOW MUCH, which is why bounding a journal by hand cost twelve probes on 2026-08-06 (debt 1786054029). env[1] = scanned bytes RETAINED in buf and safe to parse (always a whole number of records) env[2] = dropped_oldest file_bytes - scanned env[3] = truncated 0 or 1. THE CALLER MUST SURFACE THIS. A partial read reported as complete is the defect this file exists to end; declare it or fail loud, never imply it. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 6 importers

nx_syscalls.nx nx_logtail.nx nx_govern_sweep.nx nx_logtail_gate.nx nx_resmon.nx nx_resmon_lib.nx nx_rungclose.nx nx_ws_kickoff_sync.nx

imports: nx_syscalls.nx

imported by: nx_govern_sweep.nxnx_logtail_gate.nxnx_resmon.nxnx_resmon_lib.nxnx_rungclose.nxnx_ws_kickoff_sync.nx

structs

none

consts

40const LT_ENV_SLOTS: i64 = 4
41const LT_NL: i64 = 10

functions

44func lt_shift_down(b: *u8, from: i64, len: i64) -> i64
called by 1: lt_read_tail
75func lt_read_tail(path: *u8, buf: *u8, cap: i64, env: *i64) -> i64
109func lt_complete(env: *i64) -> i64
called by 2: mainmain