[Bug]: Backup packs `.watch_tasks.json` but restore rejects it — backup/restore round-trip broken whenever a watch task exists
Issue Origin
Observed or reproduced in a real environment
Bug Description
ov backup packs viking://resources/.watch_tasks.json into the OVPack, but ov restore rejects watch control files. Result: any instance with at least one watch task produces backups that cannot be restored — the backup/restore round-trip is broken by a first-class feature.
The asymmetry is at the code level:
- The backup walk (
_backup_entries) traverses all public scopes with hidden files visible and only excludes.relations.json— watch control files pass through into the pack; - The restore/import path enforces
is_watch_task_control_uri, which the backup walk never applies.
Attempting to strip the entry manually (zip -d) is blocked by design: [INVALID_ARGUMENT] ovpack entries do not match manifest — the manifest integrity check works as intended, so a "poisoned" pack has no salvage path.
Steps to Reproduce
Requires auth_mode = "api_key" (dev mode returns 403 on all pack endpoints):
- Start the server with
server.auth_mode = "api_key"; register an ADMIN user and point the CLI config at its key - Create one watch task:
ov add-resource https://example.com/ --watch-interval 1440 ov wait(drain), thenov backup→ succeeds;unzip -l <pack>showsfiles/resources/.watch_tasks.jsoninsideov restore <pack> --on-conflict overwrite→ fails
Verified on a fresh isolated instance: an empty workspace plus a single URL watch task is sufficient.
Expected Behavior
Backup and restore round-trip. Either exclude the watch control file from the backup walk (preferred — it describes per-instance scheduling state, not portable data), or have restore skip it with a notice instead of failing the whole pack.
Actual Behavior
[INVALID_ARGUMENT] cannot import watch task control file: viking://resources/.watch_tasks.json
Restore aborts; the only current workaround is canceling all watch tasks before taking the backup.
Minimal Reproducible Example
The four steps above *are* the minimal repro — no data other than one watch task is needed. Pack content check: `unzip -l backup.ovpack | grep watch_tasks` → `files/resources/.watch_tasks.json`.
Error Logs
# restore of a pack produced on an instance with one watch task:
[INVALID_ARGUMENT] cannot import watch task control file: viking://resources/.watch_tasks.json
# after manually removing the entry (zip -d), integrity check fires as designed:
[INVALID_ARGUMENT] ovpack entries do not match manifest
OpenViking Version
main @ 98a0104a (reproduced on the 0.4.14.dev100 editable install at 7e7ad2e1; relevant code paths unchanged through 98a0104a)
Python Version
3.12.10
Operating System
macOS
Model Backend
OpenAI
Additional Context
Root cause: backup traversal ↔ restore validation asymmetry (verified on main @ 98a0104a):
- Restore/import:
validate_import_target_uri(openviking/storage/ovpack/policy.py) rejects watch control files viais_watch_task_control_uri; scopedov export(validate_export_source_uri) has the same guard. - Backup:
_backup_entries(openviking/storage/ovpack/operations.py) walks every public scope withshow_all_hidden=True, filtered only byis_excluded_rel_path— andEXCLUDED_FILENAMESis just{".relations.json"}. The watch-control predicate is never consulted, so the pack is produced in a state restore cannot accept.
Suggested fixes (by preference):
- Skip watch-control URIs in the backup walk — the predicate already exists;
- Alternatively, restore skips (and logs) the watch control file instead of failing the entire pack.
Impact: any backup-based workflow — machine migration, off-site copies, relay-style handoffs — breaks the moment a watch task exists. Watch tasks are a normal feature, not an edge case; the intersection is common. Also a prerequisite for the companion feature request (Git-backed backup relay). Suggested acceptance item there: instances with watch tasks can complete backup → restore.
感觉是这样的
在当前代码中确认备份与恢复的规则存在不一致:_backup_entries() 会将 watch task 的内部控制文件打入备份包,但恢复校验会拒绝导入这些文件,因此只要实例存在 watch task,备份恢复流程就会失败。
可以在备份遍历时排除所有 is_watch_task_control_uri(...) 对应的控制文件
我想试试修复这个问题,并补充“备份后可正常恢复”的回归测试。
Supplement: the packed control file may also carry credentials. to_storage_dict() persists
auth_state (Git username/token, Feishu access tokens) into .watch_tasks.json, while
API/MCP/CLI responses use the public to_dict(), which excludes it. Since backup packs the
storage file as-is, plaintext tokens can travel with the pack even though restore rejects
the file — this further supports excluding watch-control URIs from backup, and existing
packs produced on instances with authenticated watches may already contain tokens.
A quick note for maintainers since two PRs now target this issue:
- #4149 implements suggested fix 1 (exclude watch-control URIs from the backup walk); its
test covers the full
.watch_tasks.json/.bak/.tmptriple. - #4150 implements suggested fix 1 + 2 (same backup exclusion, plus restore skips the control file with a log instead of failing the whole pack, so packs already produced on affected instances become recoverable).
Both PRs make the identical change in _backup_entries (operations.py), so whichever merges
first will require the other to rebase.