Skip to content

Fix stateful-sensor crash on GetStatus; add explicit Status API#5

Merged
Nicolas Palpacuer (NickPPC) merged 1 commit into
mainfrom
fix-stateful-sensor-status
Jun 5, 2026
Merged

Fix stateful-sensor crash on GetStatus; add explicit Status API#5
Nicolas Palpacuer (NickPPC) merged 1 commit into
mainfrom
fix-stateful-sensor-status

Conversation

@NickPPC

Copy link
Copy Markdown
Collaborator

Summary

The viam:sensor-bundle:stateful-sensor model crash-looped on deployed machines (observed on machine Cappuccina): the module panicked with a SIGSEGV (exit code 2) and was repeatedly restarted. The model embedded resource.Named but never initialized it, so the sensor service's GetStatus RPC invoked the promoted Status method on a nil receiver. This PR fixes the crash and adds an explicit Status API so the model owns the behavior.

Changes

  • resources/statefulsensor: Initialize the embedded resource.Named via name.AsNamed() (matching the sensor-monitor model), which fixes the nil-receiver panic in the GetStatus path.
  • resources/statefulsensor: Drop the now-redundant name field and custom Name() method, deferring to the embedded Named.
  • resources/statefulsensor: Add an explicit Status(ctx) method returning operational metadata (file_path, num_keys) instead of the empty default — distinct from Readings, which returns the stored value itself.

Testing

  • Added TestStatus covering the Status API: asserts file_path/num_keys before and after a set (0 → 2 keys), and guards against the nil-receiver crash regression.
  • go build ./..., go vet ./..., and gofmt all clean; full test suite passes.

Root cause

The crash signature from the machine logs:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 ...]
sensorbundle.(*sensorBundleStatefulSensor).Status(...)  <autogenerated>:1
go.viam.com/rdk/protoutils.GetStatusFromResourceServer(...)
go.viam.com/rdk/components/sensor.(*serviceServer).GetStatus(...)

resource.Named is an interface declaring Name(), DoCommand(), and Status(). The struct overrode the first two but not Status(), and the constructor left the embedded interface nil — so any GetStatus call dereferenced nil.

Claude Code Prompts Used

  • "check the logs for issue with the current module on the Viam machine with part ID 5be4df6e-b9ae-4a5f-acc0-e258d51be17d"
  • "create a new worktree off of origin/main"
  • "yes" (apply the fix plus a GetStatus regression test)
  • "Can you also add an explicit Status API if not present?"
  • "commit and open a PR"

🤖 Generated with Claude Code

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>
@NickPPC Nicolas Palpacuer (NickPPC) merged commit 4c7f671 into main Jun 5, 2026
3 checks passed
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