Non-atomic file writes causing data corruption and complete task loss during concurrent operations
@kanaseprathamesh568-a11y is already working on this.
Since Nov 12, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reading lib/app/utils/home_path/impl/data.dart, especially _mergeTasks(), and reproduce the concurrent sync and local-task update scenario described in the issue. Trace how .task/all.data is read and rewritten; done means concurrent operations no longer leave partial or empty task data and updates remain intact after a crash-safe replacement.
Written by the indexing model from the issue text.
Description
Describe your issue
The current implementation of task persistence in
lib/app/utils/home_path/impl/data.dart uses non-atomic, synchronous file operations without any locking mechanism, which introduces severe race conditions and data loss scenarios.
Specifically, the _mergeTasks() method:
Reads the entire file into memory
Clears the file (writeAsStringSync(''))
Rewrites tasks line-by-line using multiple append operations
This approach is unsafe under concurrent access or unexpected crashes.
Why this is critical
File is explicitly truncated before rewrite
Multiple independent write operations increase failure risk
No locking → race conditions between sync and local updates
Crash between truncate and write → permanent data loss
This impacts:
Sync operations
Local task creation
Background updates
Steps to reproduce
Launch the app
Trigger a sync operation (fetch tasks from server)
At the same time, add a new task locally
Observe .task/all.data file behavior
Result:
File may become partially written or completely empty
Some or all tasks disappear permanently
What was the expected result?
Task file updates should be atomic and crash-safe
Concurrent operations should not corrupt data
No data loss should occur under any circumstance
Code reference
Problematic implementation:
void _mergeTasks(List tasks) {
var lines = File('${home.path}/.task/all.data')
.readAsStringSync(); // NOT ATOMIC
var taskMap = { /* build map */ };
File('${home.path}/.task/all.data')
.writeAsStringSync(''); // TRUNCATE
for (var task in taskMap.values) {
File('${home.path}/.task/all.data').writeAsStringSync(
'$task\n',
mode: FileMode.append, // Multiple writes
);
}
}
Root cause
No file locking mechanism
Non-atomic write strategy
Multiple I/O operations instead of a single transaction
No crash recovery or backup strategy
Key improvements:
Use a mutex/lock (e.g., synchronized package)
Write to a temporary file first
Replace original file using atomic rename
Maintain a backup file for recovery
Replace multiple writes with single batch write
High-level approach:
await lock.synchronized(() async {
final tasks = _readAllTasks();
final updated = merge(tasks, newTasks);
await tempFile.writeAsString(allTasksInOneString);
if (mainFile.existsSync()) {
await mainFile.copy(backupFile.path);
}
await tempFile.rename(mainFile.path); // atomic replace
});
Impact
Prevents total data loss
Eliminates race conditions
Ensures crash-safe persistence
Improves reliability of sync + local updates
Put here any screenshots or videos (optional)
No response
How can we contact you (optional)
No response
Would you like to work on this issue?
Yes
By submitting this issue, I have confirmed that:
- I have starred the repo ⭐ and watched 👀 it on GitHub and followed the contribution guidelines.
- Dominant language
- Dart
- Stars
- 246
- Forks
- 184
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CCExtractor/taskwarrior-flutter
-
Fix misaligned text "Select the directory" in settings tileMay be free again @alabeddev claimed this 241 days ago, and no pull request is open. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
CCExtractor/taskwarrior-flutter#639 · 2 comments ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Drawer should close automatically when navigating to a new screenMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Sensitive Credentials Stored in Plain Text Files Without EncryptionMay be free again @sahu-virendra-1908 claimed this 238 days ago, and no pull request is open. Openbug
Difficulty 5/5 Over a week Newbie friendliness 45/100
CCExtractor/taskwarrior-flutter#645 · 1 comment ·
All issues in CCExtractor/taskwarrior-flutter
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 60/100
hiddify/hiddify-app#2668 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
toyota-connected/emb_cli#358 ·
Maintainers usually reply within 1 day
-
area: import beta cluster: callers box improvements severity: minor status: confirmed type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ibanner56/CallersCompendium#2366 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ccch1mneyyy/dsh-Go#1777 ·
Maintainers usually reply within 1 day
-
area: mobile documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
CommandLineCoding/Elephant#383 ·
Maintainers usually reply within 1 day