Repository navigation
feat(studio): turn keep-alive off with keepAlive: [] - #41
92Infinitus92 merged 7 commits into
Conversation
There was a problem hiding this comment.
Summary
This PR adds a per-override Keep alive switch to the scenario editor. It only appears when the selected template has a non-empty keepAlive list, and it defaults to on. The flag goes through the same paths as fetchBeforeUse: editor state, scenarioFromApiData and buildUpdatePayload. Overrides saved without the field load as keepAlive: true, so older scenarios keep working.
The change is small and consistent, and I found no blocking bugs. The state is reset in every place fetchBeforeUse is reset. It is also restored correctly when an existing override is reopened, because the restore runs after handleActionSelect has reset it.
Notes
- Unrelated file:
.github/workflows/claude-review.ymlis added here but has nothing to do with the feature. It may be better as a separate PR, or the description should mention it. keepAliveis always sent: every override now carries an explicitkeepAlive: true, including templates that don't use keep-alive. This only matters if the backend treats "missing" differently fromtrue; worth checking against LimeChain/surfpool#53.- Hidden
falsevalue: if a saved override haskeepAlive: falseand its template later loses itskeepAlivelist, the switch is hidden butfalseis still restored and saved again. It is harmless, but the user can't see or change it. - Test coverage: the tests cover the data mapping only. The editor save path (lines 812/853) and the restore on edit (line 1629) have no tests, which matches how
fetchBeforeUseis tested today.
| if (action.fetchBeforeUse !== undefined) { | ||
| setFetchBeforeUse(action.fetchBeforeUse); | ||
| } | ||
| if (action.keepAlive !== undefined) { |
There was a problem hiding this comment.
If the template no longer has a keepAlive list, this still restores a saved false, but the switch is hidden (templateHasKeepAlive is false). The value is then saved again without the user seeing it. One option is to restore it only when foundAction.template?.keepAlive?.length is non-zero. Another is to show the switch whenever keepAlive === false, so the user can still turn it back on.
| <label className="text-sm text-zinc-400">Fetch before use</label> | ||
| <Switch checked={fetchBeforeUse} onChange={setFetchBeforeUse} color="purple" /> | ||
| {templateHasKeepAlive && ( | ||
| <> |
There was a problem hiding this comment.
Small accessibility issue: this <label> isn't linked to the Switch with htmlFor/id or by wrapping it, so clicking the text doesn't toggle the switch and screen readers don't announce a name. The "Fetch before use" label next to it has the same problem, so both could be fixed together.
…ps its account alive
There was a problem hiding this comment.
Summary
Adds a per-override keepAlive flag (default true) to the scenario editor, the API→scenario mapping (scenarioFromApiData) and the metadata-only PATCH (buildUpdatePayload). The "Keep alive" switch only appears when the selected template has a non-empty keepAlive list. It is wired the same way as fetchBeforeUse, and every reset path also resets keepAlive to true. The change is small and consistent with existing patterns, and the tests cover the default value, keepAlive: false, and the reopen-in-editor behaviour.
Issues
- Unrelated file in the diff: this PR also adds
.github/workflows/claude-review.yml, which the description doesn't mention. It should be split into its own PR, or at least called out. The workflow puts the PR title and body straight into the prompt. Because the job is read-only and limited togitand read tools, the impact of a prompt injection there is small, but reviewers should know about it. - Inconsistent handling of a saved
keepAlive: falseon a template with no keep-alive list: when the editor reopens such an override, it deliberately drops thefalse(see the comment atscenario-editor.tsx:1629). The background sync (:326) andbuildUpdatePayloadinstead pass through whatever was stored. As a result, a hiddenfalsestays on an override until someone opens it in the editor, and then it silently flips totrue. Either normalise it the same way in every path, or keep it everywhere. - The backend default gets hard-coded: every override is now PATCHed with an explicit
keepAlive: true, including overrides on templates that have no keep-alive list. If the backend default ever changes, saved scenarios won't pick it up. Consider leaving the field out when it istrueorundefined, so the backend keeps control of the default (the description says presets already do this). - Nit: the description says there are two new vitest cases, but there are three (editor,
scenarios-api,scenarios-data).
| label: action.action, | ||
| enabled: original.enabled ?? true, | ||
| fetchBeforeUse: action.fetchBeforeUse || false, | ||
| keepAlive: action.keepAlive ?? true, |
There was a problem hiding this comment.
This path keeps a stored keepAlive: false even when the template has no keep-alive list. The reopen path at ~L1629 deliberately drops it. So a hidden false survives until someone opens the override in the editor, and then it silently becomes true. Consider handling it the same way in both paths (this one, L979 and buildUpdatePayload).
| label: action.action, | ||
| enabled: original.enabled ?? true, | ||
| fetchBeforeUse: action.fetchBeforeUse || false, | ||
| keepAlive: action.keepAlive ?? true, |
There was a problem hiding this comment.
Every override now gets an explicit keepAlive: true, so the backend default is frozen into stored scenarios. Consider sending the field only when it is false, e.g. ...(action.keepAlive === false && { keepAlive: false }), and making keepAlive optional in OverridePayload.
| <Switch checked={fetchBeforeUse} onChange={setFetchBeforeUse} color="purple" /> | ||
| {templateHasKeepAlive && ( | ||
| <> | ||
| <label className="text-sm text-zinc-400">Keep alive</label> |
There was a problem hiding this comment.
Minor a11y: the <label> isn't associated with the Switch (no htmlFor/id and it doesn't wrap the control), so screen readers won't announce "Keep alive" for the toggle. The existing "Fetch before use" label has the same problem.
| @@ -0,0 +1,141 @@ | |||
| name: Perform a code review when a pull request is created. | |||
There was a problem hiding this comment.
This workflow isn't related to the keep-alive feature and the PR description doesn't mention it. Please split it into a separate PR, or at least call it out, so it gets its own review. It also puts the PR title and body directly into the prompt.
1ba5344
into
feat/scenarios/override/keep-alive-toggle-support
Studio side of LimeChain/surfpool#53: an override can turn keep-alive off for its account with
"keepAlive": [], and Studio never sends a boolean.The editor shows a "Keep alive" switch when the override's template imports keep-alive:
keepAliveis left out, so the template keeps the account fresh every slot;keepAlive: [], so from this override on nothing refreshes the account and its fields age (for example to test a stale price).Reading an override back:
[]sets the switch off; anything else (absent, a non-empty array, an old cached boolean) sets it on, as the engine treats it. A hidden switch (a template with no keep-alive imports) never changes what the override carries, so a saved[]goes back as[]on save and on Play. The payload builders (editor save, Play,buildUpdatePayload) sendkeepAliveonly when it is[].Tests cover on and off, a reopened
[], turning it back on, a non-empty array read as on and not sent, a hidden switch keeping[]on save and on Play, and no boolean on save or Play. vitest 387 passed,tsc --noEmitclean, lint 0 errors.