Skip to content

Log the active Issue context when the Runner is stopped - #193

Merged
xqliu merged 1 commit into
mainfrom
muyan-pilot/xqliu-orbi-issue-48-e56325e9
Aug 30, 2026
Merged

xqliu merged 1 commit into
mainfrom
muyan-pilot/xqliu-orbi-issue-48-e56325e9

Conversation

@xqliu

@xqliu xqliu commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #48

run_id=e56325e9

What

When systemd (or any caller) stops the Runner with SIGTERM, the journal
now shows which Issue context was active BEFORE the generic Stopped
line, and the live Pi child is shut down — no orphan Pi:

[run_id] run_stopping issue=N title="..." signal=SIGTERM phase=... branch=... worktree=... session=...
[run_id] run_stopped issue=N result=interrupted

A stop before claiming an Issue logs run_stopped result=idle without
any invented Issue fields.

How (smallest complete change)

  • bootstrap_runner.py:
    • _ACTIVE_RUN context bound at the claim (process_issue) and on
      resume (main), cleared when the delivery ends; carries
      issue/title/branch/worktree + the live Pi child. No new id: the run
      id is the existing _CURRENT_RUN_ID, phase/session come from the
      existing activity snapshot of the worktree's .pi-session
      (- when absent).
    • _handle_stop (SIGTERM) installed in main() right after logging —
      covers pre-claim, claim, implement and delivery wait. Logs
      run_stopping with the full scene, TERMs the live Pi child (only
      if alive) and waits for it, logs run_stopped result=interrupted,
      exits 128+signum (143). Idle stop: one run_stopped result=idle
      line.
    • stream_pi registers the Pi Popen after spawn and clears it after
      the child is reaped, so the handler never signals an already-exited
      child.
  • tests/test_bootstrap_runner.py: 11 new tests, including the
    acceptance proof — a REAL subprocess SIGTERM test (real Runner
    process, real long-running Pi-like child, real SIGTERM) asserting the
    ordering (run_stopping before run_stopped, both before the
    process is gone), every field, exit 143, no orphan child, and the
    idle stop.
  • README.md: journal section documents run_stopping /
    run_stopped.

The systemd unit description stays static (per the Issue). No timeout,
retry framework, tracing backend or second ID is added.

Verification

  • Full suite: 1239 passed (baseline 1228 + 11 new tests).
  • 100% line and branch coverage: TOTAL 15603 stmts, 0 miss, 2202 branches, 0 partial.
  • Details in the worktree's test.log (run artifacts, gitignored by
    design).

When systemd stops the Runner with SIGTERM, the journal now shows which
Issue context was active BEFORE the generic Stopped line, and the live
Pi child is shut down (no orphan Pi):

- run_stopping issue=N title="..." signal=SIGTERM phase=... branch=...
  worktree=... session=... — before the stop, with the full scene
  (phase/session from the existing activity snapshot, the existing
  run_id prefix — no new id)
- run_stopped issue=N result=interrupted — after the Pi child exits
- run_stopped result=idle — a stop before the claim, no invented
  Issue fields

The handler is installed in main() right after logging (covers
pre-claim, claim, implement and delivery wait), the in-flight scene is
bound at the claim and on resume, and stream_pi registers/clears the
live Pi child so the handler signals exactly the child that is alive.
The process exits 128+signum (143 for SIGTERM). The systemd unit
description stays static.

Fixes #48
@xqliu
xqliu merged commit 4b3212b into main Aug 30, 2026
1 check passed
@xqliu
xqliu deleted the muyan-pilot/xqliu-orbi-issue-48-e56325e9 branch September 11, 2026 12:51
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.

Log active Issue context when Runner is stopped

1 participant