Skip to content

feat(schedule): gate spend on progress, spend only after writeback - #325

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/schedule-control-layers
Open

raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/schedule-control-layers

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

Two optional control-plane layers on top of the keepalive scheduler. Both are inert by
default
, so a caller that passes neither behaves exactly as before.

SpendGate is asked before each turn and adds the one signal the continuation gate cannot
see: a brake on runs that reported no progress (RunOutcome.progress_made is False). It is
fail-closed — an unset field never defaults to "run".

run_turn orders one turn as execute → typed result → validation → durable writeback →
spend, so quota is never spent on a turn that did not write back. Asking for spend without a
writeback raises rather than quietly spending, and a failed spend keeps the writeback.

Both module docstrings record which decisions mirror the LOOPX contracts and why, so the
next reader does not have to reconstruct the provenance.

Changes

  • core/schedule/should_run.py (new): ShouldRunDecision + SpendGate
  • core/schedule/turn_transaction.py (new): TurnReceipt + run_turn
  • core/schedule/scheduler.py: consult the gate between runs; document both layers
  • core/schedule/__init__.py: export both
  • tests/test_schedule.py: 23 cases — 11 gate, 7 transaction, 3 scheduler

Behaviour

Unchanged when unused. spend_gate=None and no writeback/spend hooks reproduce the previous
scheduler path exactly; the new tests pin that the layers stay out of the way.

Tests

pytest tests/test_schedule.py                          -> 39 passed (23 new)
ruff check --select E4,E7,E9,F --ignore=E402           -> clean
ruff format --check                                     -> 5 files already formatted

Scope note

The full local CI replay was not run. Verification is targeted (the schedule suite plus
lint). Upstream CI is the authoritative gate.

Two optional control-plane layers on top of the keepalive scheduler, both
inert by default so existing callers behave exactly as before:

- SpendGate is asked before each turn and adds the signal the continuation
  gate cannot see: a brake on runs that reported no progress
  (RunOutcome.progress_made is False). Fail-closed: an unset field never
  defaults to "run".
- run_turn orders one turn as execute -> typed result -> validation -> durable
  writeback -> spend, so quota is never spent on a turn that did not write
  back. Asking for spend without a writeback raises instead of silently
  spending.

- core/schedule/should_run.py (new): ShouldRunDecision + SpendGate
- core/schedule/turn_transaction.py (new): TurnReceipt + run_turn
- core/schedule/scheduler.py: consult the gate between runs
- core/schedule/__init__.py: export both layers
- tests/test_schedule.py: 23 cases (11 gate, 7 transaction, 3 scheduler)

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant