Skip to content

dobatch_wait fails with misleading r(198) when DOBATCH_STATA_PID holds more than 2,500 PIDs #4

Open

Description

@tatyanaderyugina

Summary

dobatch_wait (v1.1, 28jan2026) fails when $DOBATCH_STATA_PID holds more than 2,500 PIDs. It parses the global with syntax [, pid(numlist >0 integer)], and Stata caps a numlist at 2,500 elements. Because the call is wrapped in cap, the user sees a misleading message:

Error parsing the global variable DOBATCH_STATA_PID
DOBATCH_STATA_PID must contain only positive integers
r(198);

The real error is r(123), pid() invalid -- invalid numlist has too many elements.

This came up in practice: a driver script launched 8,808 jobs with dobatch (Stata 18 MP, Linux), then crashed at the final dobatch_wait even though every job had launched normally.

Minimum working example

No background jobs are needed. The example only exercises the PID parsing (DOBATCH_WAIT_TIME_MINS = 0 skips the polling loop).

global DOBATCH_WAIT_TIME_MINS = 0   // skip the polling loop; only parsing is tested

* 2,500 PIDs: parses fine
global DOBATCH_STATA_PID ""
forvalues i = 1/2500 {
	global DOBATCH_STATA_PID "$DOBATCH_STATA_PID `=100000+`i''"
}
cap noi dobatch_wait
di "2,500 PIDs: rc = " _rc

* 2,501 PIDs: fails with r(198) "must contain only positive integers"
global DOBATCH_STATA_PID ""
forvalues i = 1/2501 {
	global DOBATCH_STATA_PID "$DOBATCH_STATA_PID `=100000+`i''"
}
cap noi dobatch_wait
di "2,501 PIDs: rc = " _rc

* The underlying error that dobatch_wait's -cap syntax- swallows
local 0 ", pid($DOBATCH_STATA_PID)"
cap noi syntax [, pid(numlist >0 integer)]
di "direct syntax call: rc = " _rc

Output (Stata 18.0 MP, Windows 11; the original failure was on Linux):

2,500 PIDs: rc = 0

Error parsing the global variable DOBATCH_STATA_PID
DOBATCH_STATA_PID must contain only positive integers
2,501 PIDs: rc = 198

pid() invalid -- invalid numlist has too many elements
direct syntax call: rc = 123

The global DOBATCH_STATA_PID = trim("$DOBATCH_STATA_PID") step in dobatch.ado is fine at this length (tested up to 8,808 PIDs, about 70,000 characters). Only the numlist parse in dobatch_wait fails.

Possible fixes

  • Validate the PIDs without a numlist, e.g. loop over the words with confirm integer number and check that each is > 0.
  • On Unix, ps -p accepts the full list. On Windows, a very long Get-Process -Id a,b,c,... command line could hit the command-line length limit, so it may need to be checked in chunks.
  • At minimum, report the actual syntax error (or mention the 2,500 limit) instead of "must contain only positive integers."

Workaround

Clear the global before waiting, so dobatch_wait falls back to waiting for all background Stata MP processes:

global DOBATCH_STATA_PID ""
dobatch_wait

(On a shared Unix server this also waits for other users' stata-mp processes, since the count comes from ps aux.)

Activity

  1. added a commit that references this issue on Oct 2, 2026
  2. added a commit that references this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions