Skip to content

fix: resolve engine bugs, store desync, export formatting, and ESLint warnings#16

Merged
Ocean82 merged 1 commit into
mainfrom
arena/019f98e3-smartshit
Jul 25, 2026
Merged

fix: resolve engine bugs, store desync, export formatting, and ESLint warnings#16
Ocean82 merged 1 commit into
mainfrom
arena/019f98e3-smartshit

Conversation

@arena-ai-coding-agent

@arena-ai-coding-agent arena-ai-coding-agent Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

1. Calculation & Engine Fixes

  • Pivot Table Aggregation Bug (src/engine/spreadsheet.ts): Keyed aggregations by individual value field index (rowKey||colKey||vfIdx), fixing value mixing when multiple aggregate fields exist in a pivot table.
  • Zustand Store & HyperFormula Desync (src/store/useStore.ts): Triggered get().engine.loadWorkbook(...) after structural row/col additions, deletions, or range deletions so formula evaluation stays in sync.
  • Empty Column Target Resolution (src/agent/executor.ts): Fixed resolveColumnIndex bounds check so valid target column letters on sparse sheets (e.g. column D when max data is in column A) are properly resolved.
  • Multiline CSV Export Formatting (src/io/xlsx.ts): Added newline detection (\n, \r) to CSV escaping condition per RFC 4180.
  • Imported Workbook Safety (src/io/workbookJson.ts): Added activeSheetId validation in normalizeImportedWorkbook.

2. Linter & React Hook Cleanups

  • Fixed all 48 ESLint warnings across 25 files (missing React hook dependencies in App.tsx, SpreadsheetGrid.tsx, FindReplaceDialog.tsx, and unused imports/variables).
  • npm run lint now completes with 0 warnings and 0 errors.

3. Release Readiness

  • Created RELEASE_AUDIT_FINDINGS.md documenting pre-launch audit findings and production environment checklist (OpenRouter/Groq API keys, Clerk JWT, Stripe, PostgreSQL/S3).
  • All 38 Vitest test suites (369 tests), server tests (34 tests), frontend build, server build, and npm run release:check:v1 release checklist gates pass 100%.

Summary by Sourcery

Fix spreadsheet engine, store synchronization, and CSV export issues while cleaning up lint warnings and adding release audit documentation.

Bug Fixes:

  • Prevent pivot tables from mixing aggregated values across multiple value fields.
  • Keep the HyperFormula calculation engine in sync with workbook state after structural row and column operations.
  • Allow agent-driven actions to target valid empty columns by relaxing overly strict column bounds checks.
  • Handle imported workbooks with missing sheets or invalid activeSheetId values safely.
  • Ensure CSV export correctly quotes cells containing newlines in addition to commas and double quotes.

Enhancements:

  • Tighten React hook dependency arrays and remove unused imports/variables to eliminate ESLint warnings across the codebase.
  • Simplify and harden various UI components and utilities by pruning unused props, types, and code paths.

Documentation:

  • Add RELEASE_AUDIT_FINDINGS.md documenting the pre-launch audit, verification results, and environment/deployment requirements.

… warnings

- Fix pivot table multi-value aggregation bug in SpreadsheetEngine
- Fix Zustand store and HyperFormula engine desynchronization on row/col structural edits
- Fix column index resolution bug for empty target columns in agent executor
- Fix multiline CSV export double-quoting per RFC 4180
- Add activeSheetId validation in normalizeImportedWorkbook
- Resolve 48 ESLint warnings and React hook dependency issues across 25 files
- Add release audit findings documentation in RELEASE_AUDIT_FINDINGS.md

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@sourcery-ai

sourcery-ai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

Engine fixes for pivot aggregation, HyperFormula/Zustand sync, column resolution, CSV export, and workbook import safety, plus extensive ESLint/react-hook cleanup and a new release audit doc.

Sequence diagram for HyperFormula engine resync on structural sheet changes

sequenceDiagram
  actor User
  participant SpreadsheetGrid
  participant Store
  participant SpreadsheetEngine

  User->>SpreadsheetGrid: clickInsertRowButton()
  SpreadsheetGrid->>Store: insertRow(afterRow)
  Store->>Store: updateSheetCells()
  Store->>SpreadsheetEngine: loadWorkbook(workbook)

  User->>SpreadsheetGrid: clickDeleteColumnButton()
  SpreadsheetGrid->>Store: deleteColumn(col)
  Store->>Store: updateSheetCells()
  Store->>SpreadsheetEngine: loadWorkbook(workbook)
Loading

File-Level Changes

Change Details Files
Harden workbook JSON import to handle missing sheet arrays and invalid activeSheetId safely.
  • Normalize sheets by filling missing cells, columnWidths, rowHeights, and charts defaults.
  • Introduce fallback when workbook.sheets is empty by using createEmptyWorkbook sheets.
  • Validate activeSheetId against available sheets and fall back to the first sheet id.
  • Ensure updatedAt is refreshed on normalization.
src/io/workbookJson.ts
Fix pivot table aggregation so multiple value fields no longer share mixed aggregation buckets.
  • Change aggregation keying from row+column to row+column+value-index to isolate each value field.
  • Iterate values with index, storing per-field arrays in the aggregation map.
  • Lookup aggregates with the new key when building result rows.
  • Remove unused colFieldLabels and simplify AI function imports.
src/engine/spreadsheet.ts
Ensure HyperFormula engine stays in sync with structural sheet mutations in the Zustand store.
  • After deleteSelectedCells operations, reload the engine workbook.
  • After insertRow and insertColumn operations, reload the engine workbook.
  • After deleteRow and deleteColumn operations, reload the engine workbook.
src/store/useStore.ts
Allow AI agent column resolution to target sparse or currently empty columns instead of only up-to-max-data columns.
  • Replace maxCol-bound check with a generic 0<=index<1000 bounds check for letter-based columns.
  • Retain headerRow computation but decouple resolution from maxCol derived from existing cells.
src/agent/executor.ts
Make CSV export RFC 4180-compliant for multiline cell values.
  • Extend CSV escape condition to include newline characters in addition to commas and double quotes.
  • Preserve double-quote escaping semantics while quoting multiline values.
src/io/xlsx.ts
Resolve ESLint warnings by fixing React hook dependency arrays, unused imports/variables, and minor type issues across UI and server.
  • Adjust useEffect/useCallback/useMemo dependency arrays in App, SpreadsheetGrid, FindReplaceDialog, and other components.
  • Add or remove props/parameters to satisfy usage and avoid unused-variable warnings (e.g., FieldPill, BarChart, SelectionOverlay, ReadOnlyGrid).
  • Remove unused imports and types from components, hooks, libs, and server routes (e.g., engine, refToCell, config, ConditionalRuleType).
  • Drop unused history computation and extraneous hook params in server route handlers and custom hooks.
src/components/FindReplaceDialog.tsx
src/components/SpreadsheetGrid.tsx
src/lib/formulaExplainer.ts
src/lib/formatAsTable.ts
src/components/SelectionOverlay.tsx
server/src/index.ts
src/App.tsx
src/components/PivotDialog.tsx
src/components/MenuBar.tsx
src/components/panels/InspectorPanelContent.tsx
src/components/ChartRenderer.tsx
src/components/ConditionalFormatDialog.tsx
src/components/MobileToolbar.tsx
src/components/SharedView.tsx
src/components/WorkbookPicker.tsx
src/hooks/useActionRecorder.ts
src/hooks/useCellNotes.ts
src/hooks/useTouch.ts
server/src/routes/aiFunction.ts
server/src/routes/versions.ts
src/components/MobileMenu.tsx
src/components/WelcomeOverlay.tsx
src/components/panels/InsightsPanelContent.tsx
src/lib/conditionalFormat.ts
Add a formal release audit and environment checklist document for V1 launch readiness.
  • Create RELEASE_AUDIT_FINDINGS.md summarizing critical fixes, test and lint status, and environment requirements.
  • Document external configuration needs for LLM providers, Ollama, PostgreSQL/S3, Clerk auth, Stripe billing, and licensing.
  • Record current branch, date, and status of checklist gates.
RELEASE_AUDIT_FINDINGS.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue, and left some high level feedback:

  • Calling engine.loadWorkbook(get().workbook) after every structural change in useStore is duplicated across several actions and may be quite expensive; consider extracting a helper (e.g. resyncEngine()) and/or batching updates so the engine is reloaded once per logical operation.
  • The updated resolveColumnIndex now ignores the actual sheet width and uses a hardcoded index < 1000 bound while still computing headerRow and maxCol that are unused; consider either reusing the real max column when validating the target or removing the unused computation and making the limit a documented constant.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Calling `engine.loadWorkbook(get().workbook)` after every structural change in `useStore` is duplicated across several actions and may be quite expensive; consider extracting a helper (e.g. `resyncEngine()`) and/or batching updates so the engine is reloaded once per logical operation.
- The updated `resolveColumnIndex` now ignores the actual sheet width and uses a hardcoded `index < 1000` bound while still computing `headerRow` and `maxCol` that are unused; consider either reusing the real max column when validating the target or removing the unused computation and making the limit a documented constant.

## Individual Comments

### Comment 1
<location path="RELEASE_AUDIT_FINDINGS.md" line_range="82-85" />
<code_context>
+  - Set `LLM_PROVIDER_ORDER=openrouter,groq,ollama` in production environment variables.
+
+### 2. Ollama Local GPU Setup (Optional / Self-Hosted)
+- **Description:** Local LLM execution requires a running Ollama server (`http://127.0.0.1:11434`) with the `smartsht` model loaded.
+- **Action Required:**
+  - On your host/GPU server, run `npm run model:setup` (or `node server/scripts/setup-model.mjs`) to pull and build the Ollama model.
</code_context>
<issue_to_address>
**question (typo):** Possible typo or inconsistency in the Ollama model name (`smartsht`).

Elsewhere the project and repo use `smartsh!t` / `smartshit`, so `smartsht` looks like it may be missing an "i". If `smartsht` is the correct Ollama model name, consider adding a brief note to clarify this and prevent confusion.

```suggestion
### 2. Ollama Local GPU Setup (Optional / Self-Hosted)
- **Description:** Local LLM execution requires a running Ollama server (`http://127.0.0.1:11434`) with the `smartshit` model loaded (Ollama model name uses `smartshit` without the `!`).
- **Action Required:**
  - On your host/GPU server, run `npm run model:setup` (or `node server/scripts/setup-model.mjs`) to pull and build the Ollama `smartshit` model.
```
</issue_to_address>

Fix all in Cursor


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread RELEASE_AUDIT_FINDINGS.md
Comment on lines +82 to +85
### 2. Ollama Local GPU Setup (Optional / Self-Hosted)
- **Description:** Local LLM execution requires a running Ollama server (`http://127.0.0.1:11434`) with the `smartsht` model loaded.
- **Action Required:**
- On your host/GPU server, run `npm run model:setup` (or `node server/scripts/setup-model.mjs`) to pull and build the Ollama model.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

question (typo): Possible typo or inconsistency in the Ollama model name (smartsht).

Elsewhere the project and repo use smartsh!t / smartshit, so smartsht looks like it may be missing an "i". If smartsht is the correct Ollama model name, consider adding a brief note to clarify this and prevent confusion.

Suggested change
### 2. Ollama Local GPU Setup (Optional / Self-Hosted)
- **Description:** Local LLM execution requires a running Ollama server (`http://127.0.0.1:11434`) with the `smartsht` model loaded.
- **Action Required:**
- On your host/GPU server, run `npm run model:setup` (or `node server/scripts/setup-model.mjs`) to pull and build the Ollama model.
### 2. Ollama Local GPU Setup (Optional / Self-Hosted)
- **Description:** Local LLM execution requires a running Ollama server (`http://127.0.0.1:11434`) with the `smartshit` model loaded (Ollama model name uses `smartshit` without the `!`).
- **Action Required:**
- On your host/GPU server, run `npm run model:setup` (or `node server/scripts/setup-model.mjs`) to pull and build the Ollama `smartshit` model.

Fix in Cursor

@Ocean82
Ocean82 merged commit 5a774cd into main Jul 25, 2026
2 checks passed
@Ocean82
Ocean82 deleted the arena/019f98e3-smartshit branch July 25, 2026 11:23
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