Repository navigation
Description
Context
The failed-start cleanup stack in createApp calls indexBatch.idle() (packages/ui-server/src/app.ts:642-643), webTools.close() (same file:837-851) and apifyEdits.close() (same file:1347-1349). None appears explicitly in the normal close path (await Promise.allSettled([...httpRequests.keys()]), same file:1507-1537) or in WsHost.close (packages/ui-server/src/ws/host.ts:911-919). The policy-root continuity descriptor’s separate fix belongs to #4273.
A bounded keyless reproduction on main 63bb400b3 and Bun 1.4.4 used the real createApp from packages/ui-server/tests/app-writer-cleanup.test.ts with its native-app fixture. Posting a fictional Apify setting through the local route returned 200 and a pending review. At the shared createApifyPolicyEdits boundary, a spy forwarded all real behavior and counted calls to the returned close(). Normal app.close() completed with APP_SHUTDOWN_CANCELS_PENDING_SETTINGS expected 1, received 0. The probe declined the pending review in teardown. The result establishes the missing normal-close call for that resource. Index-batch and web-executor consequences still need their own evidence.
Scope
Reconcile the normal and failed-start ownership of those three existing resources. Verify whether each has an indirect owner, including normal tool/session and writer draining. Retain one owner for each resource and correct any missing cleanup at the appropriate shutdown boundary.
Out of scope
Changes to unrelated trust, source acquisition, provider history, normal worker admission, or the separately owned policy-root descriptor.
Acceptance criteria
- Record the normal and failed-start owner and its ordering relative to the journal, worker admission and SQLite shutdown for each resource.
- Each corrected gap has an actual app lifecycle test with pending work and the intended failing assertion, restored proof and a meaningful mutation.
- Repeated close and failed start leave no owned pending work. Cleanup errors remain observable and later cleanup runs.
Verification
Run the focused bun run test packages/ui-server/tests/app-writer-cleanup.test.ts lifecycle controls. To repeat the bounded failure, wrap the real edits factory’s close in the existing app fixture, submit {change: {enabled: true}, base_hash: null} to the fixture’s policy route, confirm pending state, and observe the cancellation call during normal app close. Decline pending fixture work during teardown.
Contract impact
No machine-shape change expected. This restores the existing app-close resource ownership.
2026-11-20 triage — Grounded the shutdown repair in source and the pending-review reproduction. Classified as p2 unscheduled fix work.
Activity