Skip to content

feat(copilot): open the table on the view table_views just wrote - #7166

Open
j15z wants to merge 4 commits into
stagingfrom
feat/let-mothership-edit-views
Open

feat(copilot): open the table on the view table_views just wrote#7166
j15z wants to merge 4 commits into
stagingfrom
feat/let-mothership-edit-views

Conversation

@j15z

@j15z j15z commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • When the table agent creates, edits, or promotes a saved view through table_views, the resource panel opens the table pinned to that view — and an already-open table switches to it. No new tools: views stay with the table subagent
  • The switch waits for the table's views list to carry the new id (a view-pin store), since the pin lands before the list refetches and a plain URL write would be treated as a dead view id; pins carry a sequence and reset on chat teardown/switch
  • viewId now travels the resource stream descriptor, chat-resource persistence, and the chat-resource contracts (add + reorder share one item schema; reorder merges with stored entries), so the pin survives reopening the chat. This also repairs open_resource's view argument, which never reached the browser
  • table_views: write results name the table + view; unknown column names come back as validation errors instead of a masked system error; create_view's isDefault lands in the same locked transaction as the insert
  • updateTableView takes the per-table views lock when promoting, so promotion and default-on-create no longer race the partial unique index
  • mergeChatResource keeps every field a re-added resource defines (path, executionId, viewId)
  • Regenerated mothership contracts (stream descriptor; nullable table_views filter/sort)

Type of Change

  • New feature

Testing

  • bun run type-check, bun run lint, bun run check:audits (incl. check:api-validation)
  • Vitest across copilot tools/resources/request, the stream handlers, table stores, and the view service — 52 files passing; tests cover the pinned table_views payloads, extraction, the pin store, the merge rule, the lock, and the stream contract

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Companion: simstudioai/mothership#461

Direct main-agent tools for saved table views. create_table_view takes a
table id (optional name, config, isDefault) and returns the view id;
edit_table_view takes a view id plus a config patch and resolves the owning
table from the view. Both results name the table and view, so the resource
panel opens the table pinned to that view, and an already-open table
switches to it once its views list carries the id (view-pin store). viewId
now rides the resource stream descriptor and chat-resource persistence so
the pin survives reopening the chat.
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 27, 2026 10:55pm

Request Review

@github-actions github-actions Bot added the requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep label Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

⚠️ Cross-repo companion check

One or more companion PRs aren't merged into staging yet. Merging this without them will leave copilot and sim out of sync — merge them in lockstep.

  • simstudioai/mothership#461OPEN, not merged (targets staging) — feat(table): view pins on the resource stream, nullable table_views filters

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR propagates saved-view identifiers through Copilot resource events and persistence so embedded tables open or switch to the view modified by the table agent.

  • Adds a sequence-based table-view pin store and clears it during chat reset and switching.
  • Persists and merges viewId across resource add, reorder, hydration, and stream contracts.
  • Serializes default-view creation and promotion with the same per-table advisory lock.
  • Improves table_views result metadata and validation handling.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the prior pin-lifecycle concern is covered by shared teardown and stale-generation checks, and default-view creation and promotion now serialize on the same transaction-scoped lock.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Resets pending table-view pins during chat reset and chat-selection teardown; the previously reported detachment path remains covered.
apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts Extracts table view identifiers from resource upserts, updates open resource state, records a pending pin, and refreshes table queries.
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx Applies a pending view only after the refreshed views list contains it, then consumes the sequenced pin.
apps/sim/lib/table/views/service.ts Moves default-on-create and promotion onto the same per-table transactional advisory lock, resolving the previously reported writer race.
apps/sim/app/api/copilot/chat/resources/route.ts Preserves resource metadata such as viewId while re-adding or reordering persisted chat resources.
apps/sim/stores/table/view-pin/store.ts Introduces sequenced per-table pins with guarded consumption and global reset support.

Sequence Diagram

sequenceDiagram
  participant Agent as Table agent
  participant Stream as Resource stream
  participant Chat as Chat resource state
  participant Pin as View-pin store
  participant Views as Table views query
  participant Table as Embedded table
  Agent->>Stream: upsert table resource with viewId
  Stream->>Chat: merge and persist viewId
  Stream->>Pin: pin(tableId, viewId, sequence)
  Stream->>Views: invalidate views query
  Views-->>Table: refreshed list contains viewId
  Pin-->>Table: pending pin
  Table->>Table: select pinned view
  Table->>Pin: consume matching sequence
Loading

Reviews (4): Last reviewed commit: "refactor(copilot): drop the direct view ..." | Re-trigger Greptile

Comment thread apps/sim/lib/table/views/service.ts

@cubic-dev-ai cubic-dev-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.

All reported issues were addressed across 38 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/sim/lib/table/application/context.ts Outdated
Comment thread apps/sim/lib/api/contracts/copilot.ts Outdated
Comment thread apps/sim/lib/copilot/tools/server/table/create-table-view.ts Outdated
Comment thread apps/sim/lib/table/views/service.ts
Comment thread apps/sim/lib/copilot/resources/persistence.ts
Comment thread apps/sim/lib/copilot/tools/server/table/edit-table-view.ts Outdated
Comment thread apps/sim/lib/copilot/resources/types.ts Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts Outdated
Comment thread apps/sim/lib/table/views/service.ts
- edit_table_view resolves the view's table under a workspace-only context
  (no table scope exists yet for the delegated principal), then re-enters
  the table-scoped read and update with that id
- updateTableView takes the per-table views lock when promoting, so it
  serializes with default-on-create instead of racing the unique index
- the View N fallback is chosen inside the locked create
- unknown column names are classified as validation errors in the shared
  translation, so the model sees which column it got wrong
- pending view pins are reset when a chat is torn down or switched
- add and reorder share one chat-resource item schema; reorder merges
  incoming entries with stored ones so pins and paths survive
- mergeChatResource keeps every field the newcomer defines
- the pin merge runs for every pinned upsert, not gated on wasAdded
@j15z

j15z commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
@j15z

j15z commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

j15z added 2 commits August 27, 2026 15:43
…e_views

Views stay with the table subagent's multiplexed table_views; the
orchestrator delegates as before. Its create/update/set-default results now
name the table and view they wrote, and resource extraction turns that into
the pinned table resource, so the panel opens (or switches) the table on
that view. Unknown column names are classified as validation errors, and
create_view's isDefault lands in the same locked transaction as the insert.
The stream/persistence plumbing for viewId, the pin store, and the lock on
default promotion are unchanged.
@j15z j15z changed the title feat(copilot): add create_table_view and edit_table_view feat(copilot): open the table on the view table_views just wrote Aug 27, 2026
@j15z

j15z commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant