Skip to content

fix(connector): sealed BYOC jobs finish cleanly; secrets_ref key opens the report; no job escapes a stop - #2523

Merged
abrichr merged 1 commit into
mainfrom
claude/byoc-sealed-staging
Nov 22, 2026
Merged

abrichr merged 1 commit into
mainfrom
claude/byoc-sealed-staging

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Follow-up to #2300, stacked on it. Retarget to main once #2300 merges.

What this fixes

Fail-open class: an unknown outcome reported as a failure, or as a halt for every job.

  1. Sealed bundles halted every job. The connector wrote its own plaintext inputs into the run directory: governed_policy.json, params.json, managed-dispatch.json, readback-params.json and qualification-authority.json. A sealed bundle's run directory is a sealed set, and its finalize refuses any plaintext file, so each sealed job made its writes and then halted as child_outcome_unknown. These inputs now go in a 0700 staging directory next to the run, inside the job's 0700 temporary directory. That directory is removed when the job ends, however it ends. The child gets the same files at their new paths.
  2. A key delivered only by secrets_ref couldn't open the report. The child received the bundle key but the daemon did not, so the sealed report was unreadable and the run halted. The report is now opened with the key from the child's environment. The key is used in memory for that read only and is never logged or written.
  3. A stop could miss a job that was just submitted. A stop signal between pool.submit and registering the job's future left that job out of the shutdown cancel_job. The job id is now listed before the submit.

Tests

The new tests are in packages/flow/tests/test_connector_sealed_staging.py.

  • A real child process seals the run the way the governed child does: a sealed writer, a sealed report.json, then finalize(adopt_external=True). It runs through the real _subprocess_runner, with the key only in secrets_ref. The job finishes as success, not halted. The run directory is empty before the child starts, the staging directory is 0700, and everything is removed afterwards.
  • A sealed report read without the child's key gives no report.
  • A plaintext file in a sealed run directory makes finalize refuse. This is the failure the staging move avoids.
  • A stop between submit and register still cancels the job.

The governed openadapt_flow run child itself is not exercised end to end here, because that needs a qualified program and a live managed-delivery authority. The connector suites pass (202 tests, 81 subtests), along with the sealed-at-rest tests, mypy and ruff. Before the fix, three of the four new tests fail.

…s_ref opens its report; no job escapes a stop

fail-open class: lost-outcome-as-failure (unknown outcome).

- The connector staged its own plaintext inputs (governed_policy.json,
  params.json, managed-dispatch.json, readback-params.json,
  qualification-authority.json) inside the run directory. A sealed bundle's
  run directory is a sealed set whose finalize refuses any plaintext file, so
  every sealed job wrote and then halted as child_outcome_unknown. These files
  now go to a 0700 staging directory beside the run, inside the job's 0700
  temporary directory, which is removed when the job ends however it ends. The
  child gets their paths as before.
- A bundle key delivered only through the job's secrets_ref reached the child
  but not the daemon, so the sealed report could not be opened and the run
  halted. The report is now opened with the key from the child's environment.
  It is held in memory for the read only and is never logged or written.
- A stop signal between pool.submit and listing the job's future left that job
  out of shutdown's cancel_job. The job id is now listed before the submit.

Tests (tests/test_connector_sealed_staging.py):
- A real child process seals the run as the governed child does (writer,
  sealed report, finalize with adopt_external) through the real
  _subprocess_runner, with the key only in secrets_ref. It finishes as
  success, not halted. Nothing is in the run directory before the child, the
  staging directory is 0700, and everything is removed afterwards.
- A sealed report read without the child's key is unknown.
- A plaintext file in a sealed run directory is refused.
- A stop between submit and register still cancels the job.
The governed `openadapt_flow run` child itself is not exercised end to end. It
needs a qualified program and a live managed-delivery authority.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: a662c56

Gemini cross-vendor review of the full diff against feat/byoc-runner-pilot. Below is a faithful summary of Gemini's output. It found no blockers.

  1. Plaintext in the run directory. All plaintext files the connector generates have moved to the staging directory: params.json, governed_policy.json, qualification-authority.json, managed-dispatch.json and readback-params.json. run_dir stays clean, so the sealed finalize succeeds.
  2. Staging permissions and cleanup. The staging directory is created 0700 and explicitly chmoded. It sits inside the TemporaryDirectory, so it is wiped on every exit path: success, failure or exception.
  3. Key exposure. The key is read from child_env in memory and passed straight to the sealed reader. It is never logged, written to disk, or put in the connector's argv or process table.
  4. Report read. resolve().relative_to(root.resolve()) keeps the read inside the sealed root. Every fallback fails closed, returning {} for a missing file, a wrong key or a decryption failure. json.loads plus the dict check means garbage cannot read as success.
  5. Pending set. It is guarded by active.lock. The id is added before pool.submit and removed after the future is registered, so a stop in between still reaches the job through active.ids() and shutdown's cancel_job.
  6. Tests. They prove what they claim: the real-child sealed run, key handling, the plaintext refusal, and the submit/register gap.

Base automatically changed from feat/byoc-runner-pilot to main November 22, 2026 15:14
@abrichr abrichr closed this Nov 22, 2026
@abrichr abrichr reopened this Nov 22, 2026
@abrichr
abrichr merged commit 69f6757 into main Nov 22, 2026
108 of 111 checks passed
@abrichr
abrichr deleted the claude/byoc-sealed-staging branch November 22, 2026 16:24
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.

1 participant