Skip to content

fix(openai-compat): ask for kiro-cli sign-in only when the turn runs on it - #36755

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/openai-compat-harness-login
Nov 15, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/openai-compat-harness-login

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: POST /v1/chat/completions stops refusing requests for a missing kiro-cli sign-in when the request's turn runs on a harness that does not sign in through kiro-cli.

Today the endpoint answers 503 kiro_prerequisite_required whenever kiro-cli is signed out, whatever harness serves the turn. On a host whose default harness is claude, codex, opencode, goose, pi, copilot or deepseek, every OpenAI-compatible request fails while chat in the same slot works.

Why it matters

OpenAI SDK clients pointed at a gateway on any non-kiro harness get a 503 for a CLI the turn never uses. Seven of nine harnesses are affected (R-LAU-12 in docs/architecture/harness-gap-analysis.md).

Not a goal

What changed (motivation → approach → change)

Symptom: a signed-out kiro-cli blocks every completion. Cause: api_completions called reject_if_kiro_unverified before it knew which harness the turn would run on. Change: it now asks rerun_signs_in_via_kiro_cli for the resolved slot first, the same check regenerate, edit-resend and rewind use, and gates only when that answer is yes. For this endpoint, whose turn reuses the slot's live session, the check also reads the provider already registered for it (reuses_live=True), since a live one runs the turn whatever the config now selects: its own backend decides, one naming no backend keeps the gate, and a dead one falls back to the config because it is replaced. Edit-resend and rewind discard that provider, so they keep judging the backend a fresh session would start on. An unreadable harness keeps the gate. When it gates, the call passes turn_gate_target(state, slot.key) to reject_if_kiro_unverified as the reruns do, so the KAS engine-bundle route (#25562) is still served by Crew's own sign-in.

The check moved below app isolation, so an app caller is told 403 for a slot it may not reach before any sign-in answer. Because the probe can await, a refused request retracts the slot it created only through _retract_failed_newborn (kept if another send took it up), and before dispatch the handler re-checks that the slot is still registered, not closing (404) and not busy (409), as chat_send does. The spec paragraph in learn-cron-dashboard.md and the gate docstrings now name this caller.

Backwards compatibility

Compatible: a kiro-cli turn is still refused with the same 503 body; other harnesses now proceed, and a malformed or unauthorized request now gets its 400/403/409 before the 503.

Removes nothing: no route, key or check is removed; the gate is narrowed to the turns it describes.

Tests

  • test/test_openai_compat_harness_gate.py: kiro turn 503 vs claude/codex 200 for named and ephemeral slots with no slot left behind; app isolation 403 ahead of the gate; endpoint stays on the caller-auth path list; a turn started during the probe answers slot_busy; a slot closed during the probe is not run; a refusal keeps a new slot another send took up during the probe; a live provider decides in both directions (kiro-cli or unnamed live provider gated under a codex config, live codex provider not gated under a kiro config), a dead one falls back to the config.
  • test/test_kas_bundle_readiness_gate.py: the three /v1/chat/completions gate tests from fix(readiness): accept Crew's sign-in for turn gates on the KAS bundle route #25562 now drive the gate at its new place: a named slot's own session is gated, an unauthorized app gets 403 before the gate reads its target, and a new ephemeral slot is gated on its own session and removed when refused.
  • test/test_rerun_readiness_scope.py: only a caller that reuses the live provider is gated by it; edit-resend and rewind that discard a live kiro-cli provider are not.
  • test/test_openai_compat.py, test/test_members_dm_thread_resume_and_reservation.py: the existing 503-shape test pins a kiro-cli turn; mock slots carry is_closing = False.

Proof: not provable -- prove.py timed out

prove.py PROVED the first revision (b109157: the claude/codex and app-isolation cases fail without the fix), then timed out on the current one because the closed-slot test hangs without its fix. The later hunks were proven by hand: reverting each fails test_a_live_provider_names_the_harness_the_turn_reuses[-503]/[None-503] and test_a_slot_closed_during_the_probe_is_not_run, and reverting the reuses_live split fails test_a_rerun_that_discards_a_live_kiro_cli_provider_is_not_gated_by_it; prove.py timed out on the whole-diff revert (the closed-slot test hangs without its fix)

Manual verification

N/A — the handler is covered end to end with the real slot registry and harness selection; no UI.

Related Issues

Fixes #36754

Sibling sweep

Swept: git grep -n "reject_if_kiro_unverified(" -- src/
Sibling: src/kiro_crew/dashboard/chat_regenerate.py -- not affected -- already gated by rerun_signs_in_via_kiro_cli
Sibling: src/kiro_crew/dashboard/chat_rewind.py -- not affected -- already gated by rerun_signs_in_via_kiro_cli
Sibling: src/kiro_crew/dashboard/handlers/agents.py -- not affected -- /api/models spawns kiro-cli itself
Sibling: src/kiro_crew/dashboard/handlers/sessions.py -- not affected -- usage scrape spawns kiro-cli itself

Pattern harvest

Rule candidate: review-prompt
Pattern: a kiro-cli readiness gate in front of a turn must first ask which harness runs that turn.

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

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 6135207e3b575d6d5e74814729276386f199440a touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The gate now runs where the turn's harness is known and the caller is authorized, using the check the reruns already use. Nothing is taken away.

Notes

  • Regenerate also keeps the slot's live session (chat_regenerate.py:163, :534), but it still calls rerun_signs_in_via_kiro_cli without reuses_live=True. So the same live-provider-versus-config split can still occur there. That belongs in a follow-up, not this PR.

[DESIGN-REVIEWED] 6135207

Description read

[DESCRIPTION-READ] ff934e4bf809706d9e8b7d45c6c289229474c1c57b10965f233b929777cd454d

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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 6135207e3b575d6d5e74814729276386f199440a — 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. The gate now asks which harness runs the turn, which is the cause in #36754. Each item that rides along comes from the gate's new position.

Notes

  • Item 3: one sibling is left unfixed. chat_regenerate.py:163 and :534 call rerun_signs_in_via_kiro_cli without reuses_live. The docstring says "Regenerate keeps the live session", so a live kiro-cli provider under a claude config is still not gated on regenerate. This is a deferred point patch, not a demand. Grep rerun_signs_in_via_kiro_cli\( in dashboard/: 5 call sites, 1 passes reuses_live=True.

What this change ships

Inventory (7 items) — 6 justified

Intent: let OpenAI SDK clients use a gateway on a non-kiro harness while kiro-cli is signed out. FIX.

  1. Completions on claude/codex/other non-kiro harnesses no longer get a 503 when kiro-cli is signed out — justified
  2. A malformed request gets its 400 and an unauthorized app its 403 before any 503 — justified
  3. A live registered provider decides the gate, over whatever the config now selects — justified
  4. A refused request removes the ephemeral slot it created, but keeps a slot another send took up — justified
  5. A slot closed or taken during the probe answers 404/409 and does not run — justified
  6. The 409 slot-busy body moves into a shared helper — rides along
  7. The spec paragraph and gate docstrings now name this caller — justified

[FIRST-PRINCIPLES-REVIEWED] 6135207

Description read

[DESCRIPTION-READ] f4001fe9fb2580f59d0f089dd31e2ae19e863233e56c7b1d6ba3178ccf892b47

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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6135207e3b575d6d5e74814729276386f199440a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6135207

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6135207e3b575d6d5e74814729276386f199440a false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6135207e3b575d6d5e74814729276386f199440a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6135207

Verdict parsed from the review's SHA-scoped output markers for commit 6135207e3b575d6d5e74814729276386f199440a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6135207e3b575d6d5e74814729276386f199440a false-positive: <reason, 20 to 500 characters>

@iamwhatever
iamwhatever force-pushed the fix/openai-compat-harness-login branch from b109157 to 39d9ed9 Compare November 13, 2026 18:26
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 13, 2026
@KiroCrewCaptain

KiroCrewCaptain commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 499 lines, more than the 400 it may approve on its own.

The completions endpoint now asks for a kiro-cli sign-in only when the turn runs on a kiro-cli harness, using the same rerun_signs_in_via_kiro_cli check the reruns use. With reuses_live=True, a live provider's own backend decides. The session map stores the AcpProvider wrapper, whose capabilities property is a real SessionCapabilities, so live non-kiro sessions are not gated. Dead providers fall back to the config, matching how get_or_create replaces them; the one case it keeps (claude per_session) can only cause a needless 503, never an ungated kiro-cli turn. The check now runs after app isolation. A newly created slot refused with 503 is retracted through _retract_failed_newborn. Before dispatch the handler re-checks that the slot is registered, not closing and not busy. Tests cover each new behaviour, and CI and all review lanes are green.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 6135207e3b · 499 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@iamwhatever
iamwhatever force-pushed the fix/openai-compat-harness-login branch from 39d9ed9 to f817094 Compare November 13, 2026 19:08
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 13, 2026
@iamwhatever
iamwhatever force-pushed the fix/openai-compat-harness-login branch from f817094 to 6680c84 Compare November 13, 2026 20:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 13, 2026
@iamwhatever
iamwhatever force-pushed the fix/openai-compat-harness-login branch from 6680c84 to 73b5ed7 Compare November 13, 2026 21:53
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 13, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Disposition for the GPT note downgraded on f8170941bcf4 (kiro_readiness.py:388, a live non-Kiro provider under a Kiro config still gated):

Fixed in 73b5ed7beca0. With reuses_live=True, a live provider's own backend now decides in both directions, a provider naming no backend keeps the gate, and a dead provider falls back to the configured backend because the session manager replaces it. Covered by test/test_openai_compat_harness_gate.py::test_a_live_provider_names_the_harness_the_turn_reuses (the Kiro-config / live-Codex case answers 200; the dead-provider cases follow the config).

Known limit, not changed here: if turn admission resets an unpinned slot's live session because its inherited model changed, the replacement turn can start on Kiro and answer 502 turn_failed instead of 503 kiro_prerequisite_required. That path is fail-visible and needs no auth change; mirroring the admission reset predicate in the readiness gate would couple the two and is left out of this PR.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 14, 2026
…on it

POST /v1/chat/completions refused every request with 503
kiro_prerequisite_required while kiro-cli was signed out, whatever harness
the turn ran on. Reuse rerun_signs_in_via_kiro_cli, as regenerate,
edit-resend and rewind do, so a turn on any other harness is its own
sign-in authority. The check now runs after app isolation, and a refused
request drops the slot it created. Caller auth is unchanged.
@iamwhatever
iamwhatever force-pushed the fix/openai-compat-harness-login branch from 73b5ed7 to 6135207 Compare November 15, 2026 02:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 15, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 15, 2026 03:49

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed head 6135207 and found nothing that blocks merge. The checks: the sign-in gate now runs after the app-isolation checks, so a caller cannot use it to probe a slot it is not allowed to reach. Harness identity is a positive membership test, and an exception or an unreadable selection keeps the gate. The live provider decides only while it is alive. After the probe, a re-check refuses a slot that was replaced, closed or taken by another turn. A refused newborn slot is retracted, but a slot another send took up is kept. Regenerate, edit-resend and rewind keep their current behaviour.

Done well: the fix reuses the existing rerun_signs_in_via_kiro_cli check instead of adding a parallel one, and the handler tests run the real api_completions against the real slot registry.

Optional:

  • test/test_openai_compat_harness_gate.py:125 and :196 stub _run_chat with a bare AsyncMock(), so a regression of the post-probe re-check hangs until the test timeout instead of failing by name. AsyncMock(side_effect=_fake_run_chat) makes the same mutation fail in a few seconds.
  • No test pins if freshly_created: (openai_compat.py:642) or or slot.is_closing (:658). An assertion that a pre-existing empty s1 survives a 503, plus a probe that sets is_closing without popping the slot, would pin both.
  • The PR body's sibling sweep line says regenerate is "not affected". Regenerate calls the check without reuses_live, so a follow-up issue would describe it more accurately.

@KiroCrewCaptain
KiroCrewCaptain merged commit ced9489 into main Nov 15, 2026
99 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/openai-compat-harness-login branch November 15, 2026 03:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 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.

OpenAI-compatible endpoint requires kiro-cli sign-in on every harness

2 participants