DFilterForge Retrospective 05: A pinned tshark, keyless CI, and on-demand GPUs

This post is DFilterForge's engineering checklist: tshark pinned and built from source, until upstream moved the source tarball; how the runner safely executes model-written filters; how the field catalog freezes to byte-identical exports; how CI rescored every committed run without keys or network access, and how pytest filled /tmp and back-to-back merges cancelled CI runs; starting and stopping GPUs on demand on Modal, with open endpoints, startup crashes, scaling to zero and preemption, circuit breakers and rate limits, networks that only block the data plane, and waiting for a GPU; finally, the Windows host and dependency upgrades.

Published
Reading time
15 min read
Category
Retrospectives
Tags
Translated from
the Chinese original
Contents8 sections

This is the fifth post in the DFilterForge retrospective (series overview). The first four covered judging correctness, repair, measurement, and training; this one gathers the engineering side:

  • how tshark is pinned;
  • how model-written output is run safely;
  • how CI recomputes every number without keys;
  • the pitfalls of starting and stopping GPUs on demand on Modal.

The website-related parts go in the next post.

Every number in this post comes from committed records in the repository1.

tshark: pinned version, built from source

All scoring depends on tshark, so its version must be nailed down:

  • Build: built from the official Wireshark 4.6.8 source, after verifying the source tarball’s SHA-256.
  • Run: no network, no Linux capabilities, no root (Dockerfile, compose.yaml).

But while the version was pinned, the download URL was not:

  • On October 8, when PR #28 was merged, the hosted CI failed at the docker compose build test step. The run on the PR and the one pushed to main failed the same way, and the Pages deployment was skipped as a result.
  • The reason: after Wireshark released a new version, it moved 4.6.8 out of download/src/, and the old URL returned 404. Every build without a cache failed; local builds stayed green because of their cache layers.
  • The fix was to download from download/src/all-versions/ instead, which keeps every released version. The SHA-256 was unchanged, so the built tshark was unchanged too (add7874).

A hash guarantees the bytes, not the address. And the local cache happened to hide the problem.

There is also an unfixed risk, recorded in the limits of offline scoring:

  • The base image is pinned only by the tag ubuntu:24.04, not by digest.
  • A from-scratch build recompiles tshark and refreezes the field catalog on whatever image the tag points to at that moment.
  • The catalog in the archive and the one in the image are no longer the same. Once the tag points to a new image, a from-scratch build may produce a tshark and catalog that differ from the archive, and rescoring would report inconsistencies across the board.

Letting tshark run model-written output

A model-written filter is untrusted input, and what receives it is a large parser written in C. The core of the runner is these two pieces:

src/dfilterforge/runner.py (excerpt)Python
output, runtime_ms = self._execute(
    [
        "-n",
        "-r",
        f"/proc/self/fd/{snapshot.fileno()}",
        "-Y",
        display_filter,
        "-T",
        "fields",
        "-e",
        "frame.number",
    ],
    pass_fds=(snapshot.fileno(),),
    frame_limit=self._limits.max_frames,
    classify_exit=True,
)

# ……

environment = {
    "PATH": _SEARCH_PATH,
    "HOME": "/nonexistent",
    "XDG_CONFIG_HOME": "/nonexistent",
    "WIRESHARK_CONFIG_DIR": "/nonexistent",
    "WIRESHARK_PLUGIN_DIR": "/nonexistent",
    "LANG": "C",
    "LC_ALL": "C",
    "TZ": "UTC",
}
# ……
process = subprocess.Popen(
    [str(self.executable_path), *arguments],
    stdin=subprocess.DEVNULL,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=False,
    close_fds=True,
    start_new_session=True,
    pass_fds=pass_fds,
    env=environment,
    cwd="/",
)

A few key points:

  • Arguments: the filter is passed as a separate argument after -Y, never through a shell. tshark outputs only the frame number of each selected packet.
  • Capture file: opened with O_NOFOLLOW, confirmed to be a regular file within the size limit, then copied into an anonymous temporary file while its SHA-256 is computed. tshark reads this snapshot through /proc/self/fd/N, so the bytes it reads are exactly the ones that were hashed.
  • Environment: the environment variables are replaced wholesale; config and plugin directories point to nonexistent paths; language and timezone are fixed.
  • Process: tshark starts in a new session, and the whole process group is SIGKILLed on exit.
  • Limits: at most 5 seconds per call; capture 16 MiB; filter 8,192 bytes; stdout 2 MiB; stderr 64 KiB; 100,000 frames. Frame numbers must also be strictly increasing.
  • Container: UID 10001, no network, read-only root filesystem, all capabilities dropped; 1 CPU, 512 MiB memory, at most 128 processes.
  • tshark itself: compiled without Lua and without native plugins.

None of these boundaries shows up in accuracy. Ablation 001 compares it with the most direct approach: the same binary, the same arguments, the same environment and 5-second timeout, but calling subprocess.run directly and reading all of the output.

Bounded runnerDirect call
Selected frames match labels81 / 8181 / 81
Error examples killed27 / 2727 / 27
F11.01.0
p95 latency77.35 ms83.21 ms
Lines of code36642
Fake tshark printing 1,000 frame numbersStops at output_limitTakes them all

On accuracy alone, the two approaches are identical. The difference only shows up with a fake tshark. Incidentally, the bounded runner’s p95 is actually faster. It stayed.

One more thing: the harness’s own failures. Before September 21, any nonzero exit code from tshark was recorded as tshark_failed, which meant it was charged to the model. Now they are split by exit code:

  • Exit code 4: the filter was rejected. If the first line of tshark’s stderr is its fixed “is not a valid protocol or protocol field” message, it is recorded as an unknown field.
  • Exit codes 3 and 14: the capture could not be read.

Six inputs used for verification: previously none of them could be distinguished; now all six can. A truncated capture prints two frames before failing, and the runner discards those two frames rather than returning a partial result.

The original wording: a scorer that cannot tell “the model’s filter was rejected” from “the probe capture could not be read” will charge the harness’s failures to the model.

Field catalog: frozen, and not trusted

The field catalog has two uses:

  • C2 and C4 retrieve fields from it;
  • the C3 and C4 compilers check field names, types, operators, and values against it.

It is exported from the pinned tshark into SQLite: 266,369 field records (protocols included; 266,363 unique names after deduplication) and 1,709,593 value rows. Two independent exports are byte-identical, both 299,327,488 bytes. Getting there requires handling one detail:

src/dfilterforge/catalog_runtime.py (excerpt)Python
# tshark registers some value tables in process-dependent hash-map order.
# Sort each indexed group to bound sort memory and preserve duplicates.
names = database.execute(
    "SELECT DISTINCT name FROM staging ORDER BY name COLLATE BINARY"
)
for (name,) in names:
    records = database.execute(
        "SELECT record FROM staging WHERE name = ? "
        "ORDER BY record COLLATE BINARY",
        (name,),
    )
    # ……

# ……
# Never overwrite an existing freeze, including one currently in use.
with output.open("xb"):
    pass
# ……
# Remove staging pages; file bytes depend only on canonical rows.
database.execute("VACUUM")

A few measures:

  • Sorting: tshark registers some value tables in an order that depends on the process’s hash-map order, which can differ between runs. So the rows are grouped by name and sorted group by group.
  • VACUUM: run once at the end, so the file bytes depend only on the sorted data rows.
  • No overwrite: the export opens the file with mode xb, so an existing file is never overwritten.
  • Read-only: at use time it is opened with mode=ro&immutable=1, and trusted_schema is off.

Ablation 002 compares a much simpler approach: only checking tshark’s version number.

  • On 27 legitimate samples, the two approaches produce identical results, and the simple one is a bit faster, with p95 5.335% lower.
  • But on 10 specially constructed dangerous inputs, the difference appears. These inputs include a boolean comparison with the wrong type, a wrong profile, a wrong field catalog, a stale field list, and a tampered field type. The full approach rejects all 10 before any capture runs; the simple approach catches only 2, and the other 8 proceed to capture execution.

There is also a small pitfall: the same IR compiles differently with and without the field catalog.

  • Without the field catalog, IPv4, IPv6, and byte-string literals get quotes; with it, they do not.
  • Offline evaluation went through the path without the catalog, but replay recompiled through the path with the catalog and then compared text.
  • So any record containing such a predicate could never be replayed.

Offline evaluation was later changed to bind the field catalog as well (32ff957).

CI: no keys, no network

Every model answer is committed to the repository as-is. CI does the following in containers with no network and no API keys (README, ci.yml):

  • rescore every committed run and compare against the committed scores;
  • rebuild the SFT headline numbers, the baseline ladder, and the judge table from those scores, and rebuild session costs from run records and billing;
  • re-derive every repair round, and every cross-model summary (pool).

A few details:

  • Zero is also a failure. The rescoring loop counts how many directories it checked, and fails if it checked none. That way, if the directory structure changes and the loop checks nothing, CI will not show a pass.
  • Mounts must actually be there. Steps in the test container that need to read docs/ mount it read-only and start with test -d. If the mount is missing, the step fails rather than being skipped (the third post covered what happened the time it was skipped).
  • pytest filled /tmp. Compose gives the test container a 128 MB tmpfs at /tmp, and pytest keeps every test’s temporary directory until the whole session ends. By test 892 of 1,005 it was full: 21 tests failed with ENOSPC, and coverage data could not be written. The original says that the code had not changed since bb037b8, so this test suite had long been running on the edge. After switching to keep only failed tests’ temporary directories, /tmp usage dropped to 1% (b3fa85f).
  • Back-to-back merges cancel CI runs. CI groups runs by ref, and a new run in the same group cancels the old one. PR #42 merged into main 20 seconds after #41, so the run on 89184f6 was cancelled, and main only completed on 407d383. PR #37 merged 7 seconds after its own CI started, so the run on the PR was cancelled and the one on main became the only record.
  • No rebasing. The repair-round smoke tests record the commit hash of the branch head at the time in their manifest, so the repair-arms branch is never rebased; it merges with merge commits, so that commit hash does not become an orphan. In fact, all 46 PRs merged into main are merge commits.

Inference for the 1.7B model runs on Modal (serve_vllm.py, self-served-runs.md):

  • one L4, running vLLM 0.21.0;
  • at most one container, scales to zero after 5 minutes idle, startup waits up to 15 minutes;
  • the first cold start took about 6 minutes from deployment to the first answer, of which the vLLM engine startup took 249 seconds;
  • the last command of every session is modal app stop, leaving no deployed app between sessions.

This is where the most pitfalls were.

An open endpoint spins up a GPU (e2d813f). The original design had the Modal proxy unauthenticated, with vLLM checking keys itself. But vLLM’s key only protects /v1; requesting /health, /version, /metrics, or requesting /v1 without a key, would all spin up an L4. And the address was not hard to find:

  • the repository is public, with the app and class names written in it;
  • every published run manifest records the service’s hostname.

The original estimates that a crawler probing every few minutes could keep the GPU warm at about $1 per hour until the $10 budget burned out. This problem was found before the first deployment. The fix was to use Modal’s proxy authentication token: requests without the token are rejected with 401 by the proxy before any container starts.

vLLM crashing at startup holds the L4 for 15 minutes (65318fb):

  • the startup function returned immediately after starting the process, never checking whether vLLM was still alive;
  • Modal considers the container ready only when the port starts listening. So if vLLM crashed at startup, it would hold the L4 until the 15-minute startup timeout, about $0.25 each time;
  • changed to wait until the port accepts connections, and to fail immediately if the process exits. This problem was also found before the first deployment.

Scaling to zero and preemption burn retries. The two sessions on October 8:

  • In the first, the service had already stopped when the first pass over dev split seed 17 went out, and every item got a 503; 26 C1 items in the seed 42 dev split also got 503s.
  • In the second, while running test split seed 17, Modal preempted the container. The replacement container came up, stopped again 11 seconds later, and the next one was not ready for another six or seven minutes.
  • In these gaps, every request got a 503 or 502, and each used up one of an item’s three attempts. The 26 seed 42 dev C1 items failed twice more when resumed, exhausted their three attempts, and were recorded as provider_failed; the 370 test items were left with only two attempts.

The fix came in three steps:

  1. On the October 18 catch-up run, the calls were wrapped in a PowerShell watchdog that stopped at the first failed answer. All 370 items got answers on the first attempt, and the session bill was $0.26.
  2. After that session, a rule was added to the operations manual: wake the service before every invocation (3f0eeb5).
  3. On October 25, the circuit breaker was written into the calling code itself: the first 5xx, 408, 429, timeout, or disconnection ends the pass. That way one outage costs only one item one attempt (8b4b3b0). The 429 was later removed; see the next item.

The circuit breaker nearly trapped the hosted-model runs (9e577c1). The first version of the circuit breaker also stopped on HTTP 429, and the problem was:

  • on the hosted-model side, the only failures were 429s: the deepseek test-split run went in three passes, and 776 of 1,202 attempts were 429s;
  • the run manifest records at most 32 passes (invocations), and each 429 ended a pass, leaving the next pass to fill in;
  • at the pace of the committed runs, the 33rd continuation would be rejected, and answers already paid for could not be published.

On the self-served side, failures were all bursts of 5xx. The two kinds of failure had to be handled separately: 429 no longer ends the pass, leaving retries to the next pass; 5xx, 408, timeouts, and disconnections still stop. This change was committed 18 minutes after the first version, and was not merged with the problem in it.

Networks that only block the data plane. On October 18, deploying on a certain network, the deployment itself succeeded because api.modal.com was reachable; but every TLS connection to *.modal.direct was reset, and not a single request reached the service. Fortunately no request was sent, no container started, and no money was spent. A rule was added to the operations manual:

  • before deploying, request /v1/models once without a token; you must get an HTTP status code back (Modal’s proxy itself returns 401);
  • a reset connection or a timeout means this network blocks the service;
  • check both PowerShell and Python’s http.client, because the latter is the transport the calling code actually uses, and it does not go through Windows proxy settings;
  • if either side gets no status code, switch networks, such as a phone hotspot.

Waiting for an L4 (240d4df). In a session on October 27, 503s continued for 15 minutes, and the logs only said the function was waiting for a GPU_L4 worker: Modal had no L4 to give at that moment, no container started, and no billing. The rule: end the session and come back another day; never switch GPU types, because every row must run on the same L4 stack.

Deploying on Windows. The project’s CI runs on Linux, but deployments are launched from Windows:

  • Paths: the server code used Path for cache paths, which is WindowsPath on Windows, so the image ended up with ENV HF_HOME='\cache\hf' written into it, and the build failed with “error unescaping string”. CI on Linux could not see this. Changed to PurePosixPath (90247a1).
  • Stopping the service: modal app stop asks y/N, and pressing Enter means no, so the service was not actually stopped. Every stop command in the manual now has -y (0198bfc).
  • Downloading: modal volume get downloading into a nonexistent directory writes all files to the same path and then fails. The manual now creates the directory first.
  • Addresses: the service address in the config file was written only once, but the $url typed by hand in each session could differ, so a paid run could hit the wrong host. Changed to rewrite the config from the session’s own $url each time.
  • Wake-up loop: it originally swallowed all errors, retrying silently every 15 seconds forever; with a wrong key, it would keep getting 401s. Changed to print every failure, stop immediately on 401, 403, or 404, and wait at most 15 minutes. This was found before the first deployment, using a local stand-in service (72d47c5).

Two more things, recorded in the original’s limits as “Not observed” on the live service: requests without a token should get a 401; the service should scale to zero on its own (because every session was stopped manually). This limit was written on the evening of October 8 and has not been changed since.

Windows host

The development machine is Windows, but the code has to run in Linux containers, which led to a few more issues:

  • Path arguments: Git Bash rewrites path arguments passed to Docker, so every Docker command needs MSYS_NO_PATHCONV=1 in front.
  • Line endings: the script that simulates CI locally was written with CRLF line endings, so the last pytest argument of every command had a carriage return appended, and the three steps that mount docs/ all failed with exit code 4, reporting file not found.
  • Tests that fail only on the host: the test that creates a symlink is rejected on the host (WinError 1314) but passes in the container; pyright needs --pythonplatform Linux to avoid flagging POSIX-only interfaces.

Dependencies

When Next.js was upgraded to 16.4.1, three security advisories were unreachable on the statically exported site, but the upgrade was done anyway. The original’s reasoning: the upgrade is cheap, so “the alerts close instead of being dismissed” (c1a1978).

Summary

  • Pinning a version means considering the download URL too. A hash guarantees the bytes, not the address, and a local cache will hide the problem;
  • untrusted input goes to a bounded runner. These boundaries do not show up in accuracy; they need specially constructed inputs to trigger;
  • an export that must reproduce byte-for-byte has to rule out every source of nondeterminism, such as hash-map order and leftover pages in the database;
  • the rescoring loop must count how many directories it checked; zero is also a failure;
  • if records store commit hashes, do not rebase the branches;
  • for on-demand GPUs, close the door first—authentication—before thinking about saving money;
  • outages and rate limits are different failures; the circuit breaker’s rules must be written separately;
  • deploying on Windows and testing on Linux: paths and line endings can both go wrong.

The next post covers the website: how a website that forbids hand-written numbers still displayed one wrong number on a phone.

Footnotes

  1. The repository is WeiGuang-2099/DFilterForge. The source and documents linked in this post are all pinned to the commit 09bb537 of November 9, 2026. ↩︎