Get job ID from within a job

Say I launch a job using job_id = rstudiapi::jobRunScript(...). Then I have the job_id in the main session, but how do I access it from within the child session? Failed attempts include

  1. parsing through environmental variables. It fails because Sys.setenv() is session-specific.
  2. Figuring out how rstudiapi:::callRemote() works. Seems you can only launch rstudiapi functions.
  3. rstudioapi::documentId() does not return the job id.

Goal: I'd like to wrap the code in try() and let the child itself call rstudioapi::jobSetState(job_id, "failed") if an error is caught. This enables returning work up until the error to minimize loss. In the future, I may also want to callrstudioapi::jobSetProgress() from within the job.