Skip to content

Maint/improve - #26

Merged
viseshrp merged 8 commits into
mainfrom
maint/improve
Feb 23, 2026
Merged

Maint/improve#26
viseshrp merged 8 commits into
mainfrom
maint/improve

Conversation

@viseshrp

Copy link
Copy Markdown
Owner

No description provided.

Add explicit verification barriers so tab/data mutations only happen after successful persistence or restore confirmation.

Condense changes:
- Add verifyCondenseWrite() in background condense flow.
- After appendSavedGroup(), read back the saved group and verify id/url/title parity.
- Skip chrome.tabs.remove() when verification fails, leaving source tabs open.
- Log verification failures with runtime_context for diagnosis.

Restore changes:
- Add chunk-level restore verification in restore.ts.
- Verify each restore chunk against expected URL multiplicity (supports duplicates) using created tab metadata first, then window query fallback.
- Accept pendingUrl during verification to handle immediate post-create tab state.
- Fail restoreTabs() when verification cannot confirm expected URLs.
- Keep discard scheduling logic but ensure settings-toggle abort path flushes pending discards before aborting workers.
- Remove unreachable branch guards in chunk sizing/empty-chunk logic for clarity and maintainability.

Single restore (list page):
- In restoreSingle(), verify the restored tab exists (url or pendingUrl) before removing it from saved storage.
- If verification fails, keep the saved entry and show a user-facing status.

Docs:
- Update README and architecture docs to describe the new verification guardrails for condense and restore flows.
Expand integration coverage for the new atomic behavior and verification semantics.

Background condense tests:
- Add case proving tabs remain open when persisted group verification fails.
- Add case proving duplicate-reject condense that saves zero tabs leaves source tabs open and does not duplicate saved entries.

List page action tests:
- Add restore-single case where verification fails and the tab remains in storage/list.
- Add restore-all failure case where group storage is preserved.

Restore logic tests:
- Keep fallback verification path covered by stripping tabs from create() response while still creating real windows.
- Update fallback query-failure expectation to false (cannot verify restore => fail-safe).
- Add duplicate-URL restore test to cover multiset verification logic.

These tests ensure database/list entries are only removed after restore success is actually verified, matching the atomicity requirement.
Implement URL-scheme filtering in the shared condense eligibility path so browser-internal tabs are never saved or closed during condense.\n\nWhat changed:\n- Added a centralized internal-URL prefix blocklist in shared condense helpers.\n- Updated eligibility filtering to reject internal browser surfaces while preserving existing pinned/list-tab behavior.\n- Normalized URL comparisons for list-tab matching and filtering decisions without mutating the original stored URL string.\n- Kept save-path logic aligned with eligibility filtering so persistence and filtering stay consistent if helpers are reused.\n\nWhy:\n- Users should not lose internal Chrome surfaces (for example settings/devtools/about pages) due to condense actions.\n- This keeps condense focused on user-content tabs and prevents surprising browser-UI disruption.\n\nTest coverage added:\n- Unit: explicit filtering assertions for chrome://, devtools://, and about: URLs.\n- Integration: end-to-end condense flow assertion that internal tabs remain open while eligible web tabs are condensed.
Update project documentation to reflect the new condense eligibility rule that excludes browser-internal tabs.\n\nWhat changed:\n- README: documented internal URL schemes skipped during condense.\n- spec.md: updated eligible-tab definition to explicitly exclude internal browser URLs.\n- spec.md: removed outdated non-goal that said there was no internal-tab special casing.\n- TEST_PLAN.md: updated core condense scenario wording to include internal-tab filtering.\n\nWhy:\n- Keeps behavioral docs aligned with implementation and tests.\n- Reduces ambiguity for maintainers and reviewers when validating condense behavior.
Root cause:\n- Collapse/expand state was inferred from transient DOM classes on group cards.\n- During imports, cards can be reconciled/recreated in different orders while storage-change refreshes run, so new and existing groups could end up with inconsistent collapse behavior.\n\nImplementation:\n- Added  as the explicit source of truth for per-group collapse state.\n- Added  to persist state changes and  to sync card visuals from state without triggering eager loads.\n- Updated  to write state first, then update DOM, then lazy-load only when expanded.\n- Updated index reconciliation (/) to prune stale collapse entries.\n- Updated  to derive the toggle-all state from  instead of DOM class inspection.\n- Updated first-render default collapse logic to initialize state () directly.\n- During post-initial renders, new groups now get deterministic defaults: if collapse-all is active, they start collapsed; otherwise they start expanded. Existing groups preserve their saved per-key state.\n- Updated delegated group toggle handler to use  so all collapse paths share one stateful implementation.\n\nTests:\n- Added integration coverage for append-import behavior:\n  - Existing groups keep their pre-import collapse/expand state.\n  - Newly imported groups expand when collapse-all is not active.\n  - Newly imported groups collapse when collapse-all is active.\n\nComplexity:\n- State updates remain O(1) for individual toggle operations and O(n) for full reconciliation/render passes (same asymptotic behavior as before).\n- No additional nested loops or quadratic paths were introduced.
Adds explicit import behavior documentation in the Export / Import JSON section.

Documented rules:
- Existing groups keep their current collapse/expand state after import.
- Newly imported groups inherit the current global list mode:
  - collapsed when Collapse all is active
  - expanded otherwise.

This matches the deterministic behavior implemented in list-page state management and covered by integration tests.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @viseshrp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and user experience of the extension by introducing critical safety guardrails for tab management. It ensures that tab condense and restore operations are verified for data integrity before modifying saved states, preventing data loss. Additionally, it refines the handling of browser-internal tabs during condense and improves the persistence of group collapse states on the list page, leading to more predictable and reliable behavior.

Highlights

  • Enhanced Data Integrity: Implemented strict verification steps for both condensing and restoring tabs, ensuring data is successfully written to storage before source tabs are closed or removed.
  • Improved Condense Logic: Browser-internal URLs (e.g., "chrome://", "about:") are now automatically skipped during the condense process, preventing unintended saving of non-user content.
  • Refined Restore Behavior: Single tab restores now consistently open in new windows, and all restore operations include verification to confirm tabs are successfully opened before being removed from saved lists.
  • Persistent Collapse States: The list page now correctly preserves the collapse/expand state of existing groups during import operations and applies default collapse rules to newly imported groups based on the global setting.
  • Robust Error Handling: Added explicit error handling and logging for verification failures during condense and restore, ensuring a more stable user experience.
Changelog
  • README.md
    • Added "Safety guardrails" to the feature list.
    • Updated condense description to include skipping internal URLs and verification.
    • Updated restore descriptions to include verification steps.
    • Clarified import behavior regarding group collapse states.
  • TEST_PLAN.md
    • Updated condense scenario to explicitly mention filtering internal tabs.
  • docs/architecture.md
    • Added "verify saved group by reading it back" step to condense flow.
    • Added "verify tab exists in restored window" step to single restore flow.
    • Added "verify restored chunk URLs exist in target windows" step to group restore flow.
    • Updated descriptions for single and group restore to reflect post-verification removal from storage.
  • entrypoints/background/condense.ts
    • Introduced verifyCondenseWrite function to check if a saved group can be read back correctly.
    • Integrated verifyCondenseWrite into condenseCurrentWindow to prevent closing source tabs if verification fails.
    • Imported readSavedGroup and SavedTab type.
  • entrypoints/nufftabs/index.ts
    • Removed createDiscardSession and getReuseWindowContext imports.
    • Added collapsedGroupKeys to ListPageState to manage group collapse states.
    • Updated removeIndexedGroupKey and setIndexedGroups to manage collapsedGroupKeys.
    • Refactored group collapse logic into setGroupCollapsePreference and applyGroupCollapsedDomState.
    • Modified setGroupCollapsed to use the new state management.
    • Updated syncAllGroupsCollapsedState to derive state from collapsedGroupKeys.
    • Modified applyDefaultCollapse to clear collapsedGroupKeys and add collapsed groups directly.
    • Adjusted renderGroups to handle initial collapse and new group collapse states during import.
    • Updated handleGroupAction for 'toggle-collapse' to use the new collapse state functions.
    • Revised restoreSingle to always create a new window for the restored tab and added verification logic before removing the tab from storage.
  • entrypoints/nufftabs/restore.ts
    • Removed LIST_PAGE_PATH import and getReuseWindowContext export.
    • Modified createDiscardSession to ensure cancelPendingDiscards is called before abortController.abort().
    • Added hasExpectedUrls function for multiset matching of URLs.
    • Added verifyRestoredChunk function to verify restored tabs in a window.
    • Removed getReuseWindowContext function.
    • Updated restoreTabs to use verifyRestoredChunk and throw an error if verification fails, preventing removal of saved tabs.
    • Removed redundant chunk.length === 0 check in restoreTabs.
  • entrypoints/shared/condense.ts
    • Defined INTERNAL_TAB_URL_PREFIXES for browser-internal URLs.
    • Added isCondensableTabUrl function to check if a URL is condensable.
    • Updated filterEligibleTabs to use isCondensableTabUrl and normalize list URL.
    • Updated saveTabsToList to use isCondensableTabUrl and preserve original URL string.
  • spec.md
    • Updated "Eligible tab definition" to explicitly exclude browser-internal URLs.
    • Removed the "No special casing for chrome:// or internal tabs" point from non-goals.
  • tests/e2e/extension.spec.ts
    • Updated comment for single restore test to reflect "into a new window".
    • Modified assertion for single restore to not.toBe(listWindowId).
    • Added new e2e test repeated single restores remain stable and open outside the list window.
  • tests/integration/actions.test.ts
    • Added integration test preserves existing collapse states and expands new groups on append import.
    • Added integration test keeps newly imported groups collapsed when collapse-all is active.
    • Added integration test restores a single tab into a new window.
    • Added integration test keeps a single tab in storage when restore cannot be verified.
    • Added integration test keeps a group in storage when restore-all fails.
  • tests/integration/background_condense.test.ts
    • Added integration test skips chrome internal tabs during condense.
    • Added integration test does not close source tabs when saved-group verification fails.
    • Added integration test leaves tabs open when duplicate rejection filters out all eligible tabs.
  • tests/integration/restore_logic.test.ts
    • Imported vi from vitest.
    • Added waitForPredicate utility function.
    • Updated creates new windows when reuse is not allowed test description to creates new windows for restore batches.
    • Added test restores duplicate URLs without under-counting verification matches.
    • Modified returns false when restoration fails to simulate window creation failure.
    • Removed getReuseWindowContext related tests.
    • Updated discards restored tabs when enabled but keeps the focused tab to use waitForPredicate.
    • Added test logs unexpected discard-session failures.
    • Modified uses fallback discard ids when window tabs are missing (reuse branch) to drop tabs payload for verification.
    • Modified handles fallback discard lookup failures test description to fails restore when fallback verification lookup fails and changed assertion to toBe(false).
  • tests/unit/condense_logic.test.ts
    • Updated test description filters pinned and list tab URLs to filters pinned, list tab, and browser-internal URLs.
    • Added test cases for browser-internal URLs (chrome://, devtools://, about:) to filterEligibleTabs.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov

codecov Bot commented Feb 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.05882% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.9%. Comparing base (510196b) to head (c77530d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
entrypoints/nufftabs/restore.ts 86.9% 5 Missing and 1 partial ⚠️
entrypoints/background/condense.ts 85.0% 3 Missing ⚠️
entrypoints/shared/condense.ts 89.4% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main     #26     +/-   ##
=======================================
+ Coverage   94.5%   94.9%   +0.3%     
=======================================
  Files         17      17             
  Lines       2064    2120     +56     
  Branches     529     555     +26     
=======================================
+ Hits        1952    2012     +60     
+ Misses        99      96      -3     
+ Partials      13      12      -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant improvements, primarily focused on adding safety guardrails to prevent data loss during condense and restore operations. The new verification steps are a great addition. The refactoring of the group collapse/expand logic and the filtering of internal browser URLs are also valuable enhancements. I've identified one regression where the 'save memory on restore' feature is no longer working for single-tab restores, and a minor documentation issue. Overall, this is a solid set of changes that improves the extension's reliability.

Comment thread docs/architecture.md
@viseshrp
viseshrp merged commit eb52c12 into main Feb 23, 2026
5 checks passed
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