Fix stateful-sensor crash on GetStatus; add explicit Status API#5
Merged
Merged
Conversation
The stateful-sensor model embedded resource.Named but never initialized it, leaving the embedded interface nil. The sensor service's GetStatus RPC calls the promoted Status method, which dereferenced the nil receiver and crashed the module with a SIGSEGV (exit code 2), producing a restart/crash loop on deployed machines. Initialize the embedded Named via name.AsNamed() (matching the sensor-monitor model) and drop the now-redundant name field and Name() method. Also add an explicit Status method so the model owns the API and returns useful operational metadata (file_path, num_keys) instead of the empty default. Add a regression test covering Status. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ale Paredes (ale7714)
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
viam:sensor-bundle:stateful-sensormodel crash-looped on deployed machines (observed on machineCappuccina): the module panicked with a SIGSEGV (exit code 2) and was repeatedly restarted. The model embeddedresource.Namedbut never initialized it, so the sensor service'sGetStatusRPC invoked the promotedStatusmethod on a nil receiver. This PR fixes the crash and adds an explicitStatusAPI so the model owns the behavior.Changes
resource.Namedvianame.AsNamed()(matching thesensor-monitormodel), which fixes the nil-receiver panic in theGetStatuspath.namefield and customName()method, deferring to the embeddedNamed.Status(ctx)method returning operational metadata (file_path,num_keys) instead of the empty default — distinct fromReadings, which returns the stored value itself.Testing
TestStatuscovering theStatusAPI: assertsfile_path/num_keysbefore and after aset(0 → 2 keys), and guards against the nil-receiver crash regression.go build ./...,go vet ./..., andgofmtall clean; full test suite passes.Root cause
The crash signature from the machine logs:
resource.Namedis an interface declaringName(),DoCommand(), andStatus(). The struct overrode the first two but notStatus(), and the constructor left the embedded interface nil — so anyGetStatuscall dereferenced nil.Claude Code Prompts Used
🤖 Generated with Claude Code