Skip to content

companion: pin MAX_CONTACTS so every unit agrees on the contact table - #22

Merged
A13xB0 merged 1 commit into
mainfrom
companion-contacts-max-contacts
Sep 8, 2026
Merged

A13xB0 merged 1 commit into
mainfrom
companion-contacts-max-contacts

Conversation

@A13xB0

@A13xB0 A13xB0 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

A native companion loads its contacts at boot and reports none to any client (MeshBench/meshbench#725). Traced to a One Definition Rule violation in this host build.

MAX_CONTACTS sizes ContactInfo contacts[MAX_CONTACTS+MAX_ANON_CONTACTS] inside the shared BaseChatMesh, with num_contacts declared right after it. The companion's examples/companion_radio/MyMesh.h raises MAX_CONTACTS from BaseChatMesh.h's default 32 to 100. On hardware platformio passes that to every unit; build.sh compiles each .cpp alone, so BaseChatMesh.cpp kept 32 and MyMesh.cpp saw 100. The BaseChatMesh subobject then had two layouts, and num_contacts two offsets: addContact (compiled in BaseChatMesh.cpp) wrote it at one offset, getNumContacts/the iterator (inlined into MyMesh.cpp) read it at another.

Measured against a host companion at companion-v1.17.1 with a debug print: addContact walks num_contacts 0→1→2→3 while getTotalContactSlots() reads 8 in the same run. With -DMAX_CONTACTS=100 the same binary reports count=3 and yields all three contacts.

MAX_GROUP_CHANNELS was already pinned here for precisely this reason; MAX_CONTACTS was the one that was missed. The comment now says why both are load-bearing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9HbD44EKWWTRYgxbFGxf6

MAX_CONTACTS sizes a contacts array inside the shared BaseChatMesh, and the
companion's MyMesh.h raises it from the base default of 32 to 100. On real
hardware platformio passes that to the whole build; this host build compiles
each .cpp on its own, so BaseChatMesh.cpp kept 32 while MyMesh.cpp saw 100,
and the BaseChatMesh subobject had two layouts. num_contacts lived at two
offsets, so a contact added through one translation unit was invisible
through another: a companion loaded its contacts3 at boot and reported none
to any client, and every advert it learned went the same way.

MAX_GROUP_CHANNELS was already pinned here for exactly this reason; this adds
the one that was missed. Verified against a host companion built at
companion-v1.17.1: it reported 0 contacts before and its full list after.

MeshBench/meshbench#725

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9HbD44EKWWTRYgxbFGxf6
@A13xB0
A13xB0 merged commit 5a5bc84 into main Sep 8, 2026
1 check passed
@A13xB0
A13xB0 deleted the companion-contacts-max-contacts branch September 8, 2026 22:42
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