Skip to content

Treat RMG's own wall-time stop as terminal, and bound SA/ARC by max_T3_walltime - #226

Open
alongd wants to merge 2 commits into
mainfrom
i098-killed-step
Open

alongd wants to merge 2 commits into
mainfrom
i098-killed-step

Conversation

@alongd

@alongd alongd commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

T3 reads "the terminal marker is absent" as "the step did not finish", with no third state for "the
step was killed at a recorded time". Two symptoms fall out of that one gap, and this PR closes both.

 check_rmg_status()                    # was -> tuple[bool, bool]
-  'MODEL GENERATION COMPLETED' in log -> (True, True)
-  log exists, marker absent           -> (True, False)   # restart_rmg set: the run repeats
+  'MODEL GENERATION COMPLETED'        -> RMGRunStatus(began=True, terminated=True)
+  RMG's own wall-time stop line       -> RMGRunStatus(began=True, terminated=True,
+                                                      walltime_stop=RMGWalltimeStop(...))
+  log exists, neither                 -> RMGRunStatus(began=True, terminated=False)  # unchanged

 execute()
+  try:
     _execute_iterations()
       for each iteration:
         run_rmg()
-        run_sa() / run_arc()          # unbounded: a step that never returns is never cut
+        with _bounded_by_max_t3_walltime():   # one-shot SIGALRM for the remaining budget
+          run_sa() / run_arc()
         if check_overtime(): break    # still there, still between steps
+  except T3WalltimeExceeded:
+    log_max_time_reached()            # summaries and footer still written

 run_arc()
   try: arc.execute()
+  except T3WalltimeExceeded:          # BaseException: the handler below cannot see it
+    logger.error(... ARC project directory: <paths['ARC']> ...)
+    raise
   except Exception: logger.error('ARC crashed with ...'); raise

A run that RMG itself stopped at its wall time is now terminal: restart_rmg is not set, so the
same wall time is not spent twice. The stop time is kept per iteration in rmg_walltime_stops, read
from RMG's execution terminated at line, else the run start plus its last Execution time, else
RMG.log's mtime — the source is recorded alongside the time, so a weaker source is visible as one.

max_T3_walltime now bounds the long step rather than only the gap between steps. The timer
terminates live multiprocessing children before raising, because a ProcessPoolExecutor otherwise
waits for its running tasks on the way out. T3WalltimeExceeded derives from BaseException so an
except Exception inside the bounded step cannot swallow the budget.

No scheduler coupling: T3 learns nothing about PBS. max_T3_walltime's default and units are
unchanged, and a normally completed run is handled exactly as before.

Evidence

Before: a wall-time-killed RMG writes no MODEL GENERATION COMPLETED, so check_rmg_status()
returned (True, False), restart_rmg was set, and the run was repeated from the start — which
contradicts the project decision that a wall-time kill counts as converged with its kill time
recorded. A step that never returned was never cut, because the only budget check sat after it.

After: 16 new tests in tests/test_main.py cover both halves, including the negative controls
that matter most here —

test_rmg_walltime_stop_is_terminal_and_not_restarted                        # the fix
test_rmg_log_without_walltime_stop_is_still_restarted                       # a crash is NOT a kill
test_rmg_max_iterations_stop_is_still_restarted                             # nor is a max-iteration stop
test_rmg_walltime_stop_in_an_earlier_run_of_an_appended_log_does_not_count  # appended logs
test_rmg_completed_run_is_distinguishable_from_a_walltime_stop
test_rmg_walltime_stop_time_sources                                         # all three sources
test_max_t3_walltime_bounds_a_step_that_never_returns                       # the bound fires
test_max_t3_walltime_bound_stops_a_process_pool                             # children are terminated
test_max_t3_walltime_bound_arms_nothing_without_a_budget_and_always_restores
test_max_t3_walltime_already_spent_fires_at_once
test_resumed_arc_run_is_bounded_by_max_t3_walltime                          # restart() path too
test_max_t3_walltime_bound_leaves_the_callers_children_alone                # only this step's children
test_max_t3_walltime_bound_restores_the_callers_itimer                      # the caller's own alarm
test_a_cut_arc_run_logs_its_project_directory                               # the cut is reported

Full suite on the branch, run locally: 2 failed, 2899 passed, 463 warnings in 2555.52s.
tests/test_main.py alone at this head: 63 passed in 208.22s.
ruff check . → All checks passed!

Build and Test T3 is red at this head, and it is red on main too — this branch did not cause
it.
main's own daily CI was green through 2026-11-15 and has failed every day from 2026-11-16
to 2026-11-24 inclusive, nine consecutive runs, the last six at the unchanged head 4043bb98. This
PR was opened 2026-11-24, eight days after main went red. The 14 failures are all in
tests/test_pdep/test_pes_qm.py and tests/test_pdep/test_pes_loop_integration.py and are
level-of-theory spelling mismatches (wb97xd vs wb97xd2023) plus the prior-QM adoption that
depends on them — CI resolves ARC at its HEAD rather than a pin, so an upstream rename turned the
expectations stale. Those two files are not reachable from this diff, which touches only
t3/main.py's wall-time path and tests/test_main.py, and all 66 of their tests pass locally
at this head (66 passed in 107.28s) against an older local ARC.

Both failures are pre-existing and environmental, proven by running each id alone in a separate
source tree at official/main, one at a time:

test id alone on official/main alone on this branch
tests/test_functional.py::test_computing_thermo FAIL — cantera._utils.CanteraError … Application::findInputFile FAIL, identically
tests/test_simulate/test_cantera_idt.py::test_worker_failure_logging FAIL — socket.py:236 PermissionError: [Errno 1] Operation not permitted FAIL, identically

The second is the sandbox the run happened in, not the code: its brute-force IDT SA spawns workers
that cannot open a socket there. It is expected to pass in CI.

What a user sees change, and what is still not covered (CLEAN line 6)

1. ARC jobs already submitted to a server are left running, and now say so. When the budget runs
out inside the bounded ARC step, nothing cancels anything server-side. Until this PR that was also
silent: T3WalltimeExceeded derives from BaseException, so the except Exception around
arc.execute() cannot see it, and the ARC terminated, execution time: ... line is skipped — the
unwind reached only log_max_time_reached(), which names a time limit and no directory. run_arc
now logs an error naming the ARC project directory (self.paths['ARC']) and saying the submitted
jobs may still be running there and that T3 will not collect their results.
Test: test_a_cut_arc_run_logs_its_project_directory — asserts the project directory and both
claims appear in the message; proven red without the handler in a clean git archive tree
(AssertionError: Expected 'error' to have been called once. Called 0 times.).
Not covered: T3 still does not cancel those jobs. This PR makes the fact visible; it does not add
cancellation, and a user who wants the jobs stopped must do it on the server.

2. A cut inside process_arc_run cannot be read as done on the next run. The ARC finalization
marker is the idempotence guard: run_arc clears it before the run and it is written only once the
method completes, so a cut anywhere inside leaves no marker,
check_arc_finalization_complete() is False, and the restart re-runs the whole method. The
mid-method t3_status updates are in memory and die with the process, so no partial status is
persisted. The one step that writes a durable directory, _capture_pdep_ts_artifacts(), is
crash-safe by construction rather than by luck: the capture is built in a staging directory,
self-verified with the same verify_capture() a downstream consumer would use, and only then
swapped into place (existing tree renamed aside, then os.replace onto the vacant path), so
PDep_capture is never observed partial and the os.path.isdir(...) check upstream of it cannot
see a torn capture.
Test: the restart path is covered by test_resumed_arc_run_is_bounded_by_max_t3_walltime; the
marker and capture-swap behaviour is pre-existing and already covered by the tests/test_pdep
capture tests this PR does not touch.
Not covered: a cut mid-capture can leave the staging directory and the renamed-aside
old-capture temporary directory on disk. That is disk litter, not a wrong read — nothing
enumerates either — and this PR does not clean it up.

3. The timer terminates only the children the bounded step itself started, and none of them holds
a file T3 reads later.
_on_alarm snapshots multiprocessing.active_children() on entry and
terminates only children absent from that snapshot, so a caller's own pool survives. Of the children
a bounded step starts, the only one that writes a file is the brute-force SA worker in
t3/simulate/cantera_idt.py, and it writes exactly one: the perturbed mechanism copy
<SA>/{thermo|kinetics}_{index}.yaml, removed in a finally that a SIGTERM from terminate()
skips — so a cut can leave one behind. Nothing reads it: there is no glob or listdir over
paths['SA'] anywhere in t3/, the path is deterministic per task, and the next run's
perturb_enthalpy / perturb_reaction_rate_coefficient overwrites it unconditionally. The SA YAMLs
themselves (paths['SA IDT dict'], paths['SA IDT dict top X']) are written by the parent after
the pool closes, and the workers run with save_yaml=False — so a terminated child cannot leave a
half-written SA YAML at all.
Test: test_max_t3_walltime_bound_leaves_the_callers_children_alone (the snapshot) and
test_max_t3_walltime_bound_stops_a_process_pool (no pool worker survives the cut).
Not covered: the leftover perturbed-mechanism file is not deleted on a cut.

What a reviewer should look at: the finally in _bounded_by_max_t3_walltime() — it restores
the caller's handler before rearming the caller's timer, and restores the remaining time rather
than the original delay. Getting that order wrong lands the caller's alarm in our handler and raises
out of a finally.

Merge Danger

Door: two-way

Every change is additive or a widening of a return value; reverting restores the previous behaviour
exactly. Nothing persisted on disk changes format.

Blast Radius: callers of check_rmg_status()

check_rmg_status() returns RMGRunStatus instead of tuple[bool, bool]. It is still a tuple, so
indexing and began, terminated, *_ = ... keep working, but a caller written as
began, terminated = t3.check_rmg_status() now raises ValueError: too many values to unpack —
walltime_stop is a third field. Every in-tree caller is updated; an out-of-tree caller of this
method would need the same one-line change.

The second risk worth naming is the SIGALRM timer. It is armed only when max_T3_walltime is set,
only from the main thread (elsewhere it logs a warning and runs unbounded, as before), and the
previous handler and timer are restored in a finally. A process that installs its own SIGALRM
handler around a T3 call gets it back unchanged.

Comment thread tests/test_main.py Resolved
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect T3 restart decisions and its long-running SA and ARC work.

The PR needs changes before merging because queued RMG retries and pressure-dependent SA still bypass the intended stop behavior.

Findings

  1. P1 RMG repeats stopped runs ▶
  2. P1 Some SA ignores the deadline ▶

Summary

This PR recognizes RMG's own wall-time stop and adds timers around SA and ARC work.

  • RMG wall-time stops no longer trigger a full restart.
  • T3 stops long SA and ARC steps when its time budget runs out.

Reviews (2) · Last reviewed commit: "Treat RMG's own wall-time stop as termin..." · Reviewed by Greptile

Comment thread t3/main.py Resolved
Comment thread t3/main.py Resolved
Comment thread t3/main.py Resolved
…lltime

check_rmg_status() now reports a third state. When the latest run in
RMG.log ends in RMG's wall-time TERMINATED block, the run is terminal,
so a restart no longer re-runs it. Its stop time is recorded in
T3.rmg_walltime_stops, apart from a normally completed run. Logs
without that block (crash, foreign kill, max-iterations stop) are
restarted as before.

max_T3_walltime is now enforced while the SA and ARC steps run, not
only between steps. A SIGALRM timer cuts the step, terminates T3's
multiprocessing children, and skips the final RMG run.
@alongd

alongd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

@greptileai review

Comment thread t3/main.py
Comment on lines +1919 to +1921
rmg_status = self.check_rmg_status()
if rmg_status.walltime_stop is not None:
self.record_rmg_walltime_stop(iteration=self.iteration, walltime_stop=rmg_status.walltime_stop)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 RMG repeats stopped runs

run_rmg() checks for a wall-time stop only after rmg_runner() returns. With rmg_execution_type='local', the runner still treats that stop as a failure and can submit the same run up to five times before returning. Users can therefore spend the same wall-time budget repeatedly. Apply the terminal-stop check inside the runner's retry decision too.

Comment thread t3/main.py
if self.t3['sensitivity']['global_observables'] is not None \
and any(go.lower() == 'idt' for go in self.t3['sensitivity']['global_observables']):
idt_simulate_adapter = simulate_factory(simulate_method='CanteraIDT',
with self._bounded_by_max_t3_walltime():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Some SA ignores the deadline

The new SA timer ends before determine_species_and_reactions_to_calculate(), but that method also runs pressure-dependent SA. For a selected pressure-dependent reaction without cached results, it reaches run_arkane_job() without a timeout. That calculation can still exceed max_T3_walltime indefinitely. Include this SA path in the remaining budget and pass that budget to the Arkane timeout.

…rkane job

The local-queue re-submit loop now ends when the run it waited for
stopped at RMG's own wall time. The wall-time detector moved from
t3/main.py to t3/runners/rmg_runner.py so both can use the one parser.
A crash is re-submitted exactly as before.

The P-dep SA's Arkane job gets the remaining max_T3_walltime as its
timeout. A spent budget or a timed-out job raises T3WalltimeExceeded,
so T3 ends as it does when the Cantera SA or ARC runs out of time.
Without max_T3_walltime the call is unbounded, as before.

ArkaneMESolverAdapter takes a timeout and forwards it.

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.

2 participants