Device and WAN traffic metering
Work record: #26, parent #11. @arbi/traffic consumes arbi-accounting/1.0 without changing its schema, generators or protocol exports. Host evidence establishes implemented source and isolated network behavior. It does not establish mobile-provider charging or installed operation.
Application collection point
ApplicationMeter.upload counts the bytes handed to each instrumented submission, including a submission that subsequently fails. download counts each chunk received before yielding it, including discarded/aborted prefixes. Interrupted transfers retain attempted/received bytes; repeats receive distinct IDs and optional retryOf, so successful object size never replaces actual attempts. submit retains an open attempt until its local transport callback completes or fails. If the process crashes before a submission callback or the following accounting commit, its last committed prefix becomes a crashed record with an explicit in-flight collection gap. A queued buffer is not pre-counted as a measured submission. Completed means this instrumented operation completed, not confirmed remote delivery.
Every raw attempt includes realm, explicit simulation/live origin, site, source device/boot/session, boundary/link, direction, exclusive category/component inclusion, explicit caller maxAgeMs, optional media topology, raw start/end timestamps, outcome and any gap. Media metadata is allowed only for the accounting contract's supported video/TURN categories; viewer count never multiplies bytes. Recording is rejected and remains disabled under #68.
The current edge and simulated Pi pod instrument authenticated TLS plaintext frames, including their four-byte application framing, at the actual socket submit/receive point. Known discovery writes are reconnect, diagnostics are control, pod snapshots are telemetry; unclassified incoming chunks are unknown. Reconnection frames are counted on every new link. Inseparable framing stays in that category; TLS handshake, DNS, TCP/IP retransmissions and wire overhead are not invented as payload categories. Separate interface counters can observe more of that traffic. Health HTTP traffic and other application/library paths are outside these taps and remain part of unclassified interface traffic where collected.
Both ends report their own LAN perspective. Pod upload and edge download can corroborate the same bytes but cannot be added. All current edge/module endpoints remain loopback under ADR-0008; their boundary is always lan. A deployment's explicit garden-sim, relay or viewer scope may be used by the reusable application adapter when that actual path is established. Relay payload remains in its traffic category with actual topology metadata; only separately observed overhead may become turn, tls or transport-overhead. The package enables no media path or recording.
Linux interface collection
The native collector reads /sys/class/net/<configured-interface>/statistics/tx_bytes and rx_bytes as uint64 decimal strings, Linux kernel boot ID, /proc/uptime, interface index/link index/address/type, network namespace inode and a caller-maintained deployment epoch. Interface identity is hashed, never logged. It compares identity and boot before/after the read to reject replacement during collection. Reads are individually bounded to 4 KiB. RX/TX are interpreted according to the explicitly configured boundary: garden-facing transmit/receive maps to garden upload/download; an oppositely oriented adapter must normalize direction before supplying snapshots.
Sysfs reads are separate, not atomic packet snapshots. Counters are kernel/driver collection-point evidence, potentially including retransmissions, protocol overhead and non-ARBI/background traffic; exact inclusion and coverage must be configured from actual topology/driver evidence. Unknown inclusion uses includes: [] and coverage: unknown. A total has null device/category, leaving its entire delta unattributed until an independent same-layer partition exists. Payload, interface and provider values overlap and are never added, nor is an interface residual automatically called overhead or background.
lo and type 772 interfaces reject any boundary other than LAN. No interface scan, route inference or automatic garden-SIM selection occurs. Bridges, VLANs, VPNs, router LAN ports, dual SIMs and relay tunnels need a separately established canonical collection point. Duplicate collection points are comparison views, not additional allowance consumption. An interface replacement that reuses every identity field is not observable from this snapshot; the owner must increment the deployment epoch on that reconfiguration. A hidden reset that overtakes the previous value before the next sample likewise needs device evidence. Neither sysfs nor a matching loopback count certifies carrier charging coverage.
Linux is the supported native OS collector. macOS/Windows native counters are explicitly unavailable, while portable application instrumentation and SQLite tests work on the development host. CI runs a mandatory native Linux check rather than skipping the owning collector. The existing edge may optionally collect lo every five seconds with partial coverage, a 64 MiB per-direction delta bound and a 15-second maximum sample interval; this is diagnostic loopback coverage, not an uplink collector or throughput promise.
Optional router/modem adapter
RouterCollector takes an explicit CounterConfig (key, collection-point ID, full scope, layer, counter width, component inclusion, coverage, maximum delta/sample interval and freshness) plus a report callback or null. The accepted report is a maximum 4 KiB JSON CounterSample containing bootId, interfaceId, counterId, time, upload, download and wraps. Time contains UTC/null, monotonic nanoseconds as a decimal string, clock ID and uncertainty/null. wraps is null or per-direction cumulative verified hardware wrap counts, never a guess based on a decrease. Snapshot parsing rejects missing/extra fields and invalid/overflowing registers.
One poll is active at a time, with a configured timeout up to ten seconds. The vendor HTTP/modem callback must bound allocation while reading its response and honor cancellation; an adapter that ignores abort remains quarantined at one outstanding request. Missing configuration produces not-configured; unsupported counters can be recorded explicitly with unavailable; failures, malformed reports and timeout produce not-reported. Those records contain null deltas, never zero usage. Coverage cannot be inferred from report availability. Polling and storage errors remain explicit to the caller.
No vendor-specific router protocol or actual modem/carrier support is claimed. A vendor translator must establish reboot/register/interface identity, uptime, direction, counter width, resets and physical coverage before use. Secrets, endpoints, private interface names, real-site reports and configurations stay outside this public repository. Provider support in the current edge remains explicitly unavailable. The common collector can represent a separately configured provider register, but carrier period ingestion, invoice reconciliation and rollups are owned by #35/#63, not implemented here.
Epochs, discontinuities and clock uncertainty
All byte and nanosecond registers use canonical decimal strings/BigInt, never floating-point counter subtraction. The first sample is a baseline with null delta. Counter/register identity change, interface replacement, boot change, decreasing monotonic time, missed/too-wide sample windows and reset start a fresh epoch with null delta. The raw previous/current samples and gap reason are retained in the same committed record. A counter decrease without verified wrap evidence is a reset. Verified wraps use exact modulus arithmetic, but a negative or above-configured maximum delta is rejected as reset, including multiple implausible wraps. Neither negative usage nor a huge wrap guess can escape as measured usage.
Same-boot OS counters can preserve usage across a process crash/offline restart within the configured observation interval; beyond it, the collector explicitly rebaselines a gap. Failed collection or storage marks existing baselines dirty. The next successful sample records a gap rather than treating the failed window as continuous or zero. Stable OS boot identity and monotonic time are independent of the collector process boot/session.
Raw bytes remain useful when clock uncertainty is unknown. Accounting observations require a known UTC mapping, nondecreasing wall/monotonic time on the same clock, and elapsed-time agreement within explicit uncertainty plus quantization. Otherwise the raw record carries clock-uncertain with no fabricated UTC observation. Known UTC endpoints use their actual millisecond timestamps; a same-timestamp interval retains raw evidence without fabricating a future end/observation. Raw timestamps/uncertainty remain attached. The edge has no accepted synchronized source clock, so its default uncertainty is null and it exposes raw byte attempts only. Billing-window assignment must await real clock evidence or an explicitly estimated mapping in #35. Linux /proc/uptime has ten-millisecond granularity; native tests use a local unsynchronized UTC reference with an explicit 20 ms tolerance, not a trusted billing clock.
Bounded durability and failure handling
One supervised writer owns each SQLite file. Realm/environment, site, simulation/live mode and device binding persist across boots; another binding rejects reuse. Active attempts store committed prefixes. Raw counter samples, resulting deltas/observations and their baseline transition commit atomically. Terminal pending records and hashes survive offline operation and restart. A caller-provided durable receipt matching the first terminal pending ID/hash precedes deletion; acknowledgement loss leaves the same record replayable. There is no cloud sink or receipt issuer in this slice.
The spool uses SQLite DELETE journaling, FULL synchronization/fullfsync, a 25 ms busy timeout, explicit maximum database pages, up to 32 counter baselines, maximum record count and maximum reserved record bytes. Each record reserves 8 KiB, including terminal metadata; raw body overflow rejects. Baselines are bounded separately by source count and the physical page limit. DELETE-journal peak storage must be reserved alongside the database; page count is not a total-filesystem quota. A persistent loss count and dirty active records/baselines expose logical capacity, SQLITE_FULL, locking or unavailable storage. If even the failure marker cannot commit, bounded volatile loss status remains degraded; an OS crash may lose that volatile marker and is a power/storage qualification limitation.
Pending data is never evicted to make room. At capacity, strict transfer wrappers report failure; diagnostic taps continue transport and expose degradation/unknown lost usage. Existing stopped/faulted behavior, module authority and safety deadlines do not consult accounting. Current Linux service owns a private StateDirectory=arbi-edge; private settings can place the SQLite file there. The simulation's temporary files are deleted only when that synthetic fixture is explicitly disposed. There are no implicit production paths or identities. Actual selected-host storage power-loss, corruption/restore and cgroup/sandbox acceptance remain external gates under ADR-0008.
Validation and remaining owners
Run portable tests with pnpm --filter @arbi/traffic test and pnpm --filter @arbi/edge-controller test. The native comparison is pnpm --filter @arbi/traffic test:linux after build on Linux; it fails on other OSes. Run owning typechecks/builds, pnpm docs:check, pnpm protocol:check, pnpm scenario:check and git diff --check as well. The evidence record identifies the exact conditions and acceptance limits.
Cloud idempotent ingestion and billing periods #35, transfer budgets #45, reporting UI #55, and integrated cellular/router/provider comparison #63 remain separate. No local motion, camera workflow, firmware install, provider integration, loaded bench or installed physical gate is cleared.