Skip to content

Index instance retention lookups - #52

Merged
cardmagic merged 6 commits into
mainfrom
fix/indexed-instance-retention
Sep 16, 2026
Merged

cardmagic merged 6 commits into
mainfrom
fix/indexed-instance-retention

Conversation

@cardmagic

@cardmagic cardmagic commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Opt-in instance pruning filters by actor type and updated_at_ms, but the SQL schema had no index supporting that lookup. Finding one expired instance among 2,000 retained/recent records scanned an unrelated index. Migration 10 adds (actor_type, updated_at_ms, id) so the database can narrow expired candidates before checking pending work.

The migration runs before the existing polling-migration early return, covering installed version-nine databases as well as fresh installs. Index creation can be retried after interruption. Doctor now expects migration 10, and the changelog and parity ledger describe the optimization. Retention predicates, timestamps, pending-work protections, batch sizes, and deletion order remain unchanged.

This is the JavaScript companion to Ruby #69. JavaScript already compares its timestamp directly, so its fix adds a supporting index. Run runtime.install() as part of upgrading to a release containing this change; older runtimes reject the newer schema version.

Prepare patch release 0.15.1 with matching runtime and package metadata and dated release notes. The packaged-install smoke test and version/release-note tests pass for 0.15.1.

Validation:

  • Current commit b6cac4be71d1eaef4c93d33c9cb95d9350a3c6a4: PR CI and branch CI passed. Greptile reports 5/5 on this commit, with no unresolved review threads.
  • The regression failed before the index was added. Temporarily restoring the original schema installer reproduced the failure on SQLite, PostgreSQL, and MySQL; restoring the fix passed all four new scenarios on each database.
  • Plan regressions inspect the index actually selected for single-policy preview and pruning queries, using 2,000 instances with rare expiration. They cover fresh installation, a populated version-nine upgrade, and an interrupted upgrade where the index already exists. A separate behavior test verifies different actor cutoffs and retention of unconfigured actors.
  • Full local suite on Node 24.18: 404 passed, 28 environment-specific skips across 55 files. Node 24.4 compatibility suite: 394 passed, 38 environment-specific skips.
  • PostgreSQL 17 adapter suite: 49 passed, no skips. MySQL 26.7 adapter suite: 38 passed, seven PostgreSQL-only skips. The new retention cases have no skips on either adapter.
  • pnpm run check, pnpm run format:check, and pnpm run build passed.
  • The existing PostgreSQL 14/18 and MySQL 8.0/8.4 CI jobs now run the retention regression through their package scripts.

Query-plan limit: older SQLite versions can still choose a primary-key scan for the combined OR predicate across actor policies. This migration supplies the missing index and fixes the measured single-policy workload; it does not force planner choices or rewrite multi-policy SQL. That behavior is documented rather than asserting a universal index-selection guarantee in the tests.

Find expired actor instances through actor type and update time instead
of scanning retained instances. Install the index in migration 10 before
the existing polling-migration early return, and update doctor checks.

Verify actual pruning plans on SQLite, PostgreSQL, and MySQL, including
version-nine upgrades, interrupted installs, and multiple policies.

See cardmagic/solid-objects-ruby#69
@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head bc7f764.

Older SQLite versions may choose a primary-key scan for an OR across
multiple actor policies even with the retention index. Keep explicit
index-selection regressions for fresh and upgraded single-policy data.
Verify distinct cutoffs and unconfigured actors in a separate behavior
test without requiring an optimizer choice for that different workload.

The full Node 24.4 suite and all new MySQL and PostgreSQL cases pass.
@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head a324551, including the Node 24.4 compatibility correction.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds schema migration 10, creating an index over (actor_type, updated_at_ms, id) to accelerate opt-in instance-retention lookups, and updates diagnostics, documentation, release metadata, and cross-database regression coverage.

  • Applies the retention index to fresh installations and upgrades from schema version 9.
  • Preserves retryability when index creation succeeded but migration recording was interrupted.
  • Expands PostgreSQL and MySQL test commands to run the retention regression.
  • Prepares package and runtime version 0.15.1 with a matching dated changelog entry.

Confidence Score: 5/5

The PR appears safe to merge with no outstanding correctness, security, release-consistency, or repository-rule issues.

The current code consistently applies and records migration 10, exercises fresh and interrupted upgrade paths, and keeps package, runtime, and changelog versions aligned at 0.15.1. All five earlier findings were manually resolved without explanatory replies and therefore are not outstanding.

Important Files Changed

Filename Overview
src/schema.ts Adds retryable migration 10 and creates the actor-type/update-time retention index before the existing polling-migration early return.
test/instance-retention.test.ts Covers index selection, fresh installation, version-nine upgrades, interrupted upgrades, distinct actor policies, and retention behavior across supported databases.
src/doctor.ts Updates schema diagnostics to require and report migrations 1 through 10.
package.json Bumps the package to 0.15.1 and includes retention tests in PostgreSQL and MySQL adapter suites.
src/version.ts Keeps the exported runtime version aligned with package version 0.15.1.
CHANGELOG.md Records the dated 0.15.1 release and its schema-installation requirement.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Install[runtime.install] --> Check{Migration 10 recorded?}
    Check -->|Yes| Existing[Continue schema installation]
    Check -->|No| Index[Create instances retention index]
    Index --> Record[Record migration 10]
    Record --> Existing
    Existing --> Retention[Preview or prune instances]
    Retention --> Lookup[Filter by actor_type and updated_at_ms]
    Lookup --> Pending[Check pending-work protections]
Loading

Reviews (5): Last reviewed commit: "chore: prepare version 0.15.1" | Re-trigger Greptile

Comment thread test/instance-retention.test.ts Outdated
Comment thread test/instance-retention.test.ts Outdated
Name the query-plan fields emitted by each supported database and infer
forwarded query arguments from DatabaseConnection. Flatten the upgrade
setup so index removal and migration reset are explicit sequential steps.
Comment thread test/instance-retention.test.ts Outdated
Comment thread test/instance-retention.test.ts Outdated
Comment thread test/instance-retention.test.ts Outdated
Forward get directly and derive the all argument tuple from DatabaseConnection so generic callbacks keep their explicit native contract.
@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head 3254be7. The query-plan rows now have explicit per-database fields, forwarded query arguments use DatabaseConnection parameter types, and upgrade setup uses sequential conditions. Type checks and Node 24.4 retention tests pass.

Capture connection reads as well as transactional candidate queries and independently require the preview and pruning plans to use the retention index.
@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai please review current head 9804e56. The preview-plan feedback is now covered independently: the tests assert one preview plan and two pruning plans, all using the retention index. Prior typing and nested-condition feedback remains addressed. pnpm run check and the Node 24.4 retention regressions pass.

Align the package and runtime versions and date the retention index
release notes for the patch release.
@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai please review current head b6cac4b. This prepares patch version 0.15.1: package and runtime versions match the dated changelog. Version/release-note tests and the packaged-install smoke test pass.

@cardmagic
cardmagic merged commit be9b67c into main Sep 16, 2026
19 checks passed
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