Skip to content

RSDK-13995: Clean up old .prog files on start - #6326

Merged
Katie Peters (katiepeters) merged 1 commit into
viamrobotics:mainfrom
angelapredolac:RSDK-13995
Aug 31, 2026
Merged

RSDK-13995: Clean up old .prog files on start#6326
Katie Peters (katiepeters) merged 1 commit into
viamrobotics:mainfrom
angelapredolac:RSDK-13995

Conversation

@angelapredolac

@angelapredolac Angela Predolac (angelapredolac) commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary
On startup, the data manager now renames orphaned .prog files (left behind when a previous viam-server process died mid-capture) to .capture so sync uploads them instead of skipping them forever. Unlike #5996 (reverted in #6036 / APP-16267 — see the postmortem for full background), the pass runs only on an instance's first Reconfigure before any collectors exist, and an mtime guard skips any .prog file modified after process start, so live collector files are never touched.

Testing

Unit Testing: Added tests covering orphan renaming, the mtime guard, non-.prog files being left untouched, and that a second Reconfigure never re-runs the pass or disturbs a live collector's open .prog file.

Manual Testing: On a real machine, SIGKILLed viam-server mid-capture and verified on restart that the orphan was renamed and its readings synced to app, and that both in-place reconfigures and full service rebuilds leave live .prog files untouched with capture uninterrupted.

@angelapredolac Angela Predolac (angelapredolac) added the safe to test This pull request is marked safe to test from a trusted zone label Aug 3, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 3, 2026
@n0nick

Copy link
Copy Markdown
Member

please link to previous attempt's postmortem doc in the PR description, for future reviewers :)

@n0nick Sagie Maoz (n0nick) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also, PR title should start with RSDK-13995: ..., not the branch name :)

Comment thread services/datamanager/builtin/builtin.go Outdated
Comment thread services/datamanager/builtin/builtin.go
Comment thread services/datamanager/builtin/builtin_test.go
Comment thread services/datamanager/builtin/builtin_test.go
Comment thread services/datamanager/builtin/builtin_test.go Outdated
Comment thread services/datamanager/builtin/builtin_capture_test.go Outdated
Comment thread services/datamanager/builtin/builtin_capture_test.go
Comment thread services/datamanager/builtin/builtin_capture_test.go Outdated
Comment thread services/datamanager/builtin/builtin.go Outdated
Comment thread services/datamanager/builtin/builtin.go Outdated
@angelapredolac Angela Predolac (angelapredolac) changed the title angela/Rsdk 13995: Clean up old .prog files on start RSDK-13995: Clean up old .prog files on start Aug 4, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 4, 2026

@n0nick Sagie Maoz (n0nick) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you! 🙏

@viam-overwatch

Copy link
Copy Markdown

Hey Angela Predolac (@angelapredolac) — this PR has been approved and CI has been green for 4+ business days. Ready to merge?

Auto-comment from overwatch. Will not re-nudge for 7 days.

@CLAassistant

CLAassistant commented Aug 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 14, 2026

@gloriacai01 gloriacai01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes:

  1. builtin.go — renamedOrphanProgFiles bool replaced with renameOrphanProgFilesOnce sync.Once, and the orphan rename is now launched as separate goroutine outside b.mu and async, so a large capture directory doesn't stall Reconfigure.
  2. builtin_capture_test.go — the integration test's immediate post-startup assertions are wrapped in testutils.WaitForAssertionWithSleep to
    account for the rename now happening in a background goroutine.

Manually tested:

  1. Seeded 50 orphan .prog files using the seed script, backdated to before processStartTime so the mtime guard wouldn't skip them.
  2. Added a 5-second time.Sleep to renameOrphanedProgFilesToCapture to make the async gap obvious.
  3. Restarted viam-server and pulled the logs. The key sequence at 18:38:13:
    - New END at 18:38:13.637
    - finished renaming orphaned .prog files to .capture at 18:38:18.617 — 5 seconds later

Proving Reconfigure returned immediately and the rename ran in the background.
4. Removed the sleep before committing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left one very tiny comment. Other than that, we're 100% sure that sync.Once will do what we want/survive reconfigures?

Comment thread services/datamanager/builtin/builtin.go Outdated
// a large capture directory does not stall Reconfigure; the mtime guard
// makes this safe — any .prog file written after process start belongs to a
// live collector and is skipped.
captureDir := captureConfig.CaptureDir

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there a reason this is pulled out into a separate variable?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 17, 2026
@gloriacai01

Copy link
Copy Markdown
Member

Left one very tiny comment. Other than that, we're 100% sure that sync.Once will do what we want/survive reconfigures?

Katie Peters (@katiepeters) the mtime guard will ensure we survive reconfigures

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 18, 2026
@gloriacai01 gloriacai01 added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 18, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 18, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 18, 2026
@gloriacai01 gloriacai01 added go Pull requests that update go code and removed go Pull requests that update go code labels Aug 18, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 18, 2026
@viam-overwatch

Copy link
Copy Markdown

Hey Angela Predolac (@angelapredolac) — this PR has been approved and CI has been green for 3+ business days. Ready to merge?

Auto-comment from overwatch. Will not re-nudge for 7 days.

@viam-overwatch

Copy link
Copy Markdown

Hey Angela Predolac (@angelapredolac) — this PR has been approved and CI has been green for 8+ business days. Ready to merge?

Auto-comment from overwatch. Will not re-nudge for 7 days.

@katiepeters
Katie Peters (katiepeters) merged commit 86af76a into viamrobotics:main Aug 31, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test This pull request is marked safe to test from a trusted zone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants