Skip to content

04 Final Submission — Slice E: Tunnel byte counters (Issue #6) - #8

Merged
blitzcrieg1 merged 1 commit into
blitzcrieg1:mainfrom
karuka744:fix/issue-6
Nov 29, 2026
Merged

blitzcrieg1 merged 1 commit into
blitzcrieg1:mainfrom
karuka744:fix/issue-6

Conversation

@karuka744

@karuka744 karuka744 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Implements Slice E of #6.

What changed

Adds bytes_tx and bytes_rx to network_egress evidence so an investigation
can tell a DNS-sized connection from a bulk transfer.

  • src/json.rs — EgressEvent gains bytes_tx: u64 / bytes_rx: u64;
    to_json() emits them as bare integers inside tool.arguments.
  • src/proxy.rs — tunnel() now returns (tx, rx); the client→upstream thread
    reports its byte count back through its JoinHandle. bytes_tx also includes
    the request bytes already written to the upstream before the relay loop
    (initial_bytes). The success event is emitted at connection close with
    the final totals.
  • src/emit.rs — tests updated; the ingest-delivery test asserts the counters
    reach the POST body.
  • scripts/smoke.sh — asserts counters are non-negative ints on every event,
    positive on both success events, and 0/0 on the refused and failed attempts.
  • README.md — Events section documents the counters and the close-time emission.

Why it keeps the evidence policy destination-only

The counters are sizes, not content. The tunnel sums the bytes it relays in
each direction; no relayed byte is inspected, buffered for inspection, or
recorded. The declared fields are still scheme, method, host, port, policy, connection_established plus the two integer counts. denied and error
attempts relay nothing and carry 0/0. Direction: bytes_tx is
client → destination (egress payload), bytes_rx is destination → client.

Behavior change (before/after)

Totals are known only once a connection closes, so the success event now
fires at close instead of at open. denied/error timing is unchanged
(reply first, emit second). A never-closing tunnel therefore records its
observation when it finally ends rather than when it starts — the counts are
the point of the slice, and they do not exist until close.

Before (main): success event, no byte fields.

"arguments":{"scheme":"http","method":"GET","host":"127.0.0.1","port":PORT,"policy":null,"connection_established":true}

After (this branch — real line from target/release, synthetic loopback
origin, requested path /secret-path?token=abc):

{"source_app":"agentmetry","adapter":"guard","event_type":"network_egress","correlation_id":"","session_id":"","timestamp_utc":"2026-11-29T17:24:15.166281Z","outcome":"success","tool":{"qualified":"guard.egress","server":"guard","command":"GET 127.0.0.1:49264","arguments":{"scheme":"http","method":"GET","host":"127.0.0.1","port":49264,"policy":null,"connection_established":true,"bytes_tx":130,"bytes_rx":114}}}

The path and query (secret-path, token=abc) appear nowhere in the event —
only the destination and the byte volumes.

Tests

  • cargo test --locked — 47 passed; 0 failed.
  • cargo clippy --all-targets -- -D warnings — clean.
  • scripts/smoke.sh — passing.

No new third-party crates. Synthetic traces and markers only.


Terminal output proving the gate (local)

$ cargo test --locked
running 47 tests
test json::tests::byte_counters_render_as_bare_numbers_inside_arguments ... ok
test proxy::tests::connect_acknowledges_and_relays_only_tunnel_bytes ... ok
test proxy::tests::http_forwards_original_target_without_logging_it ... ok
test proxy::tests::failed_upstream_never_records_success ... ok
test emit::tests::hostname_ingest_url_is_delivered ... ok
...
test result: ok. 47 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.54s

$ cargo clippy --all-targets -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s

$ cargo build --release
    Finished `release` profile [optimized] target(s)

$ bash scripts/smoke.sh
smoke: OK (loopback, strict policy, destination-only evidence)

Toolchain used locally: stable-x86_64-pc-windows-gnu (self-contained linking;
no MSVC/mingw linker was present on the host, so rustup + the gnu target were
installed to verify). The GNU override is local rustup state, not committed.

Files changed

 README.md        |  7 ++++++-
 scripts/smoke.sh | 26 ++++++++++++++++++++++++++
 src/emit.rs      |  5 +++++
 src/json.rs      | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/proxy.rs     | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
 5 files changed, 125 insertions(+), 8 deletions(-)

Fixes #6


Bounty payout (no bank/Stripe):

  • PayPal: [email protected]
  • USDC / ETH (ERC-20): 0xA5562760194Aa3399e260E6eE3d8D2D987514CeD
  • SOL / USDC (Solana): 5XXbb5HWXRyrSMptThXeR2Wk4B6syaJGBt8mdfn6QKyq

Slice E of blitzcrieg1#6. Record bytes_tx and bytes_rx on network_egress evidence so
an investigation can tell a DNS-sized connection from a bulk transfer.

The counters are sizes only, never content: the tunnel sums the bytes it
relays in each direction and no relayed byte is inspected or stored, so the
destination-only evidence policy (method, host, port, connection_established)
is unchanged. denied and error attempts relay nothing and carry 0/0.

Totals are known only at connection close, so the success event is now
emitted when the tunnel closes instead of when it opens. denied/error
emission timing is unchanged (reply first, emit second).

Unit tests cover rendering and both tunnel directions; scripts/smoke.sh
asserts positive counters on the two success events and 0/0 on the refused
and failed attempts.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@blitzcrieg1

Copy link
Copy Markdown
Owner

Reviewed against the slice E acceptance criteria. I ran the full gates locally at this head: cargo test --locked 47 passed, cargo clippy --all-targets -- -D warnings clean, release build clean, and scripts/smoke.sh passes including the byte-counter assertions. The destination-only evidence policy holds: sizes only, no relayed byte inspected. The emit-at-close behavior is documented and acceptable; timestamps still record connection start.

Two process items before this can merge:

  1. The program rules require the slice to be claimed in a comment on guard: contribution slices, one PR each, claims open #6 by the PR author before the PR is opened. Post that claim, naming slice E.
  2. The PR description is a task note rather than a description. Replace it with the actual summary (the text under "PR description" in the body is a good start).

After both, I will approve the CI workflows and re-check at the updated head.

@blitzcrieg1
blitzcrieg1 merged commit 60a477a into blitzcrieg1:main Nov 29, 2026
5 checks passed
@blitzcrieg1

Copy link
Copy Markdown
Owner

Merged with credit. Slice E lands as-is: bytes_tx / bytes_rx on network_egress evidence, sizes only, zeros on denied and errored attempts. You will be credited in the next Guard release notes, the same way community detection contributions are credited in the main repository. Thanks for seeing the process items through.

Slices A, B, C, D, F and G remain open on #6 for anyone else reading.

blitzcrieg1 added a commit that referenced this pull request Nov 29, 2026
Ships slice E from #6, contributed by @karuka744 in #8: bytes_tx and
bytes_rx on network_egress evidence, sizes only, zeros on denied and
errored attempts. Destination-only evidence policy unchanged.

Generated by Mistral Vibe.

Co-authored-by: Mistral Vibe <[email protected]>
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.

guard: contribution slices, one PR each, claims open

3 participants