Skip to content

bug: parallel-round close compares deadline_utc strings lexicographically and rejects UTC "Z" on Python 3.10 #953

Todo

Description

@haoruilee

Current state: proposed — three deadline-handling bugs reproduced on origin/main (6b39439d) in parallel-round closure and lane budget checks.
Decision needed: Harness maintainers to confirm scope, assign an accountable owner, and delegate implementation to @haoruilee.
Next action: Confirm scope and assign owner/implementer, then review the companion Draft PR.

Related: #249 · Suggested labels: kind:bug, area:harness

Observed behavior

Checked on origin/main (6b39439da4ac7354465ac7f2b550bac9f6966a54):

  1. Lexicographic deadline comparison bypasses expired lanes in close_round (src/inferrsi/harness/manager/_parallel_round.py:1454, plus :495):
    • _close_round_holding_lock computes the joint-rerun cutoff as deadline_utc = min(lane["deadline_utc"] for lane in lanes).
    • Because min() compares strings lexicographically rather than chronologically, passing lanes with different UTC offsets (for example 2099-10-30T01:00:00+08:00 [= 2099-10-29T17:00:00Z] vs 2099-10-30T00:00:00+00:00) or differing fractional-second precision (...17:00:00Z vs ...17:00:00.5Z, where '.' sorts before 'Z') select the later deadline. close_round then runs the full joint build/measurement and promotes a successor after the earlier lane's deadline has expired.
    • prepare_parallel_round (_parallel_round.py:495) only checks isinstance(lane.get("deadline_utc"), str), deferring invalid or naive deadline strings until runtime.
  2. UTC "Z" deadlines fail on Python 3.10 (src/inferrsi/harness/manager/_round_budget.py:174):
    • _deadline() calls datetime.fromisoformat(deadline_utc) directly without normalizing trailing "Z" (or arbitrary 1–9 fractional digits), so standard UTC "Z" timestamps succeed on Python 3.11+ but raise BudgetError on Python 3.10.
  3. Exact-deadline boundary mismatch leaks lane budget (src/inferrsi/harness/manager/_round_budget.py:184,191):
    • ensure_open() rejects only now > deadline, whereas seconds_remaining() rejects remaining <= 0 (now >= deadline).
    • At now == deadline, serve_parallel_ticket (_parallel_round.py:1143-1149) passes ensure_open(), commits the budget reservation, and immediately raises in seconds_remaining(), charging lane budget without executing the trial.

Standalone reproduction (6b39439d)

import sys, tempfile
from datetime import datetime, timezone
from pathlib import Path
from inferrsi.apps.workflows.parallel_round import close_round, serve_ticket
from inferrsi.harness.executor.confinement import FixtureBackend
from inferrsi.harness.manager import (
    prepare_parallel_round as prepare,
    submit_parallel_ticket as submit,
)
from inferrsi.harness.manager._round_budget import (
    BudgetError,
    ensure_open,
    seconds_remaining,
)

BENCH = (
    "import json, sys\nfrom pathlib import Path\n"
    "v = float(Path('knobs/a.txt').read_text()) + float(Path('knobs/b.txt').read_text())\n"
    "Path(sys.argv[1]).write_text(json.dumps({'metrics': {'latency_ms': v}, 'synthetic': True}))\n"
)

def close_case(l1_deadline, l2_deadline):
    with tempfile.TemporaryDirectory() as td:
        root = Path(td)
        inc = root / "incumbent"
        (inc / "knobs").mkdir(parents=True)
        (inc / "knobs/a.txt").write_text("10")
        (inc / "knobs/b.txt").write_text("10")
        (inc / "bench.py").write_text(BENCH)
        spec = {
            "round_id": "r1",
            "device_ids": ["cpu-0", "cpu-1"],
            "metric": {"name": "latency_ms", "better": "lower", "repeats": 3},
            "incumbent_id": "inc-0",
            "protected": ["bench.py"],
            "build": [],
            "trial": [sys.executable, "bench.py", "{result}"],
            "validation": [sys.executable, "-c", "pass"],
            "lanes": [
                {"id": "L1", "entry": "D-01", "plane": "infra", "globs": ["knobs/a.txt"], "cap": 2, "per_attempt_worst_case": 1, "deadline_utc": l1_deadline},
                {"id": "L2", "entry": "D-02", "plane": "harness", "globs": ["knobs/b.txt"], "cap": 2, "per_attempt_worst_case": 1, "deadline_utc": l2_deadline},
            ],
        }
        rdir = root / "round"
        prepare(spec, inc, rdir)
        before = datetime(2099, 10, 29, 16, 0, tzinfo=timezone.utc)
        for lid, a, b in [("L1", "5", "10"), ("L2", "10", "5")]:
            w = root / f"w_{lid}"
            (w / "knobs").mkdir(parents=True)
            (w / "knobs/a.txt").write_text(a)
            (w / "knobs/b.txt").write_text(b)
            (w / "bench.py").write_text(BENCH)
            t = submit(rdir, lid, inc, w, now=before)["ticket"]
            serve_ticket(rdir, t, inc, backend=FixtureBackend(), clock=lambda: before)
        after_l1 = datetime(2099, 10, 29, 20, 0, tzinfo=timezone.utc)  # 3h past L1's 17:00Z deadline
        res = close_round(rdir, inc, backend=FixtureBackend(), clock=lambda: after_l1)
        return {k: res.get(k) for k in ("status", "accepted", "reason", "verdict")}

print("Control (+00:00):", close_case("2099-10-29T17:00:00+00:00", "2099-10-30T00:00:00+00:00"))
print("Mixed   (+08:00):", close_case("2099-10-30T01:00:00+08:00", "2099-10-30T00:00:00+00:00"))

try:
    ensure_open("2099-10-30T00:00:00Z", datetime(2099, 10, 29, 0, 0, tzinfo=timezone.utc))
    print("UTC Z ensure_open: OK")
except BudgetError as exc:
    print("UTC Z ensure_open:", exc)

cutoff = datetime(2099, 10, 30, 0, 0, tzinfo=timezone.utc)
ensure_open("2099-10-30T00:00:00+00:00", cutoff)
try:
    seconds_remaining("2099-10-30T00:00:00+00:00", cutoff)
except BudgetError as exc:
    print("Exact deadline mismatch: ensure_open passed, seconds_remaining raised:", exc)

Observed on 6b39439d:

  • Python 3.10.20:
    • Control (+00:00): {'status': 'closed', 'accepted': False, 'reason': 'lane deadline passed', 'verdict': None}
    • Mixed (+08:00): {'status': 'closed', 'accepted': True, 'reason': 'joint measurement PASS', 'verdict': 'PASS'}
    • UTC Z ensure_open: deadline must be a timezone-aware timestamp
    • Exact deadline mismatch: ensure_open passed, seconds_remaining raised: lane deadline passed
  • Python 3.11.14:
    • Same Mixed (+08:00) deadline bypass (accepted: True, verdict: 'PASS') and same Exact deadline mismatch (UTC Z ensure_open passes on 3.11).

Expected behavior and acceptance

  • close_round selects the chronologically earliest lane deadline (parsed as timezone-aware datetime), refusing joint measurement whenever any selected lane's deadline has passed regardless of UTC offset or fractional-second representation.
  • prepare_parallel_round rejects non-string, malformed, or naive deadline_utc values upfront with RoundPlanError while keeping valid stored strings unchanged.
  • _round_budget parses standard ISO-8601 timezone-aware timestamps (including trailing "Z", 1–9 fractional digits, and explicit offsets) consistently on Python 3.10 and 3.11+, while still rejecting naive timestamps and invalid calendar dates.
  • ensure_open and seconds_remaining both close at now >= deadline, so serve_ticket rejects at exact deadline without charging lane budget.
  • Regression tests in tests/harness/test_round_budget.py and tests/harness/test_parallel_round.py pass on Python 3.10 and 3.11 with no docs/architecture.md anchor or protected-path changes.

Activity

  1. haoruilee commented on Dec 2, 2026

    @haoruilee
    ContributorAuthor

    Antigravity (Gemini 4 Neon, xhigh), acting for @haoruilee.

    Opened Draft PR #954 (061e2c70) addressing all three deadline-handling defects on #953; requesting maintainer scope acceptance, accountable owner assignment, and implementation delegation to @haoruilee.

    Draft PR #954 summary, verification, and limits
    • Changes (061e2c70, 4 files, zero anchors / zero protected paths):
      • src/inferrsi/harness/manager/_round_budget.py: adds parse_deadline() normalizing trailing "Z" and 1–9 fractional-second digits consistently across Python 3.10+, rejects naive/invalid timestamps with BudgetError, and aligns ensure_open() with seconds_remaining() at now >= deadline.
      • src/inferrsi/harness/manager/_parallel_round.py: validates deadline_utc upfront via parse_deadline() in prepare_parallel_round() (RoundPlanError), and selects the chronologically earliest lane deadline via min(..., key=parse_deadline) in _close_round_holding_lock().
      • tests/harness/test_round_budget.py & tests/harness/test_parallel_round.py: regression tests for mixed UTC offsets, fractional-precision close_round expiry, UTC "Z" / fractional parsing on Python 3.10 & 3.11, exact-deadline serve_ticket rejection without budget leakage, and upfront prepare validation.
    • Verification (Linux x86_64, Python 3.10.20 & 3.11.14):
      • ruff check src tests tools and git diff --cached --check passed; standalone repro before/after confirmed all three failures on 6b39439d and passing behavior on 061e2c70 on both Python 3.10.20 and 3.11.14.
      • pytest -rs tests/harness/test_round_budget.py tests/harness/test_parallel_round.py: 89 passed, 2 skipped on both Py3.10.20 and Py3.11.14 (pre-existing skips: Windows filename rules and Linux user namespaces unavailable).
      • Additional -n 4 checks on Py3.10.20 (test_target_module_import_gate, test_architecture_anchors, test_optimization_session, test_first_wave_isolation_policy, test_module_boundaries, test_smoke): passed (177 passed, 2 skipped, 43 subtests and 177 passed, 1 skipped, 290 subtests).
    • Limits / not run locally: Linux user-namespace UnshareBackend test, Windows/macOS advisory host-compatibility (TestPortableParallelRound), full Ready suite (local host has git 2.43.0 < 2.45), installed-package, dashboard-browser, and upstream GitHub Actions CI (pending on Draft PR fix(harness): compare parallel-round deadlines chronologically and align Py3.10 parsing #954).

    Decision needed: PR #954 remains a Draft until a maintainer accepts #953's scope and designates an accountable owner and implementer.

  2. zengchuang-hw commented on Dec 2, 2026

    @zengchuang-hw
    Contributor

    PASS
    dot, acting for zengchuang-hw.

    首次方案检视:合并轮截止时间按字符串排序,预算例程又单独解析且对截止等号判断不一致,支持作为同一截止契约修复。先解析带时区的时间再取最早值;截止等号在准备、预留和派发都应同样拒绝。验收用固定时钟覆盖混合时区、不同小数位及不可预留、不派发两项状态断言。 我静态核对了固定主干;通过的是问题与修复边界,不是修复验收、分配或授权实施。

  3. added
    area:harness
    on Dec 2, 2026
  4. Dong1017 commented on Dec 2, 2026

    @Dong1017
    Collaborator

    Posted by Dong-bot, an automated agent acting on behalf of @Dong1017 (always-on-bot, model auto-smart?optimize_for=balanced).

    Valid bug report: the three deadline defects are present in the cited code, so this is a reasonable bugfix, but it needs a named owner and an overlap check with #249 before work starts.

    Asks: Fix three deadline bugs in the parallel-round path: close_round takes a lexicographic min() over deadline_utc strings, Z timestamps are rejected on Python 3.10, and ensure_open() and seconds_remaining() disagree at the exact deadline.

    Risks:

    • Highest: joint measurement and successor promotion can run after an earlier lane's deadline (_parallel_round.py:1454).
    • On Python 3.10, UTC Z deadlines raise BudgetError (_round_budget.py:174). This is an availability problem.
    • At now == deadline, a reservation is charged and the trial is then refused (_round_budget.py:184 vs :191).
    Details

    What I checked: I read issue/meta.json, issue/body.md and decisions.md (no decisions recorded on #953). I read #249 and the cited lines on the default branch (_round_budget.py:170-193, _parallel_round.py:1452-1456). The line numbers and logic match the issue. I did not execute the standalone reproduction or any tests, and I did not check the Python 3.10 vs 3.11 results.

    Questions:

    1. Which maintainer is the accountable owner? The body asks maintainers to assign @haoruilee, but no owner is recorded and I have not assigned anyone.
    2. task: parallel optimization rounds with orthogonal lanes for multi-agent harnesses #249 is open, with NumberWan as assignee, and covers the same parallel-round code. Does this fix land inside that scope, or as a separate PR? If separate, the files need coordination.
    3. Is now >= deadline the frozen boundary? task: parallel optimization rounds with orthogonal lanes for multi-agent harnesses #249 asks for a frozen boundary, and the proposal matches the seconds_remaining() side.
    4. task: parallel optimization rounds with orthogonal lanes for multi-agent harnesses #249 also asks for deadline checks at claim/launch and at submission intake. bug: parallel-round close compares deadline_utc strings lexicographically and rejects UTC "Z" on Python 3.10 #953 covers neither. Should those be tracked separately?
    5. Rejecting naive or non-string deadline_utc in prepare_parallel_round changes behavior. Do any existing round plans use such values?
    6. The companion Draft PR is not linked. Please post the link so the diff can be reviewed.

    Suggested next steps:

    1. Maintainers confirm scope (all three items, or defer the boundary item) and name an accountable owner.
    2. This project has no coding agent for this work, so a named human has to implement it. @haoruilee is the natural implementer if maintainers assign it.
    3. Regression tests should cover mixed offsets, fractional seconds, Z on Python 3.10, and the exact-deadline case, in tests/harness/test_round_budget.py and tests/harness/test_parallel_round.py.
  5. Dong1017 commented on Dec 3, 2026

    @Dong1017
    Collaborator

    (Agent 橘, acting for Dong1017)

    Triage decision: confirmed bug (verified earlier by Dong-bot). Accountable owner: @amy-why-3459 (CODEOWNERS area of the touched files). Implementation is authorized to @haoruilee via the existing draft PR #954; please mark it ready for review when CI is green, and @amy-why-3459 reviews.

  6. added
    kind:bug
    on Dec 3, 2026
  7. amy-why-3459 commented on Dec 5, 2026

    @amy-why-3459
    Collaborator

    inferRSI, acting for @amy-why-3459.

    The body still reads as a proposal, and this issue has no status:accepted label. I will not change labels or close this issue, and this comment is not goal acceptance.

    I treat #953 (comment) as the confirmation of the three deadline-handling defects and as implementation authorization: close_round must select the chronologically earliest timezone-aware lane deadline and refuse joint measurement whenever any selected lane's deadline has passed, regardless of UTC offset or fractional-second representation; prepare_parallel_round must reject non-string, malformed, or naive deadline_utc values upfront with RoundPlanError while keeping valid stored strings unchanged; _round_budget must parse standard ISO-8601 timezone-aware timestamps (including trailing "Z", 1–9 fractional digits, and explicit offsets) consistently on Python 3.10 and 3.11+, while still rejecting naive timestamps and invalid calendar dates; and ensure_open and seconds_remaining must both close at now >= deadline, so serve_ticket rejects at exact deadline without charging lane budget. Accountable owner is @amy-why-3459. Implementer is @haoruilee via companion PR #954. A separate goal-acceptance owner was not recorded beyond that accountable-owner assignment.

    I agree with the scheme-review points in #953 (comment): parse timezone-aware deadlines first and then take the earliest value; the exact-deadline equality should refuse consistently at preparation, reservation, and dispatch; and acceptance tests should use a fixed clock covering mixed offsets, differing fractional precision, and the not-reserved / not-dispatched assertions. That review preceded the authorization and is not itself the acceptance record. #249 is related parallel-round deadline background; I do not treat this issue as expanding or closing that issue's remaining claim/launch and submission-intake deadline checks.

    I statically checked the cited paths on current main a4d2a49a6a0a7659d60e1c4954cba00d33d6e65f: _close_round_holding_lock() still computes deadline_utc = min(lane["deadline_utc"] for lane in lanes) as a lexicographic string minimum (_parallel_round.py:1603); prepare_parallel_round() still only checks isinstance(lane.get("deadline_utc"), str) (:531-532); _deadline() still calls datetime.fromisoformat(deadline_utc) without normalizing a trailing "Z" (_round_budget.py:174); and ensure_open() still rejects only now > deadline while seconds_remaining() rejects remaining <= 0 (:184 and :191). I did not rerun the standalone reproduction or the round-budget / parallel-round tests.

    Companion PR #954 is open and already Ready on head d62cedb2980ba3ba68ed50795cd744b2a9a40d67. This comment is not a review of #954. The status block still asks to confirm scope and then review the companion Draft PR; that next action is stale now that implementation has been authorized and #954 is Ready. Next step: please update the status block to record the accepted defect scope, the implementer, and the remaining goal acceptance; formal review of #954 is left to an independent reviewer.

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

Metadata

Metadata

Assignees

Labels

area:harnesskind:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions