Repository navigation
feat(apps): add acquire_worker_slot with a per-app limit and timeout - #18360
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The helper has zero callers in the repo, and the builtin apps keep their own hand stamping, so this ships a second way to do the same thing. Not justified as shipped
What this change shipsInventory (10 items) — 8 justifiedIntent: let apps own a background worker session through a supported, bounded seam instead of setting private slot attributes by hand. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] 6b71904 Description read[DESCRIPTION-READ] 7f8ba3a398171d9c3f98bcb6caeda018b03e6d1cc1383d3e3be2469af1dc11b8 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Leases and worker trust grants aren't tied to the app's lifecycle, so disabling or reloading an app leaves its auto-approve grant live and can lock the app out. Watch
[DESIGN-REVIEWED] 6b71904 Description read[DESCRIPTION-READ] ebd8b1e22754f130ebbd87ed9c119d47abaef4dc2621f4e79b17efab3ce1f0f2 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 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
bf4f7dd to
d70863e
Compare
d70863e to
28eca9f
Compare
|
On the First Principles concern about the limit: the default limit of 1 with an acquire timeout is the maintainer's recorded decision on #509 (latest comment there). Moving the builtin apps onto the helper stays out of this PR's goal. |
|
This adds a new public app-kit API, kiro_crew.apps.worker_slots.acquire_worker_slot (402 new prod lines plus 418 test lines). It gives a per-app lease limit (default 1), an acquire timeout, re-stamping of the slot's owner and project, and trust that is a TTL-bounded SafetyOverride scoped grant instead of the permanent slot._trust. I read the module and the lane results. Checks are green, the GPT/Opus/Design lanes have no findings, and the author answered First Principles' CONCERNS by citing the maintainer decision on #509. First Principles also noted the helper has zero in-repo callers. Trying to break it: the owner check only refuses a slot whose _app is a different app. So acquire_worker_slot on the key of any existing slot with no _app (for example a human's dashboard chat) takes it over: it stamps _app (hiding it from the sidebar), sets project, and can attach the app's scoped auto-approve grant (worker_slots.py, the |
iamwhatever
left a comment
There was a problem hiding this comment.
Deep re-review of a held PR (I tried to break it). Adds a supported app-kit helper so apps stop hand-stamping slot._app/project/_trust; trust becomes a TTL-bounded audited SafetyOverride scope instead of the permanent _trust flag, which is a real improvement. Head 28eca9f is MERGEABLE, no CHANGES_REQUESTED, GPT/Opus/Design have no findings; First Principles CONCERNS (limit of 1, zero callers) was answered by citing the maintainer decision on #509. Attack tried: the hold's reason still stands and I proved it. get_or_create_slot (dashboard/state.py:7878) returns any existing slot, and the only owner check is owner and owner != app (worker_slots.py:374), so an unowned slot is adopted. A probe test with a human chat slot (_origin="user", project=/home/me/secret-repo) under acquire_worker_slot(trust=True) got _app="evil-app", project=/tmp/x and the app's auto-approve scope; after release the scope was withdrawn but the chat stayed hidden (_app) and stayed moved to /tmp/x, with nothing telling the user. Apps already hold dashboard state, so this is not a new privilege, but a supported helper should not make taking over a person's chat the easy path. Limit, timeout, folded-key and TTL paths look right. Requested change: src/kiro_crew/apps/worker_slots.py:372-375 -- before get_or_create_slot, read pre = state.get_slot(key); if pre exists with an empty _app and getattr(pre, "_origin", "") is SlotOrigin.USER or SlotOrigin.CRON, raise ValueError("slot ... belongs to a person/cron; an app may only adopt slots it created"). Keep the re-stamp for unowned APP/untagged slots (the ChatEmbed case). Add one test: a USER-origin slot is refused and left unchanged. On the owner decision: Allow the helper to adopt only slots it created or unowned APP/untagged ones, never USER or CRON origin. Reason: that keeps the ChatEmbed re-stamp case working and closes the takeover of a person's chat. Keep the default limit of 1 as #509 already decided. Risk: medium. — crew-pr-reviewer
|
Done in 02f565c: an unowned |
02f565c to
993d952
Compare
|
Rebased onto main and folded the fix into commit 2; the previous head was GPT / Opus ( |
|
E2E case 17b ( |
Apps that own agent sessions stamped private slot attributes by hand and had to re-stamp them whenever another path created the slot first. acquire_worker_slot owns that: it re-stamps the app owner and working directory on every acquire, caps each app at one lease by default (set_worker_slot_limit changes it) and one lease per slot key, waits up to a timeout and raises WorkerSlotTimeout with a clear message. Blanket trust is a SafetyOverride scoped grant on slot._trust_scope, not the never-expiring slot._trust flag, so it is audited fail-closed, re-checked per approval and never cached as a session policy. Trusted patterns are audited fail-closed before they are added. Both end on release or after a TTL of at most 24h. Closes #509
An unowned slot a person or a cron job opened is refused with ValueError and left unchanged. Unowned app-origin or untagged slots are still re-stamped (the ChatEmbed case).
993d952 to
6b71904
Compare
|
This adds a new public app-kit API, acquire_worker_slot, with a per-app lease limit, an acquire timeout and TTL-bounded SafetyOverride trust grants that replace the permanent slot._trust. iamwhatever's earlier request is addressed: worker_slots.py:383 now refuses an unowned USER- or CRON-origin slot, and it checks the slot get_or_create_slot actually returned, so a folded key spelling is refused too. Unowned APP/untagged slots still re-stamp for ChatEmbed. Tests were added for both, and I read the head code. The GitHub review decision still shows CHANGES_REQUESTED at 28eca9f, so iamwhatever needs to re-review. HOLD because this is a new feature (~400 prod lines) that grants auto-approve trust (permission surface). The Design CONCERNS on head 6b71904 also has no target=design disposition, and both of its points are real. First, disable_app/uninstall_app never release the app's leases or deactivate its worker trust scopes, so a running worker keeps auto-approving until the TTL ends, and a reloaded backend can lock itself out at limit 1. Second, adopting untagged slots is looser than spec_builder._ensure_worker_slot. Suggested fix: release leases and call deactivate_scope for app::worker:* on disable/uninstall, with a test, and either adopt only _origin == APP slots or document why untagged ones are safe. — crew-pr-reviewer |
buluoray
left a comment
There was a problem hiding this comment.
Reviewed at 6b71904.
This gives apps one supported call to own a hidden, project-scoped worker session, capped at one per app with a bounded wait, and replaces the permanent session trust flag with an audited, expiring scoped grant. The limit, timeout, folded-key, owner and TTL paths hold up, and the earlier request is fixed: worker_slots.py:383 refuses an unowned user/cron slot on the slot actually returned, before anything is stamped, with tests on the real DashboardState. Breaking that check, the other-app owner check, the failure-path reservation release, or trust withdrawal on release each reddens named tests in test/test_apps_worker_slots.py. CI on this head: 85 success, 13 skipped, 0 failing. I did not run the full suite locally.
Two things block, both raised in the earlier hold and not yet addressed:
-
Untagged slots include people's channel conversations. Only
userandcronare refused, so an unowned slot with an empty_originis still adopted. Empty origin is what background create paths produce on purpose:dashboard/channel_slots.py:569opens the Slack/Discord conversation tab untagged, anddashboard/state.py:8003-8015names Slack, workflow inject and the OpenAI-compatible endpoint as untagged. Adopting one of those hides a person's conversation and repoints its project, the same harm as the USER case. The ChatEmbed reason does not appear to need it: chat-send stamps origin from the request (chat_handlers.py:852-855), and spec_builder's_ensure_worker_slotalready refuses every unscoped slot. Please adopt an existing unowned slot only when_origin == SlotOrigin.APP(or not at all), add a test with an untagged channel slot, and correct the spec bullet "Only app slots are adopted" and the commit title, which currently overclaim. -
Disable/uninstall leaves leases and trust live. Nothing outside the module references it, so
disable_app/uninstall_appnever release an app's leases or deactivateapp:<app>:worker:*. A disabled app's worker keeps auto-approving until the TTL (up to 24h), and a reloaded backend that lost its lease object while the slot still exists is locked out at the default limit of 1 until a restart. Please add a release-all-for-app call wired into disable/uninstall, with a test, and narrow the spec's "a lease the app lost cannot lock it out" to what is actually reclaimed.
Non-blocking follow-ups:
release()and the acquire failure path await the condition lock before touching the registry; a second cancellation while that lock is contended leaves the lease or reservation in place. The dict updates can be done synchronously, with onlynotify_allunder the lock.- The spec says a failed acquire creates no slot, but a failure after
get_or_create_slot(for example inside the trust grant) leaves the newly created, already stamped slot behind. - Pattern withdrawal can remove an identical pattern a person added while the lease was held.
Problem / Motivation
Goal: Apps that own agent sessions get a supported
acquire_worker_slothelper, limited to one worker per app by default, with an acquire timeout.Today an app that runs a background worker agent has to stamp private slot attributes (
slot._app,slot.project,slot._trust) itself, and re-stamp them on every acquire because a restart or another create path rebuilds the slot without them. The app-dev skill documents this as a stopgap pending #509. There is also no bound on how many worker slots one app holds, and trust is often granted with no expiry.Why it matters
Apps are coupled to private internals that can change under them, and a blanket permanent trust flag quietly exempts more and more sessions from interactive approval as apps copy the recipe.
Not a goal
AppContextfield for the helper.What changed (motivation → approach → change)
Gap → one seam that owns the stamping and the bounds → the new module
kiro_crew.apps.worker_slots:acquire_worker_slot(state, app, key, *, project, agent, model, trust, trusted_patterns, trust_ttl_secs, timeout)creates the slot if missing, re-stamps the app owner and working directory on every acquire (another create path, such as ChatEmbed's own POST, can create the slot without them), and returns aWorkerSlotLease(usable asasync with).set_worker_slot_limit(app, n)changes it live (raising it wakes waiters; lowering it never revokes a held lease). The limit is advisory and self-set for a cooperating app._originuserorcron) is refused and left unchanged, under any spelling of its key; unowned app-origin or untagged slots are still re-stamped (the ChatEmbed case).timeoutseconds (default 30), then raisesWorkerSlotTimeout:app 'x' already holds 1 of its 1 worker slot(s); waited 30s for one to be released. Release a lease (...) or raise the limit with set_worker_slot_limit().A timed-out or failed acquire creates no slot and holds no lease.trust=Truenever writesslot._trust(it does not expire and is cached as the session's"auto"policy that subagents read later). It activates aSafetyOverridescoped grant and setsslot._trust_scope, the same shape the task runner and issue_radar use: audited fail-closed, re-checked on every approval, never cached as a session policy. If the grant is refused,lease.trust_grantedis False.trusted_patternsare added only after their audit row is written withcritical=True.trust_ttl_secs(default 1h, max 24h); zero, negative, infinite or over-cap TTLs are refused. Only what the lease added is withdrawn; a human's session trust or another scope already on the slot is left alone.The skill's Worker Slots section now shows the helper instead of the stopgap, and
app-kit-platform.mdgains section 23 with the contract.Plain module function rather than an
AppContextSDK: apps that own slots already hold the dashboardstate, and this keeps the change free of manifest schema work. The default limit of 1 with a timeout is the maintainer's decision on #509.Backwards compatibility
Compatible: the helper is new and opt-in. No existing caller changes, and slots acquired the old way behave exactly as before. The default limit of 1 only applies to code that calls the new helper.
Removes nothing: no code path, key or function is removed; only the skill's stopgap recipe text is replaced by the supported call.
Tests
test/test_apps_worker_slots.py(red on main: the module does not exist; 34 passed with the change):async withform releases; a failed slot create frees the lease;_trust_scope, never_trust;_slot_is_trustedis True while held and False after release;_persistable_session_policystays"";call_laterspied) and withdraws both grants when fired, plus one short-TTL run awaited withasync_wait_until;user/cron-origin slot is refused and left unchanged, including through a folded key on the realDashboardState; an untagged slot is still re-stamped.Local gate: black, isort, flake8, mypy over the package, comment-history and brand gates, docs-lint, and
scripts/local-gate.pybackend (91 passed). The frontend step oflocal-gate.pycould not run here (npm registry auth); this PR touches no frontend code.Manual verification
N/A — the helper is pure slot bookkeeping with no UI; unit coverage drives every branch against a stand-in state.
Related Issues
Closes #509
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.