Repository navigation
Parse the object pool into an object tree of its own - #949
Conversation
The parsing thread wrote into the object tree of the working set while the server and the application used it on other threads (Open-Agriculture#775). It now parses into an object tree of its own, which starts as a copy of the current one, so a later pool transfer can still replace and add objects. join_parsing_thread(), which the server calls from update(), takes the parsed tree over if the pool was parsed successfully. If parsing failed, the object tree stays as it was, and the transfers of that run are not marked as parsed. The parent of the faulting object is now found when the fault is set, so the working set can report it from the parsed tree. Two tests relied on the objects that a failed parse left in the tree. StatusMessageReportsTheNewAddressOfTheActiveWorkingSetMaster uploaded a pool that ends with an empty Data Mask, which the parser rejects because it expects at least 12 bytes; it now adds a Number Variable after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
gunicsba
left a comment
There was a problem hiding this comment.
Thanks, parsing into a tree of its own is a good step for #775. I checked it against ISO 11783-6:2018 Annex C. Page numbers are the printed ones.
Matches the standard
- C.2.6 (p. 209-210) says the VT "shall keep the new/updated objects separate from the original pool" and merges them "before the VT sends the End of Object Pool response". Parsing into a separate tree and taking it over in
join_parsing_thread(), right before the response, matches that closely. - The old tree staying visible until the join is explicitly allowed: commands sent between End of Object Pool and its response "will be applied to either the original pool or the updated pool" (C.2.6, p. 210).
- The End of Object Pool response still waits for the parse (C.2.5, p. 208), and on success the parent and faulting object are sent as NULL Object ID, as C.2.5 bytes 3 to 6 require.
Comments inline, most important first
- The parent search for the faulting object now runs on the parsing thread and reads objects that the main thread may change at the same time (C.2.6 requires the VT to handle commands during an update).
iopFilesRawDatais still changed on the parsing thread, and Store Version can read it at the same time.- A question about keeping the old pool after a failed update, since C.2.6 says the VT deletes the whole pool. It also covers changes to the live map during parsing, which are lost at the join.
- Tests: the Working Set in the updated pool has no objects, which Table B.2 doesn't allow, and two wait loops have no bound.
…when joining The parser no longer starts from a copy of the whole object tree. It gets only the Working Set and Working Set Special Controls objects, which parsing checks against, and join_parsing_thread() adds the objects it parsed to the current tree. Objects added to the tree while the thread runs stay. The parent of a faulting object is now looked up in join_parsing_thread(), in the new objects and the current tree, and no longer on the parsing thread. The trimming of the transfers and their processed flags also moved there, and Store Version is answered with an error while a pool is parsed and not answered yet, as it reads the transfers on the CAN thread. Tests wait a bounded time for the parsing thread, and the Working Set in their pool has one object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
gunicsba
left a comment
There was a problem hiding this comment.
Thanks, I went through 351f36c against my earlier comments and ISO 11783-6:2018. Page numbers are the printed ones.
Resolved
- Parent search off the worker: the worker only records the faulting object, and
join_parsing_thread()looks up the parent on the main thread. It searches the parsed objects and the current tree, where a parsed object hides a current one with the same ID. Taking the lower of the two IDs keeps the "lowest ID" rule.TheParentOfAFaultingObjectCanBeInTheCurrentPoolcovers a parent in the original pool. - Transfers changed on the worker: trimming and
processednow happen in the join, so the worker no longer changes the transfers. Rejecting Store Version until the End of Object Pool is answered closes the race with the CAN thread. Byte 6 bit 3 "Any other error" is the right code for it (E.5, p. 229). The test fails without the change, good. - Objects added during parsing: the parser starts with only the Working Set and any Working Set Special Controls object, and the join adds only parsed objects. So objects added in the meantime stay, and the map isn't copied on End of Object Pool anymore. I checked that
parse_next_object()looks up nothing else in the tree, so a partial update that refers to objects of the original pool still parses. This also follows C.2.6 (p. 209) more closely: "keep the new/updated objects separate from the original pool" until they are merged before the response. - Bounded waits: fine, and keeping the tests in
vt_server_tests.cppforTestWorkingSet::add_object()makes sense.
Failed update as a follow-up: fine with me, as long as this PR keeps main's behaviour and the docs say so, which they do. Could you open an issue for deleting the pool and setting byte 7 bit 3 after a failed update (C.2.6, p. 209; C.2.5, pp. 208-209), so it doesn't get lost? It fits with the deletion reason hook discussed on #952.
One thing, my mistake again: the Working Set child I suggested is Data Mask 1000, and Table A.2 (p. 72) doesn't allow a Data Mask as a child of a Working Set. Details are inline. I made the same comment on #951.
I built 351f36c on Windows (MSVC Debug), and the 105 VT server and working set tests pass with ctest.
A Data Mask isn't allowed as an object of a Working Set. The test for a parent in the current pool now replaces the Container. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
… the destructor join_parsing_thread() hands the success and the failure to take_over_parsed_objects() and set_fault_from_parser(), and Store Version saves the transfers through store_object_pool(), so neither nests more than three levels. The destructor of the working set catches an exception from joining, as a destructor must not throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
|
Opened #958 for deleting the pool and setting bit 3 after a failed update. 1edb1a8 only restructures, after SonarCloud findings on our fork: |
was_object_replaced() from Open-Agriculture#946 now gets its list in join_parsing_thread(), from the parsed objects whose ID was already in the object tree, instead of from a copy of the whole tree taken on the parsing thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
gunicsba
left a comment
There was a problem hiding this comment.
Thanks, this is a big step for #775. I checked it against ISO 11783-6:2018 (section and printed page numbers below).
What matches the standard
- C.2.6 Updating pools at runtime (p. 209–210): "The VT shall keep the new/updated objects separate from the original pool, until reception of the End of Object Pool message. The objects shall be merged into the original pool before the VT sends the End of Object Pool response." That is exactly what this PR does: the thread parses into its own tree, and
join_parsing_thread()merges it in the sameupdate()that sends the response. - C.2.6: "The VT shall handle commands and macros from a Working Set even while that Working Set is updating its object pool." Before this PR, the parsing thread wrote into the tree that those commands use. Now they act on the current tree and nothing changes it underneath them.
- C.2.6 also allows the old tree to stay visible until the join: commands sent between End of Object Pool and its response "will be applied to either the original pool or the updated pool".
- 4.6.10.3 (p. 25): "When the VT receives an object with an existing Object ID, the existing object is replaced".
take_over_parsed_objects()does this, and keeps objects that the update doesn't send ("all other objects will remain in VT memory following the update", C.2.6). - E.6 Load Version command (p. 229): "If an object pool is already loaded it is overwritten", so clearing the tree before a Load Version is fine.
- Leaving the delete-after-failed-update (C.2.5, p. 208, byte 7 bit 3, and C.2.6) to #958 makes sense.
- Looking up the parent among both the new objects and the current tree, where a new object hides a current one with the same ID, fills bytes 3–4 of the End of Object Pool response (C.2.5) well for updates.
What needs a change or a look, most important first
- Blocking: the ESP32 PlatformIO build fails. The
try/catchin the destructor doesn't compile without exceptions:isobus_virtual_terminal_server_managed_working_set.cpp:111:24: error: exception handling disabled, use '-fexceptions' to enable(all threeesp32_platformio_object_pooljobs). The core library has notryanywhere else. See the inline comment. - Store Version while a pool is parsed. E.4 (p. 228) says the command "can be sent at any time" and stores "the copy of the actual object pool". "Any other error" is a valid answer (E.5, byte 6 bit 3), so this isn't wrong. While an update is parsed, the actual pool is still the one from before it, though, and its transfers are already complete. See the inline comment.
- For later, not for this PR. The parser only gets the Working Set and Working Set Special Controls objects. Two checks need the current pool: 4.6.10.3 "the replaced objects shall be of the same type", and C.2.5 byte 7 bit 1 "unknown object reference". Neither is implemented today, but with this design they can only happen in the join, not on the thread. That's worth keeping in mind for the rest of #775.
🤖 Generated with Claude Code
Since Open-Agriculture#960 a replaced object must keep its type. The parser's own object tree holds only the objects of its run, so it now gets the type of every object of the current pool and fails the parse when a parsed object would replace one of another type. Store Version keeps the blank and invalid label checks from Open-Agriculture#938 and stores through store_object_pool(). With Open-Agriculture#951 merged, the small test pool no longer needs a Number Variable after the Data Mask. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
The library also builds without exceptions, as the PlatformIO ESP32 example does, where the try/catch from 1edb1a8 doesn't compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL
Part of #775: the parser no longer writes into the object tree or the transfers that the server and the application use.
What
start_parsing_thread()gives the parsing thread an object tree of its own. It starts with only the Working Set object and any Working Set Special Controls object of the current tree, which parsing checks a later Working Set and a second Working Set Special Controls object against. The rest of the tree isn't copied.join_parsing_thread(), which the server calls fromupdate(), does everything that changes the working set:add_or_replace_object()only sees the parser's own tree, so the parser also gets the type of every object in the current tree, and the parse fails at the lowest object ID that would change its type. The faulting object and its parent are reported as for any other parse error.VirtualTerminalWorkingSetBasegetsset_object_pool_fault(), which sets the faulting object together with its parent.get_object_pool_faulting_parent_object_id()still searches its own tree, as before, if only the faulting object was set.The parser itself (
parse_iop_into_objects()andparse_next_object()) is unchanged. The working set parses through a privateObjectPoolParser, which derives fromVirtualTerminalWorkingSetBase.Behaviour changes
join_parsing_thread(), the old object tree is still visible.EndOfObjectPoolResponseReportsNoParentWhenTheFaultyObjectHasNoIDchecked the opposite and now checks this.StatusMessageReportsTheNewAddressOfTheActiveWorkingSetMasteruses the shared small pool, which needs Accept an empty Data Mask or Working Set at the end of a transfer #951 (merged).Not in this PR
update()#952.Tests
ParsedObjectsReplaceTheObjectTreeOnlyWhenTheThreadIsJoined: also checks that the transfer is only trimmed at the join and that an object added during parsing stays.AFailedTransferLeavesTheObjectTreeAsItWasAndReportsTheFault: the parent is a new object.TheParentOfAFaultingObjectCanBeInTheCurrentPool: the parent is in the current tree.ALaterTransferCannotReplaceAnObjectWithAnotherType: a Number Variable with the ID of a Container of the current pool fails the parse, and the tree keeps the Container.StoreVersionIsRejectedUntilThePoolIsAnswered.They stay in
vt_server_tests.cpp, as they use itsTestWorkingSet. All tests pass exceptNackForUnmanagedWorkingSetIsSentToTheWorkingSetMasterNotGlobally, which also fails on main when the whole suite runs, and passes alone.🤖 Generated with Claude Code
https://claude.ai/code/session_014h8cGiqsZ1BE7bEWjop5tL