← Back to Pull requests

fix(runtime): reject hour-24 timestamps instead of rolling them #9697

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 01, 2026 02:47 UTC
Author

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->

Goal And Delivered Outcome

  • Outcome basis / optional anchor: no written issue. The request in this PR is the basis.

  • Goal/source and gap: parseIsoTimestamp accepted T24:00:00 by rewriting the hour to 00:00, then Date.parse rolled that text to the next midnight. Scheduler backoff, host-failure retention, and active lease deadlines followed the rolled instant. Python parse_timestamp and the Todo codec already reject the token.

  • Observable before → after: 2026-01-01T24:00:00Z was read as 2026-01-02T00:00:00.000Z (1767312000000). A host-update failure with that failed_at stayed inside the 24h TTL. A monitor schedule and a backoff current/updated clock did not throw. An active lease with that expires_at stayed active at 2026-01-01T23:30:00Z. After the change those reads are rejected: scheduler timestamps are null, illegal clocks throw must be an ISO timestamp, and leaseIsActive throws expires_at must be a valid timestamp.

  • Issue/task and intended base: Related to the existing illegal-calendar rejection for Feb 31 / Nov 31. Base is main at 1bdf851e9447bc7c22ab29d10948a674bf4687c4. This does not close an issue.
  • Defect

    T24:00:00, T24:00:00.000Z, T24:00:00+08:00, and a space-separated 24:00:00Z are not clock fields in this codec. Date.parse turns them into the next midnight (2026-01-01T24:00:00+08:00 became 2026-01-01T16:00:00.000Z). The shared reader used that rolled instant for:

  • scheduler backoff current_time / updated_at (an illegal clock could count as an elapsed interval)

  • scheduler monitor generated_at / explicit_next_due_at

  • host-update failure retention (a rolled failed_at stayed inside the TTL and could suppress a later host update)

  • leaseIsActive (a lease expiring at T24:00:00Z remained active at 23:30 the same calendar day)
  • Reproduction

    On 1bdf851e9447bc7c22ab29d10948a674bf4687c4, before the codec change, with the new assertions present:

    node --no-warnings --experimental-sqlite --experimental-strip-types --test \
      tests/control_plane_ts/scheduler_state_store.test.ts \
      tests/control_plane_ts/scheduler_state_transition_rules.test.ts \
      tests/control_plane_ts/task_lease_lifecycle.test.ts
    

    Result: 39 tests, 34 passed, 5 failed.

  • timestamp codec: Expected null, actual 1767312000000 for 2026-01-01T24:00:00Z

  • failure retention: the T24:00:00Z failure was kept instead of []

  • monitor schedule and backoff: Missing expected exception: 2026-01-01T24:00:00Z

  • lease: Missing expected exception from leaseIsActive at 2026-01-01T23:30:00Z
  • Root cause

    In parseIsoTimestamp, hour 24 was rewritten to 00:00 on the same calendar day so the round-trip check passed. The returned Date was then parsed from the original text, and Date.parse rolled T24:00:00 to the next midnight. Non-zero minutes at hour 24 were already rejected; exact 24:00:00 was the hole. Feb 31 and leap seconds were already rejected.

    Fix

    Reject hour 24 before the calendar check. Do not rewrite it to 00:00 and do not return the rolled Date. This is the same fail-closed rule Python and the Todo microsecond codec already use. Writers that emit toISOString() never produce hour 24, so ordinary persisted deadlines are unchanged.

    Author Declaration

  • Written by: @Duang777
  • Implemented against

  • Specification and revision: loopx/control_plane/runtime/time.py stable ISO grammar (reject hour 24; do not carry an end-of-day rollover) and the scheduler contract in tests/control_plane_ts/scheduler_state_transition_rules.test.ts that an illegal calendar must not count as an elapsed backoff interval. No separate RFC revision.

  • Criteria:
  • | Criterion (spec clause) | Disposition | Symbol / path | Test or command |
    | --- | --- | --- | --- |
    | Hour 24 is not a valid clock and must not roll to the next midnight | implemented | parseIsoTimestamp | scheduler timestamp / backoff / monitor schedule tests |
    | An active lease must not stay live on a rolled 24:00 deadline | implemented | leaseIsActive | task_lease_lifecycle.test.ts |
    | Blank or missing scheduler updated_at still counts as elapsed | implemented | schedulerProgressionIntervalElapsed | existing backoff blank-updated_at test, still passing |

  • Self-check before submission: read parseIsoTimestamp, the scheduler timestamp/backoff callers, and leaseIsActive. Confirmed Date.parse rollover in Node before editing. Did not change hardlink, historical ACK, or noop-recovery code.
  • Scope And Continuation

  • Completed scope and remaining work: complete within this scope. The shared ISO reader now rejects hour 24 for every caller of parseIsoTimestamp, including scheduler state and lease expiry.

  • Slice boundary / successor: N/A. External text that intentionally used RFC 3339 24:00:00 as next midnight now fails closed instead of moving the deadline.
  • Validation

  • Tested revision: 68317b50a5ad559d95a6800cc75d11f3bea3e41a

  • Run state: finished

  • Input classes: synthetic
  • | Check kind | Result | Public-safe evidence / limitation |
    | --- | --- | --- |
    | unit | passed | Same three Node test files after the fix, plus monitor_metadata.test.ts, causal_blocked_wait.test.ts, and canonical_task_lease_renew.test.ts: 139 passed, 0 failed. |
    | regression_parity | passed | The five assertions above failed on the pre-fix tree and passed after rejecting hour 24. |
    | static | passed | npm run typecheck:control-plane exited 0. |
    | integration | passed | uv run --extra test pytest tests/control_plane/test_monitor_state_owner.py -q: 49 passed. uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick: merge gate passed. One advisory maintainability ratchet did not involve these files and did not fail the gate. examples/control_plane/monitor-scheduler-contract-smoke.py passed. |
    | unit | failed | npm run test:control-plane: 6928 tests, 6917 passed, 6 failed, 5 skipped. The 6 failures are task_lease_hardlinks.test.ts and task_lease_workspace.test.ts Git-origin/worktree cases (task_repository must be a credential-free Git remote...). The same 6 failures reproduce on unmodified main in this environment and do not touch the timestamp reader. |

  • Coverage and gaps: the changed reader is covered by scheduler codec, failure retention, monitor schedule, backoff, and lease activity. Broader control-plane TypeScript tests were run. The pre-existing worktree identity failures were not treated as a pass.
  • Residual risk

    A hand-written or externally supplied T24:00:00 deadline is now unreadable instead of “next midnight.” In-repo writers do not emit that token. Offset hour 24 (+24:00) was already rejected.

    Frontend / Visual Evidence

  • UI impact: none

  • Before: N/A

  • After: N/A

  • First viewport and preview: N/A

  • States and viewports shown: N/A

  • Source data: none

  • Attention review: N/A

  • Craft review: N/A
  • Type of Change

  • Bug fix

  • New feature

  • Breaking change

  • Refactoring (no functional changes)

  • Documentation update

  • Test update
  • LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)

  • Capability or extension (providers, adapters, skills)
  • <!-- CURSOR_AGENT_PR_BODY_END -->

    <div><a href="https://cursor.com/agents/bc-0d8be500-20e7-53d6-a032-2a38a62e06d6?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-0d8be500-20e7-53d6-a032-2a38a62e06d6&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: loopx-agent Review duration: 93m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.57) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #9697"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%