Skip to content

Keep newer local edits to tasks, notes and projects when importing a backup - #96

Merged
rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/import-keeps-newer-edits
Oct 26, 2026
Merged

rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/import-keeps-newer-edits

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Bug

Importing a backup reverts tasks, notes and projects edited since the backup was made. For example: you download a backup, keep writing in a note, then import the backup again (or a copy of it from another device). The note goes back to its old text with no warning.

Memories already have a guard for this: importData skips a memory when existing.updated_at >= m.updated_at, and the README documents it. The project, task and note upserts have no such guard and always overwrite.

Fix

The three upserts now update only when the backup copy is newer (ON CONFLICT(id) DO UPDATE ... WHERE excluded.updated_at > tal_<table>.updated_at). That matches the memory rule. New records and records that exist only locally behave as before, and a backup copy newer than the local one still imports. The README sentence on import and the importData doc comment now say this covers tasks, notes and projects too.

Test

New case in apps/agent/test/backup-import.test.ts: it creates a project, a task and a note, then imports older backup copies of each with different text. It expects the local versions to stay. Then it imports a newer note copy and expects that one to apply.

cd apps/agent && npx vitest run test/backup-import.test.ts -t "does not revert"

  • Before the fix (current main): fails, expected 'Trip, old' to be 'Trip, current'.
  • After the fix: passes. The full agent suite passes (77 files, 652 tests), and tsc --noEmit and biome are clean.

…backup

Import already skips a memory whose local copy is newer than the backup's, but tasks, notes and projects were overwritten unconditionally, so importing an older backup silently reverted anything edited since it was made. Their upserts now update only when the backup copy is newer.
@rociiu

rociiu commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thanks @rudycelekli — clear write-up and a solid regression test. Merging!

@rociiu
rociiu merged commit 6114dae into rociiu:main Oct 26, 2026
1 check passed
pablopfg added a commit to pablopfg/talorys that referenced this pull request Oct 28, 2026
…quieter logs (#13)

<!-- claude-projects-attribution: {"github_login":"pablopfg"} -->
_Requested by **Pablo** · [project
thread](https://claude.ai/code/project/chan_01548W9A2AStvwh6Y6QFd3YH?thread=cmsg_01548W9A2AStvwh6Y6QFd3YHCuLNruan51BNAoAR9y64zW)_

Plan, phase 1, PR 3. This closes what was left of AGT-04, and also
AGT-07, AGT-08 and AGT-09 from the handoff audit.

## Changes

- **AGT-04 (backup import).** rociiu#96 made "newer copy wins". But a forged
date such as `9999-…` still beat every later local edit.
- Any date that can't be read, or that is more than 5 minutes in the
future, is stored as the import time. It never replaces an existing
task, note, project or memory.
- The import route now reads at most 10 MB, down from 25 MB. Each kind
of record has a cap (`MAX_IMPORT_RECORDS`). A backup over either limit
is refused whole: nothing is imported.
  - The web upload check is now 10 MB too.
- **AGT-07 (budget day).**
- `UsageService` counts the day in the owner's timezone, read from
settings. Before, the budget reset at UTC midnight, which is 21:00 in
Brasília. An unusable timezone falls back to UTC.
  - Semantic recall's own embedding caps still use the static UTC day.
- Tool calls from a chat turn or scheduled run that fails now count
toward the day (`finally`).
- **AGT-08 (logs).** Workers AI and chat-turn failures log only
`errorSummary`: the error name plus any 3–4 digit code. The message can
quote a prompt or a note, so it is no longer logged.
- **AGT-09 (update check).** The npm update check now starts off on new
installations. The docs say how to turn it on.
- I updated the changelog (Alterado and Segurança) and
`docs/security.md`, and added the pt-BR text for the new error.

## Tests

- `npm run lint`, `typecheck`, `build` and `npm test` all pass (879
tests).
- There are 9 new tests in `apps/agent/test/import-and-budget.test.ts`:
- a forged future date, then a local edit, then the same file imported
again;
  - unreadable dates;
  - the record cap, which imports nothing;
  - the day in São Paulo and in Tokyo;
  - the fallback for an invalid timezone;
  - tool calls counted on a failed turn;
  - `errorSummary`.
- `update-check.test.ts` now turns the check on where it needs it, and
has a test that it starts off.

## Upgrading

No migration. Existing installs keep their saved update-check setting.

---
_Generated by [Claude
Code](https://claude.ai/code/session_012XDDEe3xJunmyfeKA7zqv2)_

Co-authored-by: Claude <noreply@anthropic.com>
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