Skip to content

fix(apps): restart an app's backend when enabling it mints the owner-enable marker - #39252

Draft
chenmingwei23 wants to merge 4 commits into
mkt-app/sel-gateway-clientfrom
mkt-app/o2-backend-restart
Draft

chenmingwei23 wants to merge 4 commits into
mkt-app/sel-gateway-clientfrom
mkt-app/o2-backend-restart

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Fixes #39160.

Stacked on #38807 (base mkt-app/sel-gateway-client); rebase on main and retarget to main once #38807 merges.

An app enabled before its owner-enable marker existed spawns its backend without KIROCREW_GATEWAY_ORIGIN. Re-enabling it as the owner mints the marker, but the enable route reused the running backend, so the app kept no origin until a restart.

The enable route now records whether the marker stood before the enable. When the enable minted it, the route stops the app's backend before starting it, so the new spawn gets the origin. A re-enable with the marker already present does not restart.

Tests (test/test_enable_restarts_backend_on_new_marker.py): enable, drop the marker, re-enable -> stop then start with the marker in place; re-enable with the marker present -> start only.

Spec: none (repair)
Ticket: none (repair batch)

…rmalized operation

Spawned app backends hold no SEL key, so their audit rows reach the log through the
gateway's _sel route and a client that only holds the per-app secret. These tests pin:

- the route and the client write the row as app:<name> with the operation kept under
  the app's namespace;
- the operation is normalized and the row is kept: 'Publish Doc' is stored as
  'Publish_Doc', a newline or control character becomes '_', a 300-character operation
  is clipped to 64 and an empty one is stored as 'unnamed';
- a backend has no SEL key, and the builtin backends' own operation names are stored as
  written;
- a critical write the gateway did not take refuses the action.
…nnot read the SEL key

A spawned app backend now holds only its per-app secret. Its audit rows go to the
gateway's POST /api/apps/{name}/_sel route through apps/sel_client.py, and the gateway
signs and appends them as app:<name>. The backend's sel() is that client, the SEL key
is masked from the backend, and the built-in security callers log through sel().

The operation is normalized by one function, sel_client.normalize_operation, that the
client and the route both call: every character outside [A-Za-z0-9_.-] becomes '_',
the result is clipped to 64 characters, and an empty one is stored as 'unnamed'. The row
is kept, so no newline or control character reaches a text view of the log. Credentials
are redacted before the operation is normalized, including a tool name.

The client posts the row as UTF-8 rather than ASCII escapes, so three 500-character
fields of astral characters stay under the route's 16 KiB body cap, and a lone surrogate
in a field is replaced instead of raising.

A critical write waits (bounded, as the exit drain does) for the rows queued before it, so
it cannot land ahead of an earlier row.

The docs describe the route, the client and the normalized operation.
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 21e926c5f08afbf0def5bab7bc825ff91ba38c9d — 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

This fixes the cause: the gateway origin is read only when the backend spawns, so a restart gated on the marker the enable just minted is the smallest fix.

Notes

  • Item 2 — rides along: if not had_marker: also runs stop_app_backend on a first enable, when no backend is running yet. It does no harm, so this is inventory only.

What this change ships

Inventory (3 items) — 2 justified

Intent: an owner who re-enables an app that predates its owner-enable marker should get a backend that can reach the gateway without a manual restart. This is a FIX (#39160, plus a test that fails on base).

  1. Re-enabling an app that just gained its owner-enable marker restarts its running backend so the new spawn gets the gateway origin — justified
  2. A first enable also calls a stop on a backend that is not running before it starts one — rides along
  3. Re-enabling an app that already has the marker keeps reusing the running backend — justified

[FIRST-PRINCIPLES-REVIEWED] 21e926c

Description read

[DESCRIPTION-READ] 33d5e1a019d526818d58906449592ef29d3df79577ce3d8550d65fc00df9a9e5

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: a successful enable always leaves the marker in place (manager_activation.py refuses the enable when it cannot mint it), so not had_marker correctly means "this enable minted it", and restarting the backend is the cause-level fix.

Notes

  • stop_app_backend returns a bool that the route ignores. If the stop fails, start_app_backend reuses the stale backend, which still has no origin, and no warning is logged. That is no worse than before the change, but it is a quiet failure on the path this PR exists to fix.

[DESIGN-REVIEWED] 21e926c

Description read

[DESCRIPTION-READ] 9a8e3d1d2aaee67a1051fdf149796a924cb1e06e5328ef13f78dca57dbb1e618

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 21e926c

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

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 21e926c5f08afbf0def5bab7bc825ff91ba38c9d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 21e926c

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

@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 18, 2026
@chenmingwei23
chenmingwei23 force-pushed the mkt-app/sel-gateway-client branch from d1aa2f6 to 5b59d52 Compare November 18, 2026 21:06
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 18, 2026
@chenmingwei23
chenmingwei23 force-pushed the mkt-app/sel-gateway-client branch 8 times, most recently from b399a28 to 045e1ed Compare November 19, 2026 13:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant