Skip to content

Field sync after #2316: send back only what the phone changed #2468

Open

Description

@Mavrick-F

Part of #1902.

#2316 made Bring Back refuse a package that was already brought back, or whose offline area has been synced or brought back since the package was made. Before that, a second phone with a copy of the same package quietly undid the first phone's edits and deleted its new features. The refusal stops the data loss, but only one package per area can be out at a time, and several crews splitting up an area is a normal way to work.

Below is how I'd fix that. It changes how Bring Back from #2029 works out what the phone did, so @giswqs, please say if the phone side has a constraint I've missed. Anyone else who sees a problem, please say so before I start.

Why the second phone can't come back

Bring Back works out what the phone did by comparing the phone's whole map with a snapshot of the area. Any row that differs counts as a phone edit. Every sync and every Bring Back replaces that snapshot with the home data, so after phone A comes back, the snapshot no longer matches what phone B was given. B's untouched rows then look like edits, and the rows A added look like B deleted them.

The same comparison causes two other problems. An attribute added at home while the crew is out makes every phone row look different, so the whole return is refused (the ignored test audit_office_adds_a_field_while_crew_is_out reproduces it). And a feature added on the phone gets a new id at home when its id was taken there meanwhile, and a later sync of the area can replace it under yet another id, losing any office edit made to it in between.

Proposal: the phone sends its changes, not its map

Field apps that sync several devices don't compare whole datasets. In QFieldCloud each device sends a list of changes: the feature, the attribute, the old value and the new one. The server applies them one at a time, and a change whose old value no longer matches the server's current value is a conflict. CloudKit and CouchDB do the same with a version stamp on each record. Neither keeps anything per device, and the work grows with the number of edits rather than the size of the data.

For RustGIS:

  1. The returned package carries a change list: the features the phone added, the ids of those it deleted, and for each feature it edited, the attributes and geometry it changed along with their values when the package was made.
  2. Bring Back applies the list. A change whose old value still matches home goes in. One that doesn't is a conflict, handled as today: the last one back wins, with a notice. Nothing outside the phone's changes is compared, so an attribute the office added is left alone, and a second phone's untouched rows are never taken for edits.

Changes name their feature by id. Feature ids are already saved and come back unchanged in a package, so nothing new is needed there. Features added on the phone take the next free id at home, as they do now, and that stops mattering because each return comes from a fresh package.

Home keeps nothing extra per package, and the area snapshot is no longer part of the comparison. The same package returned twice must still be refused, or its changes would apply twice, so the generation check from #2316 stays.

How the phone builds the list is still open. It can record each edit as it's made, or compare its map with the package it was given at the moment it sends. The second leaves editing untouched, but only works if the phone keeps the original package and can read it without loading it whole, which fits the zip package in piece 7 of #1853. I'll check what the phone keeps today before choosing.

Order

  1. Fix the added-attribute refusal on its own, by matching attributes by name instead of by position. It's written and passes the tests, and it's needed either way.
  2. Then the change list. Its code reads and writes rows through the accessors from refactor(data): accessors for a layer's rows and fields, and a count of direct uses (#2431) #2459, so it adds nothing to what [Bug]: Undo steps on a large layer each hold a full copy of its rows, so memory grows with every edit #2431 has to move.

Not covered here

The other gaps found in the phone code (no recovery copy, Save never writing back, a worse position replacing a better one, what a field package leaves behind) are tracked in #2485, most of them now seen on an Android phone. Background sync is left out there as a direction question.

Two small gaps stay open too. An offline map renamed at home isn't refreshed by Bring Back, because the open map is found by its name; the edits themselves reach the area, which is found by its id. And a package made before field_origin existed keeps its link to the home table if it's renamed to .rgispkg, which can delete rows on Save; that one is being fixed on its own.

Activity

  1. self-assigned this
    on Nov 19, 2026
  2. TonyPhini commented on Nov 20, 2026

    @TonyPhini

    +1 to the change list. Several crews on one area is exactly how fieldwork goes, and this is the approach that scales.

    Some background: in my free time I've been building a private field app, RustField, that reads and writes .rgis projects and syncs several phones with a three-way merge, field by field. A few things from it that may help here:

    • How the phone builds the list: RustField does your second option. The phone keeps the copy it was given (the base), and at sync time it compares base and current map feature by feature and attribute by attribute. Editing code stays untouched, and the list is always complete, including edits made in ways nobody thought to record.

    • Deleted on the phone, edited at home: if a deletion carries only the id, it silently removes an office edit. RustField keeps the feature edited and reports a conflict. With a change list, the deletion could carry the feature's values from when the package was made, so it becomes a conflict when home no longer matches, like any other change.

    • The value that loses a conflict: whichever version wins, RustField keeps the other value in a list of conflicts the user can review, so nothing typed in the field disappears. A notice alone is easy to dismiss and lose.

    • Attributes by name: agreed with step 1. RustField has always matched by name, and it is what makes an office adding or reordering a field harmless.

    I'm a surveyor rather than a developer, and I write code with Claude. What I can bring for sure is field testing: once the change list is in, I'll try it on an iPhone with real survey data, and I'd be glad to help with choosing per conflict which version wins on Bring Back (it's in the open items of #1902).

  3. TonyPhini commented on Nov 20, 2026

    @TonyPhini

    If it's easier to talk things through outside the issue, I'm happy to do so: you can reach me at antoniomariafini@gmail.com

  4. 30 remaining items

  5. Mavrick-F commented on Nov 22, 2026

    @Mavrick-F
    MemberAuthor

    @TonyPhini, thank you for the feedback, that was extremely helpfu. All three steps are in main now: fields matched by name (#2589), the change list with one id per package, so several phones can work one area (#2597), and a saved list of each conflict's losing version under Data › Offline › Conflicts (#2735). A field deletion no longer removes an office edit. When home deleted a feature the field edited, the edit goes into that list.

    Next is choosing which version wins for each conflict. How does RustField let the user pick? I'd rather build on what works for you than guess.

  6. TonyPhini commented on Nov 23, 2026

    @TonyPhini

    Thanks, that was fast! I'll try all three on an iPhone with real data.

    To be honest about your question: RustField doesn't let the user pick yet. The rule is fixed: for the same field changed both ways, the server version wins, and the phone's value goes into a "To review" list. Each entry shows layer · feature · field, a one-line explanation of what happened, and the two values side by side ("Yours" / "Server"). If yours was the right one, you type it again in the feature form. Then a single "Reviewed, archive" clears the list.

    What I learned from using it, and what I'd do with your Conflicts list:

    -Keep the automatic rule at sync time. In the field you often sync in a hurry or with poor signal, so sync should never stop to ask questions. The choice comes later, from the list.
    -One button per entry to use the other value. Retyping is where mistakes happen, especially with long codes or numbers. Applying it as a normal edit means it syncs again like anything else and can be undone.
    -A choice for a whole feature or layer, not only per value. After a day when the office renamed codes, there can be dozens of conflicts that all need the same answer.
    -For deleted vs. edited: offer "delete anyway" next to "keep it".
    -For geometry, show both versions on the map. Two lists of coordinates mean nothing to a person.
    -Show when each version was made and by which package or phone. That's usually what lets you decide.
    -Don't let one tap dismiss everything. In RustField, "archive" clears the whole list at once, and it's too easy to tap without reading. Better to resolve or dismiss each entry, or at least ask for confirmation.
    Happy to test whatever you build on iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions