Skip to content

feat(linux): decode utmp, wtmp and btmp login-accounting records - #11853

Merged
morluto merged 20 commits into
morluto:mainfrom
XiaoBinGan:feat/linux-utmp-records
Nov 27, 2026
Merged

morluto merged 20 commits into
morluto:mainfrom
XiaoBinGan:feat/linux-utmp-records

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Linux login-accounting files do not have one record layout, so the same bytes decode into different session ids, timestamps and addresses depending on the libc and ABI that wrote them.

Fixes #11351 (first slice: layout selection and record decoding).

Scope of this slice

This slice publishes the layouts and decodes complete records. It deliberately stops
there, so review has a boundary to work against:

In this PR Deferred
Six published profiles, resolved by name Android bionic layout
Complete records, plus coverage for a tail that reaches the timestamps —
Diagnostics for ambiguity, truncation, budget, undecodable fields, inexact 64-bit values, unpublished names Cross-file session correlation (wtmp openers against closers)
Offset tables, arithmetic checks, byte-order coverage Any CLI or MCP surface

The deferred rows are written as slice 2 and slice 3 tasks in
docs/specs/linux/utmp-login-accounting/tasks.md rather than promised here.

Problem

The record tail has three shapes, not one.

glibc selects between two of them with __WORDSIZE_TIME64_COMPAT32 in bits/utmp.h:

#if __WORDSIZE_TIME64_COMPAT32
  int32_t ut_session;
  struct { int32_t tv_sec; int32_t tv_usec; } ut_tv;
#else
  long int ut_session;
  struct timeval ut_tv;
#endif

Read from glibc's own headers, sysdeps/x86/bits/wordsize.h defines that macro as 1 and sysdeps/aarch64/bits/wordsize.h as 0.

musl (include/utmpx.h) is the third: ut_session is always int, followed by __ut_pad2 — or preceded by it on a big-endian host so the pair stays in host order — and ut_addr_v6 is unsigned where glibc declares int32_t.

Profile Record ut_session ut_tv ut_addr_v6
glibc-time32 384 336, 4 340, 4 + 344, 4 348, signed
glibc-time64 400 336, 8 344, 8 + 352, 8 360, signed
glibc-time64-be 400 336, 8 344, 8 + 352, 8 360, signed
musl-time64 400 336, 4 (pad at 340) 344, 8 + 352, 8 360, unsigned
musl-time64-be 400 340, 4 (pad at 336) 344, 8 + 352, 8 360, unsigned

Two failures follow from guessing:

  • A 400-byte file is either glibc with 64-bit time or musl with 32-bit time. Reading musl bytes as the glibc layout folds the padding into the session id's high half.
  • Record length names no layout at all. A truncated tail lets a larger record explain any shorter length, so 384 bytes is one x86 record and also an aarch64 record missing its last 16 bytes.

Approach

  • src/domain/linux/utmp.ts publishes the five profiles with the header each derives from, shares the record head, and derives the tail offsets from the profile's session width, padding side and time width.
  • parseUtmpFile requires a profile. An omitted one reports ambiguous_format listing every profile, because the length cannot narrow the list: filtering by divisibility would advertise a smaller layout for bytes a larger one wrote.
  • Records decode independently: a truncated tail, or a ut_type with no glibc name, keeps the records before it inspectable.
  • Fixed-width strings decode through strictUtf8; a field with no terminator or invalid UTF-8 still reads as far as it can and is named in undecodedFields.
  • Reads go through BinaryReader, so bounds and truncation use the shared parser algebra.
  • Signed fields are sign-extended at their declared width: ut_type and the exit status at 16 bits, ut_session at its profile width, tv_sec as a signed time_t. glibc's x86 bits/utmp.h declares that tail int32_t tv_sec, not __uint32_t, so the 32-bit path stays signed and a pre-epoch timestamp does not become a 2106 one.
  • A 64-bit field outside Number's exact range is reported as imprecise_field with the stored decimal, so two distinct records cannot collapse onto one value.
  • maxRecords is admitted only as a nonnegative safe integer; anything else is invalid_record_budget, rejected rather than clamped, so the retained records, omitted and the record ceiling stay consistent.

docs/specs/linux/utmp-login-accounting/ carries the offset tables, the remaining slices and the outstanding verification.

Evidence

src/domain/linux/utmp.test.ts — 33 tests, all passing:

  • each profile decodes at its own offsets, including musl's 340 session offset on a big-endian host against 336 on both little-endian families
  • a musl address word stays unsigned (0xffffffff, not -1)
  • the two 400-byte families are distinguishable, which is why the profile is stated rather than inferred
  • every layout truncated by 16 bytes still appears in the candidate list, which an exact-divisibility filter got wrong
  • a truncated tail that reaches the timestamps decodes with coverage naming what the bytes did not reach (ut_addr_v6[3], __glibc_reserved), so an absent word is never read as a zero, while a tail that stops inside the first time word still returns no record
  • an unknown ut_type stays inspectable with its numeric value
  • a field without a terminator is reported and still readable
  • an empty file returns no records and no layout claim
  • NaN, 1.5, -1 and Infinity are rejected as maxRecords; 0 and 1 are accepted and their diagnostics agree
  • a 64-bit session of 2^53+1 reports exact: "9007199254740993" while the number stays 9007199254740992, and an exactly representable one stays silent

Also run on this change: tsc --noEmit, oxlint (0 errors), oxfmt --check, scripts/verify/architecture-guards.mjs, scripts/verify-module-boundaries.mjs.

Not verified

  • The layouts are derived from glibc's and musl's headers, not from a captured file. No real wtmp from any ABI was decoded; that is the first thing to confirm before advertising the capability, and it is tracked as outstanding in tasks.md.
  • The 32-bit musl layout, where timeval is 8 bytes, is not published: no capture has confirmed its size.
  • No Android (bionic) profile is claimed.
  • Slice 1 only. There is no CLI or MCP surface and no cross-file correlation yet; both are planned in plan.md.

Author readiness

Human owner: @XiaoBinGan

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-27T16:35:39.512619Z 20eac25 New commits
ℹ️ 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.

@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: f34c2f09f7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge within its stated decoding-only scope.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The PR appears safe to merge within its stated decoding-only scope.

Summary

Adds a domain parser for Linux login-accounting files with six explicit layouts.

  • Linux login records decode with a caller-chosen libc layout.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Input bytes and options] --> B{Options valid?}
  B -->|No| E[Return named errors]
  B -->|Yes| C{Empty file?}
  C -->|Yes| D[Return no records]
  C -->|No| F{Published profile supplied?}
  F -->|No| E
  F -->|Yes| G[Count records within the limit]
  G --> H[Read whole members and name missing members]
  H --> I[Return records and issues]
Loading

Reviews (14) · Last reviewed commit: "fix(linux): keep every whole utmp member..." · Reviewed by Greptile

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.test.ts Resolved
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

All six findings were valid and are fixed in d94e9d694.

Invalid UTF-8 aborted the file (P1). decodeFixedWidth checked isStrictUtf8 and then called the fatal decoder anyway, so a malformed byte threw past the declared Result and discarded every record decoded before it. The field now keeps its readable prefix and is named in undecodedFields; nothing throws.

Length could select a layout a truncation explains (P1). A 400-byte record truncated to 384 left only the x86 profile, which then read the session and timestamp at the wrong offsets. Since this parser accepts truncated tails, no length proves the ABI, so parseUtmpFile now requires a stated profile and reports ambiguous_format with the candidate names otherwise. selectUtmpProfile and utmpProfileCandidates remain as helpers for a caller that wants to pick from a list.

Signed fields (P2). ut_type and the exit status now sign-extend at 16 bits instead of 32, so 0xffff reads as -1. tv_sec is sign-extended at its profile width, so a pre-epoch timestamp stays negative instead of becoming 4294967295.

Full-width fields (P2). glibc marks these members __attribute_nonstring__; a four-byte ut_id commonly fills its width, and that is now decoded evidence rather than an undecoded_field diagnostic. Only malformed UTF-8 marks a field.

Unbounded retention (P2). maxRecords (default UTMP_RECORD_LIMIT, 10 000) caps the records one call materializes and reports record_budget_exceeded with the count omitted. The plan's paging slice will build on that budget rather than on a full-file materialization.

Fixtures agreeing with a wrong layout (P2). The published offsets are now pinned by a literal-offset fixture that never calls utmpFieldLayout, so a wrong derivation cannot make the fixture agree with it. The derived-offset fixtures stay for the multi-field cases, where they catch a helper that drifts from the parser.

Also corrected the musl paragraph that contradicted the table: on a big-endian host musl puts __ut_pad2 before ut_session, which is why musl-time64-be reads the session at 340 while both little-endian families read it at 336.

Verified on this push: 22 tests pass, one per finding, plus tsc --noEmit, oxlint (0 errors) and the architecture guards. Not verified, unchanged: no real wtmp has been decoded yet, and the 32-bit musl layout is still unpublished.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Two of the five re-posted findings were already fixed in d94e9d694 and the comments target the earlier commit (865b51329): the profile is now required (options.profile === undefined reports ambiguous_format with the candidates) and signed takes 16 | 32 | 64, with ut_type and the exit status passing 16. Nothing further to change there.

The two findings that target the current head were valid and are fixed in dd3660083.

The comparison never exercised the divergence. It wrote a musl record with zero padding, so both profiles returned 4711 and the test proved nothing about why the profile matters. It now sets __ut_pad2 to a non-zero value and asserts both readings: glibc returns 2^32 + 4711 because it takes bytes 336..344 as one 64-bit session id, musl returns 4711. That is the concrete cost of stating the wrong profile.

The fixtures still relied on the layout helper. A literal-offset fixture now pins the musl layout too — session at 336, seconds at 344, microseconds at 352, an unsigned address word at 360 — without calling utmpFieldLayout. The derived-offset fixtures stay for the multi-field records, where they catch the helper drifting from the parser, which a literal fixture alone cannot see.

The spec paragraph contradicted its own table. Both 400-byte families hold 64-bit seconds at 344 and microseconds at 352, so their timestamps agree; the differences are the session width, the padding side and the address signedness. The paragraph now says that, and adds the big-endian consequence: musl puts the padding before the session id, moving it from 336 to 340.

Verified: 23 tests pass, plus tsc --noEmit, oxlint (0 errors) and the architecture guards.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

These three repeat findings from the earlier rounds and do not match dd3660083, the commit they are attached to. Line references on the current head:

"truncation-compatible profiles ambiguous" / "exact-divisibility filter leaves only linux-x86-64". That filter and those profile names no longer exist. parseUtmpFile requires a stated profile: utmp.ts:401 is if (options.profile === undefined) → ambiguous_format with the candidate names, returned before any record is decoded. There is no length-based selection left to be wrong, so a truncated aarch64 record cannot be read as x86 evidence — it is refused without a profile.

"Sign-extend fields at their declared widths". utmp.ts:257 is const signed = (value: number | bigint, bits: 16 | 32 | 64), and the 16-bit callers are utmp.ts:324 (ut_type), :337 (exit termination) and :338 (exit code). 0xffff now reads as -1; the test sign-extends a 16-bit field at its declared width pins it.

"Fixtures reuse utmpFieldLayout" / "the musl/glibc comparison". Fixed in the same commit. utmp.test.ts:384 pins the published offsets with literal literals and never calls the helper; utmp.test.ts:216 does the same for musl. utmp.test.ts:203 now sets __ut_pad2 to a non-zero value and asserts the two readings differ — glibc returns 2^32 + 4711, musl 4711 — so the divergence is exercised rather than assumed.

The derived-offset fixtures that remain are deliberate: they detect the helper drifting from the parser, which literal fixtures cannot see, while the literal fixtures detect a wrong derivation, which derived fixtures cannot see. Both are needed; neither substitutes for the other.

If the review tooling is re-posting a cached analysis, re-running it against dd3660083 should clear these. The only check still red on this PR is Validate author declaration, which the human owner completes.

Comment thread src/domain/linux/utmp.ts Resolved

@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: dd3660083a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
@deskinsjerri1-commits

deskinsjerri1-commits commented Nov 17, 2026 via email

Copy link
Copy Markdown

@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: 833acf1151

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
吴佳浩 added 7 commits November 18, 2026 11:11
Linux login-accounting files do not have one layout. glibc's `bits/utmp.h`
makes `ut_session` and `ut_tv` 32-bit under `__WORDSIZE_TIME64_COMPAT32` and
`long` without it, so an x86-64 record is 384 bytes and an aarch64 record is
400. The tail carries the session id, the timestamp and the address, so decoding
it under the wrong layout produces plausible but wrong values.

Publish the supported profiles with the header and macro each comes from, derive
the tail offsets from the profile's own widths, and decode one file under an
explicitly stated profile. Record length narrows the layout but never names the
byte order, and a length that is a multiple of every layout narrows nothing, so
an ambiguous file is reported and refused rather than guessed.

Records decode independently, so a truncated tail or an unknown `ut_type` keeps
the records before it inspectable. Fixed-width strings decode through
`strictUtf8`, and any field without a terminator or valid UTF-8 is named.

Reads go through `BinaryReader`, so bounds and truncation use the shared parser
algebra.

Verified by `src/domain/linux/utmp.test.ts` (11 tests): both layouts, profile
selection and ambiguity, truncated tails, unknown types, unterminated fields and
empty files. `tsc --noEmit`, `oxlint`, `oxfmt --check`, the architecture guards
and the module-boundary check all pass.

Not verified: the layouts are derived from glibc's headers, not from a captured
host file. No real `wtmp` from either ABI was decoded, no Android (bionic)
profile is claimed, and there is no CLI or MCP surface yet.
…tely

The first version named the profiles after an architecture, which conflated two
different families that produce the same 400-byte record: glibc without
`__WORDSIZE_TIME64_COMPAT32`, where `ut_session` is `long`, and musl's
`struct utmpx`, where it is `int` followed by `__ut_pad2`. Reading musl bytes as
the glibc layout folds that padding into the session id's high half.

musl also declares `ut_addr_v6` as `unsigned`, and on a big-endian host it puts
`__ut_pad2` before `ut_session` so the pair stays in host order, which moves
every later offset by four bytes.

Profiles are now named after the layout they describe, carry the padding side and
the address signedness, and the tail offsets are derived from those facts.
`utmpFieldLayout` computes musl's big-endian session offset as 340 against 336
for both little-endian families, and the new test asserts that difference.

`docs/specs/linux/utmp-login-accounting/spec.md` gains the per-profile offset
table and the reason 400 bytes alone does not identify a layout.

Verified by `src/domain/linux/utmp.test.ts` (15 tests): the five profiles, the
padding side difference, an unsigned address word, the two 400-byte families
disagreeing on which bytes are the session id, and every diagnostic from the
first commit. `tsc --noEmit`, `oxlint`, `oxfmt --check` and the architecture
guards pass.

Not verified: still no real captured file, and the 32-bit musl layout is not
published because no capture has confirmed its size.
…offsets

The five profiles publish a record length and a set of offsets that must agree:
the head, the tail and `__glibc_reserved[20]`, padded to the 8-byte alignment
`struct timeval` forces. A profile whose stated size drifted from its arithmetic
would decode every record after the first at the wrong offset, so the test
recomputes the size instead of trusting the constant.

Also records in the spec that `utmp(5)` documents the glibc split with its own
macro spelling, so the two glibc shapes rest on two independent sources rather
than one header.

Verified: 16 tests pass, including the new invariant over all five profiles.
Six findings, all valid:

- **Invalid UTF-8 aborted the file.** `decodeFixedWidth` called the fatal decoder
  after `isStrictUtf8` said the bytes were malformed, so one bad byte threw out of
  the declared `Result` and discarded the records decoded before it. The readable
  prefix is now kept and the field is named; nothing throws.
- **A full-width field was called malformed.** glibc marks these members
  `__attribute_nonstring__`, and a four-byte `ut_id` commonly fills its width, so
  a valid full-width sequence is now decoded evidence.
- **Signed fields were widened before sign-extension.** `ut_type` and the exit
  status passed 32 bits for a 16-bit field, so `0xffff` read as 65535, and
  `tv_sec` skipped sign conversion entirely. Every field is now sign-extended at
  its declared width, and `tv_sec` stays negative for pre-epoch timestamps.
- **Length could select a layout that a truncation explains.** A 400-byte record
  truncated to 384 left only the x86 profile, which then decoded the session and
  timestamp at the wrong offsets. Because this parser accepts truncated tails, a
  length never proves the ABI, so `parseUtmpFile` now requires a stated profile and
  reports `ambiguous_format` with the candidates when none is given.
- **Retention was unbounded.** `maxRecords` (default 10 000) caps the records one
  call materializes and reports `record_budget_exceeded` with the count omitted.
- **Fixtures could agree with a wrong layout.** The published offsets are now
  pinned by a literal-offset fixture that does not call the layout helper.

`docs/specs/linux/utmp-login-accounting/spec.md` records the signed widths, the
nonstring rule, the required profile and the record budget.

Verified: 22 tests pass, including one per finding. `tsc --noEmit`, `oxlint`
(0 errors) and the architecture guards pass.
…field

The comparison wrote a musl record with zero padding, so both profiles returned
the same session id and the test could not show why the profile must be stated.
It now sets the padding to a non-zero value and asserts the divergence: glibc
reads bytes 336..344 as one 64-bit session id and returns `2^32 + 4711`, musl
reads the 4-byte session and returns `4711`.

Adds a literal-offset fixture for the musl layout as well, pinning session at 336,
seconds at 344, microseconds at 352 and an unsigned address word at 360 without
calling `utmpFieldLayout`, so a wrong derivation cannot move the fixture with it.

Corrects the spec paragraph that contradicted its own table: both 400-byte
families hold 64-bit seconds at 344 and microseconds at 352, so the timestamps
agree; the differences are the session width, the padding side and the address
signedness.

Verified: 23 tests pass, `tsc --noEmit`, `oxlint` (0 errors) and the architecture
guards pass.
@XiaoBinGan
XiaoBinGan force-pushed the feat/linux-utmp-records branch from 833acf1 to c31d6b8 Compare November 18, 2026 03:12

@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: c31d6b8a3d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved

@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: bbd97a3ce1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
@XiaoBinGan
XiaoBinGan force-pushed the feat/linux-utmp-records branch from e73b2d0 to 292497f Compare November 18, 2026 04:07

@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: 292497f77c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved

@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: c1ea48a153

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
XiaoBinGan pushed a commit to XiaoBinGan/rea that referenced this pull request Nov 18, 2026
Slice 2 of morluto#11351. `buildUtmpTimeline` orders every supplied record by its own
timestamp and links a `DEAD_PROCESS` record to the session that opened it, so a
`utmp` snapshot and the `wtmp` record that ended it are one session.

Correlation links; it never collapses. Two records that share a user, terminal
and timestamp stay two entries, because nothing in the accounting files says they
are the same event — a failed login and a successful one on one terminal can
share every visible field. That invariant has its own test.

`btmp` records are failed logins, so they never open or close a session whatever
their `ut_type` says. A close with no matching open is reported as
`unmatched_close` rather than dropped, and a repeated file label is reported as
`duplicate_entry_id` instead of silently discarding the record.

Ordering uses `compareUnicodeCodePoints`, so a timeline does not depend on the
host locale.

Not a PR yet: slice 1 (morluto#11853) is still awaiting review and the queue must not
grow. The branch is pushed only as a backup.

Verified: 23 tests across the two linux modules pass; `tsc --noEmit`, `oxlint`
(0 warnings) and `oxfmt --check` pass.
XiaoBinGan pushed a commit to XiaoBinGan/rea that referenced this pull request Nov 18, 2026
Slice 2 of morluto#11351. `buildUtmpTimeline` orders every supplied record by its own
timestamp and links a `DEAD_PROCESS` record to the session that opened it, so a
`utmp` snapshot and the `wtmp` record that ended it are one session.

Correlation links; it never collapses. Two records that share a user, terminal
and timestamp stay two entries, because nothing in the accounting files says they
are the same event — a failed login and a successful one on one terminal can
share every visible field. That invariant has its own test.

`btmp` records are failed logins, so they never open or close a session whatever
their `ut_type` says. A close with no matching open is reported as
`unmatched_close` rather than dropped, and a repeated file label is reported as
`duplicate_entry_id` instead of silently discarding the record.

Ordering uses `compareUnicodeCodePoints`, so a timeline does not depend on the
host locale.

Not a PR yet: slice 1 (morluto#11853) is still awaiting review and the queue must not
grow. The branch is pushed only as a backup.

Verified: 23 tests across the two linux modules pass; `tsc --noEmit`, `oxlint`
(0 warnings) and `oxfmt --check` pass.
Comment thread src/domain/linux/utmp.ts Resolved

@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: 9be238e739

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved

@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: 566363e8a0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/linux/utmp.ts Resolved
Comment thread src/domain/linux/utmp.ts Resolved
@morluto morluto added the enhancement New feature or request label Nov 22, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@XiaoBinGan thanks for the PR — there are 4 open review threads here:

Could you address or reply to these? Once they're resolved and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

- Describe struct utmp once as a member table (`utmpMembers`) derived from
  the profile layout. Decoding, coverage and the tail rule all read it, so
  the separate modeled, identifying and reserved extents are gone.
- A truncated tail is a record as soon as it holds ut_type whole. Every
  member it holds is decoded and every other one is null and named in
  `coverage.missing`, so a tail cut before the timestamps keeps its type,
  pid, strings, exit status and session instead of being dropped.
- Freeze the published profiles and their list, so a caller mutating
  `result.profile` or an exported profile cannot change later parses.
- Remove docs/specs for this feature: the repository now keeps specs,
  plans and task lists in issue or pull request discussions, not in Git.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 17:44
@morluto
morluto merged commit 6a9affe into morluto:main Nov 27, 2026
40 checks passed
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Maintainer review: defects fixed and brittleness pass

Merged main into your branch (335656a, a plain merge with no conflicts; the branch was about 2,400 commits behind) and pushed 20eac25 on top. Nothing of yours was rewritten.

Defects fixed:

  • Truncated tails dropped complete members: a tail cut before the timestamps lost its type, pid, strings, exit status and session. A tail is now a record once it holds ut_type; every whole member is decoded, and the rest are null and named in coverage.missing.
  • Exported profiles were mutable at runtime: they and their list are now frozen.
  • The two earlier coverage threads were already fixed by your 566363e; I verified and resolved them.

Brittleness found and fixed:

  • Three separate extents: modeledExtent, identifyingExtent and reservedEnd were each hand-derived from the layout. struct utmp is now described once, as utmpMembers(profile), and decoding, coverage and the tail rule all read that table.
  • Field decoding was positional and repeated four times: each member is now read through the table by name.

Deliberately left:

  • A partially present string member (a tail cut inside ut_host) is treated as absent, because a partial nonstring field cannot be told apart from a short value.
  • No tool or reader is wired up yet: this PR adds only the domain parser, so there is no CLI or MCP surface to test. Profile selection is caller-stated, which is correct, since length cannot establish the ABI.

Removed: docs/specs/linux/utmp-login-accounting/{spec,plan,tasks}.md. The repository now keeps specs, plans and task lists in issue or PR discussions, not in Git (AGENTS.md, "Development"), and main no longer has docs/specs. Their content is still in this branch's history if you want to move it into the PR description.

Sources (layout cross-checked against two libcs):

  • glibc: DeepWiki, bminor/glibc bits/utmp.h. Under __WORDSIZE_TIME64_COMPAT32, ut_session is at 336, ut_tv at 340 (two 32-bit words), ut_addr_v6 at 348 and __glibc_reserved at 364, for 384 bytes. Without it, long session and timeval give 400 bytes with ut_addr_v6 at 360. Both match glibc-time32 and glibc-time64.
  • musl: DeepWiki, bminor/musl include/utmpx.h. int ut_session, __ut_pad2 on little-endian and int __ut_pad2, ut_session otherwise; unsigned ut_addr_v6[4]; char __unused[20]. This matches the musl-time64 pad placement, the unsigned address and the reserved name.
  • One discrepancy: DeepWiki's summary stated sizeof(struct utmpx) as 384 on 64-bit, but its own field list sums to 344 + 16 + 16 + 20 = 396, padded to 400 by timeval alignment. The PR's 400 and its arithmetic test are right.

Validation: npm run test:local -- src/domain/linux/utmp.test.ts (38 passed, including 3 new or rewritten tests); typecheck and lint through turbo; architecture guards. docs:check could not run locally, because the shared node_modules predates the merged main lockfile (knip 6.46.1 versus 6.47.0); CI covers it.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Inspect Linux utmp, wtmp, and btmp login-accounting records as offline Evidence

3 participants