agentleFS
discord-phpdiscord-php/DiscordPHP/.agents/skills/gateway-cache-sync-keeper/SKILL.md

gateway-cache-sync-keeper

Skill1.1k starsChanged 35 days agoMITView on GitHub

Maintain gateway event handlers — payload hydration, cache mutation, event return shapes, and handler registration. Use when touching WebSockets/Events, Handlers.php, or Event.php.

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 4 mentionsSep 2026: 13 mentionsOct 2026: 9 mentionsNov 2026: 1 mention
Dec 2025Jun 2026Nov 2026
Mentions a month of the discord-php/DiscordPHP repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about discord-php/DiscordPHP

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub and Bluesky (52 times).

On GitHub · 50

45 more on GitHub

The file

Show its rules and text

We split this skill into the rules it gives an agent

31 rules. About 0 are common, 24 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈24

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when work touches:

    line 11
  2. Distinctive:

    Keep gateway handling as real-time state sync layer:

    line 21
  3. Distinctive:

    update owning repositories and related caches

    line 48
  4. Distinctive:

    If handler only hydrates one object and ignores related caches, change is probably incomplete.

    line 53
  5. Distinctive:

    When adding or changing event family, inspect all three:

    line 57
  6. Distinctive:

    If one changes and the others do not, make sure that is intentional.

    line 63
  7. Distinctive:

    Use when payload contains user data.

    line 69
  8. Very specific:

    Use when payload contains guild member data.

    line 73
  9. Distinctive:

    Do not manually duplicate user/member cache update logic unless event family has special latency or shape constraints.

    line 75
  10. Distinctive:

    Use factory plus subtype maps when payload family is polymorphic:

    line 81
  11. Very specific:

    Do not push raw stdClass payloads deep into caches when repo already has typed part model.

    line 87
  12. Distinctive:

    create events usually instantiate new parts and set them into owning repo

    line 91
  13. Distinctive:

    update events often clone old cached part, mutate current part, and return both new and old values

    line 92
  14. Distinctive:

    delete events often pull from cache and return removed typed part plus extra status

    line 93
  15. Very specific:

    update author/mention/interacting user caches

    line 106
  16. Very specific:

    If you change MessageCreate or MessageUpdate, inspect:

    line 109
  17. Distinctive:

    Do not treat guild create as "just one guild part".

    line 123
  18. Very specific:

    update parent threads repo

    line 130
  19. Distinctive:

    avoid unnecessarily slow cache paths

    line 140
  20. Distinctive:

    Before changing a return shape, inspect:

    line 153
  21. Distinctive:

    When changing event behavior, walk this checklist:

    line 161
  22. Distinctive:

    Do counters, last IDs, or status fields need sync?

    line 167
  23. Distinctive:

    If you cannot answer each, handler is not fully understood yet.

    line 170
  24. Distinctive:

    When adding new dispatch type:

    line 174
  25. Very specific:

    add constant to Event.php

    line 176
  26. Very specific:

    add handler registration to Handlers.php

    line 177
  27. Distinctive:

    ensure any runtime option that disables events still behaves sensibly

    line 180
  28. Distinctive:

    Do not blindly overwrite cached richer state with partial payload unless code already accounts for missing fields.

    line 193
  29. Distinctive:

    prefer payload data over avoidable REST fetches

    line 197
  30. Distinctive:

    Stop if you see:

    line 204
  31. Distinctive:

    update event overwriting rich cached fields with partial sparse payload

    line 210

≈ “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

Skill: gateway-cache-sync-keeper

Use this skill when work touches:

  • src/Discord/WebSockets/Handlers.php
  • src/Discord/WebSockets/Event.php
  • src/Discord/WebSockets/Events/*

This is event-to-cache coherence skill. Load it when changing gateway dispatch behavior, event return shapes, or cache mutation.

Goal

Keep gateway handling as real-time state sync layer:

  • dispatch payloads become typed parts
  • related repositories get updated immediately
  • emitted event payloads stay semantically useful
  • caches for users, members, channels, messages, threads, guilds stay coherent

Read in this order

  1. src/Discord/WebSockets/Event.php
  2. src/Discord/WebSockets/Handlers.php
  3. Matching part/repository families
  4. Representative events:
    • src/Discord/WebSockets/Events/MessageCreate.php
    • src/Discord/WebSockets/Events/MessageUpdate.php
    • src/Discord/WebSockets/Events/GuildCreate.php
    • src/Discord/WebSockets/Events/GuildDelete.php
    • src/Discord/WebSockets/Events/InteractionCreate.php
    • src/Discord/WebSockets/Events/ThreadListSync.php
    • src/Discord/WebSockets/Events/GuildMemberAdd.php

Core contract

Event classes in this repo are not dumb payload forwarders. They:

  • interpret transport payloads
  • instantiate correct typed parts, often via runtime TYPES maps
  • update owning repositories and related caches
  • warm user/member caches from nested payloads
  • preserve secondary invariants like counters or last_message_id
  • return semantic values used by userland listeners

If handler only hydrates one object and ignores related caches, change is probably incomplete.

Three files usually move together

When adding or changing event family, inspect all three:

  1. src/Discord/WebSockets/Event.php — constant
  2. src/Discord/WebSockets/Handlers.php — registration
  3. src/Discord/WebSockets/Events/<Name>.php — implementation

If one changes and the others do not, make sure that is intentional.

Event base helpers to use

cacheUser(object $userdata)

Use when payload contains user data. Keeps top-level user cache current.

cacheMember(MemberRepository $members, array $memberdata)

Use when payload contains guild member data. Keeps guild member cache current. Some event families override details for performance reasons, like InteractionCreate.

Do not manually duplicate user/member cache update logic unless event family has special latency or shape constraints.

Hydration rules

Prefer typed parts immediately

Use factory plus subtype maps when payload family is polymorphic:

  • channels from Channel::TYPES
  • interactions from Interaction::TYPES
  • components from component TYPES

Do not push raw stdClass payloads deep into caches when repo already has typed part model.

Create vs update vs delete semantics matter

  • create events usually instantiate new parts and set them into owning repo
  • update events often clone old cached part, mutate current part, and return both new and old values
  • delete events often pull from cache and return removed typed part plus extra status

Preserve those shapes unless you have strong compatibility reason to change them.

Coherence rules by family

Message events

These are easy to break because they carry many side effects:

  • store or update message in channel/thread repo when configured
  • keep last_message_id current
  • handle message-content intent limits correctly
  • update author/mention/interacting user caches
  • preserve old/new payload behavior on update

If you change MessageCreate or MessageUpdate, inspect:

  • message cache behavior
  • intent-gated content handling
  • DM vs guild channel routing
  • thread message counting or parent lookup logic

Guild create/delete/update families

Guild events often do bulk cache work:

  • guild create populates guild repo plus member, user, voice state, thread, stage instance, scheduled event, sound caches
  • guild delete must preserve unavailable-vs-removed semantics

Do not treat guild create as "just one guild part". It is bootstrap event for several nested repositories.

Thread events

Threads are child collections hanging off parent channels. Thread handlers usually must:

  • locate parent channel
  • update parent threads repo
  • possibly update thread member state
  • preserve thread counters or metadata

Interaction events

Interaction handlers are latency-sensitive. They still must:

  • hydrate correct interaction subtype
  • cache resolved users/members
  • avoid unnecessarily slow cache paths
  • invoke registered command handlers/autocomplete flow

Event return-shape rules

Userland listens to emitted values. Keep return shapes stable and meaningful.

Common patterns already used:

  • MessageCreate returns new Message
  • MessageUpdate returns [newOrData, oldMessage]
  • GuildDelete returns [$guildPartOrData, $unavailableFlag]

Before changing a return shape, inspect:

  • existing event listeners in examples/tests/docs
  • parity with sibling events in same family
  • whether old state is required for consumers

Cache path playbook

When changing event behavior, walk this checklist:

  1. What is primary part produced by payload?
  2. Which repository should own it?
  3. Which parent or child repositories also need update?
  4. Which related users or members appear in payload?
  5. Do counters, last IDs, or status fields need sync?
  6. What should event listener receive back?

If you cannot answer each, handler is not fully understood yet.

Registration playbook

When adding new dispatch type:

  1. add constant to Event.php
  2. add handler registration to Handlers.php
  3. create event class
  4. choose emitted event aliases if handler needs alternatives
  5. ensure any runtime option that disables events still behaves sensibly

Partial payload and intent rules

Gateway payloads are not always full objects.

Examples:

  • message update may be partial
  • message content may be missing without MESSAGE_CONTENT intent
  • interaction-related payloads may favor speed over full cache warmup
  • guild create member lists vary with guild size and enabled intents

Do not blindly overwrite cached richer state with partial payload unless code already accounts for missing fields.

Performance rules

  • prefer payload data over avoidable REST fetches
  • reuse cache lookups instead of broad scans when possible
  • but preserve correctness for parent-child lookup when repo shape demands it
  • interaction path should avoid slow cache resolution that delays response handling

Smells

Stop if you see:

  • event class added without handler registration
  • cache update for primary part but not related repositories
  • raw payload stuffed in cache when typed part exists
  • user/member data in payload ignored even though later code depends on cache
  • update event overwriting rich cached fields with partial sparse payload
  • return shape change with no thought for existing listener contract

Checklist before commit

  • event constant and handler registration aligned
  • correct subtype hydration path used
  • primary and related repositories updated
  • user/member caches updated where payload carries them
  • partial/intents behavior preserved
  • event return shape still intentional and compatible
  • tests/docs/examples checked if public listener contract changed

Bottom line

Gateway events are cache-synchronization code. Treat them like consistency-critical logic, not like thin adapters. One missed repository update can make the whole object graph lie.

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.