Skip to content

feat(cloud): support per-workspace tool invocation retention and payload trimming - #1994

Open
Alegan55 wants to merge 1 commit into
HelpCode-ai:mainfrom
Alegan55:feat/per-workspace-tool-log-retention
Open

Alegan55 wants to merge 1 commit into
HelpCode-ai:mainfrom
Alegan55:feat/per-workspace-tool-log-retention

Conversation

@Alegan55

@Alegan55 Alegan55 commented Dec 5, 2026

Copy link
Copy Markdown

Summary

Adds per-workspace retention and payload trimming overrides in KgCronService for tool invocation logs while preserving global environment defaults (INVOCATION_RETENTION_DAYS default 90 days and INVOCATION_PAYLOAD_RETENTION_DAYS default 14 days).

Changes

  • Injects optional OrgSettingsService into KgCronService and resolves per-workspace overrides for invocation_payload_retention_days and invocation_retention_days with fallback to global environment defaults and safe handling for non-numeric or disabled values.
  • Updates trimOldPayloads() (via trimPayloadsForScope) and retention() to run scoped cleanup for overridden workspaces and exclude overridden organizationId values from global fallback passes.
  • Adds unit tests in packages/backend/src/ee/cloud/kg-cron.service.spec.ts covering per-workspace payload trimming, row pruning with notIn exclusions, and invalid setting fallbacks.

Type

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance improvement
  • Other (describe below)

Testing

  • Added/updated unit tests
  • Tested manually (describe steps below)
  • No tests needed (explain why)

Ran pnpm --filter @anythingmcp/backend test ee/cloud/kg-cron.service.spec.ts ee/cloud/kg-cron-batch.service.spec.ts (all 14 tests passing).

Checklist

  • My code follows the existing code style
  • I have tested my changes locally
  • I have updated documentation (if applicable)
  • All existing tests pass (npm test)
  • This PR has a descriptive title

Related Issues

@Alegan55
Alegan55 requested a review from helpcodeai as a code owner December 5, 2026 12:29
@helpcodeai

Copy link
Copy Markdown
Contributor

recheck

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Alegan55

Alegan55 commented Dec 5, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Dec 5, 2026

@helpcodeai helpcodeai 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.

Thanks for picking this up, and for signing the CLA.

We can't merge it as it is. Here is what needs to change:

  1. Move it out of ee/. Every change is under packages/backend/src/ee/. That folder uses the commercial license and we don't take outside changes there (see AGENTS.md and LICENSING.md). Issue #1971 puts the new sweep in the audit module, outside ee/, so it runs on Cloud and on self-hosted. The existing Cloud sweep in kg-cron.service.ts can stay as it is; we will connect the two on our side.
  2. Values of 0 or below. An override of 0 or less removes the workspace from the global pass and is then skipped, so its rows are never trimmed or deleted. Please ignore such values and fall back to the default.
  3. Only shorten on Cloud. A value above the default keeps rows longer than the platform limit. On Cloud the effective value must be min(override, default). On self-hosted any positive value is fine, and empty keeps today's behaviour.
  4. Payload setting. #1971 asks to clear input, output, error and intent completely after N days, whatever their size, and keep tool, status, duration and time. This PR only shortens large payloads, like the global trim.
  5. Key names. Please use the keys from #1971: invocation_payload_days and invocation_retention_days.
  6. Keep the diff small. The PR switches the whole file to double quotes. Please keep the existing style (npm run lint in packages/backend). OrgSettingsService is injected but not used.

Tests: please cover that the shorter value wins on Cloud, other workspaces keep the default, other workspaces' rows are left alone, and every query is filtered by organizationId.

Happy to review again once it lives outside ee/.

This branch has not been deployed

No deployments
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.

2 participants