Skip to content

refactor(core): name every event kind in one enum - #624

Draft
PiquelChips wants to merge 3 commits into
mainfrom
refactor/core-event-kind
Draft

PiquelChips wants to merge 3 commits into
mainfrom
refactor/core-event-kind

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What and why

Event kinds such as operation_failed and action_succeeded were string
literals in the store, the daemon (telemetry spans, exec recording) and core's
timeline. This adds EventKind to piqueld-core, a string_enum! with a
doc comment on each of its 55 kinds, and uses its variants wherever a kind is
recorded or compared. Part of PQD-161.

  • The store's event writers (operation_event, environment_event_on,
    record_environment_event, secret_event_on, the journal's steps and
    SecurityEvent::kind) take an EventKind, so a misspelt kind no longer
    compiles.
  • Every SQL statement that wrote or matched a kind literal now binds
    EventKind::…as_str(), the denial-burst cooldown included.
    EXPLAIN QUERY PLAN shows SQLite still searches its partial index
    security_denial_bursts once the value is bound.
  • Migrations can't name EventKind, so a store test reads the migrated
    schema and checks that every kind an index or view spells out parses as
    one.
  • A compared_as_string! macro gives a string-kept wire field From/==
    with an enum. ApiErrorCode now uses it too, replacing its handwritten
    impls.

Nothing changes on the wire. Every variant's string is the literal it replaces.

Fields and places kept as strings:

  • Event.kind stays String. Stored history holds kinds older daemons
    recorded, and a client may read kinds a newer daemon adds, so a typed field
    would fail to read them. It's compared through Event::known_kind or ==,
    as ApiErrorCode is. Keeping it a string also keeps the OpenAPI document
    and generated client identical.
  • EventFilter.kind (the --kind filter and the dashboard's kind picker)
    stays String: it filters on whatever kinds history holds.
  • The schema keeps its literals, since migrations can't change: the
    security_denial_bursts index (access_denial_burst) and the
    operation_progress view (operation_failed, action_failed).
    kinds_the_schema_spells_out_are_event_kinds ties them to EventKind.
  • The dashboard's kind_badge keeps its substring tone heuristic. It must
    also tone kinds this build doesn't know.

Proof: a test tying the schema's kinds to EventKind, the existing tests
unchanged, and a codes-only diff showing that all 101 replaced literals map
to a variant with the same string.

Commands and results
  • Top of the stack (refactor(core): name device login statuses in one enum #628, 310aef13b):
    cargo nextest run -p piqueld-core -p piqueld-store -p piqueld -p piqueld-client -p piquelctl --all-features:
    1006/1006 passed. This PR's last change after that run (binding
    EventKind::AccessDenialBurst in place of the equivalent
    SecurityEvent::DenialBurst.kind()) was rechecked with store clippy and
    the store's denial-burst, security and schema tests: 4/4 passed.
  • kinds_the_schema_spells_out_are_event_kinds finds access_denial_burst,
    operation_failed and action_failed. It fails, naming action_failed,
    when ActionFailed's string is temporarily changed (reverted).
  • EXPLAIN QUERY PLAN, in a temporary test that has since been removed: the
    cooldown filter gives SEARCH events USING INDEX security_denial_bursts (resource=? AND actor_user_id=? AND created_at_ms>?)
    both with the literal and with kind=? bound to
    EventKind::AccessDenialBurst.
  • No per-enum round-trip test: string_enum! builds as_str and parse
    from one table, and a duplicate string fails -D warnings (checked by
    temporarily giving ActionFailed the string action_succeeded:
    unreachable pattern in names.rs).
  • The only test change is one call that the new signature forces
    (record_environment_event(…, EventKind::CommandFinished, …)). Every
    assertion still compares against the old literal strings.
  • Clippy -D warnings for piqueld-core, piqueld-store, piqueld,
    piqueld-client, piquelctl (--all-targets --all-features) and the
    wasm32 line for piqueld-ui and piqueld-client: clean.
  • generate_openapi --check: every generated file is up to date.
  • just docs: 0 errors.
  • Codes-only diff (each literal the diff removes, against the variant added
    in its hunk and that variant's string): 101 literals replaced, 0 without a matching variant.
    The only kind literals left outside tests are the enum's own table and the
    migrations.
  • Not taken: passing EventKind::X.as_str() inline to sqlx::query!.
    query! borrows its arguments, so an inline temporary fails with E0716
    ("temporary value dropped while borrowed"). That's why each query binds it
    to a local first.

Checklist

  • The feature reaches each surface in AGENTS.md it applies to,
    documentation included, with its reverse states. (Internal refactor:
    no surface changes. docs/dev/rust-conventions.md documents the rule.)

Note

Written by Claude Opus 5.5 in Claude Code (via T3 Code)

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Event kinds were string literals in the store, the daemon's telemetry and
exec recording, and core's timeline. `EventKind` in piqueld-core names each
one, with a doc comment, and every place that records or compares a kind
uses its variant, including SQL, where the kind is now a bound parameter.

`Event.kind` stays a `String`: history holds kinds older daemons recorded,
and clients may read kinds a newer daemon adds. It is compared through
`Event::known_kind` or `==`, as `ApiErrorCode` is. The denial-burst query
keeps its literal, since its partial index only serves a literal.

Part of PQD-161
The cooldown query binds `EventKind::AccessDenialBurst` like every other
site: `EXPLAIN QUERY PLAN` shows SQLite still searches
`security_denial_bursts` once the value is bound, so the literal it kept
was never needed.

Migrations can't name `EventKind`, so a store test reads the migrated
schema and checks that every kind an index or view spells out (the
denial-burst index, the `operation_progress` view) parses as one.

`compared_as_string!` takes one type, and `EventKind` drops the serde
derives nothing uses, with the test of them: the macro already rejects a
duplicate string (`unreachable_patterns`).

Part of PQD-161
@PiquelChips
PiquelChips force-pushed the refactor/core-event-kind branch from a18ecbd to 311f5c2 Compare November 22, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant