Skip to content

fix(elements): degrade gracefully on unrecognised Task record layout - #54

Open
colinlove wants to merge 1 commit into
hutcheb:mainfrom
colinlove:fix/task-record-layout-mismatch
Open

colinlove wants to merge 1 commit into
hutcheb:mainfrom
colinlove:fix/task-record-layout-mismatch

Conversation

@colinlove

Copy link
Copy Markdown
Contributor

This fix is part of a series found with AI assistance (Claude Code) — see the first PR in this batch for the full disclosure.


One Task record's whole binary layout doesn't match the known offsets (newer Studio/firmware version?)

Note: this patch touches the same file as 0004/0006/0008 and adds the
same from loguru import logger as log import each does. If applying more
than one of these to acd/l5x/elements.py at once, keep a single copy of
that import line — see the top-level README's "Applying more than one
patch to the same file" note.

Symptom

ValueError: Task record contains too many scheduled programs

aborting the entire export, on a file dated 2025 (i.e. likely a newer
Studio 5000 / firmware version than this comment in the source references:
"These offsets were reverse-engineered from CIPDemo_RevEng.ACD").

Root cause

TaskBuilder.build() reads a Task's scheduled-program list as a u16
count followed by N u32 comment_ids, at a fixed offset
(program_offset = 0x5A) within the record. On the file in question, the
count read back was 46563 (and, for a second task in the same file,
22458) against a sane maximum of ~1028 — clearly not a real count.
Investigating further: every other field read from this record's fixed
offsets is also wrong
— rate_us, type_val, priority, and
watchdog_us (at 0x106C/0x10F6/0x10F8/0x110A) all read back as
0, which is not a plausible task configuration. This isn't one corrupt
field; the whole record's layout has shifted, most likely because this is
a genuinely different Task binary layout from a Studio/firmware version
newer than the one this code was reverse-engineered against.

Fix

This isn't a quick fix — recovering the real offsets for whatever layout
version this is requires the same kind of from-scratch reverse-engineering
as the rest of this file's fixed-offset table, which is out of scope for a
drop-in patch (no other example of this layout was available to
reverse-engineer against; if you can point at a second file with the same
shape, or the vendor documentation for the newer Task record format, this
could be finished properly). Instead, this degrades gracefully: when the
scheduled-program count exceeds the theoretical maximum for the field's
size, log a warning identifying the task and export it anyway with an
empty scheduled-program list, rather than failing the whole project's
export over one field of one task.

Suggested validation

If you have access to a project saved by a newer Studio 5000 / firmware
version than CIPDemo_RevEng.ACD was built with, dumping its MainTask
(or any Task) comps record and comparing byte-for-byte against a known-good
older one at the documented offsets would be the fastest way to find the
real offsets and turn this into a proper fix rather than a graceful
degradation. Happy to help gather more sample data if that would help —
see the top-level README for how to reach the author of this patch set.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@santiagolgzz

Copy link
Copy Markdown

Thanks for this. I tested it on 20 projects: it stops the crash, but on the two public files that hit it, the tasks come out with blank settings. I've opened a small PR into your branch that recovers them: colinlove#1. Happy to adjust anything.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants