Skip to content

fix(session): restore opened files reliably after restart#2019

Merged
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/restore-open-files-session
Apr 8, 2026
Merged

fix(session): restore opened files reliably after restart#2019
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/restore-open-files-session

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 8, 2026

Greptile Summary

This PR fixes two distinct bugs in session restoration: (1) in restoreFiles.js, rendered = file.render was overwritten on every iteration so a render:true on an early file was lost by a later render:false entry, causing the last file to always receive an extra forced render; (2) in main.js, sessionStorage.setItem("isfilesRestored", true) and processPendingIntents() were only reachable when restoreFiles succeeded — a thrown error would silently block all pending intent processing for the rest of the session. Both fixes are correct and well-targeted.

Confidence Score: 5/5

Safe to merge — both changes are correct, targeted bug fixes with no new issues introduced.

All findings are P2 or lower. The rendered ||= !!file.render change correctly fixes an accumulator overwrite bug. The finally-block restructuring correctly ensures isfilesRestored and processPendingIntents always run after restoration regardless of errors. The onEditorUpdate guard correctly prevents premature save-state calls. processPendingIntents handles its own per-intent errors internally, so moving it outside the outer try/catch is safe.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
src/lib/restoreFiles.js Replaces rendered = file.render (overwrites on each iteration) with `rendered
src/main.js Moves isfilesRestored marker to a finally block and processPendingIntents() outside the try/catch so both execute even after a partial restoration failure; adds an isfilesRestored guard in onEditorUpdate to prevent premature save-state calls during restoration.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[loadApp starts] --> B{files array present?}
    B -- No --> C[setItem isfilesRestored=true]
    C --> D[processPendingIntents]
    D --> E[onEditorUpdate false]

    B -- Yes --> F[await restoreFiles]
    F -- success --> G[finally: setItem isfilesRestored=true]
    F -- throws --> H[catch: log error + toast]
    H --> G
    G --> I[await processPendingIntents]
    I --> J[initFileList / TerminalManager restore]

    subgraph restoreFiles_loop [restoreFiles - per file]
        N[accumulate rendered flag] --> O{last file and not rendered?}
        O -- Yes --> P[force file.render = true]
        O -- No --> Q[new EditorFile]
        P --> Q
    end

    subgraph onEditorUpdate_sf [onEditorUpdate switch-file]
        K{saveState and isfilesRestored?}
        K -- Yes --> L[exec save-state]
        K -- No --> M[skip save-state]
    end
Loading

Reviews (2): Last reviewed commit: "fix" | Re-trigger Greptile

@bajrangCoder

This comment was marked as outdated.

@bajrangCoder bajrangCoder merged commit 1d027dd into Acode-Foundation:main Apr 8, 2026
7 checks passed
@bajrangCoder bajrangCoder deleted the fix/restore-open-files-session branch April 8, 2026 18:11
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