Skip to content

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

Merged
waleedlatif1 merged 20 commits into
stagingfrom
feat/let-mothership-edit-views
Sep 3, 2026
Merged

feat(copilot): open the table on the view table_views just wrote#7166
waleedlatif1 merged 20 commits into
stagingfrom
feat/let-mothership-edit-views

Conversation

@j15z

@j15z j15z commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Connect the existing table_views write operations to the resource panel so it opens on the view they affected
  • Persist the selected view with each chat resource so reopening a chat restores the same table view
  • Restore the selected view immediately when switching away from a chat and back, including when refreshed resource metadata arrives after the table mounts
  • Serialize table-view default changes and chat-resource persistence so concurrent updates cannot overwrite newer state
  • Keep table-view validation, stream descriptors, resource contracts, and generated mothership contracts aligned

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • bun run lint
  • bun run lint:check
  • bun run apps/sim/scripts/check-block-registry.ts origin/staging
  • bun run check:audits — 44 audits passing
  • Focused Vitest coverage — 7 files and 90 tests passing
  • Tested manually in Chrome by selecting a non-default table view, switching chats, and returning to confirm the selected view is restored

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)

Screenshots/Videos

Not included; this changes restored selection behavior without changing the table's visual design.

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.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 3, 2026 7:10pm UTC

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

All declared companion PRs are merged into staging.

  • simstudioai/mothership#461 — merged into 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 connects table-view tool operations to chat resources so affected views open and restore correctly, while serializing related persistence and default-view writes.

  • Persists table-resource viewId state and propagates explicit view clears through shared API contracts.
  • Hands view selections from streamed or refreshed resources to embedded tables.
  • Serializes chat-resource updates and all explicit default-view state changes.
  • Adds focused coverage for restoration, clearing, persistence, and locking behavior.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts Propagates table-view selections and clears into both resource state and the one-shot table pin store.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Coordinates chat-resource persistence and resets pending view pins during chat teardown and switching.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Restores a table-view pin when refreshed chat metadata supplies a selected view after mount.
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx Consumes valid pending pins once the embedded table and its view list are ready.
apps/sim/app/api/copilot/chat/resources/route.ts Serializes authenticated resource mutations and merges explicit view-selection clears transactionally.
apps/sim/lib/api/contracts/mothership-chats.ts Reuses the canonical Copilot resource body schema so clearViewId survives validation without contract drift.
apps/sim/lib/table/views/service.ts Routes every explicit default-state write through the shared per-table advisory lock.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Tool[table_views operation] --> Event[Resource update]
  Event --> Persist[Persist chat resource viewId]
  Event --> Pin[Pin selected table view]
  Persist --> Hydrate[Reopen or refresh chat]
  Hydrate --> Pin
  Pin --> Table[Embedded table adopts view]
Loading

Reviews (15): Last reviewed commit: "fix(copilot): hold a reorder for pending..." | 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
Contributor

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
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 Outdated
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

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@j15z I have started the AI code review. It will take a few minutes to complete.

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

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

1 issue found across 28 files

Confidence score: 3/5

  • In apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts, when the table already exists in chat, addResource(resource) returns false without issuing the POST, so this path only updates React state and reopening the chat can restore an old or missing viewId; persist the merged resource server-side.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts">

<violation number="1" location="apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts:129">
P2: When the table already exists in the chat, `addResource(resource)` returns false and performs no POST. This block only changes React state, so reopening the chat restores the old or absent `viewId`. Persist the merged resource for existing tables too.</violation>
</file>

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/copilot/resources/types.ts Outdated
Comment thread apps/sim/lib/table/views/service.ts Outdated
@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@j15z I have started the AI code review. It will take a few minutes to complete.

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

All reported issues were addressed across 37 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Re-trigger cubic

Comment thread apps/sim/lib/copilot/resources/client-persistence-queue.ts
Comment thread apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
Comment thread apps/sim/lib/copilot/resources/persistence.ts
Comment thread apps/sim/lib/api/contracts/copilot.ts Outdated
@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@j15z I have started the AI code review. It will take a few minutes to complete.

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

1 issue found across 37 files

Confidence score: 3/5

  • In apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts, the pin effect can drop a transition when the URL already contains the pin while a different local view creation is pending, leaving the pending state uncleared and the view transition unapplied; apply transition.pendingCreatedViewId before handling nextViewId.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts">

<violation number="1" location="apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts:69">
P1: When the URL already contains the pin but a different local creation is pending, the pin effect drops this transition before clearing the pending ref. Apply `transition.pendingCreatedViewId` before the `nextViewId` early return so view resolution does not remain blocked on the old creation.</violation>
</file>

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
Comment thread apps/sim/lib/copilot/resources/client-persistence-queue.ts Outdated
@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@j15z

j15z commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@j15z I have started the AI code review. It will take a few minutes to complete.

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

All reported issues were addressed across 37 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
Comment thread apps/sim/lib/copilot/resources/client-persistence-queue.test.ts
Comment thread apps/sim/lib/copilot/resources/client-persistence-queue.ts Outdated
@j15z

j15z commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@j15z

j15z commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@j15z I have started the AI code review. It will take a few minutes to complete.

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

All reported issues were addressed across 40 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx Outdated
Review follow-ups on the saved-view pinning work.

Correctness:
- Reorder persistence was parked by ANY pending write. A repeatedly failing
  update to an already-stored resource (a view pin) blocked tab ordering for
  the rest of the session; gate on unpersisted writes only, which are the
  ones the server's identity check can actually reject.
- A parked reorder body that the server rejects was re-parked verbatim, so a
  tab closed after the order was captured poisoned it permanently. Discard on
  400; keep retrying everything transient.
- adoptScope merged the provisional and chat-scoped updates in the wrong
  order, letting an older pending write overwrite a newer one.
- A view pin that arrived before the table finished its first adoption was
  dropped for good when the table data resolved after the views list. The
  stream path self-rescued through query invalidation; the restore path did
  not. Re-run the effect when adoption becomes possible.
- Reordering a chat holding a legacy duplicate row 400'd forever. Compare
  identity sets so the duplicate collapses on write instead.
- mergeChatResource aliased the caller's object into React state, the query
  cache and the pending-write queue at once. Copy it.

Robustness:
- The new copilot_chats FOR UPDATE transactions had no lock_timeout, and
  neither the pool nor the deployment sets one. finalizeAssistantTurn holds
  that same row across an assistant-message append, so a waiter could park a
  pool connection indefinitely. Bound all five writers.
- mergeChatResource's field list is now one declaration that fails to compile
  when MothershipResource gains a field, rather than silently dropping it
  from both the merge and its no-op check.
- Extraction can no longer emit viewId and clearViewId together, a pair the
  wire contract rejects and the merge would resolve to neither.
- Restrict the eager view-id URL write to embedded tables, leaving standalone
  table behaviour identical to staging.
- Drop the queue's unreachable unscoped bucket, its uncalled clear(), and its
  test-only getPendingUpdates().

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwmaLmAXSK2hsPBGZmkPnT
The reorder gate landed one case short: a delete that has not reached the
server leaves the server holding a resource the client's order omits, so the
order fails its identity check exactly as an unlanded add does. Gating only
on unpersisted adds let that order fire and be discarded as unsatisfiable,
losing the tab order until the next reorder or hydration.

Name the predicate for what it actually decides — whether a pending write
changes WHICH resources the chat holds — and cover both directions. A failing
update to an already-stored resource still does not park the order, which is
what the gate was narrowed for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwmaLmAXSK2hsPBGZmkPnT
@waleedlatif1

Copy link
Copy Markdown
Collaborator

@greptile review

@waleedlatif1
waleedlatif1 merged commit 7395a37 into staging Sep 3, 2026
28 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/let-mothership-edit-views branch September 3, 2026 19:18
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.

2 participants