Repository navigation
refactor(core): name every event kind in one enum - #624
Draft
PiquelChips wants to merge 3 commits into
Draft
PiquelChips wants to merge 3 commits into
PiquelChips wants to merge 3 commits into
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
This was referenced Nov 22, 2026
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
force-pushed
the
refactor/core-event-kind
branch
from
November 22, 2026 22:12
a18ecbd to
311f5c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Event kinds such as
operation_failedandaction_succeededwere stringliterals in the store, the daemon (telemetry spans, exec recording) and core's
timeline. This adds
EventKindtopiqueld-core, astring_enum!with adoc comment on each of its 55 kinds, and uses its variants wherever a kind is
recorded or compared. Part of PQD-161.
operation_event,environment_event_on,record_environment_event,secret_event_on, the journal's steps andSecurityEvent::kind) take anEventKind, so a misspelt kind no longercompiles.
EventKind::…as_str(), the denial-burst cooldown included.EXPLAIN QUERY PLANshows SQLite still searches its partial indexsecurity_denial_burstsonce the value is bound.EventKind, so a store test reads the migratedschema and checks that every kind an index or view spells out parses as
one.
compared_as_string!macro gives a string-kept wire fieldFrom/==with an enum.
ApiErrorCodenow uses it too, replacing its handwrittenimpls.
Nothing changes on the wire. Every variant's string is the literal it replaces.
Fields and places kept as strings:
Event.kindstaysString. Stored history holds kinds older daemonsrecorded, 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_kindor==,as
ApiErrorCodeis. Keeping it a string also keeps the OpenAPI documentand generated client identical.
EventFilter.kind(the--kindfilter and the dashboard's kind picker)stays
String: it filters on whatever kinds history holds.security_denial_burstsindex (access_denial_burst) and theoperation_progressview (operation_failed,action_failed).kinds_the_schema_spells_out_are_event_kindsties them toEventKind.kind_badgekeeps its substring tone heuristic. It mustalso tone kinds this build doesn't know.
Proof: a test tying the schema's kinds to
EventKind, the existing testsunchanged, and a codes-only diff showing that all 101 replaced literals map
to a variant with the same string.
Commands and results
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::AccessDenialBurstin place of the equivalentSecurityEvent::DenialBurst.kind()) was rechecked with store clippy andthe store's denial-burst, security and schema tests: 4/4 passed.
kinds_the_schema_spells_out_are_event_kindsfindsaccess_denial_burst,operation_failedandaction_failed. It fails, namingaction_failed,when
ActionFailed's string is temporarily changed (reverted).EXPLAIN QUERY PLAN, in a temporary test that has since been removed: thecooldown 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 toEventKind::AccessDenialBurst.string_enum!buildsas_strandparsefrom one table, and a duplicate string fails
-D warnings(checked bytemporarily giving
ActionFailedthe stringaction_succeeded:unreachable patterninnames.rs).(
record_environment_event(…, EventKind::CommandFinished, …)). Everyassertion still compares against the old literal strings.
-D warningsforpiqueld-core,piqueld-store,piqueld,piqueld-client,piquelctl(--all-targets --all-features) and thewasm32 line for
piqueld-uiandpiqueld-client: clean.generate_openapi --check: every generated file is up to date.just docs: 0 errors.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.
EventKind::X.as_str()inline tosqlx::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
AGENTS.mdit applies to,documentation included, with its reverse states. (Internal refactor:
no surface changes.
docs/dev/rust-conventions.mddocuments the rule.)Note
Written by Claude Opus 5.5 in Claude Code (via T3 Code)