Skip to content

fix(db): hook_perf_baseline filters wrong column (#1494 residual) - #1500

Merged
namastex888 merged 2 commits into
devfrom
fix/hook-perf-baseline-view-subject
Apr 29, 2026
Merged

namastex888 merged 2 commits into
devfrom
fix/hook-perf-baseline-view-subject

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Companion fix to #1494. dog-fooder-11eb's verdict flagged that migration 056 filtered WHERE kind = 'hook.delivery' but actual rows carry subject='hook.delivery', kind='system', data._kind='span'. View was returning 0 rows regardless of dispatch activity.

Migration 057 replaces the view to filter on subject='hook.delivery' AND data->>'_kind'='span'.

Empirical

  • BEFORE: SELECT count(*) FROM hook_perf_baseline → 0
  • AFTER: SELECT count(*) FROM hook_perf_baseline → 5

genie doctor --perf and the hookify-perf-foundation telemetry now actually work.

Companion fix to #1494 (which fixed the schema accept). dog-fooder-11eb's
verdict (state/evidence/followups-1490-1491-1493/REPORT.md) flagged a
SECOND bug after the schema fix landed: the view created by migration
056 filtered `WHERE kind = 'hook.delivery'`, but the actual emitted
genie_runtime_events row carries:

  subject = 'hook.delivery'   ← what we want to filter on
  kind    = 'system'          ← what migration 056 incorrectly filters on
  data->>'_kind' = 'span'     ← span marker

Net effect: rows accepted into the table never appeared in the view, so
`genie doctor --perf` and `hook_perf_baseline` queries always returned
empty. The hookify-perf-foundation telemetry (#1485) was inert.

Fix: migration 057 replaces the view to filter on
`subject='hook.delivery' AND data->>'_kind' = 'span'`.

Empirical: BEFORE migration: SELECT count(*) FROM hook_perf_baseline → 0
                AFTER migration: SELECT count(*) FROM hook_perf_baseline → 5

Daemon-mode hook telemetry now actually populates the view that
`genie doctor --perf` reads from.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e5b34859-59bb-465c-82a0-37dc1d538922

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hook-perf-baseline-view-subject

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in the hook_perf_baseline view by correcting the filter criteria to use the subject column instead of kind and ensuring only completed spans are included. Feedback was provided to improve the resilience of the duration_ms calculation by using a safe numeric cast to prevent the view from failing on malformed data.

COALESCE(data->>'event', '<unknown>') AS event_name,
COALESCE(data->>'tool', '<none>') AS tool_name,
COALESCE(data->>'hook_name', '<unknown>') AS handler_name,
NULLIF(data->>'duration_ms', '')::numeric AS duration_ms,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The direct cast ::numeric is not safe and will cause the entire view query to fail if data->>'duration_ms' contains a non-numeric value (e.g., from malformed event data). This would make the hook_perf_baseline view and any dependent features unusable until the bad data is cleared.

To make the view more resilient, it's better to validate the value before casting. A CASE statement with a regular expression can be used to safely attempt the conversion, coercing invalid values to NULL. These NULL values will then be filtered out by the outer WHERE duration_ms IS NOT NULL clause.

    (CASE WHEN data->>'duration_ms' ~ '^[0-9]+$' THEN (data->>'duration_ms')::numeric END) AS duration_ms,

#1494 residual)

Tests were inserting rows with kind='hook.delivery' (the OLD filter the view
no longer matches) and asserting they appeared in hook_perf_baseline. After
migration 057 changes the view to filter on subject='hook.delivery' AND
data._kind='span', tests must insert rows in that shape.

Updates:
- DELETE sweep now matches both subject AND legacy kind for cleanup
- INSERT statements add subject='hook.delivery', kind='system' (matches real
  emitter shape per 11eb verdict)
- Test fixture data JSON now includes _kind: 'span' so the new view's
  WHERE data->>'_kind' = 'span' clause matches

Validation: 5/5 src/db/migrations/hook-perf-baseline.test.ts pass.
@namastex888
namastex888 merged commit 753d47e into dev Apr 29, 2026
13 of 15 checks passed
@automagik-genie
automagik-genie deleted the fix/hook-perf-baseline-view-subject branch September 25, 2026 04:50
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