Ktor: preserve requirements through advanced agent edits
Work through Kotlin examples of real application boundaries: Apply backpressure to Ktor background work with a bounded coroutine channel; Preserve Kotlin coroutine cancellation in a Ktor service. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.
Download the Ktor rule pack ZIP · Inspect the YAML rules
Kotlin
Launching one detached coroutine per incoming request lets traffic outrun a slow downstream service. A finite channel bounds pending work; trySend tells the route when it must return an overload response. A lifecycle-owned scope keeps the worker attached to application shutdown.
Broken edit flagged · corrected edit passes
Kotlin
A broad exception handler can turn request cancellation into normal success. That prevents structured parents from stopping work and may cause the caller to send stale data or continue a mutation. Handle ordinary failures separately from cancellation.
Broken edit flagged · corrected edit passes
Use a correction as a saved requirement
Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.
Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.
Official Ktor documentation · All language and framework recipes