Expand description
Run a journey in the logged-on user’s interactive session from a session-0 (SSH) process. Run a journey in the logged-on user’s interactive desktop session from a session-0 process (an SSH logon or a service on Windows), through a ONE-SHOT Task Scheduler task.
Why: a hidden WebView2 app never gets a ready window from session 0, so a native journey driven over SSH fails with “app window never became ready … session 0”. The whole journey command (the harness AND the app) must run in the interactive session; this module relaunches it there.
Design (see the README, Windows section):
- Opt-in only:
opted_in(--interactiveorRIGHTKIT_QA_INTERACTIVE=1). Without it a session-0 process keeps failing with the existing clear error (Decision::NotOptedIn). decideis pure: it mapsSessionFactsto aDecision. The task is only created when the current account is the console (logged-on interactive) account.- The task runs THIS executable in
__child <spec.json>mode (child_main), nevercmd.exeor a shell: the journey program and its arguments travel as JSON data and are spawned as argv, so no journey argument is ever parsed by a shell. Only one generated path appears on the task command line, quoted with theCommandLineToArgvWrules (quote_windows_arg) and XML-escaped (task_xml). - The child redirects stdout and stderr to files in a private temp dir and writes the exit code file last, by rename (atomic). The parent polls, streams new output, and propagates the code.
run_interactiveowns a cleanup guard: the task is ended and deleted and the temp dir removed on success, error, timeout and unwinding.
Account and token: LogonType = InteractiveToken, UserId = the current account, RunLevel = LeastPrivilege. No password is stored, requested or accepted. Task Scheduler runs an
InteractiveToken task only for a user who is logged on, in that user’s session.
Structs§
- Account
- A Windows account,
domain\user(domain may be empty). - Child
Spec - Everything the child wrapper needs; written as JSON into the job directory.
- Request
- One interactive run.
- Schtasks
schtasks.exefrom%SystemRoot%\System32, invoked with argv (no shell).- Session
Facts - What the process can tell about where it runs. Pure data so
decideis testable. - Task
Spec - What the generated task runs.
Enums§
- Console
User - Who is logged on at the physical console.
- Decision
- Stream
Constants§
- CHILD_
MARKER_ ENV - Set by the child wrapper in the journey’s environment so a journey never relaunches itself.
- ERR_
FILE - EXIT_
FILE - OPT_
IN_ ENV - Opt-in environment variable (
1ortrue). - OUT_
FILE - PID_
FILE - SPEC_
FILE - Files inside the job directory.
- TASK_
FOLDER - Task Scheduler folder every one-shot task lives in; the task name is
<folder><uuid>. - TASK_
XML_ FILE - WRAPPER_
FAILED - Exit code the wrapper reports when it could not start the journey at all.
Traits§
- Scheduler
- Task Scheduler operations, a trait so the orchestration is tested without a real scheduler.
Functions§
- child_
main - The child wrapper, run inside the interactive session as
<exe> __child <spec.json>. Reads and deletes the spec, starts the journey with the files as stdout and stderr, records its pid, waits, then writes the exit code file by rename. Returns the journey’s exit code. - decide
- non_
interactive_ reason Some(reason)when the process is outside the interactive desktop;Nonewhen interactive or undeterminable (the same rule the launch hint uses).- opted_
in - True when the flag is given or the environment value is
1/true. - parse_
exit_ code - Parse the exit code file: one decimal integer. Windows codes above
i32::MAX(for example0xC0000005) are accepted as unsigned and returned with the same bit pattern asi32. - quote_
windows_ arg - Quote one argument for a Windows command line (
CommandLineToArgvWrules). - run_
interactive - Run the request through
schedand return the journey’s exit code. Output is handed tosinkas it is written. Errors: task creation or start failure, the task never starting, the timeout (the journey tree is killed), an unreadable exit file. - same_
account - Same account: user names equal ignoring case, and domains equal ignoring case unless either side has none.
- select_
env - Environment forwarded to the journey. Scheduled tasks do not inherit the SSH environment, so it
is explicit: every
RIGHTKIT_*variable (except the opt-in and child markers), the variables named inpass(case-insensitive), thenexplicitpairs, which win. - session_
facts - Facts about this process. Not Windows: nothing known, so
decidereturnsDirect. - task_
xml - The one-shot task definition: no triggers (started only by
/run), InteractiveToken for the given user, least privilege, no password anywhere, a hard execution time limit. - utf16le_
with_ bom - UTF-16 little endian with a byte order mark: the encoding
schtasks /xmlalways accepts.