Skip to content

refactor(runtime): add stale trigger cleanup and activity tracking - #5386

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/trigger-storage-stale-cleanup-w2
Open

refactor(runtime): add stale trigger cleanup and activity tracking#5386
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/trigger-storage-stale-cleanup-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add optional lastActivityAt timestamp to TriggerState to track when trigger states were last modified
  • Introduce prune(maxInactiveMs) method to JsonFileStorage to remove inactive connection states after a configurable duration
  • Update isTriggerState validator to accept and properly validate the new optional field
  • Prevent unbounded storage growth from abandoned connections

Rationale

Trigger states are persisted but had no cleanup mechanism. Connections that are abandoned without explicit disable() calls would accumulate indefinitely in the storage file, causing both disk usage and load time to grow unbounded over time. The new prune() method enables periodic cleanup of stale entries.

Test plan

  • bun test packages/runtime/src/trigger-storage.test.ts — 9 tests pass, including 4 new prune-specific tests covering:
    • Removal of legacy states without timestamps
    • Age-based removal beyond configurable thresholds
    • Invalid timestamp handling
    • No-op behavior when all states are recent
  • bunx tsc --noEmit in packages/runtime/ — no type errors
  • bun run fmt — no formatting issues

The change is behavior-preserving for existing code paths; lastActivityAt is optional and prune() is opt-in.

Verification

Run bun test packages/runtime/src/trigger-storage.test.ts to verify prune concurrency and edge-case safety.


Summary by cubic

Adds activity tracking to trigger states and a prune cleanup to remove stale entries. This prevents storage growth from abandoned connections.

  • New Features
    • Add optional lastActivityAt on TriggerState, set via TriggerStateManager.set().
    • Add prune(maxInactiveMs) to JsonFileStorage to delete entries without timestamps or older than the threshold.
    • Update isTriggerState to validate lastActivityAt when present.

Written for commit 6b016b7. Summary will update on new commits.

Review in cubic

Adds optional lastActivityAt timestamp to TriggerState and introduces a prune() method to JsonFileStorage to remove inactive trigger states after a configurable duration. This prevents unbounded storage growth when connections are abandoned without being explicitly cleaned up.

Includes comprehensive unit tests for pruning logic covering:
- Removal of states without timestamps (legacy data)
- Age-based removal beyond configurable thresholds
- Invalid timestamp handling
- No-op when all states are fresh

The isTriggerState validator is updated to accept and validate the optional field.
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