Skip to content

Fix build: restore wa-automate SessionManager + Windows rimraf globs#3329

Open
t0g3pii wants to merge 5 commits into
open-wa:masterfrom
t0g3pii:fix/build-sessionmanager-and-rimraf
Open

Fix build: restore wa-automate SessionManager + Windows rimraf globs#3329
t0g3pii wants to merge 5 commits into
open-wa:masterfrom
t0g3pii:fix/build-sessionmanager-and-rimraf

Conversation

@t0g3pii
Copy link
Copy Markdown

@t0g3pii t0g3pii commented May 8, 2026

Summary

  • Restore missing SessionManager source file so @open-wa/wa-automate builds again.
  • Make @open-wa/node-red clean scripts Windows-safe by enabling rimraf globbing.
  • Validate s3Sync into a real S3Config only when required credentials exist.
  • Prevent S3 sync timer leaks and overlapping backups by storing/clearing the timer handle and scheduling with a non-overlapping loop.
  • Harden stop() to be best-effort so timer/S3 cleanup still runs if local compression stop fails.
  • Fix root turbo scripts to be cross-platform (Windows/macOS/Linux) and only exclude the actual docs workspace package.

Test plan

  • pnpm -C packages/wa-automate run build
  • pnpm -w run build

Summary by CodeRabbit

  • New Features

    • Added session management with local compression and optional S3 backup/restore capabilities
    • Session backup URL generation with configurable expiration settings
  • Chores

    • Updated build configuration and package management scripts

Re-add the wa-automate SessionManager source (previously ignored via a broad .gitignore rule) and make node-red clean scripts work on Windows by enabling rimraf globbing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Adds exported SessionManager (local compression + optional S3 backup/restore), anchors /session/ and /newsession/ in .gitignore and ignores *.mdx, updates Node-RED clean scripts to use rimraf --glob, and removes legacy exclusions from root turbo scripts.

Changes

Session Management System

Layer / File(s) Summary
Project Configuration
.gitignore, integrations/node-red/package.json, package.json
Anchors /session/ and /newsession/ ignore patterns, adds *.mdx; updates Node-RED clean:editor/clean:runtime to use rimraf --glob; removes legacy workspace exclusions from root turbo scripts.
Session Manager Type Definition
packages/wa-automate/src/session/SessionManager.ts
Adds SessionManagerConfig type with sessionId, dataDir, optional S3Config, syncInterval, and feature flags for local compression and S3 backup.
Session Manager Class and Constructor
packages/wa-automate/src/session/SessionManager.ts
Adds exported SessionManager class with private fields (config, logger, localCompression, s3Sync, timer, syncInFlight) and constructor storing config and initializing logging.
Lifecycle Management
packages/wa-automate/src/session/SessionManager.ts
start() conditionally initializes local compression and optional S3SyncManager and starts periodic sync; stop() stops compression, clears timers, resets guards, and clears s3Sync.
Session Operations
packages/wa-automate/src/session/SessionManager.ts
backupSession() uploads local .data.zst to S3 (or returns null if S3 not configured); restoreSession(filename) restores from S3; getSessionBackupUrl(filename, expiresIn) generates signed URL or returns null.
Periodic Sync Loop
packages/wa-automate/src/session/SessionManager.ts
Implements a setTimeout-based tick loop with a syncInFlight guard to avoid overlapping backups; errors are caught and logged.
S3 Config Parser & Factory
packages/wa-automate/src/session/SessionManager.ts
parseS3Config() validates S3 config; createFromConfig() maps external config into SessionManagerConfig, applying defaults and enabling features based on parsed S3 settings.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I nibble bytes and zip with care,
Sessions tucked in bundles fair,
Clouds hum softly on the wire,
Gitignore sweeps the muddy mire,
Rimraf globs — a tidy lair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: restoring the SessionManager source file and fixing Windows compatibility for rimraf glob patterns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@t0g3pii
Copy link
Copy Markdown
Author

t0g3pii commented May 8, 2026

Just a quick hint here, i have NOT removed the filters for this pr, its ur choice if u remove them since theyre doing trouble currently

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.gitignore:
- Line 72: The .gitignore entry "*.mdx" is unclear since no .mdx files exist;
either remove the "*.mdx" pattern from .gitignore if it's unnecessary or retain
it but explicitly document its purpose in the PR description (e.g., "preventive
rule for future MDX build artifacts or editor-generated files") so reviewers
know it's intentional—refer to the "*.mdx" pattern when making the change and
update the PR description accordingly.

In `@packages/wa-automate/src/session/SessionManager.ts`:
- Line 11: SessionManagerConfig currently declares an unused compressionOptions
field; either remove compressionOptions from the SessionManagerConfig type (and
any callers relying on it) or, if you intended it to control compression, add
compressionOptions to the CompressionOptions interface and thread it through
createFromConfig so it is passed into LocalSessionCompression when constructing
compression (update the createFromConfig call site that currently hardcodes '-1
-T0' to use the new config value and ensure LocalSessionCompression's
constructor accepts and uses that option).
- Around line 109-121: startPeriodicSync currently discards the setInterval
handle causing timers to leak and preventing clearInterval in stop; modify
startPeriodicSync to store the timer id on the instance (e.g., this.syncTimer)
and ensure stop clears it (clearInterval/clearTimeout) and nulls the reference
when this.s3Sync is disabled; also prevent overlapping backups by replacing
setInterval with a recursive setTimeout or add a running flag inside
startPeriodicSync to skip if backupSession is still in-flight (use the same
this.backupSession() reference) so concurrent writes to S3 cannot occur and
captured references can be released for GC.
- Around line 123-134: Replace the unsafe double-cast and the naive
enableS3Backup gate in SessionManager.createFromConfig: instead of doing
clientConfig.s3Sync as unknown as S3Config, validate/parse clientConfig.s3Sync
against the expected S3Config shape (or a Zod schema) and only construct an
S3Config object when required credentials (bucket, region, accessKeyId,
secretAccessKey) are present; set enableS3Backup to true only if the
parsed/validated S3Config is non-null and contains those required fields, and
pass that validated S3Config into the SessionManager constructor so
S3SyncManager receives a correctly-shaped config (use createFromConfig,
SessionManager, S3Config, S3SyncManager, and enableS3Backup as anchors).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d7337363-3ba5-46a1-bd12-d1a06da53565

📥 Commits

Reviewing files that changed from the base of the PR and between 0c39444 and 9e7a6e8.

📒 Files selected for processing (3)
  • .gitignore
  • integrations/node-red/package.json
  • packages/wa-automate/src/session/SessionManager.ts

Comment thread .gitignore
Comment thread packages/wa-automate/src/session/SessionManager.ts Outdated
Comment thread packages/wa-automate/src/session/SessionManager.ts
Comment thread packages/wa-automate/src/session/SessionManager.ts
t0g3pii and others added 3 commits May 8, 2026 16:11
Parse and validate s3Sync into an S3Config only when required credentials are present; enableS3Backup is now gated on validated config.

Co-authored-by: Cursor <cursoragent@cursor.com>
Store the periodic S3 sync timer handle so stop() can clear it, and avoid overlapping backupSession calls by scheduling via setTimeout with an in-flight guard. Also drop unused compressionOptions config field.

Co-authored-by: Cursor <cursoragent@cursor.com>
Replace single-quoted turbo filters (breaks on Windows) and remove filters for non-existent legacy packages; keep docs excluded via filter on the actual docs workspace package.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/wa-automate/src/session/SessionManager.ts`:
- Around line 39-43: SessionManager currently starts S3SyncManager and periodic
uploads when config.enableS3Backup is true even if local compression is
disabled, but backupSession() always uploads the .data.zst file so periodic sync
will target a non-existent file; update the S3 startup guard in the constructor
(the branch that assigns this.s3Sync and calls this.startPeriodicSync) to
require both config.enableS3Backup and config.enableLocalCompression (or check
that LocalSessionCompression was initialized) before creating S3SyncManager and
calling startPeriodicSync, and ensure any code that references this.s3Sync
(e.g., startPeriodicSync, backupSession) handles the null/undefined s3Sync case
safely.
- Around line 46-60: The stop() method should perform cleanup on a best-effort
basis so one failing operation doesn't prevent others from running: wrap the
await this.localCompression.stop() call in its own try/catch (or use
Promise.resolve(...).catch(...)) so any rejection is logged/ignored and then
continue to clear this.syncTimer, set this.syncInFlight = false, and null out
this.localCompression and this.s3Sync; ensure each cleanup step
(localCompression.stop, clearTimeout(this.syncTimer), nulling this.s3Sync) runs
independently so the timeout and s3Sync aren't left alive if
LocalSessionCompression.stop() throws.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 37e7d821-b99b-484e-b356-5bb3de6558bb

📥 Commits

Reviewing files that changed from the base of the PR and between 61fa3b3 and a3172df.

📒 Files selected for processing (1)
  • packages/wa-automate/src/session/SessionManager.ts

Comment thread packages/wa-automate/src/session/SessionManager.ts Outdated
Comment thread packages/wa-automate/src/session/SessionManager.ts
Make stop() best-effort so one failure doesn't prevent timer/S3 cleanup, and only enable S3 periodic uploads when local compression is enabled (since backups upload the .data.zst artifact).

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
package.json (1)

30-30: 💤 Low value

Minor inconsistency: turbo run build vs turbo build.

All other task scripts use the shorthand turbo build, but publish-packages still says turbo run build. Both are equivalent in Turbo v2, but consistency reduces confusion.

♻️ Proposed fix
-    "publish-packages": "turbo run build --filter=\"!docs\" && changeset publish",
+    "publish-packages": "turbo build --filter=\"!docs\" && changeset publish",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 30, The package.json "publish-packages" script is
inconsistent with other scripts: it uses "turbo run build" instead of the
shorthand "turbo build"; update the "publish-packages" script's command string
(the value for the "publish-packages" key) to use "turbo build
--filter=\"!docs\" && changeset publish" so it matches the rest of the scripts'
style and tooling conventions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@package.json`:
- Line 30: The package.json "publish-packages" script is inconsistent with other
scripts: it uses "turbo run build" instead of the shorthand "turbo build";
update the "publish-packages" script's command string (the value for the
"publish-packages" key) to use "turbo build --filter=\"!docs\" && changeset
publish" so it matches the rest of the scripts' style and tooling conventions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9aea1f67-8827-4240-ab97-523471b6efd0

📥 Commits

Reviewing files that changed from the base of the PR and between a3172df and 861e128.

📒 Files selected for processing (2)
  • package.json
  • packages/wa-automate/src/session/SessionManager.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/wa-automate/src/session/SessionManager.ts

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