Skip to content

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

Merged
abrichr merged 11 commits into
mainfrom
codex/2376-private-runner-diagnostics
Nov 23, 2026
Merged

abrichr merged 11 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.

# Conflicts:
#	packages/flow/openadapt_flow/at_rest.py
#	packages/flow/tests/conftest.py
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: 35e0ba4

This is a delta review of the merge resolution only. The last approved head is 2af6759 (Gemini APPROVE, 2026-11-22). The new head 35e0ba4 is a merge of origin/main at 2ea7480 into 2af6759 and has no other commits. 2af6759...35e0ba4 brings in 25 commits from main, #2423 among them. To separate Gemini's edits from main's content, I compared the PR's net diff over its main parent before the sync (c416c46...2af6759) with the net diff after it (2ea7480...35e0ba4).

The approval depends on CI passing. Every check was still pending when I reviewed.

Resolution vs. main

The file list is the same as before the sync, except for one new entry, tests/test_connector_service_rotation.py (+3). The at-rest and conftest hunks were rebased onto #2423 with the same content they had before.

packages/flow/openadapt_flow/at_rest.py: keeps all of #2423

diff origin/main:at_rest.py 35e0ba42:at_rest.py (main is now c6e1750, and the file is unchanged there since 2ea7480) shows exactly four differences. All four are the PR's existing, already-approved ledger relocation:

  1. Docstring: adds the sentence "OPENADAPT_FLOW_PLAINTEXT_LEDGER_DIR relocates only this ledger." It is now attached to Encrypt recordings, bundles and runs at rest by default (key hierarchy) #2423's "each output that still can't be encrypted" bullet, and the old pre-Encrypt recordings, bundles and runs at rest by default (key hierarchy) #2423 wording ("Once every consumer reads encrypted artifacts (Encryption at rest: make the remaining artifacts sealable, then default to strict #1751)...") is gone, as it should be.
  2. Adds the LEDGER_DIR_ENV constant.
  3. ledger_path() uses LEDGER_DIR_ENV when it is set, and otherwise uses _home(). The ledger file name is unchanged, and recent_plaintext_writes() still reads through ledger_path().
  4. The AtRestRefused message for an unwritable ledger now names LEDGER_DIR_ENV instead of HOME_ENV. The refusal itself is unchanged: it still raises, and nothing is written.

No #2423 check is dropped, and no plaintext default comes back. The encrypt-by-default mode, OPENADAPT_ENCRYPT_AT_REST=0, the --no-encrypt flags, the OPENADAPT_FLOW_PLAINTEXT_AT_REST reason opt-out, unsealed_write and strict refusal are all byte-identical to main. No P0.

packages/flow/tests/conftest.py: default-at-rest mode not weakened

The only difference from main is one line in _isolation_env: "OPENADAPT_FLOW_PLAINTEXT_LEDGER_DIR": None. It unsets the new variable so that a value from the environment can't redirect the ledger during tests. OPENADAPT_TEST_DEFAULT_AT_REST handling is the same as on main: the skip hook, _SESSION_AT_REST_HOME, and the conditional unset of OPENADAPT_FLOW_PLAINTEXT_AT_REST. tests/default_at_rest_skips.txt is not touched.

test_connector_service_rotation.py autouse BYOC_PROFILE: justified, does not hide a failure

  • This file arrived from main (rotation commits 21f3283 and 4b5abe1) after the last approval. Every test in it calls windows_service.serve(). This PR adds settings.validate_run_config() to serve() before rotation and polling.
  • Production fails closed. validate_run_config() raises ConnectorConfigError when no profile is set, and also when the deployment file is unreadable or runtime.profile is not standard or regulated. serve() and connector run log the error and return 2 before any client is built. test_connector_deployment_preflight.py::test_run_and_service_refuse_invalid_profile_before_any_request covers both entry points for a missing profile, {}, demo and invalid, and asserts that no client is constructed.
  • The fixture supplies what a real deployment must have: a valid standard profile. It doesn't bypass validation. Every test in the file exercises a validly configured service, so autouse is the right scope, and setting it per test would repeat the same line in each one.
  • Without the fixture, test_unreadable_store_stops_before_polling (which asserts == 2) would pass vacuously on the missing-profile refusal. The fixture makes that test exercise the store failure again. Nit, not blocking: that test could also assert that CredRead was called, so it can't pass vacuously on some future early return.
  • test_connector_windows_service.py uses the same approach (profile in connector.toml), and it was already approved.

Protected paths and CI

  • No path in .github/agent-safety-manifest.json is touched. The only workflow changed is connector-windows-service.yml, which is unchanged since the approved head and is not protected. CODEOWNERS has only the * catch-all for the connector, at_rest.py and test paths.
  • gh pr checks 2403 at review time showed 16 checks pending and 2 skipping (External links, unsupported-python-guard). None had failed yet. "connector service (windows, py3.12)" and the flow package tests are the ones that matter for this resolution.

Verdict: APPROVE, if CI passes. The resolution keeps #2423 as it is and adds only the PR's existing ledger-dir change. The new fixture provides a required precondition and doesn't hide a missing one.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 35e0ba4

Delta review versus previously Gemini-approved head 2af67593ccbb9c80605a624d1ba00ce1a0cfbbb1: clean origin/main (2ea74802f) merge plus a focused 3-line BYOC_PROFILE fixture update in packages/flow/tests/test_connector_service_rotation.py supplying a valid runtime: {profile: standard} deployment file for validate_run_config(). Zero behavior regression. Approve for merge on green CI.

@abrichr
abrichr merged commit d82ccc9 into main Nov 23, 2026
61 of 62 checks passed
@abrichr
abrichr deleted the codex/2376-private-runner-diagnostics branch November 23, 2026 18:30
abrichr added a commit that referenced this pull request Nov 24, 2026
#2476)

* feat(flow): one verdict kernel, a fail-open harness and a fold ratchet

Fail-open blockers kept coming back one PR at a time. This fixes the
classes once:

- openadapt_flow/verdict.py: obligations fixed from the plan, settle(),
  allow-list codes, run binding, trust labels. An empty set, a short read,
  a raised probe, another run's result or an unknown code never passes.
- tests/failopen: 13 generic mutations run against every @verdict_site.
  The self-test flags 14 historical bugs rebuilt from this repository's
  code and passes their fixes; three live sites on main are strict xfails
  owned by #2470, #2258 and the connector status follow-up.
- scripts/check_verdict_folds.py: fails CI when a file gains a
  hand-written fold; never on a drop.
- verify_run: an empty or unpaired effect list is INDETERMINATE, unknown
  and unchecked (latent behind min_length=1).

See packages/flow/docs/FAIL_CLOSED.md.

* fix(flow): close the gaps a review found in the verdict kernel and harness

- settle matches on subject key and run binding; obligations dedupe on both
- a HELD token is bound to its subject, so replace() can't move it
- observe refuses to map an exception to Observed
- owned sites list their exact known failures (strict xfail per case)
- pre-fix controls are pinned copies, never live code; S3b shows the
  undo fix still passes an unlisted per-write code
- the ratchet compares per-kind totals, so moving code into a new module
  is not a new fold, judges each exit of an except, refuses a site id on
  two functions, and runs in the smoke job on every change

* fix(flow): second review round on the verdict kernel and harness

- HELD is minted only inside the kernel's constructors, so replace() can't
  copy or restore it; one result claimed by two obligations conflicts
- known failures carry the seed and lens, so a new case can't hide
- the ratchet checks every @verdict_site has a spec on every change, finds
  conditional sites, judges every branch of a returned value, and lowers
  the baseline per kind so a moved fold keeps its allowance
- M7 is out of P1; the S5 seeds plan 20 runs and a gate needing all 20
  passes

* fix(flow): settle the positive controls, verify-run folds and receipt lines on the kernel

- check_verdict_folds: count a broad handler that falls through, leaves by
  break, or names Exception in a tuple or by attribute (swallow_wide); add
  says_unchanged and empty_change_set for "nothing else changed" claims; a
  file that doesn't parse fails; a spec id is an id= or factory argument.
- verdict: count the obligations that claim a result, not repeats of it;
  add Result.nothing_else (any change refutes, zero holds only on a
  complete read).
- harness: three-level monotonicity (P6), M7 appends a separate equal
  copy, M3 says when the plan is kept, M15 partial "nothing else" read,
  M16 a result turned bad.
- hard_invariants and versions build verdicts with settle; versions no
  longer lets a duplicate or missing-history row hide another author.
- verify_run._aggregate/_observed settle against cfg.effects;
  receipt_record._line and _tally_lines move onto the kernel.
- wire_tap is a registered site now that #2470 merged.
- Baseline measured again after merging main; every kind is at or below
  a clean origin/main.

* fix(flow): close the log-call hole in the swallow check; state the provenance boundary

A handler that only logs a not-checked word still swallows; only a call that
stores the value records it. M15 must not raise a refuted seed. Observed and
Result.held say the adapter establishes which run produced a read.

* fix(flow): close the four ratchet and observed gaps Gemini found

The empty-change test is read from either side, a [0:N] slice counts like
[:N], builtins.all/any count as folds, and an unplanned verdict beside a
refuted one makes _observed unknown.

* docs(flow): record how the fold baseline was measured and why unread-first stays

* chore(flow): bump verdict_folds_baseline for connector/executor.py from main (#2403)
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