Skip to content

feat: shift watcher 60 s tick, early close, decision-taken refused at PR-open (M3.7c) - #691

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/shift-speed-watcher-latency
Nov 19, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/shift-speed-watcher-latency

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

M3.7c of the autonomous-orchestrators epic (closes #690). Ruling S7 (human, 2026-11-19) and the watcher latency work, with the human's plan decisions 1 to 3.

  • 60 s tick and a finish trigger (decision 1). The timer ticks every 60 seconds. A new pyauto-orchestrator.path unit starts the same service when the kick file %S/pyauto/orchestrator.kick changes. Workers (after .done), close-outs and branch-update sessions (after .closeout) append one line to $PYAUTO_SHIFT_KICK, best effort. PathChanged is edge-triggered: a kick that lands while a tick runs is dropped and the timer covers it. The service sets StartLimitIntervalSec=0; the path unit's TriggerLimit* keys apply from systemd 250 (249 ignores them with a warning, checked with systemd-analyze verify).
  • S7. The watcher reads labels in the gh pr view it already makes, once per PR per shift. A decision-taken PR is refused for /prm from the label alone: no close-out session, no merge slot, no CI read. It stays an "earlier" PR, so later PRs on its library wait until GitHub says MERGED or CLOSED (M3.6j ruling c unchanged). An unreadable label waits, at most one read a tick, and is refused for /prm only after 3 misses over 15 minutes.
  • Early close. With no worker live (leases in grace included), no pending re-dispatch, no close-out or branch update running, no PR in the CI grace or an updated state, no startable pick and no unreadable input (steering or Mind), the shift posts its digest on that tick. A paused shift never closes early (decision 2), nor a shadow shift, nor one that has started nothing. A task parked on a question does not hold it open (decision 3). Merges are counted up to the close.
  • Digest. "Closed early at …; review-at was …", and a "Waited behind your /prm" section with one line per library naming the PRs that waited behind a /prm-bound PR.

API Changes

None to any library. Brain internals: _orchestrator.kick_path(), early_close_ready(), close_early(), finish_shift(closed_at=), gh_pr_state returns labels; _digest.FAIL_CLOSED. See full details below.

Risks

  • With decision 3 and the early close, the M3.6j in-shift path (the human /prms a blocker mid-shift, then the waiting PR is updated and merged) runs only while other work keeps the shift open; otherwise the waiting PR goes to the next shift.
  • A steering /add posted after an early close is not read, the same as after review-at:.
  • 36 multi-tick tests in older modules are marked shift_held_open, so they test their own behaviour with the shift kept open. The reviewer re-ran them without the fixture: about 33 fail, every one a scenario the design now closes on purpose; none showed a close while something was running.

Deploy (human, when no shift is live; not done here)

After merge and pulling the canonical Brain checkout:

cp ~/Code/PyAutoLabs/organs/PyAutoBrain/bin/systemd/pyauto-orchestrator.{service,timer,path} ~/.config/systemd/user/
systemctl --user daemon-reload && systemctl --user restart pyauto-orchestrator.timer && systemctl --user enable --now pyauto-orchestrator.path

Test Plan

  • Tests first: tests/test_watcher_latency.py (32 tests). 15 failed on main in round 0 (units, kick, S7 refusal, label wait, waits behind MERGED/CLOSED, digest line, early close, parked closes, NO-CHECKS grace then close); review-round tests failed before each fix.
  • Full Brain suite: 2484 passed, 1 skipped.
  • bin/check_skill_line_counts.sh 200 PyAutoBrain, tenant firewall, install.sh --check-project-discovery: OK. systemd-analyze --user verify on the three units: clean except the two expected TriggerLimit* warnings on systemd 249.
  • Independent review (fresh Opus 5.5 session): round 1 FINDINGS (2 medium: a failed steering or Mind read let the shift close early; the systemd start limit could stall the watcher; 3 low: unbounded label re-reads, a carried merged PR reported as decision-taken, missing guard tests), fixed; round 2 FINDINGS (1 medium: 3 label misses in 2 minutes refused PRs for the shift), fixed exactly as suggested (3 misses over 15 minutes).
  • Heart scoped dev-ship verdict for PyAutoBrain: green.
  • Smoke: n/a (organism repo; no downstream script surface).
Full API Changes (for automation & release notes)

Added

  • bin/systemd/pyauto-orchestrator.path — kick-file path unit.
  • _orchestrator.KICK_ENV, kick_path(), early_close_ready(), close_early(), LABEL_READS, LABEL_READ_GRACE_S, LABELS_UNREADABLE_WHY.
  • _digest.FAIL_CLOSED (shared with _orchestrator.FAIL_CLOSED).

Changed Behaviour

  • Timer 2 min → 60 s; the service has StartLimitIntervalSec=0.
  • worker_env sets PYAUTO_SHIFT_KICK; worker, close-out and update templates write it.
  • gh_pr_state returns labels.
  • _start_closeouts refuses decision-taken at PR-open (after the carried-PR check).
  • _tick closes the shift early when nothing is live or startable; finish_shift(closed_at=) counts merges to that time.
  • Digest: early-close line and "Waited behind your /prm" section.

🤖 Generated with Claude Code

Jammy2211 and others added 3 commits November 19, 2026 14:13
…on-taken refused at PR-open

- bin/systemd: timer every 60 s; new pyauto-orchestrator.path starts the tick
  when %S/pyauto/orchestrator.kick changes. worker_env sets PYAUTO_SHIFT_KICK
  (kick_path); worker, close-out and update templates append to it after
  their verdict file, best effort.
- S7: _start_closeouts reads a PR's labels (one more field of gh_pr_state,
  once per PR per shift, unreadable waits) right after the tier check; a
  decision-taken PR is refused with no session, slot or CI read and stays an
  earlier PR in the merge order (ruling c).
- Early close: early_close_ready/close_early post the digest on the tick
  that leaves nothing live, startable or unjudged (never paused, shadow, or
  before anything started); later ticks in the window are idle or late sweep.
- Digest: "Closed early at ..." line and "### Waited behind your /prm" lines.
- Docs: AUTONOMY.md, batch AGENTS.md (with Deploy), batch/cockpit skills.
- Tests: tests/test_watcher_latency.py; multi-tick tests held open by the
  shift_held_open fixture.

#690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e limits, bounded label reads

- early_close_ready: never closes on a tick whose steering read failed
  (commands_unread) or whose plan failed closed on Mind origin/main.
- service: StartLimitIntervalSec=0; path unit: TriggerLimitIntervalSec=10s,
  TriggerLimitBurst=20; docs say a kick during a tick is dropped (edge-
  triggered) and the 60 s timer covers it.
- S7 label read: at most 3 failed reads per PR per shift, then refused
  "labels unreadable after 3 reads → your /prm", counted in the digest.
- The label read runs after the carried-PR check.
- Tests for the guards: updated PR, lease in grace, pending re-dispatch,
  unreadable carried PR, unread steering, Mind fail-closed.

#690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er 15 minutes

- A PR whose labels cannot be read goes to /prm only after LABEL_READS (3)
  misses AND LABEL_READ_GRACE_S (900 s) since the watcher first saw it, so a
  short gh outage refuses nothing; at most one read a tick, as before.
- Digest, AUTONOMY.md network surface and batch AGENTS.md wording match.
- Deploy paragraph: restart the path unit if it ever shows failed; systemd
  249 ignores the TriggerLimit keys with a warning.
- One FAIL_CLOSED constant for on_origin, early_close_ready and the digest.

#690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 1f51de1 into main Nov 19, 2026
2 checks passed
@Jammy2211
Jammy2211 deleted the feature/shift-speed-watcher-latency branch November 19, 2026 15:50
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.

feat: shift watcher 60 s tick, early close, decision-taken refused at PR-open (M3.7c)

1 participant