Skip to content

fix(pi): clear main's real-adapter lane and set-gate ratchet reds - #22951

Merged
buluoray merged 2 commits into
mainfrom
fix/pi-real-adapter-probe-wrap
Oct 22, 2026
Merged

buluoray merged 2 commits into
mainfrom
fix/pi-real-adapter-probe-wrap

Conversation

@kyleseaman

@kyleseaman kyleseaman commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Turn main's two red pi checks green again: the "Real Adapter Contract Tests" lane and the backend set-gate ratchet.

Both come from merged pi PRs that each passed alone and clash on main:

  1. Real Adapter lane (first seen at b700d47, failing run): all six pi_session tests in test/test_pi_real_adapter.py error at setup with kiro_crew.sandbox.SandboxUnavailableError: ... unshare(CLONE_NEWUSER) failed with errno 1 (EPERM), through resolve_spawn -> _pi_node_choice -> _pi_probe_wrap -> wrap_argv.
  2. Backend shards (every 3.12 shard and Windows shard 7): test/test_backend_cards_advertised.py::test_no_new_runtime_site_gates_a_field_backed_line_on_a_set fails with {('acp/client_mcp_array.py', 'ACP_BACKENDS_SESSION_MCP_ARRAY'): 4} against an allowlist of 2.

Why it matters

Both checks are required, so every backend PR rebased on main inherits two reds it did not cause (#22923 and #22911 among them). Meanwhile the pi contract facts go unmeasured and the set-gate ratchet stops guarding anything new.

Not a goal

  • Changing what the zero-tool ban does: pi still records and enforces "tools": [], kiro-cli still never reaches the record.
  • Converting the ratchet's other allowlisted sites, or raising any allowlist count.
  • Changing the sandbox, or what the real-adapter lane measures. The OS sandbox stays the only stand-in.
  • Giving the CodeBuild runners user namespaces.

What changed (motivation → approach → change)

1. Real Adapter lane (test-only, test/test_pi_real_adapter.py).

2. Set-gate ratchet (src/kiro_crew/acp/client_mcp_array.py).

  • Cause: fix(pi): honour an agent spec's zero-tool ban on pi sessions #22808 (pi zero-tool ban) added two self.backend in ACP_BACKENDS_SESSION_MCP_ARRAY tests in _mirrorless_member_mounts. test: count aliased, set-op and helper set gates in the card ratchet #22489 then merged the wider ratchet, and its allowlist for this file is 2 — the two older sites. Each PR was green alone.
  • Approach: the ratchet is shrink-only ("convert a site to read the field, then lower its count here"). Its docs offer no way to raise a count, so I left the allowlist alone. The two new sites don't ask what mcpCapabilities advertises (kiro-cli takes an array too). They ask who reads this backend's agent spec. registry.PROJECTIONS already declares that for every backend: NATIVE (kiro-cli reads it itself via --agent), MIRROR, EXTERNAL, or BROKER_ONLY (pi: no projection is written and the harness reads no spec of Crew's). The same file already reads that record rather than a set for per_tool_deny.
  • Change: records_zero_tools = projection_for(self.backend).kind is ProjectionKind.BROKER_ONLY, computed first; the early return becomes "not recording and not a member backend". Only mirror-less backends reach this function, via _resolve_session_mcp_servers after mirror_for. Today the result is the same as before: BROKER_ONLY = {pi} = mirror-less ∩ ACP_BACKENDS_SESSION_MCP_ARRAY. mirror_for has already resolved the record by this point, so an undeclared backend raised earlier and this adds no new failure mode. The file is back to its 2 allowed sites.
  • Two text-only follow-ups name the same seam: the ACP_BACKENDS_HONOR_ZERO_TOOL_BAN comment in agent_sdk/backends_mcp.py, and the rule recomputed in test_honor_zero_tool_ban_membership_matches_the_rule. The membership both describe is unchanged.

No file in this diff matches a Sensitive Change Review glob (checked with the script's own SENSITIVE_GLOBS).

Backwards compatibility

Compatible: same backends record and enforce the zero-tool ban as before (pi only, on this path); no constant, key or set membership changes.

Removes nothing: two set-membership tests are replaced by an equivalent read of the declared projection; no path, row, key or function is removed.

Tests

  • test_no_new_runtime_site_gates_a_field_backed_line_on_a_set: fails on main (4 > 2), passes here.
  • test/test_pi_zero_tool_ban.py, test/test_member_mount_pi.py: unchanged and green. Revert check: making the new predicate select NATIVE instead of BROKER_ONLY fails 8 of them, so they exercise this path.
  • test_honor_zero_tool_ban_membership_matches_the_rule: recomputes the rule through the same projection seam; the expected set is unchanged.
  • test/test_pi_real_adapter.py (-m real_adapter): the lane being fixed.

Manual verification

  • Real Adapter lane, run locally against the pinned pair from test/real_adapters (npm ci, PI_ACP_BIN / PI_ACP_PI_COMMAND pointed at it, KIROCREW_E2E_REQUIRE=1). The host's unshare -U also fails with EPERM, and its outer-sandbox env markers were unset so wrap_argv takes the same path it takes on CI. Main 912acf5: 1 passed, 6 errors (SandboxUnavailableError). This branch: 7 passed. Already green on this PR's CI at the first head.
  • Scoped backend run (208 files: mcp array, session mcp, member mount, zero-tool, mirrors, backend cards, client bindings, facades, capabilities, pi): 8029 passed. Two failures are host-environment only, not this branch. test_codex_session_mcp.py::test_the_installed_adapter_still_builds_the_frames_the_refusal_reads fails the same way on a clean main worktree (locally installed codex-acp). test_runner_facade.py fails only when the temp dir is inside the git-ignored worktree, and passes with it outside.

Related Issues

N/A: no issue; the failing main run is linked above. Clashing merges: #22807 / #22883 (lane), #22808 / #22489 (ratchet).

Pattern harvest

Not generalizable: both defects are merge-order clashes between PRs that were each green alone. The checks that caught them (the real-adapter lane and the set-gate ratchet) are the generalized guard, and they went red on the first merge that combined them.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

…-adapter lane

#22883's node-engine guard confines each 'node --version' probe through _pi_probe_wrap, which calls the sync pi_mod.wrap_argv. The lane (#22807) replaced only wrap_argv_async and the preflight, so on a runner without user namespaces every pi_session test errored at setup with SandboxUnavailableError. Replace the sync wrap by identity too, and say so in the module docstring.
@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners October 21, 2026 23:36
@kyleseaman
kyleseaman requested a review from buluoray October 21, 2026 23:36
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 56e0114331ff91f27b100f58ede575dee280075c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: both items are test-lane and ratchet repairs for main reds the description links, and no default or behaviour changes.

What this change ships

Inventory (3 items) — 3 justified

Intent: get main's two required pi checks (Real Adapter lane, set-gate ratchet) passing again so rebased backend PRs stop inheriting reds — a FIX.

  1. The pi real-adapter lane's Node probe no longer reaches the real OS sandbox (sync wrap stubbed like the async one) — justified
  2. pi's "tools": [] record is now decided by its declared BROKER_ONLY projection, not set membership; same backends record it — justified
  3. The comments and the membership-rule test now describe the zero-tool rule through the projection record — justified

[FIRST-PRINCIPLES-REVIEWED] 56e0114

Description read

[DESCRIPTION-READ] bc318f16d43cdbf079c21991c1cc9e90acc237f4dd330f868cdfad2103bc63ac

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 56e0114331ff91f27b100f58ede575dee280075c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The PR touches only backend code and tests, with no user-visible controls, strings or states, so the missing blind read leaves no evidence gap.

[UX-REVIEWED] 56e0114

Description read

[DESCRIPTION-READ] 47fe8dc1d6338a55015cf3f71886414475ced0d18a809b6a4e6aa9a41a4f19a4

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 56e0114331ff91f27b100f58ede575dee280075c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both fixes go to the cause of each red, and they behave the same as before (BROKER_ONLY is pi only).

Notes

  • Any new backend declared BROKER_ONLY will now record zero-tools automatically, even if it is outside ACP_BACKENDS_SESSION_MCP_ARRAY. That is the intended coupling. Enforcement still goes through ACP_BACKENDS_HONOR_ZERO_TOOL_BAN, and its rule test now recomputes through the same projection seam, so the two cannot drift apart without a test going red.

[DESIGN-REVIEWED] 56e0114

Description read

[DESCRIPTION-READ] b6a72afb9452458a824f268c2f45760e6ad3da64c512bada21868127f0ceac21

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 56e0114331ff91f27b100f58ede575dee280075c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 56e0114

Verdict parsed from the review's SHA-scoped output markers for commit 56e0114331ff91f27b100f58ede575dee280075c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 56e0114331ff91f27b100f58ede575dee280075c: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on 56e0114331ff91f27b100f58ede575dee280075c; Opus 5.5 adjudication downgraded every one of them. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

This comment is updated in place on each push.

Review details

BLOCKING -- website/src/pages/chat/useChatPageSessionController.ts:602 -- Immediate Back loses the pushed session’s Forward provenance

pushedEntryPending.current = false
Trigger: Switch A → B on desktop, press Back before B’s router transition commits, then narrow the viewport below 768px and press browser Forward. onPopState clears the pending destination before URL sync records B’s key.
Outcome: B’s key remains absent from pushedSessionEntryKeys; the Forward reader rejects it through popMaySwitchSession, and repairPoppedSid replaces B’s sid with A. Forward shows A and overwrites B’s history target.
Anchor: defect
Fix: Record the destination’s live history key immediately after the push, retaining commit-time recording as a fallback.

[BLOCK-MERGE-DOWNGRADED] 56e0114
[GPT-REVIEWED] 56e0114

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1: LOW harm. I confirmed every condition the failure needs:

  • Desktop push: the switch has to be a desktop push, since mobile replaces instead (useChatPageSessionController.ts:1075-1077).
  • Back inside the uncommitted window: Back has to land after the push is issued but before the router commits it. Only then does onPopState match fromKey and clear pushedEntryPending (:597-602).
  • Breakpoint crossing: the viewport then has to cross into mobile, because popMaySwitchSession rejects only when isMobile is true (sessionUrlHistory.ts:69). After that the user presses Forward, and repairPoppedSid runs (:716-718).

The result is visible on screen: Forward shows A instead of B, and only that history entry's ?sid= is rewritten. Session B is not deleted. There is no automatic recovery (none), but the user gets back by picking B in the session list.

The real fix is a third recording point keyed to how soon liveHistoryKey() reflects the push after navigate. That adds a new ordering contract to a POP/push bookkeeping path that is already intricate, and the code is outside this PR's Python-only diff. That cost is larger than a rare harm that is visible and has an exit.

[ADJUDICATION] 56e0114331ff91f27b100f58ede575dee280075c total=1 uphold=0 downgrade=1
DOWNGRADE F1 website/src/pages/chat/useChatPageSessionController.ts:602 reason=disproportionate-remedy
[GPT-ADJUDICATED] 56e0114331ff91f27b100f58ede575dee280075c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 56e0114331ff91f27b100f58ede575dee280075c: <one-sentence reason>

buluoray
buluoray previously approved these changes Oct 22, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 79cd0bc. Fixes main red on the Real Adapter Contract Tests lane (first seen on b700d47, still red on 0144ea1).

The cause holds: #22807's lane stands in for the OS sandbox by patching wrap_argv_async, but #22883 added _pi_probe_wrap, which calls the sync wrap_argv that pi.py imports at module level (pi.py:58, called at :281). On a runner without user namespaces that real wrap raises SandboxUnavailableError during resolve_spawn, so all six pi_session tests error at setup. Patching pi_mod.wrap_argv with an identity is the matching stand-in, because _pi_probe_wrap looks the name up on the module at call time.

Test-only (one file, +11/-4), no product or sandbox change, and the Real Adapter lane is green on this PR.

#22808 gated _mirrorless_member_mounts on two new 'backend in ACP_BACKENDS_SESSION_MCP_ARRAY' tests, which #22489's set-gate ratchet (shrink-only, allowlist 2 for this file) counts, so main reds test_no_new_runtime_site_gates_a_field_backed_line_on_a_set. The question those sites ask is who reads this backend's spec, which registry.PROJECTIONS declares per backend: BROKER_ONLY (pi) means no projection is written and the harness reads no spec of Crew's. Read that record, as this file already does for per_tool_deny, so the file is back to its 2 allowed sites and the zero-tool ban is unchanged.
@kyleseaman kyleseaman changed the title test(pi): stand in for the Node probe's sync wrap in the real-adapter lane fix(pi): clear main's real-adapter lane and set-gate ratchet reds Oct 22, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approve at 56e0114. This now clears both main reds on 0144ea1.

  1. Real Adapter (pi): unchanged from my earlier approve. The lane now stands in for the sync wrap_argv that _pi_probe_wrap calls (pi.py:281) as well as wrap_argv_async.
  2. Card ratchet (test_no_new_runtime_site_gates_a_field_backed_line_on_a_set, red on Linux 3.12 shard 7 and Windows shard 7): #22808 gated _mirrorless_member_mounts on membership in ACP_BACKENDS_SESSION_MCP_ARRAY, which #22489's tightened ratchet now counts. The fix reads the backend's declared projection instead (projection_for(self.backend).kind is ProjectionKind.BROKER_ONLY). Behaviour is the same for this function: it is only reached for mirror-less backends, and among the session-array backends the only mirror-less one is pi, which is the only BROKER_ONLY row in providers/mirrors/registry.py. kiro-cli stays out because its projection is NATIVE. projection_for raises on an undeclared backend, and the caller has already resolved mirror_for, so no backend falls through silently. The comment in backends_mcp.py and the capability tests are updated to match.

CI on this head: 84 passed, 0 failed, the rest still running.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 56e0114. This fixes two of the current main reds.

Set-gate ratchet:

  • The allowlist for acp/client_mcp_array.py stays at 2, and test_backend_cards_advertised.py is not changed. The two new set gates are converted to read the declared projection, so the ratchet is not weakened.
  • Equivalence: BROKER_ONLY resolves to {pi}, and the only mirror-less member of ACP_BACKENDS_SESSION_MCP_ARRAY is also pi. The removed ACP_BACKENDS_SESSION_MCP_ARRAY clause in the early return was already covered by ACP_BACKENDS_MEMBER_DISPATCH, which contains pi. The caller resolves mirror_for first, so an undeclared backend still fails before this point.
  • I ran the ratchet, test_agent_sdk_capabilities.py, test_pi_zero_tool_ban.py and test_member_mount_pi.py on this head (108 passed), and the ratchet plus the capabilities test again on this head merged with current main (68 passed).

Real Adapter lane:

  • The change adds an identity stand-in for the sync pi_mod.wrap_argv, the same stand-in the lane already uses for wrap_argv_async. It adds no skip and no condition, so a real adapter failure still fails the lane. The lane is green on this head.

Not covered here, still open on main: the shard 1 circular import in security.pass_compose, the Windows shard 6 tmpdir residue, and the main Coverage Gate red (it passes on this PR).

The code looks good to ship. I am leaving a comment, not an approval, because PR Readiness is still pending on this head. Auto-merge is already enabled, so nothing else is needed from me.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026
@buluoray
buluoray merged commit 398772f into main Oct 22, 2026
111 of 118 checks passed
@buluoray
buluoray deleted the fix/pi-real-adapter-probe-wrap branch October 22, 2026 01:46
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 22, 2026
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.

3 participants