Skip to content

ADFA-2977: Fix stale editor tabs persisting across projects after crash#1057

Merged
Daniel-ADFA merged 2 commits intostagefrom
ADFA-2977
Mar 10, 2026
Merged

ADFA-2977: Fix stale editor tabs persisting across projects after crash#1057
Daniel-ADFA merged 2 commits intostagefrom
ADFA-2977

Conversation

@Daniel-ADFA
Copy link
Contributor

Add projectPath to OpenedFilesCache so tab restoration is scoped to the correct project. After a crash or force stop, tabs from a previously opened project no longer appear when opening a different project.

@Daniel-ADFA Daniel-ADFA requested a review from a team March 9, 2026 19:49
@Daniel-ADFA Daniel-ADFA changed the title ADFA-2977:Fix stale editor tabs persisting across projects after crash ADFA-2977: Fix stale editor tabs persisting across projects after crash Mar 9, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Release Notes

Features

  • Project-scoped tab restoration: Added projectPath to OpenedFilesCache to prevent stale editor tabs from a previously opened project from appearing when switching to a different project
  • Automatic cache validation: Editor tabs are now validated during startup and discarded if they belong to a different project, preventing confusion after app crashes or force stops

Changes

  • Updated OpenedFilesCache data class to include a projectPath field with a default empty string value
  • Modified cache serialization/deserialization to persist and restore the project path
  • Added project path validation in the startup flow that compares cached project path against current project
  • All cache instantiations now explicitly capture the current project path via ProjectManagerImpl.getInstance().projectDirPath

Backward Compatibility

  • Old cache files without a projectPath field will load successfully due to the default empty string value
  • Legacy caches (with empty projectPath) will still be loaded, allowing graceful degradation for existing installations

Risks & Best Practices Violations

  • Insufficient test coverage: The existing test file (EditorHandlerActivityTest.kt) is minimal and lacks unit tests for the new project-scoped cache validation logic. This is a critical feature that should have dedicated test cases.
  • Path comparison fragility: Cache validation relies on string comparison of project paths, which could fail to match in edge cases such as symlinked paths, trailing slashes, or different path representations of the same project.
  • Silent cache discarding: When stale cache is detected, it is silently discarded with only a debug log message. Users will not receive any feedback about why expected tabs are not restored.

Walkthrough

The change adds project path context to the OpenedFilesCache data class to prevent tab state from being incorrectly restored across different projects. The editor activity now validates that the cached project path matches the current project on startup and discards mismatched caches.

Changes

Cohort / File(s) Summary
Cache Model
app/src/main/java/com/itsaky/androidide/models/OpenedFilesCache.kt
Added projectPath field to data class signature with default empty string value, updated JSON serialization constant KEY_PROJECT_PATH, and modified parse logic to read and construct cache with the new project path parameter.
Editor Activity
app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt
Updated cache construction to include projectPath from ProjectManagerImpl.getInstance().projectDirPath using named arguments, and added validation in onReadOpenedFilesCache to discard cache if project path differs from current project.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • hal-eisen-adfa
  • jatezzz
  • dara-abijo-adfa

Poem

🐰 A cache grows wise with project sight,
No longer lost when paths take flight,
Each tab now knows its native home,
No more shall stale files roam!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing stale editor tabs persisting across projects after a crash by adding project path scoping.
Description check ✅ Passed The description directly relates to the changeset, explaining the purpose of adding projectPath to OpenedFilesCache for project-scoped tab restoration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ADFA-2977

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt`:
- Around line 353-356: When comparing cache.projectPath to the current project,
treat blank cache paths as stale and avoid directly accessing
ProjectManagerImpl.getInstance().projectDirPath without guarding for
uninitialized state: change the condition to treat cache.projectPath.isBlank()
as stale (e.g., if (cache.projectPath.isBlank() || cache.projectPath !=
currentProjectPath) { log and return }), and wrap the retrieval of
ProjectManagerImpl.getInstance().projectDirPath in a try/catch for
UninitializedPropertyAccessException so that if the property isn't initialized
you log the exception and treat the cache as stale (clear/return) instead of
letting the exception bubble up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19e4393f-4c90-48c4-91ff-2ef8417e0b73

📥 Commits

Reviewing files that changed from the base of the PR and between 1f41fce and 379111b.

📒 Files selected for processing (2)
  • app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt
  • app/src/main/java/com/itsaky/androidide/models/OpenedFilesCache.kt

@Daniel-ADFA Daniel-ADFA merged commit bb82129 into stage Mar 10, 2026
2 checks passed
@Daniel-ADFA Daniel-ADFA deleted the ADFA-2977 branch March 10, 2026 14:33
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.

3 participants