agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanModelContextProtocol/.agents/skills/cancellation/SKILL.md

cancellation

Skill1 starsChanged 7 days agoMITView on GitHub

How cancellation tokens flow from the caller through Mediator, handlers and repositories to EF Core, and how tests prove they are passed on. Use when writing any async method, endpoint, handler or repository call.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every async call that can be cancelled is given the token of the request that started it, all the way down to the database.

    line 12
  2. Very specific:

    Add CancellationToken cancellationToken as the last parameter of any new async method.

    line 22
  3. Very specific:

    Use CancellationToken.None or default outside tests.

    line 39
  4. Distinctive:

    Leave the token out of one call in a chain.

    line 40

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cancellation

The rule

Every async call that can be cancelled is given the token of the request that started it, all the way down to the database. When a caller goes away, the work stops.

LayerWhere the token comes from
PresentationThe framework: an endpoint or tool parameter, HttpContext.RequestAborted, or (in Lambda) a source built from context.RemainingTime
ApplicationHandle(request, cancellationToken)
InfrastructureThe last parameter of every repository method, passed to every EF Core ...Async call

Steps

  1. Add CancellationToken cancellationToken as the last parameter of any new async method.
  2. Pass it to sender.Send(request, cancellationToken), to every repository call, and to every EF Core method (ToListAsync, CountAsync, ExecuteUpdateAsync, SaveChangesAsync).
  3. In tests, create a real token and assert it's the one that reached the mock (unit-tests):
using var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;

// Act
var result = await handler.Handle(command, token);

// Assert
_ = await reviewsRepository.Received(1).UpdateReview(command.Id, command.Stars, command.Text, token);

Don't

  • Use CancellationToken.None or default outside tests.
  • Leave the token out of one call in a chain. Every hop needs it.
  • Make the token optional (= default) on an interface method.

Check

dotnet build
dotnet test

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.