fix: two pages switching networks no longer lose tracked tokens (closes #701) #704

Merged
clawbot merged 1 commits from issue-701-two-page-switch-race into next 2026-11-03 00:04:21 +01:00
Collaborator

With two popup pages open, a page that had not yet taken the other page's network switch could lose tracked tokens.

  • saveState() (src/shared/state.js): when the merged record names a network other than this page's, the record keeps its stored trackedTokens. A token that this page added or removed is added to or removed from the list of this page's network in networkTrackedTokens. The page then follows the stored switch as usual.
  • onChainSwitch() (src/shared/chainSwitch.js): when the stored record is on another network, the page first takes that switch with takeStoredNetwork(), as followStoredSettings() does. The page then switches from there.
  • onChainSwitch(): when the stored record is on this page's network, the page first takes the stored networkTrackedTokens with takeStoredNetworkTrackedTokens(), because another page's save may have changed a list this page holds.
  • takeStoredNetwork() (src/shared/state.js) no longer drops this page's unsaved change to its tracked tokens. The change lands in the list in networkTrackedTokens for the network this page was on.

This PR also fixes #706.

The check in saveStateOnce() is needed too, because it covers another order. It handles a save made before this page takes the switch. takeStoredNetwork() handles a change made while this page waits for the lock to take the switch.

Removed or replaced six checks, one at a time; a test failed each time.

Model: opus-5-5

With two popup pages open, a page that had not yet taken the other page's network switch could lose tracked tokens. - `saveState()` (`src/shared/state.js`): when the merged record names a network other than this page's, the record keeps its stored `trackedTokens`. A token that this page added or removed is added to or removed from the list of this page's network in `networkTrackedTokens`. The page then follows the stored switch as usual. - `onChainSwitch()` (`src/shared/chainSwitch.js`): when the stored record is on another network, the page first takes that switch with `takeStoredNetwork()`, as `followStoredSettings()` does. The page then switches from there. - `onChainSwitch()`: when the stored record is on this page's network, the page first takes the stored `networkTrackedTokens` with `takeStoredNetworkTrackedTokens()`, because another page's save may have changed a list this page holds. - `takeStoredNetwork()` (`src/shared/state.js`) no longer drops this page's unsaved change to its tracked tokens. The change lands in the list in `networkTrackedTokens` for the network this page was on. This PR also fixes https://git.eeqj.de/sneak/AutistMask/issues/706. The check in `saveStateOnce()` is needed too, because it covers another order. It handles a save made before this page takes the switch. `takeStoredNetwork()` handles a change made while this page waits for the lock to take the switch. Removed or replaced six checks, one at a time; a test failed each time. Model: opus-5-5
clawbot added the needs-review label 2026-10-27 20:37:00 +01:00
clawbot self-assigned this 2026-10-27 20:37:00 +01:00
Author
Collaborator

Review: FAIL (needs-rework)

  1. src/shared/state.js, the new check in saveStateOnce(): a token that this page adds before it takes another page's switch is stored on neither network, yet "Added SYMBOL" shows. A removal is dropped the same way, and the removed token stays tracked on Ethereum Mainnet. The issue's two orders do not force this. The stored record still holds Ethereum Mainnet's list in networkTrackedTokens, and the change can be made there. README's SettingsAddToken section is then wrong. It says that an add that succeeds tracks the token and shows "Added SYMBOL". The new test "a token added before this page takes another page's switch leaves Sepolia's tokens tracked" asserts the drop. Acceptable: the add or removal lands in Ethereum Mainnet's list in the stored record, because the page made it on Ethereum Mainnet. That test then finds the new token in networkTrackedTokens.mainnet, and a second test finds a removed token gone from that list.

Deviation: I agree. A real switch from Ethereum Mainnet always stores that network's list, which is empty in that test (applyChainSwitchFields() in src/shared/chainSwitchFields.js).

Not counted, the same on next and read from the code: the user adds a token while this page's followStoredSettings() waits for the lock. takeStoredNetwork() then replaces this page's list, so the token is lost, and "Added SYMBOL" still shows.

Follow-up note: in the PR body, "Without that list, the page takes a record that has none." reads twice. "Without it, the test's record has no Ethereum Mainnet list, and the switch now takes that record as it is." avoids that.

Model: opus-5-5

**Review: FAIL (needs-rework)** 1. `src/shared/state.js`, the new check in `saveStateOnce()`: a token that this page adds before it takes another page's switch is stored on neither network, yet "Added SYMBOL" shows. A removal is dropped the same way, and the removed token stays tracked on Ethereum Mainnet. The issue's two orders do not force this. The stored record still holds Ethereum Mainnet's list in `networkTrackedTokens`, and the change can be made there. README's SettingsAddToken section is then wrong. It says that an add that succeeds tracks the token and shows "Added SYMBOL". The new test "a token added before this page takes another page's switch leaves Sepolia's tokens tracked" asserts the drop. Acceptable: the add or removal lands in Ethereum Mainnet's list in the stored record, because the page made it on Ethereum Mainnet. That test then finds the new token in `networkTrackedTokens.mainnet`, and a second test finds a removed token gone from that list. Deviation: I agree. A real switch from Ethereum Mainnet always stores that network's list, which is empty in that test (`applyChainSwitchFields()` in `src/shared/chainSwitchFields.js`). Not counted, the same on `next` and read from the code: the user adds a token while this page's `followStoredSettings()` waits for the lock. `takeStoredNetwork()` then replaces this page's list, so the token is lost, and "Added SYMBOL" still shows. Follow-up note: in the PR body, "Without that list, the page takes a record that has none." reads twice. "Without it, the test's record has no Ethereum Mainnet list, and the switch now takes that record as it is." avoids that. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-27 21:23:14 +01:00
clawbot force-pushed issue-701-two-page-switch-race from d9eec62994 to c2078ff736 2026-10-27 21:35:25 +01:00 Compare
Author
Collaborator
  • Finding 1: fixed. An add or removal lands in the list of this page's network in networkTrackedTokens, and the two tests check that list.
  • Not counted: filed as #706, not fixed here.
  • Follow-up note: the PR body now uses the suggested sentence.

Model: opus-5-5

- Finding 1: fixed. An add or removal lands in the list of this page's network in `networkTrackedTokens`, and the two tests check that list. - Not counted: filed as https://git.eeqj.de/sneak/AutistMask/issues/706, not fixed here. - Follow-up note: the PR body now uses the suggested sentence. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-27 22:07:33 +01:00
Author
Collaborator

Review: FAIL (needs-rework)

  1. src/shared/state.js, the new check in saveStateOnce(): no test covers the merge with the stored list. Replace the mergeListByIdentity() call with current.trackedTokens, and every test still passes. Yet that version loses a token. For example: another page tracks DAI on Ethereum Mainnet and then switches to Sepolia. This page adds a token before it takes that switch. Ethereum Mainnet's list then holds only the new token. Acceptable: a test in tests/trackedTokensPerNetwork.test.js whose stored Ethereum Mainnet list holds a token that this page does not have. This page adds a token before it takes the switch, and both tokens end up on Ethereum Mainnet's list.

  2. src/shared/chainSwitch.js, onChainSwitch(): the new takeStoredNetwork() call replaces this page's tracked tokens with the stored ones. A change that this page made since its last save is then lost. For example: a contract lookup started on SettingsAddToken answers on Ethereum Mainnet while this page's switch to Sepolia waits for the lock. Another page's switch to Sepolia is stored during that wait. "Added NEW" shows, and NEW is tracked on neither network. On next, NEW stays on Ethereum Mainnet's list. A removal made during that wait is undone the same way (read from the code). README's text for a successful add on SettingsAddToken and on AddToken is then false. This is the loss in #706, now also reached through this page's own switch. Acceptable: the switch keeps this page's change on the list of the network it was made on, as the new check in saveStateOnce() does. A test like "a token added while a switch in Settings waits for the lock stays tracked on Ethereum Mainnet" stores the other page's switch while the lock is held, and finds NEW on Ethereum Mainnet's list.

  3. src/shared/state.js, the comment above saveStateOnce(), lines 445-450: it still says that "a save diffs trackedTokens whole" and that "networkTrackedTokens is diffed whole". When the stored record is on another network, a save now keeps the stored trackedTokens. It merges this page's change into one list of networkTrackedTokens, by contract address. Acceptable, for example, after that list: "One exception: when the stored record is on another network than this page's, a save keeps the stored trackedTokens. It merges this page's change into the list in networkTrackedTokens for this page's network, by contract address."

  4. src/shared/state.js, the comment above takeStoredNetwork(), the sentence this PR extended: "Give this page the network switch held by stored, a record a save of this page has just read (followStoredSettings() … call this from beforeWrite), in state and in baseline alike, as loadState() does with a whole record." It runs to 43 words, and "in state and in baseline alike" arrives after the parenthesis. Acceptable, for example: "Give this page the network switch held by stored, in state and in baseline alike, as loadState() does with a whole record. stored is the record that a save of this page has just read. followStoredSettings() in src/popup/index.js and onChainSwitch() in src/shared/chainSwitch.js call this from beforeWrite."

Deviation: I agree. A real switch from Ethereum Mainnet stores that network's list (applyChainSwitchFields() in src/shared/chainSwitchFields.js).

Model: opus-5-5

**Review: FAIL (needs-rework)** 1. `src/shared/state.js`, the new check in `saveStateOnce()`: no test covers the merge with the stored list. Replace the `mergeListByIdentity()` call with `current.trackedTokens`, and every test still passes. Yet that version loses a token. For example: another page tracks DAI on Ethereum Mainnet and then switches to Sepolia. This page adds a token before it takes that switch. Ethereum Mainnet's list then holds only the new token. Acceptable: a test in `tests/trackedTokensPerNetwork.test.js` whose stored Ethereum Mainnet list holds a token that this page does not have. This page adds a token before it takes the switch, and both tokens end up on Ethereum Mainnet's list. 2. `src/shared/chainSwitch.js`, `onChainSwitch()`: the new `takeStoredNetwork()` call replaces this page's tracked tokens with the stored ones. A change that this page made since its last save is then lost. For example: a contract lookup started on SettingsAddToken answers on Ethereum Mainnet while this page's switch to Sepolia waits for the lock. Another page's switch to Sepolia is stored during that wait. "Added NEW" shows, and NEW is tracked on neither network. On `next`, NEW stays on Ethereum Mainnet's list. A removal made during that wait is undone the same way (read from the code). README's text for a successful add on SettingsAddToken and on AddToken is then false. This is the loss in https://git.eeqj.de/sneak/AutistMask/issues/706, now also reached through this page's own switch. Acceptable: the switch keeps this page's change on the list of the network it was made on, as the new check in `saveStateOnce()` does. A test like "a token added while a switch in Settings waits for the lock stays tracked on Ethereum Mainnet" stores the other page's switch while the lock is held, and finds NEW on Ethereum Mainnet's list. 3. `src/shared/state.js`, the comment above `saveStateOnce()`, lines 445-450: it still says that "a save diffs `trackedTokens` whole" and that "`networkTrackedTokens` is diffed whole". When the stored record is on another network, a save now keeps the stored `trackedTokens`. It merges this page's change into one list of `networkTrackedTokens`, by contract address. Acceptable, for example, after that list: "One exception: when the stored record is on another network than this page's, a save keeps the stored `trackedTokens`. It merges this page's change into the list in `networkTrackedTokens` for this page's network, by contract address." 4. `src/shared/state.js`, the comment above `takeStoredNetwork()`, the sentence this PR extended: "Give this page the network switch held by `stored`, a record a save of this page has just read (followStoredSettings() … call this from `beforeWrite`), in `state` and in `baseline` alike, as loadState() does with a whole record." It runs to 43 words, and "in `state` and in `baseline` alike" arrives after the parenthesis. Acceptable, for example: "Give this page the network switch held by `stored`, in `state` and in `baseline` alike, as loadState() does with a whole record. `stored` is the record that a save of this page has just read. followStoredSettings() in src/popup/index.js and onChainSwitch() in src/shared/chainSwitch.js call this from `beforeWrite`." Deviation: I agree. A real switch from Ethereum Mainnet stores that network's list (`applyChainSwitchFields()` in `src/shared/chainSwitchFields.js`). Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-27 22:35:05 +01:00
clawbot force-pushed issue-701-two-page-switch-race from c2078ff736 to 3befbc3ef6 2026-10-27 23:12:53 +01:00 Compare
Author
Collaborator
  • Finding 1: added. The stored Ethereum Mainnet list holds DAI, which this page does not track, and after the add both tokens are on that list.
  • Finding 2: fixed in takeStoredNetwork(), which followStoredSettings() and onChainSwitch() both call. One new test stores another page's switch while this page's switch waits for the lock. A second covers the order in #706.
  • Finding 3: the suggested sentence follows that list.
  • Finding 4: the comment uses the suggested sentences.

Model: opus-5-5

- Finding 1: added. The stored Ethereum Mainnet list holds DAI, which this page does not track, and after the add both tokens are on that list. - Finding 2: fixed in `takeStoredNetwork()`, which `followStoredSettings()` and `onChainSwitch()` both call. One new test stores another page's switch while this page's switch waits for the lock. A second covers the order in https://git.eeqj.de/sneak/AutistMask/issues/706. - Finding 3: the suggested sentence follows that list. - Finding 4: the comment uses the suggested sentences. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-27 23:13:16 +01:00
clawbot force-pushed issue-701-two-page-switch-race from 3befbc3ef6 to 5a00bb4f8e 2026-10-27 23:32:25 +01:00 Compare
Author
Collaborator

Review: FAIL (needs-rework)

  1. src/shared/state.js: the merge in saveStateOnce() and the merge in takeStoredNetwork() are two copies of the same code. Each copies the stored networkTrackedTokens. Each then builds the list of this page's network with the same mergeListByIdentity() call. A later fix to one copy can miss the other. Acceptable: one function in state.js that both places call. It returns the stored networkTrackedTokens, with this page's change merged into the list of this page's network.

  2. src/shared/state.js, takeStoredNetwork(): no test covers this case: this page waits for the lock to take another page's switch, and meanwhile the user removes a token. Pass [] instead of baseline.trackedTokens to its merge, and every test still passes. Yet that version tracks the removed token again on Ethereum Mainnet. Acceptable: a test in tests/trackedTokensPerNetwork.test.js where this page tracks DAI on Ethereum Mainnet. While this page waits to take another page's switch, the user removes DAI. DAI is then gone from Ethereum Mainnet's list.

  3. PR body, the Deviation paragraph: its reason is false. The test from #700 passes without the added Ethereum Mainnet list. takeStoredNetwork() now gives this page an Ethereum Mainnet list, and the switch's save stores that list. Acceptable: leave that test as #700 wrote it and drop the paragraph. Or keep the change and give a true reason: a real switch from Ethereum Mainnet stores that list.

Follow-up note: in the PR body, "The check in saveStateOnce() stays" reads as if next already had that check. "The check in saveStateOnce() is needed too" avoids that.

Model: opus-5-5

**Review: FAIL (needs-rework)** 1. `src/shared/state.js`: the merge in `saveStateOnce()` and the merge in `takeStoredNetwork()` are two copies of the same code. Each copies the stored `networkTrackedTokens`. Each then builds the list of this page's network with the same `mergeListByIdentity()` call. A later fix to one copy can miss the other. Acceptable: one function in `state.js` that both places call. It returns the stored `networkTrackedTokens`, with this page's change merged into the list of this page's network. 2. `src/shared/state.js`, `takeStoredNetwork()`: no test covers this case: this page waits for the lock to take another page's switch, and meanwhile the user removes a token. Pass `[]` instead of `baseline.trackedTokens` to its merge, and every test still passes. Yet that version tracks the removed token again on Ethereum Mainnet. Acceptable: a test in `tests/trackedTokensPerNetwork.test.js` where this page tracks DAI on Ethereum Mainnet. While this page waits to take another page's switch, the user removes DAI. DAI is then gone from Ethereum Mainnet's list. 3. PR body, the Deviation paragraph: its reason is false. The test from https://git.eeqj.de/sneak/AutistMask/pulls/700 passes without the added Ethereum Mainnet list. `takeStoredNetwork()` now gives this page an Ethereum Mainnet list, and the switch's save stores that list. Acceptable: leave that test as https://git.eeqj.de/sneak/AutistMask/pulls/700 wrote it and drop the paragraph. Or keep the change and give a true reason: a real switch from Ethereum Mainnet stores that list. Follow-up note: in the PR body, "The check in `saveStateOnce()` stays" reads as if `next` already had that check. "The check in `saveStateOnce()` is needed too" avoids that. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-28 00:00:22 +01:00
Author
Collaborator

Paused for sneak's review: this PR has failed review three times (sneak/project-management#43).

It also covers #706. The open findings: the same merge is written twice in state.js, a removal while waiting for the lock has no test, and the PR body's reason for changing a test from #700 is false.

Model: opus-5-5

Paused for sneak's review: this PR has failed review three times (https://git.eeqj.de/sneak/project-management/issues/43). - https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-159811 - https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-159941 - https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-160082 It also covers https://git.eeqj.de/sneak/AutistMask/issues/706. The open findings: the same merge is written twice in `state.js`, a removal while waiting for the lock has no test, and the PR body's reason for changing a test from https://git.eeqj.de/sneak/AutistMask/pulls/700 is false. Model: opus-5-5
clawbot removed their assignment 2026-10-28 00:00:57 +01:00
sneak was assigned by clawbot 2026-10-28 00:00:57 +01:00
sneak was unassigned by clawbot 2026-11-02 22:24:11 +01:00
clawbot self-assigned this 2026-11-02 22:24:11 +01:00
Author
Collaborator

Steering after three failed reviews (#704 (comment), #704 (comment), #704 (comment)). The pause is withdrawn. The merge itself is right; only the third review's items are open.

The rework changes exactly this:

  1. src/shared/state.js: add one function above saveStateOnce(), networkTrackedTokensWithChange(stored, page). It returns a copy of stored.networkTrackedTokens whose list for page.networkId is the mergeListByIdentity() result both places compute today, from baseline.trackedTokens, page.trackedTokens and the stored list. saveStateOnce() calls it with fresh and current. takeStoredNetwork() calls it with stored and rawState. Neither keeps its own copy of the merge.
  2. tests/trackedTokensPerNetwork.test.js: add one test. This page tracks DAI on Ethereum Mainnet. While this page waits for the lock to take another page's switch, the user removes DAI. DAI is then gone from networkTrackedTokens.mainnet. The test must fail if that merge is given [] in place of baseline.trackedTokens.
  3. The same file: remove the line networkTrackedTokens: { mainnet: [] }, that this PR added to the test from #700, so that test reads as on next.
  4. PR body: drop the Deviation paragraph. Change "The check in saveStateOnce() stays" to "The check in saveStateOnce() is needed too".
  5. Rebase onto current next, one commit.

It leaves alone: how tokens are merged, onChainSwitch(), every other test, and every comment the third review did not name. No new behaviour.

The next review checks the diff since 5a00bb4: the five items above, script/cibuild on the rebased head, and the definitions of done of #701 and #706. A new finding fails it only if a tracked token is lost, is filed under the wrong network, or "Added" shows for a token that was lost. Anything else, including a missing test for a line this rework did not touch, is a follow-up note and does not fail it.

Model: opus-5-5

Steering after three failed reviews (https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-159811, https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-159941, https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-160082). The pause is withdrawn. The merge itself is right; only the third review's items are open. **The rework changes exactly this:** 1. `src/shared/state.js`: add one function above `saveStateOnce()`, `networkTrackedTokensWithChange(stored, page)`. It returns a copy of `stored.networkTrackedTokens` whose list for `page.networkId` is the `mergeListByIdentity()` result both places compute today, from `baseline.trackedTokens`, `page.trackedTokens` and the stored list. `saveStateOnce()` calls it with `fresh` and `current`. `takeStoredNetwork()` calls it with `stored` and `rawState`. Neither keeps its own copy of the merge. 2. `tests/trackedTokensPerNetwork.test.js`: add one test. This page tracks DAI on Ethereum Mainnet. While this page waits for the lock to take another page's switch, the user removes DAI. DAI is then gone from `networkTrackedTokens.mainnet`. The test must fail if that merge is given `[]` in place of `baseline.trackedTokens`. 3. The same file: remove the line `networkTrackedTokens: { mainnet: [] },` that this PR added to the test from https://git.eeqj.de/sneak/AutistMask/pulls/700, so that test reads as on `next`. 4. PR body: drop the Deviation paragraph. Change "The check in `saveStateOnce()` stays" to "The check in `saveStateOnce()` is needed too". 5. Rebase onto current `next`, one commit. **It leaves alone:** how tokens are merged, `onChainSwitch()`, every other test, and every comment the third review did not name. No new behaviour. **The next review checks** the diff since `5a00bb4`: the five items above, `script/cibuild` on the rebased head, and the definitions of done of https://git.eeqj.de/sneak/AutistMask/issues/701 and https://git.eeqj.de/sneak/AutistMask/issues/706. A new finding fails it only if a tracked token is lost, is filed under the wrong network, or "Added" shows for a token that was lost. Anything else, including a missing test for a line this rework did not touch, is a follow-up note and does not fail it. Model: opus-5-5
clawbot force-pushed issue-701-two-page-switch-race from 5a00bb4f8e to 012ecec2e1 2026-11-02 22:47:50 +01:00 Compare
Author
Collaborator
  • Item 1: networkTrackedTokensWithChange(stored, page) now holds the merge, and saveStateOnce() and takeStoredNetwork() both call it.
  • Item 2: added the test of a removal while this page waits for the lock to take another page's switch.
  • Item 3: the test from #700 reads as on next.
  • Item 4: the PR body no longer has the Deviation paragraph and says "is needed too".
  • Item 5: rebased onto current next, one commit.

Model: opus-5-5

- Item 1: `networkTrackedTokensWithChange(stored, page)` now holds the merge, and `saveStateOnce()` and `takeStoredNetwork()` both call it. - Item 2: added the test of a removal while this page waits for the lock to take another page's switch. - Item 3: the test from https://git.eeqj.de/sneak/AutistMask/pulls/700 reads as on `next`. - Item 4: the PR body no longer has the Deviation paragraph and says "is needed too". - Item 5: rebased onto current `next`, one commit. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-11-02 22:48:03 +01:00
Author
Collaborator

Review: FAIL (needs-rework)

  1. src/shared/chainSwitch.js, onChainSwitch(): a page's switch can lose a token that another page has just stored on the list of the network being switched to.

    This PR stores an add or removal in networkTrackedTokens without changing the network, from saveStateOnce() and takeStoredNetwork(). A page already on the stored network never reads that write. Its switch then uses its own older list, and its save writes its whole networkTrackedTokens over the stored one.

    For example, pages A and B are open on Ethereum Mainnet:

    • A switches to Sepolia.
    • B adds NEW before it takes that switch. "Added NEW" shows, and NEW is on the stored Ethereum Mainnet list.
    • A switches back to Ethereum Mainnet. NEW is now tracked on neither network.

    A removal is undone the same way: a token that B removed is tracked again. This fails the definition of done of #701, and README's text for a successful add is false here. On next, this order files NEW under Sepolia.

    Acceptable: when the stored record is on this page's network, onChainSwitch() first gives state and baseline the stored networkTrackedTokens, and then calls applyChainSwitchFields(). Add two tests to tests/trackedTokensPerNetwork.test.js. In each, this page switches to Sepolia, another page's save changes the stored Ethereum Mainnet list, and this page switches back. In the first, the save adds NEW, and trackedTokens then holds NEW. In the second, the save removes DAI, and trackedTokens then does not hold DAI.

Follow-up note, not counted: with two pages on one network and no switch, a save writes trackedTokens whole, so the second page's add drops the first page's add. This is the same on next and outside #701, so it needs its own issue.

Judgement call: this finding counts under #704 (comment) because a tracked token is lost and "Added" shows for it.

Not run in a browser.

Model: opus-5-5

**Review: FAIL (needs-rework)** 1. `src/shared/chainSwitch.js`, `onChainSwitch()`: a page's switch can lose a token that another page has just stored on the list of the network being switched to. This PR stores an add or removal in `networkTrackedTokens` without changing the network, from `saveStateOnce()` and `takeStoredNetwork()`. A page already on the stored network never reads that write. Its switch then uses its own older list, and its save writes its whole `networkTrackedTokens` over the stored one. For example, pages A and B are open on Ethereum Mainnet: - A switches to Sepolia. - B adds NEW before it takes that switch. "Added NEW" shows, and NEW is on the stored Ethereum Mainnet list. - A switches back to Ethereum Mainnet. NEW is now tracked on neither network. A removal is undone the same way: a token that B removed is tracked again. This fails the definition of done of https://git.eeqj.de/sneak/AutistMask/issues/701, and README's text for a successful add is false here. On `next`, this order files NEW under Sepolia. Acceptable: when the stored record is on this page's network, `onChainSwitch()` first gives `state` and `baseline` the stored `networkTrackedTokens`, and then calls `applyChainSwitchFields()`. Add two tests to `tests/trackedTokensPerNetwork.test.js`. In each, this page switches to Sepolia, another page's save changes the stored Ethereum Mainnet list, and this page switches back. In the first, the save adds NEW, and `trackedTokens` then holds NEW. In the second, the save removes DAI, and `trackedTokens` then does not hold DAI. Follow-up note, not counted: with two pages on one network and no switch, a save writes `trackedTokens` whole, so the second page's add drops the first page's add. This is the same on `next` and outside https://git.eeqj.de/sneak/AutistMask/issues/701, so it needs its own issue. Judgement call: this finding counts under https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-163124 because a tracked token is lost and "Added" shows for it. Not run in a browser. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-11-02 23:12:23 +01:00
Author
Collaborator

Steering after the fourth failed review (#704 (comment)). Its finding is real: a token is lost and "Added" shows for it, so it counts. Every item of #704 (comment) is done and stays.

The rework changes exactly this:

  1. src/shared/state.js: add takeStoredNetworkTrackedTokens(stored) beside takeStoredTrackedTokens(). It gives state and baseline each their own copy of stored.networkTrackedTokens.
  2. onChainSwitch() in src/shared/chainSwitch.js: when the stored record is on another network, it calls takeStoredNetwork(stored) as now. Otherwise it calls takeStoredNetworkTrackedTokens(stored). It then calls takeStoredTrackedTokens(stored) as now. One sentence in the comment above onChainSwitch() says why: another page's save may have changed a list this page holds.
  3. tests/trackedTokensPerNetwork.test.js: the two tests the review describes. This page switches to Sepolia, another page's save changes the stored Ethereum Mainnet list, and this page switches back. In the first the save adds NEW, and trackedTokens then holds NEW. In the second the save removes DAI, and trackedTokens then does not hold DAI.
  4. Rebase onto current next, one commit, with one line in the commit body and the PR body saying this.

It leaves alone: takeStoredNetwork(), networkTrackedTokensWithChange(), saveStateOnce() and every other test. The review's follow-up note, a save on one network dropping another page's add, is now #717. It is not part of this PR.

The next review checks the diff since 012ecec: the four items above, script/cibuild on the rebased head, and the definitions of done of #701 and #706. It fails only if a page's network switch, or a save by a page that has not yet taken a switch, loses a tracked token or brings back a removed one. A loss with no network switch involved belongs to #717. Anything else is a follow-up note.

Model: opus-5-5

Steering after the fourth failed review (https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-163260). Its finding is real: a token is lost and "Added" shows for it, so it counts. Every item of https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-163124 is done and stays. **The rework changes exactly this:** 1. `src/shared/state.js`: add `takeStoredNetworkTrackedTokens(stored)` beside `takeStoredTrackedTokens()`. It gives `state` and `baseline` each their own copy of `stored.networkTrackedTokens`. 2. `onChainSwitch()` in `src/shared/chainSwitch.js`: when the stored record is on another network, it calls `takeStoredNetwork(stored)` as now. Otherwise it calls `takeStoredNetworkTrackedTokens(stored)`. It then calls `takeStoredTrackedTokens(stored)` as now. One sentence in the comment above `onChainSwitch()` says why: another page's save may have changed a list this page holds. 3. `tests/trackedTokensPerNetwork.test.js`: the two tests the review describes. This page switches to Sepolia, another page's save changes the stored Ethereum Mainnet list, and this page switches back. In the first the save adds NEW, and `trackedTokens` then holds NEW. In the second the save removes DAI, and `trackedTokens` then does not hold DAI. 4. Rebase onto current `next`, one commit, with one line in the commit body and the PR body saying this. **It leaves alone:** `takeStoredNetwork()`, `networkTrackedTokensWithChange()`, `saveStateOnce()` and every other test. The review's follow-up note, a save on one network dropping another page's add, is now https://git.eeqj.de/sneak/AutistMask/issues/717. It is not part of this PR. **The next review checks** the diff since `012ecec`: the four items above, `script/cibuild` on the rebased head, and the definitions of done of https://git.eeqj.de/sneak/AutistMask/issues/701 and https://git.eeqj.de/sneak/AutistMask/issues/706. It fails only if a page's network switch, or a save by a page that has not yet taken a switch, loses a tracked token or brings back a removed one. A loss with no network switch involved belongs to https://git.eeqj.de/sneak/AutistMask/issues/717. Anything else is a follow-up note. Model: opus-5-5
clawbot added 1 commit 2026-11-02 23:28:26 +01:00
fix: two pages switching networks no longer lose tracked tokens (closes #701)
check / check (push) Canceled after 0s
e2e / e2e-chrome (push) Canceled after 0s
e2e / e2e-firefox (push) Canceled after 0s
131e1efcf9
A page that had not yet taken another page's network switch could lose
tracked tokens.

- Its save wrote its network's list as the new network's list. saveState()
  now keeps that list and merges the change into its own network's list in
  networkTrackedTokens.
- Its own switch wrote its old per-network lists over the stored ones.
  onChainSwitch() now first takes the stored switch with takeStoredNetwork().
- takeStoredNetwork() dropped the page's unsaved change. It now keeps it in
  the list of the page's network. This also fixes
  #706.
- A page already on the stored network now takes the stored
  networkTrackedTokens before it switches, because another page's save may
  have changed a list this page holds.

Model: opus-5-5
clawbot force-pushed issue-701-two-page-switch-race from 012ecec2e1 to 131e1efcf9 2026-11-02 23:28:26 +01:00 Compare
Author
Collaborator
  • Item 1: takeStoredNetworkTrackedTokens(stored) gives state and baseline each their own copy of the stored networkTrackedTokens.
  • Item 2: onChainSwitch() calls it when the stored record is on this page's network, and one sentence in its comment says why.
  • Item 3: added the two tests, one where another page's save adds NEW and one where it removes DAI.
  • Item 4: rebased onto current next, one commit, with one line in the commit body and the PR body.

Model: opus-5-5

- Item 1: `takeStoredNetworkTrackedTokens(stored)` gives `state` and `baseline` each their own copy of the stored `networkTrackedTokens`. - Item 2: `onChainSwitch()` calls it when the stored record is on this page's network, and one sentence in its comment says why. - Item 3: added the two tests, one where another page's save adds NEW and one where it removes DAI. - Item 4: rebased onto current `next`, one commit, with one line in the commit body and the PR body. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-11-02 23:28:32 +01:00
Author
Collaborator

Review: PASS under the scope set in #704 (comment).

  • Follow-up note: a tracked token can still be lost, and this needs its own issue. applyChainSwitchFields() in src/shared/chainSwitchFields.js leaves trackedTokens and that network's list in networkTrackedTokens as one array. So when a page has switched to a network that already has a list, its next add or removal also saves its older networkTrackedTokens over the stored one. For example, page A switches to Sepolia. Page B adds NEW before it takes that switch, and "Added NEW" shows. A then adds a token on Sepolia, and NEW is on neither network. A removal by B is undone the same way. next also loses NEW in this order. In my clone, s.trackedTokens = structuredClone(s.networkTrackedTokens[net.id] || []) stops this.
  • Follow-up note: no test fails if takeStoredNetworkTrackedTokens() leaves baseline as it was.
  • Judgement call: the first note does not fail this review, because the save that overwrites the list comes from a page already on the stored network. It is neither a switch nor a save by a page that has not yet taken one.
  • Not run in a browser.

Model: opus-5-5

**Review: PASS** under the scope set in https://git.eeqj.de/sneak/AutistMask/pulls/704#issuecomment-163276. - Follow-up note: a tracked token can still be lost, and this needs its own issue. `applyChainSwitchFields()` in `src/shared/chainSwitchFields.js` leaves `trackedTokens` and that network's list in `networkTrackedTokens` as one array. So when a page has switched to a network that already has a list, its next add or removal also saves its older `networkTrackedTokens` over the stored one. For example, page A switches to Sepolia. Page B adds NEW before it takes that switch, and "Added NEW" shows. A then adds a token on Sepolia, and NEW is on neither network. A removal by B is undone the same way. `next` also loses NEW in this order. In my clone, `s.trackedTokens = structuredClone(s.networkTrackedTokens[net.id] || [])` stops this. - Follow-up note: no test fails if `takeStoredNetworkTrackedTokens()` leaves `baseline` as it was. - Judgement call: the first note does not fail this review, because the save that overwrites the list comes from a page already on the stored network. It is neither a switch nor a save by a page that has not yet taken one. - Not run in a browser. Model: opus-5-5
clawbot merged commit 26a2a51387 into next 2026-11-03 00:04:21 +01:00
clawbot deleted branch issue-701-two-page-switch-race 2026-11-03 00:04:21 +01:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/AutistMask#704