refactor(runtime): add stale trigger cleanup and activity tracking - #5386
Open
pedrofrxncx wants to merge 1 commit into
Open
refactor(runtime): add stale trigger cleanup and activity tracking#5386pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
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.
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.
Summary
lastActivityAttimestamp toTriggerStateto track when trigger states were last modifiedprune(maxInactiveMs)method toJsonFileStorageto remove inactive connection states after a configurable durationisTriggerStatevalidator to accept and properly validate the new optional fieldRationale
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 newprune()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:bunx tsc --noEmitinpackages/runtime/— no type errorsbun run fmt— no formatting issuesThe change is behavior-preserving for existing code paths;
lastActivityAtis optional andprune()is opt-in.Verification
Run
bun test packages/runtime/src/trigger-storage.test.tsto 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.
lastActivityAtonTriggerState, set viaTriggerStateManager.set().prune(maxInactiveMs)toJsonFileStorageto delete entries without timestamps or older than the threshold.isTriggerStateto validatelastActivityAtwhen present.Written for commit 6b016b7. Summary will update on new commits.