Skip to content

os/v3/puppy: the page proxy cut a 3600 s hold at 900 s - its bound is now the hold window plus the resume - #3484

Merged
bong-water-water-bong merged 2 commits into
mainfrom
fix/3478-proxy-hold-bound
Nov 24, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
fix/3478-proxy-hold-bound

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

os/v3/puppy: the appliance page's proxy cut a 3600 s hold at 900 s - its upstream bound is now the hold window plus the resume

engine#3478 (found while closing #3350). A held turn waits inside Lemonade's load path with NO bytes on the wire until
the hold ends (Router::wait_for_slot_clearance, third_party/lemonade src/cpp/server/router.cpp:783/:829; the hold is
taken by 1bit-heavy, POST /api/v1/hold), and the appliance page's fetch has no timeout of its own
(os/v3/puppy/embed/opt/1bit/webapp/index.html:232). So 1bit-webapp-proxy's upstream socket timeout was the only
deadline a held turn had: 900 s (os/v3/puppy/embed/usr/local/bin/1bit-webapp-proxy:91), while 1bit-heavy's default
hold window is 3600 s (os/v3/puppy/embed/usr/local/bin/1bit-heavy: maxs=3600, --help "(default 3600)"). A hold
between 15 and 60 minutes cut the page's turn - the socket timeout lands in the proxy's OSError arm, so the page got
502 "Lemonade is not answering" - while the hold was healthy.

  • the proxy's bound is now UPSTREAM_TIMEOUT = HOLD_WINDOW + RESUME_GRACE = 3600 + 900 = 4500 s: the window a held turn
    can wait (Lemonade ends the hold at max_seconds even if the wrapper is alive, heavy_work_hold.cpp:120-130) plus the
    reload of the captured models before the waiting request runs (measured first loads: 93 s stick / 154 s disk,
    docs/releases.md). 900 s was the proxy's previous whole-request bound, so nothing that fitted inside one socket
    timeout before gets a shorter one after a hold.
  • ONEBIT_WEBAPP_UPSTREAM_TIMEOUT overrides the bound (the test drives it in seconds; an operator can raise it).
  • tests/webapp_proxy_hold_timeout_test.sh: the window in 1bit-heavy and the proxy's HOLD_WINDOW are one number (CI fails
    if they drift), the bound is window + resume, and a fake silent (held) Lemonade is forwarded inside the bound and
    answers 502 AT the bound, not at the stall. CMake row webapp_proxy_hold_timeout.
  • os/v3/puppy/README.md's 1bit-heavy row now carries the contract - a held turn waits up to 3600 s, the page's proxy
    4500 s - and the streaming caveat: a held streaming turn is silent, there is no ": held" keepalive yet (the
    Lemonade-fork half of hold: a held streaming turn gets no keepalive, and the appliance proxy 900 s timeout can cut a 3600 s hold #3478, not this lane).

Not done here: the ": held" keepalive needs the Lemonade fork plus a pin bump. A hold taken with --max-seconds above
3600 can still outlast the page's proxy; that is the operator opting past the appliance's default window, and the
README says so.

Evidence:
$ sh tests/webapp_proxy_hold_timeout_test.sh # branch
ok 1bit-heavy carries the hold window (maxs=3600)
ok the proxy's hold window (3600 s) is 1bit-heavy's --max-seconds default (3600 s)
ok the upstream timeout (4500 s) is the window plus the resume (3600 + 900)
ok the resume does not go below the 900 s the socket allowed before (900 s)
ok the bound outlasts a whole default hold (4500 s > 3600 s)
ok a silent (held) upstream inside the bound is forwarded: HTTP 200 after 1 s, {"answered": true}
ok a stall past the bound answers 502 at the bound (HTTP 502 after 1 s for a 3 s stall, bound 1 s)
webapp_proxy_hold_timeout_test: ok

Control: the same test file in a throwaway worktree at origin/main (ad10a17), scripts untouched, test copied in:
ok 1bit-heavy carries the hold window (maxs=3600)
FAIL the proxy derives its bound from the hold window (HOLD_WINDOW/RESUME_GRACE/UPSTREAM_TIMEOUT: none) - it still hardcodes 900 s, shorter than the 3600 s hold window
ok a silent (held) upstream inside the bound is forwarded: HTTP 200 after 1 s, {"answered": true}
FAIL a stall past the bound answers 502 at the bound (HTTP 200 after 3 s for a 3 s stall, bound 1 s)
webapp_proxy_hold_timeout_test: FAIL (exit 1)

$ ctest --test-dir build -R 'webapp_proxy_hold_timeout|heavy_wrapper|release_check_hold_cycle' --output-on-failure
1/3 Test #80: heavy_wrapper .................... Passed 31.18 sec
2/3 Test #81: webapp_proxy_hold_timeout ........ Passed 2.39 sec
3/3 Test #160: release_check_hold_cycle ......... Passed 0.02 sec
100% tests passed, 0 tests failed out of 3

Gate: scripts/pre-pr-checks.sh --tree-only --base origin/main
pre-pr-checks: all 15 check(s) green, 3 skipped, 0 could not be told, 2 open-PR row(s) not run (--tree-only)

Refs #3478.

…its upstream bound is now the hold window plus the resume

engine#3478 (found while closing #3350). A held turn waits inside Lemonade's load path with NO bytes on the wire until
the hold ends (Router::wait_for_slot_clearance, third_party/lemonade src/cpp/server/router.cpp:783/:829; the hold is
taken by 1bit-heavy, POST /api/v1/hold), and the appliance page's fetch has no timeout of its own
(os/v3/puppy/embed/opt/1bit/webapp/index.html:232). So 1bit-webapp-proxy's upstream socket timeout was the only
deadline a held turn had: 900 s (os/v3/puppy/embed/usr/local/bin/1bit-webapp-proxy:91), while 1bit-heavy's default
hold window is 3600 s (os/v3/puppy/embed/usr/local/bin/1bit-heavy: maxs=3600, --help "(default 3600)"). A hold
between 15 and 60 minutes cut the page's turn - the socket timeout lands in the proxy's OSError arm, so the page got
502 "Lemonade is not answering" - while the hold was healthy.

- the proxy's bound is now UPSTREAM_TIMEOUT = HOLD_WINDOW + RESUME_GRACE = 3600 + 900 = 4500 s: the window a held turn
  can wait (Lemonade ends the hold at max_seconds even if the wrapper is alive, heavy_work_hold.cpp:120-130) plus the
  reload of the captured models before the waiting request runs (measured first loads: 93 s stick / 154 s disk,
  docs/releases.md). 900 s was the proxy's previous whole-request bound, so nothing that fitted inside one socket
  timeout before gets a shorter one after a hold.
- ONEBIT_WEBAPP_UPSTREAM_TIMEOUT overrides the bound (the test drives it in seconds; an operator can raise it).
- tests/webapp_proxy_hold_timeout_test.sh: the window in 1bit-heavy and the proxy's HOLD_WINDOW are one number (CI fails
  if they drift), the bound is window + resume, and a fake silent (held) Lemonade is forwarded inside the bound and
  answers 502 AT the bound, not at the stall. CMake row webapp_proxy_hold_timeout.
- os/v3/puppy/README.md's 1bit-heavy row now carries the contract - a held turn waits up to 3600 s, the page's proxy
  4500 s - and the streaming caveat: a held streaming turn is silent, there is no ": held" keepalive yet (the
  Lemonade-fork half of #3478, not this lane).

Not done here: the ": held" keepalive needs the Lemonade fork plus a pin bump. A hold taken with --max-seconds above
3600 can still outlast the page's proxy; that is the operator opting past the appliance's default window, and the
README says so.

Evidence:
$ sh tests/webapp_proxy_hold_timeout_test.sh                  # branch
ok   1bit-heavy carries the hold window (maxs=3600)
ok   the proxy's hold window (3600 s) is 1bit-heavy's --max-seconds default (3600 s)
ok   the upstream timeout (4500 s) is the window plus the resume (3600 + 900)
ok   the resume does not go below the 900 s the socket allowed before (900 s)
ok   the bound outlasts a whole default hold (4500 s > 3600 s)
ok   a silent (held) upstream inside the bound is forwarded: HTTP 200 after 1 s, {"answered": true}
ok   a stall past the bound answers 502 at the bound (HTTP 502 after 1 s for a 3 s stall, bound 1 s)
webapp_proxy_hold_timeout_test: ok

Control: the same test file in a throwaway worktree at origin/main (ad10a17), scripts untouched, test copied in:
ok   1bit-heavy carries the hold window (maxs=3600)
FAIL the proxy derives its bound from the hold window (HOLD_WINDOW/RESUME_GRACE/UPSTREAM_TIMEOUT: none) - it still hardcodes 900 s, shorter than the 3600 s hold window
ok   a silent (held) upstream inside the bound is forwarded: HTTP 200 after 1 s, {"answered": true}
FAIL a stall past the bound answers 502 at the bound (HTTP 200 after 3 s for a 3 s stall, bound 1 s)
webapp_proxy_hold_timeout_test: FAIL (exit 1)

$ ctest --test-dir build -R 'webapp_proxy_hold_timeout|heavy_wrapper|release_check_hold_cycle' --output-on-failure
1/3 Test  #80: heavy_wrapper ....................   Passed   31.18 sec
2/3 Test  #81: webapp_proxy_hold_timeout ........   Passed    2.39 sec
3/3 Test #160: release_check_hold_cycle .........   Passed    0.02 sec
100% tests passed, 0 tests failed out of 3

Gate: scripts/pre-pr-checks.sh --tree-only --base origin/main
pre-pr-checks: all 15 check(s) green, 3 skipped, 0 could not be told, 2 open-PR row(s) not run (--tree-only)

Refs #3478.
…out writing bytecode

The new ctest row failed CI two ways, both caught by existing guards:

- route_port_lock: the row starts a fake loopback upstream, and the census (tests/route_port_lock_test.py) requires
  RESOURCE_LOCK route_ports on every route test it finds -- 'webapp_proxy_hold_timeout' was in the missing list. The
  property is now set with the reason in a comment.
- update_shadow: 'every embed code file is release-owned (missing: usr/local/bin/__pycache__/1bit-webapp-proxy
  cpython-314.pyc)'. The value arm imports the proxy with SourceFileLoader, which writes its .pyc next to the script
  in the image's embed tree; the row now runs that python with PYTHONDONTWRITEBYTECODE=1, so the check never sees a
  file the release does not own.

Both rows pass locally after the fix (webapp_proxy_hold_timeout, update_shadow); route_port_lock's remaining local
failure is its pre-existing http_guard census gap on this box (the same on origin/main), not this row.
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 1ab2264)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3350 - Partially compliant

Compliant requirements:

  • The feature is implemented with 1bit-heavy wrapper that holds models during heavy work
  • Client requests are held during the pause with proper error handling
  • The same model is resumed after heavy work completes
  • Client sessions survive the pause/resume cycle

Non-compliant requirements:

Requires further human verification:

  • Verification that streaming requests get proper keepalive comments (not implemented in this PR)
  • End-to-end testing of the full pause/resume workflow with actual heavy workloads
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Proxy Timeout Bound

The proxy's upstream timeout was previously hardcoded to 900 seconds, which was insufficient for the default 3600-second hold window used by 1bit-heavy. This caused held turns to be cut off prematurely, resulting in 502 errors instead of allowing the hold to complete. The fix correctly sets the upstream timeout to HOLD_WINDOW + RESUME_GRACE (4500 seconds) to accommodate the full hold duration plus the time needed to reload models after the hold ends. This change ensures that held requests can wait for the full hold duration without being terminated by the proxy's timeout.

HOLD_WINDOW = 3600            # 1bit-heavy's --max-seconds default; tests/webapp_proxy_hold_timeout_test.sh fails if the two differ
RESUME_GRACE = 900            # the whole-request socket timeout this proxy used to allow: kept for the reload after a hold
# ONEBIT_WEBAPP_UPSTREAM_TIMEOUT scales the bound (the test drives it in seconds; an operator can raise it for a slower
# box). A hold taken with a --max-seconds above the window can still outlast it, and the page's turn is cut at this
# bound; os/v3/puppy/README.md states both numbers next to the wrapper.
UPSTREAM_TIMEOUT = int(os.environ.get("ONEBIT_WEBAPP_UPSTREAM_TIMEOUT") or HOLD_WINDOW + RESUME_GRACE)
Test Coverage for Hold Timeout

The new test verifies that the proxy's upstream timeout is correctly calculated based on the hold window and resume grace period. It also tests that a held turn inside the bound is forwarded correctly, while a stall past the bound results in a 502 error at the bound. This ensures that the proxy's timeout behavior is correctly implemented and prevents premature termination of held requests.

#!/bin/sh
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# engine#3478: a held turn waits inside Lemonade's load path with NO bytes on the wire until the hold ends, and the
# appliance page's fetch has no timeout of its own (embed/opt/1bit/webapp/index.html:232) - so 1bit-webapp-proxy's
# upstream socket timeout is the only deadline a held turn has. It was a hardcoded 900 s while 1bit-heavy's default
# hold window is 3600 s, so a hold between 15 and 60 minutes cut the page's turn with a 502 that reads as "Lemonade is
# not answering" while the hold was healthy.
#
# Two arms, both of which FAIL on the pre-fix tree (no derived bound; the 900 s socket swallows a stalled upstream):
#   1. the shipped values: the proxy's hold window is 1bit-heavy's --max-seconds default, and the upstream timeout is
#      that window plus the old 900 s resume - so the two files carry ONE number and CI fails if they drift;
#   2. a fake Lemonade that sends nothing for a while, the way a hold does. A silent upstream inside the bound is
#      forwarded and answered; one past the bound answers 502 AT the bound, not at the stall. The shipped 4500 s bound
#      cannot be waited, so the arms scale it through the proxy's own ONEBIT_WEBAPP_UPSTREAM_TIMEOUT and stay a few
#      seconds long.
# No root, no device, no real Lemonade.
set -u
here=$(cd "$(dirname "$0")/.." && pwd)
proxy=$here/os/v3/puppy/embed/usr/local/bin/1bit-webapp-proxy
heavy=$here/os/v3/puppy/embed/usr/local/bin/1bit-heavy
t=$(mktemp -d) || exit 1
bad=0
srv=
proxy_pid=
cleanup() { [ -n "$proxy_pid" ] && kill "$proxy_pid" 2> /dev/null; [ -n "$srv" ] && kill "$srv" 2> /dev/null; rm -rf "${t:?}"; }
trap cleanup EXIT
check() { if [ "$1" = 0 ]; then echo "ok   $2"; else echo "FAIL $2"; bad=$((bad + 1)); fi; }
command -v python3 > /dev/null && command -v curl > /dev/null || {
    echo "webapp_proxy_hold_timeout_test: needs python3 and curl"; exit 1; }

# 1. the shipped values: one hold window, and the proxy's bound derived from it (plus the 900 s resume it always allowed
#    for a load and a first token). On the pre-fix tree this import finds no HOLD_WINDOW and the failure names the
#    hardcoded 900 s that was shorter than the 3600 s window.
window=$(sed -n 's/.*maxs=\([0-9][0-9]*\).*/\1/p' "$heavy" | head -n 1)
[ -n "$window" ]; check $? "1bit-heavy carries the hold window (maxs=${window:-?})"
vals=$(PYTHONDONTWRITEBYTECODE=1 ONEBIT_WEBAPP_UPSTREAM_TIMEOUT= python3 - "$proxy" <<'PY' 2> /dev/null
import importlib.util, sys
from importlib.machinery import SourceFileLoader
loader = SourceFileLoader("webapp_proxy", sys.argv[1])   # the proxy has no .py suffix
spec = importlib.util.spec_from_loader("webapp_proxy", loader)
m = importlib.util.module_from_spec(spec)
loader.exec_module(m)
print(m.HOLD_WINDOW, m.RESUME_GRACE, m.UPSTREAM_TIMEOUT)
PY
)
set -- $vals
if [ $# -eq 3 ]; then
    [ "$1" = "$window" ]; check $? "the proxy's hold window ($1 s) is 1bit-heavy's --max-seconds default ($window s)"
    [ "$3" -eq $(( $1 + $2 )) ]; check $? "the upstream timeout ($3 s) is the window plus the resume ($1 + $2)"
    [ "$2" -ge 900 ]; check $? "the resume does not go below the 900 s the socket allowed before ($2 s)"
    [ "$3" -gt "$window" ]; check $? "the bound outlasts a whole default hold ($3 s > $window s)"
else
    check 1 "the proxy derives its bound from the hold window (HOLD_WINDOW/RESUME_GRACE/UPSTREAM_TIMEOUT: none) - it still hardcodes $(sed -n 's/.*HTTPConnection(\*UPSTREAM, timeout=\([0-9]*\)).*/\1/p' "$proxy") s, shorter than the $window s hold window"
fi

# 2. a fake Lemonade that sends nothing for a while, the way a hold does, with the proxy in front of it.
cat > "$t/fake.py" << 'PY'
import json, sys, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
stall_file, port_file = sys.argv[1], sys.argv[2]
class H(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"
    def log_message(self, *a): pass
    def do_POST(self):
        n = int(self.headers.get("Content-Length") or 0)
        self.rfile.read(n)
        time.sleep(float(open(stall_file).read()))   # a held turn: Lemonade sends nothing while the hold lasts
        data = json.dumps({"answered": True}).encode()
        self.send_response(200); self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data)
s = ThreadingHTTPServer(("127.0.0.1", 0), H)
s.daemon_threads = True
open(port_file, "w").write(str(s.server_address[1]))
s.serve_forever()
PY
mkdir -p "$t/app"; echo '<html>chat</html>' > "$t/app/index.html"
echo 1 > "$t/stall"
python3 "$t/fake.py" "$t/stall" "$t/up.port" & srv=$!
for _ in $(seq 1 50); do [ -s "$t/up.port" ] && break; sleep 0.1; done
up=$(cat "$t/up.port")
free_port() { python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()'; }
start_proxy() {  # <upstream timeout s>
    pport=$(free_port)
    ONEBIT_WEBAPP_APP=$t/app ONEBIT_WEBAPP_PORT=$pport ONEBIT_WEBAPP_CONF=$t/none \
        ONEBIT_WEBAPP_UPSTREAM_PORT=$up ONEBIT_WEBAPP_UPSTREAM_TIMEOUT=$1 \
        python3 "$proxy" > "$t/proxy.log" 2>&1 &
    proxy_pid=$!
    for _ in $(seq 1 50); do curl -s -o /dev/null -m 1 "http://127.0.0.1:$pport/" && break; sleep 0.1; done
}
stop_proxy() { kill "$proxy_pid" 2> /dev/null; wait "$proxy_pid" 2> /dev/null; proxy_pid=; }
ask() {  # -> sets code, elapsed s; a POST the page would send, through the proxy
    t0=$(date +%s)
    code=$(curl -s -m 30 -o "$t/body" -w '%{http_code}' -X POST -H 'Content-Type: application/json' \
        -d '{"stream":true}' "http://127.0.0.1:$pport/api/v1/chat/completions")
    elapsed=$(( $(date +%s) - t0 ))
}

# 2a. a silent upstream inside the bound is a held turn still waiting, not an error: forwarded and answered
start_proxy 4
ask
[ "$code" = 200 ] && grep -q '"answered": true' "$t/body"
check $? "a silent (held) upstream inside the bound is forwarded: HTTP $code after ${elapsed} s, $(head -c 60 "$t/body")"
stop_proxy

# 2b. a silence PAST the bound answers 502 at the bound, not at the stall. The pre-fix proxy has no such knob, so its
#     hardcoded 900 s socket waits out the stall and answers 200 where this arm wants 502.
echo 3 > "$t/stall"
start_proxy 1
ask
[ "$code" = 502 ] && [ "$elapsed" -le 2 ]
check $? "a stall past the bound answers 502 at the bound (HTTP $code after ${elapsed} s for a 3 s stall, bound 1 s)"
stop_proxy

echo "webapp_proxy_hold_timeout_test: $([ $bad = 0 ] && echo ok || echo FAIL)"
[ $bad = 0 ]

@bong-water-water-bong
bong-water-water-bong merged commit 115af14 into main Nov 24, 2026
10 of 11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/3478-proxy-hold-bound branch November 24, 2026 11:18
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 1ab2264

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant