Skip to content

feat(MEMMY-411): add BYOK memory budgets and restore historical scans - #543

Merged
syzsunshine219 merged 7 commits into
MemTensor:v1.1.9from
origami-chen:cjq_dev/token-budget
Sep 24, 2026
Merged

syzsunshine219 merged 7 commits into
MemTensor:v1.1.9from
origami-chen:cjq_dev/token-budget

Conversation

@origami-chen

Copy link
Copy Markdown
Collaborator

Description

Summary

This PR adds configurable token budgets for BYOK memory processing and
restores historical imports through initial and full scans.

Background memory processing previously had no configurable daily or lifetime
limit. Initial scans could skip historical turns, while historical backfill
could reject completed turns from before activation.

Fix:

  1. Add daily and lifetime memory budgets, defaulting to 10M and 500M tokens.
    Setting a limit to 0 disables that limit. Show usage, editable limits and
    a pause notification linking to the budget settings.
  2. Pause budget-consuming jobs at leasing and dispatch boundaries, preserving
    queued work. Resume when the local day changes, limits are updated or
    accounting recovers.
  3. Persist usage events and local budget updates atomically, retry delivery
    through a durable outbox, and reconcile usage with App totals. Abort
    reconciliation and delivery on shutdown and ignore late responses.
  4. Let initial_subset and full read all eligible historical conversations.

Related CodeUp Issue: MEMMY-411

Type of change

  • Bug fix
  • Feature

How Has This Been Tested?

Validation used Node v22.23.2 and npm 10.9.8 on macOS arm64.

  • Targeted regression checks: 43 test files, 481 passed.
  • Independent checks covering real legacy imports, deletion protection,
    scope matching, repeated scans, HTTP response-loss retries and
    memory-generation idempotency.
  • npm run lint and npm run typecheck.
  • Memory and backend builds.
  • Full repository npm test executed — failed with exit 1:
    five existing edition-sensitive failures across four files.
  • Release workflow tests: 30 passed, 5 skipped.
  • Packaging guard tests: 44 passed.
  • macOS arm64 CN unsigned package installed and manually verified:
    App 1.1.8 / Memory 2.1.3.

The five full-suite failures are:

  • App/backend/src/adapters/outbound/cloud-client/tests/cloud-client.test.ts
    — two cases expect region cn; requests use intl.
  • App/frontend/desktop/src/analytics/tests/gtag-config.test.ts
    — expects the default edition cn; receives intl.
  • App/frontend/desktop/src/components/tests/campaign-token-prompts.test.tsx
    — expects CN campaign copy; renders the intl variant.
  • App/frontend/desktop/src/pages/memory/tests/sources-sub-page.test.tsx
    — expects the memmy.cn documentation URL; receives memmy.bot.

These tests and the relevant edition-specific behavior already exist in
upstream/v1.1.9 and are unchanged by this PR.

Full-suite results:

  • Memory: 1,025 passed, 1 skipped.
  • Migrations: 129 passed, 1 skipped.
  • AgentSourceCore: 61 passed.
  • Knowledge: 43 passed.
  • Root contracts: 7 passed.
  • Backend: 920 passed, 2 failed.
  • Local API contracts: 10 passed.
  • Frontend: 1,701 passed, 3 failed.
  • Desktop: 333 passed, 106 skipped.

Memory runs twice in the default npm test command; both runs passed.
The TUI suite was executed separately after the workspace failure:
5 passed.

Checklist

  • Completed self-review.
  • Added regression coverage for the changes.
  • Complete unsigned-package installation and manual verification.
  • Assign a reviewer.

Reviewer Checklist

  • Confirm budget scope, pause/resume behavior and durable accounting.
  • Confirm historical scan limits, legacy compatibility and deduplication.
  • Verify CI results, manual verification and remaining limitations.

Daily 10M and lifetime 500M apply only to memory_summary,
memory_evolution, and document embeddings. L1 generation and
retrieval stay unpaused. 0 means unlimited.
Keep memory-side usage on disk when App is down, pause budgeted work if persist fails, and wake queued jobs after storage recovers without inventing lost events.
Abort the in-flight App usage fetch on shutdown and drop late replies so a closed SQLite database is never read or written again.
fix the problem that initial and full scans skip agent history
@syzsunshine219
syzsunshine219 merged commit 2daaba7 into MemTensor:v1.1.9 Sep 24, 2026
3 checks passed
@origami-chen origami-chen changed the title Cjq dev/token budget feat(MEMMY-411): add BYOK memory budgets and restore historical scans Sep 24, 2026
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