Skip to content

fix(memory): upgrade pre-identity member stores and restore cron tools - #12103

Merged
bolichen97 merged 1 commit into
mainfrom
fix/memory-v2-upgrade-migration
Sep 20, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/memory-v2-upgrade-migration

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

A crew member created on 0.7.0 stops working after upgrading to a build with the one-SQLite-store member memory (#11780). Picking the member in chat fails with memory_unavailable, its DM thread does not open, and switching an older session to it returns 503 member_binding_unavailable. kirocrew doctor prints "member identity is missing or ambiguous" and nothing else. There is no way to repair it: provision_memory is refused (400), rebinding is refused (409), and the old Initialize button is gone. The only way out is to delete the member and lose its memory.

The same upgrade smoke test found four more defects:

  • With mcp_gateway.enabled on, every kirocrew-cron MCP tool returns 403 member_session_unverified.
  • kirocrew chat with no gateway running lost all cron tools; they used to write the local store.
  • Reaching member provisioning before kiro_crew.validation was imported raised ImportError (circular import through artifacts -> hooks -> webhooks -> validation -> artifacts).
  • kirocrew token reported a 403 as "Could not reach gateway", hiding the reason the gateway returned.

Deleting a member also left its retained store in the dashboard memory picker, where every click was a 503, and a hand-edited non-string identity in config.json made the picker raise on hashing it.

Why it matters

Every internal toolbox 0.7.0.x install that created a crew member breaks on the next upgrade, with data loss as the only remedy. The cron 403 turns off scheduling for anyone using the pooled MCP gateway. The kirocrew chat regression removes a working feature for users who never run a gateway.

What changed (motivation → approach → change)

Defect Fix Files
Members from 0.7.0 have no identity One-shot start-of-process upgrade, repair_legacy_member_stores memory_stores.py, cli.py (prologue), slack/gateway.py (memory worker), cli_doctor.py
Cron tools 403 under the pooled gateway gatewayd forwards the session token to Kiro Crew's own control planes only mcp_gateway/gatewayd.py, mcp_caller.py, mcp_core.py
kirocrew chat lost cron tools A refused dial from a process-local identity falls back to the local store mcp_core.py, mcp_cron.py
Circular import The artifact content cap moves to the constants leaf, so validation no longer imports artifacts constants.py, validation.py, artifacts.py
kirocrew token hides the 403 reason Print the gateway's error body cli_server.py
Dead store in the picker Omit a V2 store with no living owner, and one whose identity is not a string dashboard/handlers/memory_admin.py
Interrupted upgrade stranded a store A half-published identity pair completes instead of refusing memory_stores.py

A 0.7.0 store record has an empty owner_member_id and its agent has no member_id; the new resolvers refuse it outright, and nothing later can publish the identity. So the upgrade runs once at the start of every process, before any member is resolved. For a V2 store bound to exactly one agent it completes the database identity tables and rows in place (database first, then config, so a crash resumes instead of allocating a second id), publishes member_id / owner_member_id, and keeps every existing lesson. A store bound to zero or two agents, already carrying an identity, naming another owner, or missing its database is left alone with one warning; doctor names the store, the reason and the remedy; a repairable store is reported as pending through its bound member and is not an issue, so it does not fail the command. The gateway is exempt from the CLI prologue because its boot path admits no new work; it runs the same repair in its post-readiness memory worker instead. doctor and the mcp-* servers are exempt too (read-only triage; children of a gateway that already ran it).

gatewayd spawns pooled backends from its own environment, so the per-session KIROCREW_STUB_SESSION_TOKEN never reached kirocrew-cron; the gateway now requires X-Session-Token, so every call failed. gatewayd now puts the token in the per-call caller block, but only for a backend it decided at spawn (off the event loop) is Kiro Crew's own control plane: the name is in CONTROL_PLANE_BACKENDS, the exec'd command and args match the managed spec's invocation, the child's environment carries no non-empty PYTHON* variable, and the one remaining fixed root (its CWD under -m, else the launcher's directory) holds no kiro_crew other than this process's package. The PYTHON* namespace is rejected as a whole rather than by a list of known variables: entries add import roots, run hooks or relocate user-site, so a prefix rule fails closed when a later Python adds one. gatewayd's own resolver removes that namespace from the inherited environment, so a value present at the verdict is a hand-declared overlay. An accepted control plane is then launched with PYTHONSAFEPATH as defense in depth; the verdict never depends on it. Two ride-alongs the table does not cover, both consequences of the fence rather than fixes of their own: every pooled backend gets Kiro Crew's own PYTHONUTF8/PYTHONIOENCODING re-applied after the verdict, because the namespace strip that serves the fence would otherwise take that pinning from a control plane and leave a pooled interpreter building stdio from a Windows ANSI codepage; and .github/black-baseline.txt loses the two files this change reformats, which is reformat mechanics the black gate requires, not a seventh fix. mcp_core._session_token_header reads it from the caller before the environment. A third-party backend, or a project checkout shadowing kiro_crew, never sees it.

The alternative of not pooling the control planes at all was weighed and rejected. Spawning kirocrew-core and kirocrew-cron per session would remove the token hand-over entirely, because each child could carry its own session's token in its environment at spawn. The cost is paid on every session: two extra Python interpreters per concurrent session, each importing the kiro_crew package and its MCP stack, against two processes shared across all of them. That is cold-start latency on the first tool call of every new session and a per-session memory floor that scales with concurrency — on a host already running one agent process per session. Pooling is also what the mcp_gateway rewrite exists to provide, so unpooling these two servers would carve a permanent exception into it. The fence keeps the shared processes and pays instead with one spawn-time verdict, which is cheaper and does not scale with session count. The unwrap exemption (leaving these two servers unwrapped, as the rewriter already does for an env-declaring opted-in server when forwarding is off) has the same per-session cost and is therefore rejected for the same reason.

mcp_core._send marks the one failure where nothing reached a gateway as refused; mcp_cron uses that, together with a process-local identity, to fall back to the direct host store, which is what kirocrew chat always had. Specs updated: docs/architecture/mcp.md, docs/system-specs/modules/cli.md, config.md, memory-skills-hooks.md. .github/black-baseline.txt drops the two files this change reformats.

Backwards compatibility

Compatible: the upgrade only touches V2 store records with an empty owner_member_id bound to exactly one agent, and it adds identity rows; it never deletes data, never creates a database, and refuses anything ambiguous. Token forwarding is additive and limited to Kiro Crew's own backends. The local fallback restores pre-#11780 behavior for a case that had none.

Tests

  • test/test_member_memory_upgrade.py (new, 18 tests): a 0.7.0 store resolves after the upgrade and its lessons survive; a second run changes nothing; an interrupted upgrade resumes with the identity already in the database; slug collisions get a suffix; zero or two bound agents, an existing identity, another owner's manifest, another store's database identity, and a missing database are all refused with one warning; doctor reports refused stores with a remedy and repairable ones as pending; the hook runs in the CLI prologue and in the gateway memory worker.
  • test/test_mcp_gateway_stub_session_token.py, test/test_private_cron_proxy.py, test/test_mcp_caller.py: the token reaches kirocrew-cron through the caller block, never a third-party backend; _session_token_header prefers the caller's token; refused triggers the local fallback only for a process-local identity.
  • test/test_agent_import_hoist.py: members and artifacts import in either order in a fresh interpreter, and validation never imports artifacts.
  • test/test_cli_server_more_coverage.py: kirocrew token prints the gateway's error body on HTTP errors.
  • test/test_member_memory_ownership.py: the picker omits a V2 store whose owner no longer exists.

Manual verification

Reproduced the upgrade failure on macOS with a 0.7.0-shaped store (member_id='', owner_member_id=''): require_member_memory_store raised UnknownMemoryStore: member identity is missing or ambiguous. After the upgrade the same store resolves, memory_recall returns policy_revision=member-v2, and the pre-existing lesson is returned. The token and fallback fixes were verified on a scratch copy of gatewayd against a pooled kirocrew-cron backend.

Related Issues

no linked issue: found by the post-merge smoke test of #11780; the reports it would have produced (#11471, #11569) were closed with the upgrade caveat stated in their closing comments.

Pattern harvest

Rule candidate: review-prompt
Pattern: a refactor that adds a required identity field to a persisted record must ship the one-shot backfill for records written before the field existed, plus a test that loads a pre-refactor fixture.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

@bolichen97
bolichen97 requested review from a team and smeyffret September 19, 2026 21:51
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Make Crew Members created on 0.7.0 usable again after the one-store memory refactor by upgrading their stores and identities in place at start, keeping every lesson; and fix the four defects the same smoke test surfaced (pooled cron tools 403, kirocrew chat cron regression, artifacts→hooks import cycle, kirocrew token misreporting a 403).
Not a goal: re-opening PUT /api/agents provision_memory, repairing stores bound to zero or several agents (doctor names them; a human decides), changing the session-token transport contract, or touching third-party MCP backends.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of e9b74830aa0c357ab53b3d8f278b7121be4850fb — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

CONTROL_PLANE_BACKENDS is a second spelling of acp.session_mcp.CONTROL_PLANE_SERVERS, held together by a ratchet test this PR's own constants-leaf pattern makes unnecessary.

Not justified as shipped

  • Item 5 — duplicate of src/kiro_crew/acp/session_mcp.py:108: the description says the mirror exists because "importing it would put kiro_crew.agent on the daemon's boot path" (verified — session_mcp imports agent at module scope), but this same PR solves exactly that problem for the artifact cap by moving the value to the constants leaf; count: 2 definitions of the name list plus 1 ratchet test pinning them equal (grepped CONTROL_PLANE_SERVERS).
    Subtraction: delete gatewayd.CONTROL_PLANE_BACKENDS and its ratchet test; define the list once in the constants leaf and have session_mcp and gatewayd both read it (the ARTIFACT_MAX_CONTENT_BYTES move in this diff is the template).
    Clears when: the mirror and ratchet test are deleted in favor of one leaf definition, or the boot-path constraint is shown to forbid even a leaf import.

What this change ships

Inventory (10 items) — 9 justified

Intent: FIX — a crew member created on 0.7.0 (and cron tooling generally) works again after upgrading past #11780, without data loss.

  1. A 0.7.0 member store is repaired automatically at process start (CLI prologue, gateway post-readiness worker), resuming interrupted runs — justified
  2. kirocrew doctor names each pre-identity store as pending or refused, with reason and remedy — justified
  3. Cron MCP tools work under the pooled gateway: gatewayd hands the session token to its own control planes per call — justified
  4. The token is gated on a spawn-time verification of command, args, env and import roots, with logged denials — justified
  5. New CONTROL_PLANE_BACKENDS set mirroring an existing constant — duplicate of src/kiro_crew/acp/session_mcp.py
  6. Control-plane backends lose the operator's whole PYTHON* namespace (was four keys) — justified
  7. Every pooled backend gets the UTF-8 env pair re-applied after the verdict — rides along (declared; preserves prior inherited behavior)
  8. kirocrew chat with no gateway regains local cron tools, only on a refused dial with the CLI's own identity — justified
  9. kirocrew token reports the gateway's HTTP error body instead of "could not reach gateway" — justified
  10. The dashboard memory picker omits a deleted member's retained store and non-string identities — justified

More than 10 differences exist; the import-cycle fix (artifact cap moved to the constants leaf, justified) and the two-file black-baseline drop (declared reformat mechanics) are the ones cut.

[FIRST-PRINCIPLES-REVIEWED] e9b7483

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of e9b74830aa0c357ab53b3d8f278b7121be4850fb — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the control-plane spawn verdict on Windows and pipx/--user installs — a false deny silently returns pooled-gateway cron to 403, logged only in the daemon.

[DESIGN-REVIEWED] e9b7483

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of e9b74830aa0c357ab53b3d8f278b7121be4850fb and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e9b7483

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

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e9b7483

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

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

@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 Sep 19, 2026
@bolichen97
bolichen97 force-pushed the fix/memory-v2-upgrade-migration branch from 4b1a01d to 9ff94f1 Compare September 19, 2026 22:16
@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 Sep 19, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=0e21ddd67f91 — gatewayd.py: server-name spoofing could hand the session token to a foreign backend.

The gate is no longer the name. At spawn, _spawns_own_control_plane compares the command actually exec'd (by real path) and its args against agent.managed_mcp_spec_entry(name) — the same source the spec writer emits — and records the verdict as Backend.control_plane; the connection handler forwards conn.stub_session_token on that flag only. A spec declaring a third-party --target-command under kirocrew-core now gets the caller identity and nothing else. Tests: test_a_reserved_name_on_a_foreign_command_never_sees_the_token (both reserved names), TestSpawnsOwnControlPlane (managed match, symlinked launcher, foreign binary, wrong args, name outside the set, unresolvable entry fails closed, the real managed entry matches itself). Spec: docs/architecture/mcp.md. Landed in 9ff94f1.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=fd987581e1b2 — memory_stores.py: reject multiply-linked databases before migration.

Added _require_private_member_database, the same S_ISREG and st_nlink == 1 rule the namespace lock already applies, and call it before the identity read (_legacy_member_database_identity) AND immediately before the in-place write (_complete_legacy_member_database), since the two are not one open. A hard-linked store is refused with memory.db is hard-linked to another file, left byte-identical, and doctor reports that reason. Tests: test_a_hard_linked_database_is_refused_and_its_other_name_untouched (sibling name unchanged, direct completer raises), test_a_symlinked_database_is_refused. Spec: memory-skills-hooks.md upgrade preconditions. Landed in 9ff94f1.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=03920b68f60d — CONTROL_PLANE_BACKENDS duplicates session_mcp.CONTROL_PLANE_SERVERS.

Taken the clearing condition the finding names: a ratchet test (test_control_plane_set_mirrors_session_mcp) pins gw.CONTROL_PLANE_BACKENDS == frozenset(CONTROL_PLANE_SERVERS), the same pattern the repo uses for _KIRO_REGISTRY_TYPE. Deriving it by import was rejected deliberately: acp/session_mcp.py imports kiro_crew.agent at module scope, which would put the whole agent-spec builder on gatewayd's boot path; the constant's comment now says so and names the pin. Landed in 9ff94f1.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=46f8292e3848 — Item 8: second definition of the control-plane set, or a case where the gateway's set must differ.

The set is the same set and must stay so; a ratchet test now pins the two equal (test_control_plane_set_mirrors_session_mcp). The second spelling stays because importing the first would drag kiro_crew.agent onto the daemon's boot path (session_mcp imports it at module scope) — that cost, not a semantic difference, is why the mirror exists, and the constant's comment states it. Landed in 9ff94f1.

@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 Sep 19, 2026
@bolichen97
bolichen97 force-pushed the fix/memory-v2-upgrade-migration branch from 9ff94f1 to 28afba7 Compare September 19, 2026 22:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 19, 2026
@bolichen97
bolichen97 force-pushed the fix/memory-v2-upgrade-migration branch from 28afba7 to 8eb6018 Compare September 19, 2026 23:05
@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 Sep 19, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=fd987581e1b2 — memory_stores.py: a manifest or record owner label that names another member was still adopted.

Every nonempty owner label the old build left behind must now equal the one alias bound today: _legacy_member_store_candidates refuses the store when record.owner_member names a different member and when member-memory.json names a different owner, each with its own reason (its record names owner_member 'x', not 'y' / member-memory.json names owner 'x', not 'y'), and doctor reports that reason. Tests: test_a_manifest_naming_another_owner_is_refused, test_a_record_and_manifest_that_agree_on_another_owner_are_refused, test_a_record_naming_another_owner_is_refused_without_a_manifest. Spec: memory-skills-hooks.md upgrade preconditions. Landed in 28afba7.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=02904f6955d9 — mcp_cron.py: the local-store fallback fired on the absence of an injected caller, so a dashboard-minted key with no caller could reach the host store directly.

The fallback now requires POSITIVE CLI provenance: _post returned refused=True (nothing reached a gateway) AND the session key classes as cli under infer_use_case. A dashboard key with no injected caller is the non-pooled topology and reports the gateway outage instead of writing locally. Tests: test_no_gateway_with_cli_identity_dispatches_locally, test_no_gateway_with_a_gateway_minted_key_does_not_fall_back, test_no_gateway_with_gateway_injected_identity_does_not_fall_back. Spec: docs/architecture/mcp.md, cli.md. Landed in 28afba7.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed span=0e21ddd67f91 — gatewayd.py:4147: the control-plane verdict ran synchronously on the event loop.

The spawn site now awaits asyncio.to_thread(_spawns_own_control_plane, ...), the same pattern the admission read two lines above already uses; Backend.control_plane defaults to False, so nothing rides the token while the verdict is pending. test_the_spawn_site_decides_off_the_event_loop pins that the only production call is the threaded one. Spec: docs/architecture/mcp.md. Landed in 8eb6018.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=0e21ddd67f91 — the global Python-env scrub can break third-party backends: fixed by scoping the strip to where the fence applies.

Correct, and it is the mirror of a defect I had already found on the previous head from the other side. The whole-namespace strip exists only to make the reserved-name token fence costless. A third-party backend is never handed a token, so scrubbing its environment bought zero security and changed its behaviour for nothing — and env.py:936 names the concrete casualty: "PYTHONUNBUFFERED=1 on a user's own Python MCP server is the realistic example."

env_target_resolver now removes the complete PYTHON* namespace only when the resolved server name is in CONTROL_PLANE_BACKENDS; every other backend keeps the long-standing four-key _PYTHON_ENV_PREFIXES strip, whose per-key rationale is unchanged. The fence itself is untouched and still closed: it only ever evaluates a reserved name, and for those names the namespace is still fully gone, so a value at the verdict remains a hand-declared overlay. The post-verdict UTF-8 re-apply stays where it is, unconditional for every pooled backend.

Verified in the parent rather than taken on report: test_third_party_keeps_benign_python_env fails on the previous code and passes on this one (git checkout HEAD -- gatewayd.py, run, restore). 279 scoped tests pass; black (pinned 26.3.1), isort, flake8, mypy --platform linux (pinned 1.14.1), docs-lint and the comment-history gate with COMMENT_HISTORY_BASE_REF=origin/main are green. Both spec passages now state the scope precisely.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=13e93e1f8df2 — the better alternative of unpooling the control planes was never considered in the description: fixed.

Fair: the description justified the fence in detail without ever stating why the alternative that removes the need for it was not taken. The description now weighs it, with the cost named.

Unpooling kirocrew-core and kirocrew-cron would remove the token hand-over entirely, since each per-session child could carry its own token in its spawn environment. The cost is paid on every session: two extra Python interpreters per concurrent session, each importing the kiro_crew package and its MCP stack, versus two processes shared across all sessions — cold-start latency on the first tool call of every new session, and a per-session memory floor that scales with concurrency, on a host already running one agent process per session. Pooling is also the thing the mcp_gateway rewrite exists to provide, so unpooling these two would carve a permanent exception into it. The fence keeps the shared processes and pays one spawn-time verdict instead, which does not scale with session count.

The unwrap exemption the item offers as the other clearing path is rejected on the same arithmetic: leaving these two servers unwrapped has the same per-session process cost, which is what the pooled fence exists to avoid.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=191fffafdfcb — the picker now also hides a refused pre-identity store, leaving the remedy only in kirocrew doctor: rebutted, with a follow-up noted.

The observation is accurate, but it describes a narrower population than it appears to, and the alternative is worse on the path it would change.

A pre-identity store is not normally refused: the whole point of this change is that one bound to exactly one agent is repaired automatically at the next process start, before any picker render. What stays refused is the genuinely ambiguous set — zero or two bound agents, an identity already present, a manifest naming another owner, a missing database — where the correct action differs per case and cannot be inferred. doctor already names the store, the reason and the remedy for each, and reports a repairable one as pending rather than as an issue.

Against that, the behaviour being replaced was not discoverability but a row that returned 503 on every click, with no indication of why or what to do. A "needs repair" affordance that carries the reason and the remedy would be better than both, but it is new dashboard surface — a row state, its copy, and its per-reason remedy text — and adding it here would widen a change that has already taken nine review rounds on one span, in a subsystem where every earlier widening produced a real defect. Recorded as a deliberate scope decision and a worthwhile follow-up, not an oversight.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=0e21ddd67f91 — per-user site-packages can shadow kiro_crew and still earn the session token: fixed, and the premise was partly my own miss.

Correct, and it survived two earlier rounds on this span because the earlier fix addressed the wrong half of the mechanism. Stripping PYTHONUSERBASE only relocates per-user site-packages; the interpreter still adds it from a default location, ahead of the install's own site-packages, and PYTHONSAFEPATH covers sys.path[0] rather than user-site. I verified that distinction directly against the interpreter rather than reasoning from the variable name.

The fence now inspects per-user site-packages as a second root alongside the fixed local one, with the same test it already applies: the root shadows when it holds an importable kiro_crew that is not the package this process is running. An unresolvable user-site fails closed.

The obvious remedy was rejected because it is actively wrong here. Setting PYTHONNOUSERSITE=1 would disable user-site for the child — and on a pip install --user install kiro_crew lives there, so the control plane could no longer import itself and every cron tool would fail hard. Comparing the package that is found is safe on that shape: its user-site holds the very package the gateway is running, so it matches and the token is granted. test_a_user_install_keeps_its_token pins exactly that, and it is the test that would fail if someone later "hardens" this by disabling user-site.

Reading the root is sound because the spawn is already pinned by realpath to the managed spec's own launcher, so the child runs this install's interpreter — the same one the gateway reads site from.

Verified in the parent: 282 scoped tests pass; black (pinned 26.3.1), isort, flake8, mypy --platform linux (pinned 1.14.1), docs-lint and the comment-history gate with COMMENT_HISTORY_BASE_REF=origin/main are green. Against the previous code the new test errors with module 'kiro_crew.mcp_gateway.gatewayd' has no attribute 'site', which is itself the evidence that no user-site check existed. Both spec passages updated.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=0e21ddd67f91 — per-user site-packages runs startup hooks that attestation cannot see: fixed by removing the surface, not inspecting it.

Correct, and it defeats the previous round's fix on its own terms. A .pth entry in user-site executes at interpreter startup under any filename, so checking that directory for a foreign kiro_crew package cannot observe a hook at all.

An accepted control plane is now launched with PYTHONNOUSERSITE=1 when nothing there is load-bearing — that is, when user-site does not hold the package this process is running. The package check is retained for the one case where the flag cannot be set: a --user install, whose own kiro_crew lives in user-site, and which the previous round established would be broken outright by disabling it. An unresolvable user-site is treated as holding it, leaving the child's import behaviour unchanged rather than guessing.

That combination is why this is a closure rather than another instance patch: for every install where user-site could carry a hostile hook, the directory is gone from the child's path entirely, and the only install that keeps it is the one whose user-site content the fence has already matched against this process's own package.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=fd987581e1b2 — a stale configuration can permanently strand a legacy store identity: fixed, and it was reachable from this upgrade's own write order.

Real, and worse than "stale config": the upgrade publishes the MEMBER's identity before the STORE record's, so an interruption between the two leaves the member holding an id the store lacks — and three separate checks then refused that shape forever. The candidate scan refused on already carries member_id, its claimed scan counted the bound member itself as a rival holder, and _publish_legacy_member_identity refused when either side was merely PRESENT rather than when a present value DISAGREED. The documented remedy compounded it: blanking the member_id would have put the two identities into disagreement.

All three now turn on agreement rather than presence. The bound member's own id resumes; any other holder is still a conflict and still refuses; a damaged non-string disagrees and still refuses. Two tests pin both directions, and on the previous code the resume test fails with assert [] == ['member-reviewer-…'] — the store was indeed skipped.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=5ccf98a58a41 — _allocate_member_id refuses on any non-string identity anywhere in config, so one damaged record blocks every repair: fixed.

Correct. The scan is global and the migration calls it per store, so a single unreadable record cost every other store its repair, each logging only a generic line with the real cause buried in a traceback. That is the failure this upgrade exists to end.

Allocation now takes refuse_damaged. The creation path keeps refusing, because a config it cannot read is no basis for writing a new identity into it — the guard an earlier first-principles item asked for is intact and still pinned. The migration passes False: a non-string can never collide with a string slug, so excluding it from the reservation set is sound, and the damaged record is still refused on its own behalf by the candidate scan.

Verified rather than assumed: the migration loop already catches per store, so boot was never at risk — the cost was lost repairs, not a crash. On the previous code the new test fails with assert [] == ['member-reviewer-…'].

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=037553bb3c6e — the _UTF8_PROCESS_ENV re-apply reaches every pooled backend and the description's table never lists it: fixed.

Accurate, and the asymmetry is the reason it is worth stating: only control planes lose the pair to the namespace strip, yet the re-apply is unconditional. It is unconditional deliberately — scoping it to control planes would make a third-party backend's stdio encoding depend on whether the strip had touched it, which is a worse contract than simply pinning UTF-8 for every pooled child, and it matches what ensure_utf8_console() already does for the gateway itself.

The description now names it as a consequence of the fence rather than a fix of its own, together with why it is applied after the verdict.

@bolichen97

Copy link
Copy Markdown
Contributor Author

span=6fe3e449cd8c — the black-baseline removals are reformat mechanics, not one of the declared fixes: fixed in the description.

Correct, and they are not optional: the two files this change touches are listed in .github/black-baseline.txt as known-unformatted, and the black gate requires a file it reformats to leave that list. Keeping them listed would fail the gate; removing them is the mechanical consequence of editing those files at all.

The description now says so explicitly and separates it from the six fixes rather than leaving a reader to infer that a seventh change was smuggled in.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in 1 commit (e8b94aa -> f31f25a) with no overlap in the files this PR touches; rebased clean and re-ran the scoped tests (335 passed) before pushing.

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision e9b74830aa0c357ab53b3d8f278b7121be4850fb touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 19361a4b65cd90edb0b2705fd47034aebed80574 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 19361a4

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

Member memory stores created on 0.7.0 carry no member identity: the
config record has an empty owner_member_id and the agent has no
member_id, so after the one-SQLite-store refactor every such member
fails with "member identity is missing or ambiguous" and the product
offers no repair (provision_memory is refused, the Initialize button is
gone). Add a one-shot start-of-process upgrade that, for a V2 store
bound to exactly one agent, completes the database's identity tables
and rows in place and then publishes member_id / owner_member_id to the
config, keeping every existing lesson. Ambiguous or damaged stores are
left alone with one warning and a doctor line that names the remedy.

Fix the four defects the same smoke test surfaced:

- gatewayd spawns pooled backends from its own environment, so the
  per-session token never reached kirocrew-cron and every cron tool got
  403 once the gateway required X-Session-Token. Forward the token in
  the caller block to Kiro Crew's own control planes only.
- kirocrew chat with no gateway lost its cron tools; a refused dial from
  a process-local identity now falls back to the direct host store.
- artifacts imported hooks at module scope, closing an import cycle
  that broke any process reaching members before validation.
- kirocrew token reported a 403 as "could not reach gateway", hiding
  the provenance reason the gateway returned.

Omit a deleted member's retained V2 store from the memory picker, since
no route can read it.
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