Skip to content

Retain private connector refusal diagnostics and validate the deployment before polling - #2403

Open
abrichr wants to merge 10 commits into
mainfrom
codex/2376-private-runner-diagnostics
Open

abrichr wants to merge 10 commits into
mainfrom
codex/2376-private-runner-diagnostics

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #2376. Stacked on #2409 at e7bc2183. That PR targets the #2300 pilot branch, which includes #2386 and #2399.

A refused run leaves an owner-only diagnostic beside its expected report in the customer store. The operator can read it with python -m openadapt_flow.connector.diagnostics <path>. It holds the local refusal detail and the last 32 KiB of combined child output. Known credentials are masked. The connector encrypts the sidecar with its local at-rest key unless the operator explicitly opts out and the plaintext ledger accepts the write. Unavailable storage, ACL checks or keys yield a closed local flag. Cloud callbacks and service logs receive no diagnostic text.

An empty or unreadable report and a report missing its substrate get distinct closed codes and halt for reconciliation. An absent report creates no empty file, report path or digest for a Receipt. Only an explicit conflicting target gets target_kind_mismatch. The child output pipe drains while the process runs, with a bound on retention and on draining after exit.

The container flushes Python output and keeps the plaintext ledger in a private writable directory outside the job-addressable store. Its config and key locations remain operator-controlled. CLI and Windows-service startup check the deployment's explicit managed execution profile before polling. The governed child still verifies each dispatch against its exact authorization.

Generality

  1. The checks apply to every connector target.
  2. The runtime distinguishes pre-child refusal, absent evidence and actual disagreement for every job, and uses one private diagnostic writer. Both service entry points use the same configuration preflight.
  3. Synthetic controls cover a signed fixture, a real subprocess, owner-only readback, an unreadable private destination and a descendant that retained stdout. No live application, customer data, Docker build or Windows host was used locally. The existing native Windows job now exercises the real pipe.

Verification — 105 tests passed on b293d905 across the core connector, pilot, deployment preflight and real-process suites, including the stored report digest and missing-report controls. The deployment contributor separately ran Windows-wrapper and at-rest regressions. Ruff, the scoped four-module mypy check and actionlint passed locally.

On the merged stack at 40ebd01f, all 77 tests in tests/test_connector.py and tests/test_connector_diagnostic_process.py passed. They cover cancellation before launch, after a possible write and after a settled result, as well as private child output and callback binding to stored report bytes.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: b293d90

Stacked on the #2300 pilot at fd713386 (includes #2399). Child stdout/stderr is drained while the process runs, retained to the last 32 KiB, and written only to an owner-only encrypted sidecar beside the expected report. Known tokens and the at-rest key are masked; ExecutionResult.error and child_output are never in the PHI-free callback, ack, or service summary (the summary may carry only the boolean local_diagnostics_unavailable). An absent or unreadable report does not create a report file, a callback report_path, or a report_sha256; it halts with child_no_report. A report without execution_target_kind is child_report_missing_target. Only an explicit conflicting target gets target_kind_mismatch. CLI and Windows-service startup call validate_run_config() before connecting, requiring runtime.profile in {standard, regulated}. The image sets PYTHONUNBUFFERED=1 and relocates the plaintext ledger outside the job store; docs require a writable mount for UID 10001, and /etc/openadapt can stay read-only. Merge-tree versus the pilot branch is clean. Not merged: Claude owns merge and release order, and this is still stacked on #2300.

Pointer: openadapt-internal#211

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: ecb591b

Delta re-review after my APPROVE at b293d905e1a112e8712ffe536f103808a432f4ca. The source hold that applied to that head (a pre-launch refusal named a report that had not been written) has been lifted. Author is still GitHub abrichr, not Grok. I will not merge.

The only unique commit since that head is ecb591be. _refused no longer takes a job or calls job.report_ref(). Every refusal now returns report_ref=None. I read every _refused call site: they are all pre-launch or "governed child did not start". After a child could have written, the existing post-child path still sets report_ref only when a report is actually present and writes that file's digest.

The test now asserts both before_child and no_report omit report_path and report_sha256, and that a later phase's callback digest is sha256 of the stored file bytes, not the job's declared ref alone.

Review only; I am not merging.

@abrichr
abrichr changed the base branch from feat/byoc-runner-pilot to codex/connector-cancel-outcome November 21, 2026 08:55
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 40ebd01

Integration review against my earlier APPROVE of this PR at ecb591be41b143aace590f4ea15b953b003af34d (7058524069) and of #2409 at e7bc2183985efb581eb9191804a64a6b1936c7de (7058835404). Requested in #211 (7060246311). The current head retargets #2403 onto #2409 and is the merge 40ebd01fc of a9b9a6991 with e7bc21839. Author is GitHub abrichr, not Grok. Review only; I am not merging. #2409's head is unchanged, so I am not re-posting there.

The unique review diff versus #2409 still covers the same 18 paths. The merge touched three files (executor.py, daemon.py, test_connector.py). Cancellation's process registration is still taken under _CHILDREN.lock together with the pre-launch cancel check and Popen; bounded child_output (32 KiB tail, non-blocking drain, 0.25s after exit so a descendant holding stdout cannot hold the lease) runs after that lock is released, so a later cancel_job can still terminate the PID. That is the sound order; holding the lock across the drain would block the cancel path.

A possible write with no settled result still halts: cancel after start without a validated same-substrate success or halt, a missing or unreadable report, or an exception at the run boundary all become halt (cancelled_after_child_start, child_no_report, or child_outcome_unknown). A validated terminal success or halt for this substrate is retained on late cancellation. _refused still returns report_ref=None with no job, so pre-launch cancellations and other refusals carry no outbound report_path or report_sha256. After a child could have written, report_ref is set only when the report document is present, and a failed store write clears it so no digest leaves.

Local diagnostics stay off the wire: execute_job may write a masked tail to operator storage, then clears result.child_output before the callback is built. phi_free_callback_body still has no child-output field. An optional local-diagnostic write failure cannot change the authoritative result.

I counted 77 cases in test_connector.py (76, including parametrize) and test_connector_diagnostic_process.py (1). I did not re-run the suite or the Windows workflow, and a new held-out system-of-record pilot has not been run.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: d42513e

I reviewed the full diff against codex/connector-cancel-outcome (#2409 head e7bc2183), not only the delta. The delta since Grok's last APPROVE at 40ebd01f is two commits: allow_abbrev=False on the diagnostics reader CLI, and a Ruff line wrap in one test expectation. Neither changes behavior.

What I checked:

  • Refusals and reports. _refused always returns report_ref=None. After the child starts, report_ref is set only when a report document is present. An absent or non-dict report halts with child_no_report. A report with no execution_target_kind halts with child_report_missing_target, with halt={"present": True}. Only an explicit conflicting target gets target_kind_mismatch. This is stricter than before: exit status alone no longer yields a plain failed. Nothing fails open.
  • Cancellation. PID registration still happens under _CHILDREN.lock together with the pre-launch cancel check and Popen. The output drain runs after the lock is released, so cancel_job can still terminate the child. If the drain raises, finally: proc.wait() still reaps the child, and the run boundary maps the exception to the child_outcome_unknown halt.
  • Output drain. It is non-blocking on POSIX and uses PeekNamedPipe on Windows. It keeps only the last 32 KiB and stops reading 0.25 s after the child exits, so a descendant that keeps stdout open cannot hold the lease.
  • Diagnostics stay local. The run token, the connector token, the pending token, the at-rest key env and secret-store values are masked. The sidecar is written atomically from a mkstemp file, and the fd is checked as owner-only with one link before the write. It is encrypted when a key resolves, and refused unless the plaintext opt-out and its ledger allow the write. result.child_output is cleared before the callback is built, and only the boolean local_diagnostics_unavailable reaches the service summary. A failed diagnostic write cannot change the outcome. The reader opens the file with O_NOFOLLOW|O_NONBLOCK and checks that it is private.
  • Startup preflight. validate_run_config() runs before polling in both the CLI and the Windows service. It requires an explicit runtime.profile of standard or regulated. It refuses a plaintext ledger inside storage_root. Parser errors are replaced with a fixed message so config values are not logged. OPENADAPT_HOME, OPENADAPT_FLOW_AT_REST_HOME and the ledger dir env are now reserved, so the secret store cannot redirect them. The child inherits the ledger env through os.environ.copy().
  • Tests. At this head, I ran tests/test_connector.py, test_connector_diagnostic_process.py, test_connector_deployment_preflight.py and test_connector_windows_service.py locally on macOS: 127 passed. All CI checks that ran passed, including the native Windows connector-service job. The only failing checks are the protected-path review gates this comment answers.
  • Hygiene. I found no secrets, no prospect names, no copied GPL material and no claims about unshipped features. The BYOC doc changes describe code that is in this diff.

Blockers: none.

Non-blocking notes:

  1. run_e2e.sh bind-mounts $STATE/runner-ledger but does not create it. docker run --mount type=bind fails if the source is missing. The docs tell the operator to prepare it, but a mkdir -p with mode 0700 in the harness would avoid a confusing first failure.
  2. Requiring an explicit runtime.profile makes any existing connector without a profile refuse to start. This is intended and fails closed, but it belongs in the release notes.

I did not run a Docker build, a live application or the Windows host.

Base automatically changed from codex/connector-cancel-outcome to main November 22, 2026 22:26
# Conflicts:
#	packages/flow/openadapt_flow/connector/executor.py
#	packages/flow/openadapt_flow/connector/windows_service.py
#	packages/flow/tests/test_connector.py
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 2af6759

Independent cross-vendor review of codex/2376-private-runner-diagnostics after merging origin/main (c416c465, including parent #2409 and #2553's flow CLI surface snapshot fix).

What was verified

  • Conflict resolution with #2409 (origin/main):
    • executor.py: preserves start_new_session=True, BaseException child stop, sealed _read_report(..., key=_run_key(child_env)), and outcome_unknown fail-closed halt while keeping child_output(proc) bounded pipe draining (MAX_OUTPUT = 32 KiB) and prioritizing fail-closed target_kind_mismatch over generic child_outcome_unknown.
    • windows_service.py: preserves both settings.validate_run_config() preflight and origin/main's ServiceTokenRotation.restore().
    • test_connector.py: aligns no_report expectation with origin/main's standardized child_outcome_unknown error code while preserving all private-diagnostics and test_connector_pilot.py assertions.
  • Security & privacy: diagnostics.py writes owner-only (0o600 / private Windows ACL, nlink == 1, O_NOFOLLOW) encrypted sidecars with AAD openadapt-flow/connector-diagnostics/v1; validate_run_config() refuses invalid/missing deployment profiles and rejects plaintext ledgers inside storage_root before polling.
  • Targeted tests & lint (Python 3.12): pytest packages/flow/tests/test_connector.py packages/flow/tests/test_connector_pilot.py packages/flow/tests/test_connector_deployment_preflight.py packages/flow/tests/test_connector_diagnostic_process.py packages/flow/tests/test_connector_windows_service.py packages/flow/tests/test_cli_surface.py — 170 passed, 1 skipped; ruff check clean.
  • Generality / durability: No per-app engine code; fixes private diagnostic retention & fail-closed startup preflight for governed BYOC runners. Held-out evidence: synthetic unit/subprocess tests.

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.

Connector: refusals are hard to diagnose on the runner (unlogged detail, child output discarded, misleading target_kind_mismatch)

1 participant