[GH-ISSUE #2864] tools/strata_bench.py: NameError: name 'port' is not defined — bench cannot start a server (regression from 69fe4055 / #2330) #1155

Closed
opened 2026-11-04 01:48:56 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @yusheng227507 on GitHub (Oct 17, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2864

Summary

tools/strata_bench.py is broken in v0.1.45 (477ac13c). Any run that starts its own server (i.e. --config without --url) dies immediately with NameError: name 'port' is not defined. Passing --url (pointing at an already-running server) still works, so the failure is confined to the "start the server" path.

Environment

  • Strata: v0.1.45 / commit 477ac13c
  • OS: Ubuntu (Linux), Python from the project .venv
  • Hardware: 2x RTX 2080 Ti (sm_75)
  • Config: the standard strata-*.json with "port": 8080, "host": "0.0.0.0"
  • No server running on the port at the time (so the "start our own server" branch is taken).

Steps to reproduce

  1. Make sure nothing is listening on the config's port (e.g. 8080).
  2. Run the bench without --url:
    .venv/bin/python tools/strata_bench.py --config strata-iq3_s.json --out bench/results/x
    

Actual result

It fails before loading the model (and therefore before any measurement):

Traceback (most recent call last):
  File "/home/yusheng/strata/tools/strata_bench.py", line 1037, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/yusheng/strata/tools/strata_bench.py", line 990, in main
    say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...")
                                            ^^^^
NameError: name 'port' is not defined

Exit code 1.

Expected result

The bench starts the server on the configured port, waits for readiness, and runs the suite (as it did in v0.1.44.1 and earlier).

Root cause

Commit 69fe4055 ("tools: poll the server address the config binds, not loopback (#2330)") replaced

        port = a.port or int(cfg.get("port", 8080))
        base = f"http://127.0.0.1:{port}"

with

        base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))

That removed the only assignment of the local name port, but three later uses in the same else branch still reference it (the "port is used by something that is not Strata" message, the "Starting ... on port {port}" message, and start_server(cfg_path, port, ...)). The --url path skips the branch, so it never trips.

The new test added by that commit (tools/test_bench_host.py) only exercises server_base() in isolation, so it does not catch the missing local.

Suggested fix

Restore the local name (keeping the new server_base host handling):

    else:
        port = a.port or int(cfg.get("port", 8080))
        base = server_base(cfg.get("host"), port)

Workaround (no source change)

Start the server yourself and point the bench at it, which bypasses the broken branch:

.venv/bin/python serve/server.py --engine strata --config <cfg>.json --port 8080 &
.venv/bin/python tools/strata_bench.py --url http://127.0.0.1:8080 --out bench/results/x
Originally created by @yusheng227507 on GitHub (Oct 17, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2864 ## Summary `tools/strata_bench.py` is broken in **v0.1.45 (477ac13c)**. Any run that starts its own server (i.e. `--config` without `--url`) dies immediately with `NameError: name 'port' is not defined`. Passing `--url` (pointing at an already-running server) still works, so the failure is confined to the "start the server" path. ## Environment - Strata: `v0.1.45` / commit `477ac13c` - OS: Ubuntu (Linux), Python from the project `.venv` - Hardware: 2x RTX 2080 Ti (sm_75) - Config: the standard `strata-*.json` with `"port": 8080`, `"host": "0.0.0.0"` - No server running on the port at the time (so the "start our own server" branch is taken). ## Steps to reproduce 1. Make sure nothing is listening on the config's port (e.g. `8080`). 2. Run the bench without `--url`: ``` .venv/bin/python tools/strata_bench.py --config strata-iq3_s.json --out bench/results/x ``` ## Actual result It fails before loading the model (and therefore before any measurement): ``` Traceback (most recent call last): File "/home/yusheng/strata/tools/strata_bench.py", line 1037, in <module> sys.exit(main()) ^^^^^^ File "/home/yusheng/strata/tools/strata_bench.py", line 990, in main say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...") ^^^^ NameError: name 'port' is not defined ``` Exit code 1. ## Expected result The bench starts the server on the configured port, waits for readiness, and runs the suite (as it did in v0.1.44.1 and earlier). ## Root cause Commit **`69fe4055`** ("tools: poll the server address the config binds, not loopback (#2330)") replaced ```python port = a.port or int(cfg.get("port", 8080)) base = f"http://127.0.0.1:{port}" ``` with ```python base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080))) ``` That removed the only assignment of the local name `port`, but three later uses in the same `else` branch still reference it (the "port is used by something that is not Strata" message, the "Starting ... on port {port}" message, and `start_server(cfg_path, port, ...)`). The `--url` path skips the branch, so it never trips. The new test added by that commit (`tools/test_bench_host.py`) only exercises `server_base()` in isolation, so it does not catch the missing local. ## Suggested fix Restore the local name (keeping the new `server_base` host handling): ```python else: port = a.port or int(cfg.get("port", 8080)) base = server_base(cfg.get("host"), port) ``` ## Workaround (no source change) Start the server yourself and point the bench at it, which bypasses the broken branch: ``` .venv/bin/python serve/server.py --engine strata --config <cfg>.json --port 8080 & .venv/bin/python tools/strata_bench.py --url http://127.0.0.1:8080 --out bench/results/x ```
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6271322025 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1155
No description provided.