Skip to content

feat(studio/scenarios): type the account of an override whose template names none - #42

Open
92Infinitus92 wants to merge 6 commits into
feat/scenarios/override/editor-account-supportfrom
feat/studio/editor-account-input
Open

92Infinitus92 wants to merge 6 commits into
feat/scenarios/override/editor-account-supportfrom
feat/studio/editor-account-input

Conversation

@92Infinitus92

@92Infinitus92 92Infinitus92 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

The scenario editor could not create an override for a template whose address is a pubkey with no value: it sent the template's empty address and had no field for the account. Most bundled templates are like that (Kamino, Drift, Phoenix, Pyth, Doves, Velocity and others), so for them only presets and the AI could target an account.

  • Such a template shows an "Account selection" card with the editor's Combobox. Paste an address and pick "Custom · "; an invalid one shows "Not a valid Solana address.". No account list is bundled.
  • Picking an address reads that account, so its fields fill and the account is pulled into the local VM, as reopening a saved override does. The existing stale-response guard covers it, and picking the same address again keeps the edits.
  • The read also checks the account, and each problem blocks Add and Update:
    • "No account at this address." when it does not exist;
    • "Not a account." when the template IDL's program does not own it;
    • "Could not read this account. Pick it again to retry." when the RPC returns an error or cannot be reached.
  • A template without an IDL (raw layout, such as Save) is only checked for existence, since nothing decodes its data.
  • Add and Update send account: { pubkey } with the picked address. Templates with a fixed address or a PDA keep their own address.
  • Reopening a saved override fills the field from its saved account and checks it again, so an override whose account was closed can be deleted but not updated.
  • The shared Combobox gets an optional onQueryChange prop for the invalid-address line, and MockCombobox follows it.

The card sits above "Fetch before use", because a new account reloads the action and resets that switch.

Tests in scenario-editor.test.tsx cover adding with a picked account, retyping, missing, foreign and unreadable accounts, a template without an IDL, a read cleared in flight and reopening a saved override; the new ones fail without the change.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Summary

For templates whose address is an empty pubkey, the editor now shows an Account field. A valid address loads that account, and the override saves account: { pubkey } from it. Add and Update stay disabled until the address is valid. This replaces the old Update-only fallback to existingAction.account, so Add and Update now share one path. The PDA and fixed-address paths behave as before, and the tests cover add, invalid input and reopen.

Overall the change is small and works, but there are three things to look at:

  • Changing the account throws away edits. Every edit that turns the field into a valid address calls handleActionSelect, which clears accountData, modifiedFields and fetchBeforeUse. When editing a saved override, it also bumps the request id, so the restore of the saved overrides never runs. Fixing a typo, or deleting and re-pasting the same address, silently drops the user's edits.
  • A missing or wrong account gives no feedback. If the address is valid but the account doesn't exist, or belongs to another program, getAccountInfo returns nothing to parse. The fields stay empty, Add stays enabled, and the user gets no message.
  • Unrelated workflow file. .github/workflows/claude-review.yml has nothing to do with the feature and would be better in its own PR. It also puts the PR title and body straight into the prompt. Fork PRs are skipped, but anyone who can push a branch can still steer the review text that post_feedback then posts with write access.

apps/studio/src/components/svm/scenario-editor.tsx:752

handleActionSelect resets accountData, modifiedFields, arrayEntryIndex and fetchBeforeUse on every edit that produces a different valid address. Example: the user edits fields, then changes a character in the address (valid → invalid → valid again, even back to the same value). All their edits are lost without warning. When editing a saved override, the restore after await loading (≈L1416) also bails out because accountRequestRef changed, so the saved overrides disappear too. Options: debounce, load the account on blur, or keep accountData and modifiedFields across an account change and only refresh the fields the user hasn't modified.


apps/studio/src/components/svm/scenario-editor.tsx:737

For a typed account, an empty or unparsed result (the account doesn't exist, or is owned by another program) leaves the form blank with no message. Add still saves an override for that account. Consider showing "Account not found" or "Not a account" when result.value is null or data.parsed is missing, and blocking Add in that case.


apps/studio/src/components/svm/scenario-editor.tsx:691

Small point: this early return happens after setLoadingAccountData(true). That's fine, but a check placed before the setLoadingAccountData(true) / try block, next to the !action.template?.address guard, would avoid the brief loading flicker and read more clearly.


.github/workflows/claude-review.yml:70

Unrelated to the scenario editor change, so better in a separate PR. Also, the PR title and body go into the prompt unescaped, and post_feedback publishes the model's output with pull-requests: write. Anyone who can push a branch can steer what gets posted. The risk is low, but consider leaving the body out of the prompt, or at least delimiting it as untrusted data.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

For templates whose address is a pubkey with no value, the editor now shows an Account input. When the user types a valid address, the editor loads that account, and Add/Update send { pubkey } with it. The Add/Update button stays disabled until the address is valid. Reopening a saved override fills the input from existingAction.account.pubkey. The change is small and works, and the three new tests cover the main paths.

PublicKey in web3.js ^1.98 requires the address to decode to exactly 32 bytes, so isSolanaAddress rejects short base58 strings like "abc".

Issues

  • Changing the account throws away edits. Every new valid address goes through handleActionSelect, which clears accountData, modifiedFields, arrayEntryIndex and fetchBeforeUse. Deleting one character and typing it back counts as a new address, because the invalid value in between differs from the restored one. So the account reloads and every field the user changed is lost. Consider reloading only when the address differs from the last one actually loaded, and/or keeping modifiedFields across the reload.
  • The editor can show data for an account it isn't targeting. If the user types a valid address and then edits it to something invalid or empty, no new request is made. The request for the earlier address can still finish and fill the fields. Save is disabled in that state, so it doesn't corrupt anything, but the fields don't match the input. Bumping accountRequestRef.current and clearing accountData when the address stops being valid would fix this.
  • Nothing checks that the account belongs to the template's program. If the account doesn't exist, the user can still save an override with empty overrides. If it belongs to another program, its parsed data is shown as editable fields. A short note in the UI when getAccountInfo returns null or a different owner would help.
  • Validation lives only in the button. addActionToSlot and the update path (lines 837 and 882) depend on the button being disabled. If anything else calls them, they will save { pubkey: '' }. A cheap guard in those functions would close that off.
  • Unrelated file in this PR. .github/workflows/claude-review.yml has nothing to do with the scenario editor and isn't mentioned in the PR body. It should go in its own PR. It also puts the PR title and body straight into the prompt; that's acceptable with read-only tools, but it's worth noting.

const pubkey = event.target.value.trim();
setTypedAccount(event.target.value);
if (selectedAction && pubkey !== typedAccountPubkey && isSolanaAddress(pubkey)) {
handleActionSelect(selectedAction, pubkey);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every new valid address calls handleActionSelect, which clears accountData, modifiedFields, arrayEntryIndex and fetchBeforeUse. Deleting one character and typing it back counts as a new address, because the invalid value in between differs from the restored one. So the same account reloads and every field the user changed is lost. Consider comparing against the last loaded address (e.g. a ref) rather than the previous input value.

When the input turns invalid or empty, no request is made, so a request already in flight for the old address can still fill the fields. Bumping accountRequestRef.current and clearing accountData there would keep the fields consistent with the input.

}
// A PDA template, or one that leaves the account to the override, reads the saved account.
if (accountPubkey && !addressString) addressString = accountPubkey;
if (!addressString && leavesAccountToOverride(action.template.address)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This early return skips the fetch but leaves accountRequestRef already incremented, so that part is fine. One gap remains for a typed account: if getAccountInfo returns value: null (no such account) or an account owned by another program, the user can still save. They get an empty override or one built from unrelated parsed fields. A short notice in the UI for that case would help.

modifiedFields: Array.from(modifiedFields),
fetchBeforeUse: fetchBeforeUse,
account: action.template?.address,
account: leavesAccountToOverride(action.template?.address)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation is enforced only through the button's disabled prop. A guard here, and in the update path at line 882, such as if (needsTypedAccount && !hasTypedAccount) return;, would stop any other caller from saving { pubkey: '' }.

@github-actions

Copy link
Copy Markdown

Summary

The PR adds an "Account" field to the scenario editor for templates whose address is an empty pubkey. Add and Update now send { pubkey } with the typed address, and reopening a saved override fills the field from the account it was saved with. Typing a valid address loads that account through handleActionSelect, so the existing stale-response guard covers it. Overall it's a clean change that solves a real gap (66 of the 101 templates), and the tests target the right behaviour.

Points to look at

  • Unrelated file in the PR: it also adds .github/workflows/claude-review.yml, which has nothing to do with the scenario editor. It would be better as its own PR so it can be reviewed and reverted separately.
  • Validation rules worth confirming:
    • Owner check: a missing or "foreign" account now blocks the save. That is new behaviour for Update on saved overrides; before this PR, Update kept existingAction.account without any check (see inline comment).
    • Silent fetch failures: if the account read throws, nothing blocks the save (see inline comment).
  • Edits wiped by a new address: typing a different valid address re-runs handleActionSelect, which clears modifiedFields and accountData. The PR says this happens, but no warning is shown in the UI, so a user who edits fields and then fixes a typo in the address loses those edits.

apps/studio/src/components/svm/scenario-editor.tsx:747

This blocks Update when the saved account's owner differs from idl.address. Before this PR, Update always kept existingAction.account for these templates. Any bundled preset (or IDL without a top-level address, or a template that targets an account owned by another program, e.g. an oracle/token account) where owner !== idl.address will now show "Not a … account" and leave Update disabled. Worth checking the bundled presets against this rule, or making foreign a warning instead of a hard block.


apps/studio/src/components/svm/scenario-editor.tsx:761

When fetch/json() throws (RPC down, CORS, etc.), typedAccountIssue stays null and loadedTypedAccountRef already equals the typed pubkey, so the save is allowed for an address that was never checked. Also, a JSON-RPC error response (no result) is reported as "No account at this address", which is misleading. Consider setting a distinct issue in the catch branch and when accountInfoData.error is set, or at least say the account couldn't be verified.


apps/studio/src/components/svm/scenario-editor.tsx:783

handleActionSelect sets loadedTypedAccountRef synchronously, so typedAccountPubkey === loadedTypedAccountRef.current holds during an in-flight read. This check therefore doesn't stop a save that happens before the read finishes. In practice the button is never enabled when this check is false, so it's mostly redundant. Either remove it or make it check that the read has finished (see the next comment).


apps/studio/src/components/svm/scenario-editor.tsx:2833

The button is enabled while the typed account is still loading: typedAccountIssue was reset to null and the address is valid. Clicking Add or Update at that moment saves overrides: {} and skips the missing/foreign check. Suggest (needsTypedAccount && (!hasUsableTypedAccount || loadingAccountData)).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds an "Account" combobox to the scenario editor for templates whose address is a pubkey with no value. A valid address triggers a load of that account. Add and Update send { pubkey: typedAccount } and are blocked until the address is valid and loaded. It also adds an onQueryChange prop to the shared Combobox and updates MockCombobox to match.

Overall the change is well reasoned. The stale-response guard is reused correctly, and Add/Update is hidden while loadingAccountData, so a save can't race the load. A few points:

  • Behaviour the description leaves out: the code also adds owner/existence validation ('missing' / 'foreign'), which blocks saves. That includes reopening an existing saved override whose account has since closed or whose owner differs from idl.address. This is a real behaviour change and should be described, ideally with a test for each case.
  • Unrelated file: .github/workflows/claude-review.yml has nothing to do with the feature. Please move it to its own PR so it gets its own review. It adds a write-scoped job and puts the untrusted PR title and body into the prompt.
  • Error handling: an RPC error or a thrown fetch is not handled separately (see the inline comment).

if (accountPubkey && leavesAccountToOverride(action.template.address)) {
const programId = action.template.idl.address;
if (!account) issue = 'missing';
else if (programId && account.owner !== programId) issue = 'foreign';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account.owner !== idl.address assumes the IDL's program owns every account the template edits. That fails when the IDL address differs from the deployed owner, for example Pyth price-update accounts owned by the receiver program, or a template whose IDL carries a stale or devnet address. It would block legitimate saves, including Update on overrides that were saved before this PR. Could you check this owner assumption against all 66 affected templates? Alternatively, make 'foreign' a warning rather than a hard block.

let issue: TypedAccountIssue = null;
if (accountPubkey && leavesAccountToOverride(action.template.address)) {
const programId = action.template.idl.address;
if (!account) issue = 'missing';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An RPC error response ({ error: ... } with no result) is reported as 'missing' ("No account at this address."), which is misleading. The opposite also happens: if fetch or .json() throws, the catch leaves typedAccountIssue at null, so an account that was never verified can be saved. Consider checking accountInfoData.error, and adding an error state to the catch.


const renderAccountOption = (option: TokenSelectorOption) => (
<ComboboxOption key={option.id} value={option}>
<ComboboxLabel>{option.metadata?.symbol}</ComboboxLabel>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options come from customValueOption, so the selected account is labelled Custom · <address>. "Custom" makes sense for the token selectors, but this field only ever holds a pasted address. Consider rendering option.value directly here.

return;
}
// A finished read stays, so choosing its address again keeps the edits; a read in flight must not fill the fields
if (loadingAccountData) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a finished read, clearing the field keeps the previous account's decoded fields on screen with an empty Account input. That is intentional so the edits survive re-selecting the same address, but it may confuse users. A short hint, or dimming the fields while the account is empty, would help.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The PR adds an "Account" combobox for templates whose address is a pubkey with no value. It checks the typed address, reads the account (and flags it as missing, owned by another program, or unreadable), and saves account: { pubkey } on Add and Update. Combobox gets an onQueryChange prop, and the test mock is updated to match.

The approach is sound. The stale-response handling extends the existing accountRequestRef guard, and hiding the button while a read is in flight means a save can't skip the checks. A few points are worth a look:

  • Owner check could block existing presets (main risk). An override is rejected as foreign when the account's owner isn't idl.address, and on reopen this now disables Update for saved overrides. For templates where the edited account is owned by a different program than the IDL's address (oracle and receiver setups, IDLs with a stale address), saved preset overrides that used to update fine will be stuck. Consider showing this as a warning instead of blocking.
  • Silent loss of edits. Picking a different account calls handleActionSelect, which clears accountData and modifiedFields. When editing a saved override, the restored overrides disappear with no prompt.
  • Change for raw-layout templates on reopen. No-IDL templates with a fixed address now trigger a getAccountInfo on reopen, because accountPubkey is passed. This is harmless but unintended, and it's not in the PR description.
  • Unrelated file. .github/workflows/claude-review.yml is part of this diff but has nothing to do with the feature. It would be cleaner as its own PR.
  • Minor UX issues.
    • The selected account shows in the list as Custom · <address>, because customValueOption is reused. A plain address would read better here.
    • After a missing or foreign result, picking the same address again doesn't re-read it. Only an unverified result allows a retry, so an account created afterwards can't be picked up without switching to another address first.

Tests cover the main paths. None of the three new tests covers the foreign, missing or unverified branches.

const programId = action.template.idl?.address;
if (accountInfoData.error) issue = 'unverified';
else if (!account) issue = 'missing';
else if (programId && account.owner !== programId) issue = 'foreign';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blocks saving whenever account.owner !== idl.address. Some bundled templates may edit accounts owned by a different program than the IDL's address, such as oracle and receiver accounts, or IDLs whose address isn't the deployed program. Because reopen also runs this check, Update is disabled for saved preset overrides that worked before this PR. Was this checked against all 66 affected templates? A non-blocking warning may be safer.

setTypedAccount(pubkey);
if (!selectedAction) return;
if (pubkey) {
if (pubkey !== loadedTypedAccountRef.current) handleActionSelect(selectedAction, pubkey);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When editing a saved override, choosing a different account goes through handleActionSelect, which resets accountData and modifiedFields. The overrides restored on reopen are dropped with no warning. Either keep modifiedFields and re-apply them over the new account's data, or confirm with the user before discarding.

// Without an IDL, as on raw-layout templates, only a given account is read: nothing is decoded,
// but the read checks that the account exists.
const hasIdl = !!action.template?.idl;
if (!action.template?.address || (!hasIdl && !accountPubkey)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reopen passes action.account?.pubkey for every template. No-IDL templates with a fixed address used to return early here, and now they make a base64 getAccountInfo call and set typedAccount even though no field is shown. If the read is only meant for typed accounts, gate it on leavesAccountToOverride(action.template.address).

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.

1 participant