implement-graceful-shutdown-for-your-application

implement-graceful-shutdown-for-your-application is a cursor rule for Cursor from PaulJPhilp/EffectPatterns. It costs 702 tokens per session, scanned A, original, MIT.

A TypeScript rule for shutting down a long-running Effect application cleanly when the operating system sends a stop signal.

In plain words
What is it for?
Use it in servers and other persistent processes that need to respond safely to SIGINT or similar operating-system signals.
Why use it?
It allows active work to finish or be interrupted in an orderly way and ensures resources such as database connections are cleaned up.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it in servers and other persistent processes that need to respond safely to SIGINT or similar operating-system signals.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/pauljphilp/effectpatterns/implement-graceful-shutdown-for-your-application
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatterns

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for implement-graceful-shutdown-for-your-application

README.md
[![agentmods](https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/implement-graceful-shutdown-for-your-application.svg)](https://agentmods.dev/rules/pauljphilp/effectpatterns/implement-graceful-shutdown-for-your-application)
Your own site
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/implement-graceful-shutdown-for-your-application"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/implement-graceful-shutdown-for-your-application.svg" alt="Measured on agentmods" height="20"></a>
Per session 702 This file is loaded in full into every session.
When invoked 702 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00702 $0.00702
Opus 5 $0.00351 $0.00351
Sonnet 5 $0.00140 $0.00140
Haiku 4.5 $0.00070 $0.00070

Measured 4d ago against content hash d5fb3a2a3d1e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

implement-graceful-shutdown-for-your-application scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

content/published/rules/cursor/implement-graceful-shutdown-for-your-application.mdc · 88 lines

How it starts

The opening of the file, as written. The whole thing — 88 lines — stays where its author put it; the contents beside it link to each section on GitHub.

description: Use Effect.runFork and OS signal listeners to implement graceful shutdown for long-running applications. globs: "**/*.ts" alwaysApply: true

Implement Graceful Shutdown for Your Application

Rule: Use Effect.runFork and OS signal listeners to implement graceful shutdown for long-running applications.

Example

This example creates a server with a "scoped" database connection. It uses runFork to start the server and sets up a SIGINT handler to interrupt the server fiber, which in turn guarantees the database finalizer is called.

import { Effect, Layer, Fiber, Context, Scope } from "effect";
import * as http from "http";

// 1. A service with a finalizer for cleanup
class Database extends Effect.Service<Database>()("Database", {
  effect: Effect.gen(function* () {
    yield* Effect.log("Acquiring DB connection");
    return {
      query: () => Effect.succeed("data"),
    };
  }),
}) {}

// 2. The main server logic
const server = Effect.gen(function* () {
  const db = yield* Database;

  // Create server with proper error handling
  const httpServer = yield* Effect.sync(() => {
    const server = http.createServer((_req, res) => {
      Effect.runFork(
        Effect.provide(
          db.query().pipe(Effect.map((data) => res.end(data))),
          Database.Default
        )
      );
    });
    return server;
  });

  // Add a finalizer to close the server
  yield* Effect.addFinalizer(() =>
    Effect.gen(function* () {
      httpServer.close();
      yield* Effect.log("Server closed");
    })
  );

  // Start server with error handling
  yield* Effect.async<void, Error>((resume) => {
    httpServer.once("error", (err: Error) => {
      resume(Effect.fail(new Error(`Failed to start server: ${err.message}`)));
    });

    httpServer.listen(3456, () => {
      resume(Effect.succeed(void 0));
    });
  });

  yield* Effect.log("Server started on port 3456. Press Ctrl+C to exit.");

  // For testing purposes, we'll run for a short time instead of forever
  yield* Effect.sleep("2 seconds");
  yield* Effect.log("Shutting down gracefully...");
});

// 3. Provide the layer and launch with runFork
const app = Effect.provide(server.pipe(Effect.scoped), Database.Default);

// 4. Run the app and handle shutdown
Effect.runPromise(app).catch((error) => {
  Effect.runSync(Effect.logError("Application error: " + error));
  process.exit(1);
});

Read the full file on GitHub · 88 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 88 lines · 702 tokens per session scan A d5fb3a2a3d1e

Subscribe to this mod's changes

implement-graceful-shutdown-for-your-application is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (796 stars, last pushed 2mo ago), licensed MIT. It adds 702 tokens to every session, about $0.0035 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.