Files
Pulse/internal/models
rcourtman f1f2480e86 Keep action refusals current on websocket rows (#3917)
## What was wrong

A Docker page left open kept Stop and Restart enabled after the server
began refusing them. On a mock stack with a stand-in command agent,
closing the agent left its 14 containers enabled for more than 20
seconds while REST refused them with `command_agent_disconnected`, and
the click only failed at plan time. The reverse was also wrong: after an
agent reconnected, the old refusal stayed until the page remounted.

The first sighting pointed at a websocket paint overwriting REST
readiness. It does not: the merge kept the REST answer. The cause is
that websocket rows never carried refusals, and a mounted Docker page
reads REST once, so the answer never changed. In-app navigation also
showed refused actions as enabled for about 300 ms until REST returned.

## The fix

- Each state broadcast runs the same availability check as REST. A
refused row carries `actionReadinessRef` into a new
`actionReadinessCatalog`, and a row with no ref refuses nothing.
- The websocket store expands the ref, and `mergeCanonicalResource`
takes `actionReadiness` from the incoming row alone.
- Broadcast rows keep `capabilities` whole. REST still strips what it
refuses. The drawer's operator policy form needs what a disconnected
host offers, and a stable set means a disconnect moves one ref per row.

## Cost

A check runs per capability per resource. Host and token lookups scan
every session, and each session check takes `config.Mu`, so one pass now
answers each lookup once. Planning and dispatch still read live.

Refusal pass over 5,000 containers on 100 hosts with 3 capabilities
each, on pulse-dev, using a stand-in agent server that scans sessions
like the real one:

| Estate | One lookup per pass | No memo |
| --- | --- | --- |
| All agents connected | 13.6 ms | 296 ms |
| No agents connected | 26.9 ms | 24.7 ms |

The disconnected case costs more because each check builds its error
text, and the memo does not help there. It is a pass every 2 seconds per
audience at this estate size, so I left it.

Wire cost is one ref per refused row. On the mock estate, 1,008 refused
rows of 1,782 share 9 catalog entries totalling 2,945 bytes. Catalog
entries leave out `detail`, which names one host's identity and would
give every host its own entry.

## Verification

Private mock stack built from this change, with a stand-in command agent
connected and closed while the page stayed open:

- Connecting enabled Stop on the host's 14 containers after 2.2 s with
no reload.
- Closing it disabled them with the server's reason after 5.0 s.
- `no_command_agent` rows on `proxmox-lxc-docker:` hosts show that
reason.
- First paint and in-app navigation, sampled every 50 ms, never showed a
refused action as enabled.
- Checked at 1680 and 740 wide, including the row menu and the resource
detail surface.

The new frontend tests fail without the fix: 4 of 259 in the targeted
files. Go tests passed on pulse-dev for `actionlifecycle` availability,
`monitoring` broadcast, `websocket`, `models`, `api/resourceapi` and the
action executors in `api`. I did not run the full `internal/api` suite
outside CI.
2026-11-05 01:11:01 +00:00
..