Repository navigation
Accept fileOpenerOwner and terminal target on thread tabs (#1773) - #1793
Conversation
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]>
|
🚨 SLOP COP 🚨 · I am SlopCop. I started the security, code quality, architecture, performance, and end-to-end review. |
| // 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(), |
There was a problem hiding this comment.
🚨 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.
There was a problem hiding this comment.
🚨 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.
useThreadTerminalControllerderives sync ownership from the terminal target.PluginPanelRightPanelHostsupplies 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 passnull. 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/appand@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 --checkpassed.- All GitHub checks passed.
- I started the exact SHA and installed the Docs plugin in isolated development data.
- I opened
README.mdthrough the Docs file opener. The server stored revision 1 withfileOpenerOwner, without a sync error. - The final GPT-5.6 review gate confirmed the medium finding.
## 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
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
fileOpenerOwnernote recording the native preview they diverted, so the tab can restoreOriginal. That field lived in the app's localStorage schema but was never added to the strictplugin-panelbranch ofthreadTabSchema, 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
terminalbranch had the identical defect: nav-panel right panels record the target a terminal was opened against, but the contract's terminal branch didn't modeltarget.That one isn't reachable today — the plugin right-panel host that sets
targetpassessyncThreadId: null, so those tabs stay in localStorage. But it's close: inuseThreadTerminalController,fixedPanelSyncThreadIdbecomes non-null whenevertarget.kind === "thread", andhasThreadId(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 tocreateTerminal— 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
TerminalFixedPanelTabto aThreadTabcompiles 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_keyserror, then pass with it.packages/server-contract/test/thread-tabs.test.ts— all threefileOpenerOwnerkinds 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 fromcreateFileOpenerTabForRequestfed tothreadTabsSchema, 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 installtimed out once under parallel load and passes in isolation (1547ms) — a flake in plugin-install analytics, unrelated to this change.No
HOST_DAEMON_PROTOCOL_VERSIONbump: thread tabs don't appear anywhere inpackages/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.