Skip to content

Accept fileOpenerOwner and terminal target on thread tabs (#1773) - #1793

Merged
ymichael merged 2 commits into
mainfrom
bb/fix-file-opener-tab-persistence-regression-thr_dsf2ik74qf
Aug 18, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/fix-file-opener-tab-persistence-regression-thr_dsf2ik74qf

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1773. Opening a Markdown file with the Docs plugin showed Couldn't sync tabs - unrecognized code: [fileOpenerOwner]. The file opened and edits saved, but thread-tab persistence was broken for the whole thread.

Plugin file-opener tabs attach a fileOpenerOwner note recording the native preview they diverted, so the tab can restore Original. That field lived in the app's localStorage schema but was never added to the strict plugin-panel branch of threadTabSchema, so every sync carrying such a tab was rejected outright — the rejection kills the entire save, not just the offending tab, which is why everything else looked fine.

Rather than add the field to the contract and leave two schemas to keep in sync, this deletes the app's parallel definition and points it at the contract's. That duplication was the bug, so collapsing it is the part that prevents a recurrence.

The sibling gap

The terminal branch had the identical defect: nav-panel right panels record the target a terminal was opened against, but the contract's terminal branch didn't model target.

That one isn't reachable today — the plugin right-panel host that sets target passes syncThreadId: null, so those tabs stay in localStorage. But it's close: in useThreadTerminalController, fixedPanelSyncThreadId becomes non-null whenever target.kind === "thread", and hasThreadId(panelStateId) only tests for a non-empty string, which a plugin-page panel id satisfies. It's one wiring change from firing, so it's fixed here.

The target is already modelled in the contract as terminalCreateTargetSchema — and it's literally the same value the app hands to createTerminal — so the tab branch reuses it instead of adding a third copy.

Why nothing caught either one

TypeScript checks the two schemas independently and neither was wrong on its own. Excess-property checks only apply to object literals, so assigning a typed TerminalFixedPanelTab to a ThreadTab compiles cleanly while failing at runtime against a strict Zod parse. Nothing compared producer to contract — which is what the new tests do.

Tests

Both sets were verified to fail without their fix, reproducing the reported unrecognized_keys error, then pass with it.

  • packages/server-contract/test/thread-tabs.test.ts — all three fileOpenerOwner kinds and all four terminal targets; round-trip through the server's JSON storage path; negative cases (unknown keys still rejected, mismatched owner/target payloads still rejected). The negatives pass in both states, confirming they guard strictness rather than restating the fix.
  • apps/app/src/components/plugin/file-opener-tabs.test.ts — the producer→contract link: tabs from createFileOpenerTabForRequest fed to threadTabsSchema, covering all three request kinds plus the projectless-workspace variant.
  • apps/app/src/lib/fixed-panel-tabs-state.test.ts — a targeted terminal tab survives a storage round trip and stays contract-valid.

Validation

Typecheck, lint, and tests green across @bb/app (2848), @bb/server-contract (57), @bb/server (1730), @bb/templates (44). Lint: 0 errors; the 147 warnings are pre-existing and byte-identical to base.

plugin-service.test.ts > reports one anonymous plugin_installed event per user install timed out once under parallel load and passes in isolation (1547ms) — a flake in plugin-install analytics, unrelated to this change.

No HOST_DAEMON_PROTOCOL_VERSION bump: thread tabs don't appear anywhere in packages/host-daemon-contract, so nothing here crosses the daemon wire.

Generated artifacts (bb-plugin-sdk.d.ts, plugin-sdk-dts.generated.ts) were regenerated mechanically via the package build. The surrounding enum-key reordering is dts-bundler non-determinism, the same churn carried by recent main commits; the file is left unformatted to stay byte-stable with the generator.

AGENT GENERATED: by Claude Opus 5

ymichael and others added 2 commits August 18, 2026 10:55
Opening a file with a plugin file opener (e.g. the Docs Markdown editor)
attached a `fileOpenerOwner` to the `plugin-panel` tab so the tab could
restore the built-in `Original` preview. The strict `plugin-panel` branch
of `threadTabSchema` did not model that field, so every thread-tab sync
that carried such a tab failed with `unrecognized code: [fileOpenerOwner]`
and the whole tab list stopped persisting.

Model the owner once, in the contract, as `threadTabFileOpenerOwnerSchema`,
and make the app's localStorage schema and `PluginPanelFixedPanelTab` reuse
it instead of maintaining a parallel definition that could drift again.

Regenerated the committed plugin-sdk bundled types and templates artifacts
mechanically; the surrounding enum-ordering churn is dts-bundler output.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The `terminal` branch of `threadTabSchema` had the same gap the
`plugin-panel` branch just did: nav-panel right panels record the target a
terminal was opened against, but the strict contract branch did not model
`target`, so syncing such a tab would fail with `unrecognized code:
[target]` and stop the whole tab list from persisting.

TypeScript could not catch it — excess-property checks do not apply when a
typed value (rather than an object literal) is assigned, so the app's
`TerminalFixedPanelTab` passed as a `ThreadTab` without complaint.

The target is already modelled in the contract as
`terminalCreateTargetSchema`, and it is literally the same value the app
hands to `createTerminal`, so the tab branch reuses it rather than adding a
third copy. The app's parallel `terminalFixedPanelTargetSchema` and
`TerminalFixedPanelTarget` are deleted and consumers import
`TerminalCreateTarget` from the owning package directly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop. I started the security, code quality, architecture, performance, and end-to-end review.

@ymichael
ymichael merged commit 9c1d711 into main Aug 18, 2026
10 checks passed
@ymichael
ymichael deleted the bb/fix-file-opener-tab-persistence-regression-thr_dsf2ik74qf branch August 18, 2026 18:18
// Nav-panel right panels open terminals against an explicit target and
// record it here. Absent on thread/root-compose tabs, whose surface
// owns the target. Same shape the terminal was created with.
target: terminalCreateTargetSchema.optional(),

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.

🚨 slopcop/review — A restored thread-targeted terminal can connect a plugin page tab deck to the wrong thread.

useThreadTerminalController derives tab sync ownership from the terminal target. The plugin page supplies its own panel state ID and the restored target.

A thread target then loads that thread’s tabs into the plugin panel. Later panel changes can save plugin-page tabs into the thread. This new contract field makes that incorrect write succeed.

Please add an explicit sync thread argument. Plugin pages and root compose must pass null. Thread views must pass their thread ID.

Please add a restored thread-target test. The test must verify that a plugin page makes no thread-tabs read or write.

@bb-slop-cop bb-slop-cop 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.

🚨 SLOP COP 🚨 · review

This PR lets BB save tab details that the server rejected. It saves a plugin opener’s original file and a terminal’s target.

I found one medium issue. GitHub merged the pull request before this review finished.

Finding

  • Medium: A restored thread-targeted terminal can make a plugin page use the wrong thread tab store. useThreadTerminalController derives sync ownership from the terminal target. PluginPanelRightPanelHost supplies its plugin panel state ID with that target. The controller can replace plugin tabs with thread tabs. Later panel actions can save plugin-page tabs into that thread. The new terminal target contract makes those incorrect writes succeed. Add an explicit sync thread argument. Plugin pages and root compose must pass null. Thread views must pass their thread ID. Add a restored-target test that verifies no thread-tabs read or write from a plugin page.

Architecture and tests

The PR correctly reuses terminalCreateTargetSchema. It also moves the file opener owner schema into the server contract. These changes remove the two direct schema copies that caused this bug.

The local fixed-panel tab schema still duplicates most server tab branches. A follow-up should derive shared branches from ThreadTab, after local legacy processing. Another option is one producer-to-contract test for each tab kind.

The new opener fixture uses a double cast. A typed fixture with satisfies PluginFileOpenerSlot would detect later contract changes. The “projectless” case also supplies a project ID, so it does not test the production case.

Verification

  • The security and performance reviews found no actionable issues.
  • Turbo type checks passed for @bb/app and @bb/server-contract.
  • All 2,848 app tests and all 57 server-contract tests passed.
  • Lint passed with no errors and 147 existing warnings.
  • git diff --check passed.
  • All GitHub checks passed.
  • I started the exact SHA and installed the Docs plugin in isolated development data.
  • I opened README.md through the Docs file opener. The server stored revision 1 with fileOpenerOwner, without a sync error.
  • The final GPT-5.6 review gate confirmed the medium finding.

ymichael added a commit that referenced this pull request Aug 18, 2026
## Summary

- separate terminal execution targets from thread-tab sync ownership
- keep plugin-page and root-compose terminal tabs local while thread
views continue syncing to their thread
- add restored thread-target coverage that verifies plugin pages make no
thread-tab reads or writes
- tighten the file-opener fixture and make its projectless case truly
projectless

## Why

A restored plugin-page terminal can legitimately target a thread, but
that does not make the thread the owner of the plugin page tab state.
Deriving both concepts from the terminal target could replace plugin
tabs with thread tabs and later persist plugin tabs into the thread.

## Verification

- `pnpm exec turbo run test --filter=@bb/app --force -- --run
src/components/plugin/PluginPanelRightPanelHost.test.tsx
src/components/plugin/file-opener-tabs.test.ts`
- `pnpm exec turbo run typecheck --filter=@bb/app`
- `pnpm exec turbo run lint --filter=@bb/app --force` (0 errors; 147
existing warnings)
- `git diff --check origin/main...HEAD`

Follow-up to #1793.

> AGENT GENERATED: by GPT-5
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.

Docs file opener fails tab sync because fileOpenerOwner is rejected

1 participant