mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
fix(github): bound and publish issue-title fills like other metadata writes
Skip writes that leave links untouched before normalizing, check a queued link is still wanted before reading it, publish filled titles once per repo per 2 s window, refresh the resolved rows remote clients read, never wake a stopped WSL distro for a background read, keep a selected review's PR suppression, and keep a failing write observer from failing a saved write. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
df989a7fc6
commit
0fcdfd707c
@@ -24,6 +24,8 @@ export type GitHubIssueLinkTitleFillStore = {
|
||||
getRepos: () => Repo[]
|
||||
}
|
||||
|
||||
const NOTIFY_WINDOW_MS = 2_000
|
||||
|
||||
type Job = {
|
||||
worktreeId: string
|
||||
hostId: ExecutionHostId
|
||||
@@ -53,31 +55,46 @@ export function installGitHubIssueLinkTitleFill(deps: {
|
||||
let draining = false
|
||||
let disposed = false
|
||||
|
||||
const apply = (job: Job, title: string): void => {
|
||||
const pendingNotify = new Set<string>()
|
||||
let lastNotifyAt = 0
|
||||
const flushNotify = (): void => {
|
||||
lastNotifyAt = Date.now()
|
||||
for (const repoId of pendingNotify) {
|
||||
deps.notifyChanged(repoId)
|
||||
}
|
||||
pendingNotify.clear()
|
||||
}
|
||||
|
||||
// The job's link as it is now; null once removed, retitled or its workspace re-created.
|
||||
const currentTarget = (job: Job) => {
|
||||
const meta = deps.store.getWorktreeMetaForHost(job.worktreeId, job.hostId)
|
||||
if (!meta || meta.instanceId !== job.instanceId) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
const items = getWorkspaceAttachments(meta)
|
||||
const index = items.findIndex(
|
||||
(item) => getWorkspaceReferenceIdentity(item) === job.identity && !item.title?.trim()
|
||||
)
|
||||
if (index === -1) {
|
||||
return index === -1 ? null : { meta, items, index }
|
||||
}
|
||||
|
||||
const apply = (job: Job, title: string): void => {
|
||||
const target = currentTarget(job)
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
// Restate the current review selection (null included) so the merge cannot re-pick one.
|
||||
const reviewSelection = Object.fromEntries(
|
||||
WORKSPACE_ATTACHMENT_NUMBER_SLOTS.filter(([, , type]) => type !== 'issue').map(([slot]) => [
|
||||
slot,
|
||||
meta[slot] ?? null
|
||||
])
|
||||
)
|
||||
const { meta, items, index } = target
|
||||
const reviewSlots = WORKSPACE_ATTACHMENT_NUMBER_SLOTS.filter(([, , type]) => type !== 'issue')
|
||||
// A cleared review selection must be restated or the merge re-picks one; a set one it keeps.
|
||||
const keepClearedSelection = reviewSlots.every(([slot]) => (meta[slot] ?? null) === null)
|
||||
? Object.fromEntries(reviewSlots.map(([slot]) => [slot, null]))
|
||||
: {}
|
||||
deps.store.setWorktreeMeta(hostWorktreeTarget({ id: job.worktreeId, hostId: job.hostId }), {
|
||||
...reviewSelection,
|
||||
...keepClearedSelection,
|
||||
linkedItemsBase: items,
|
||||
linkedItems: items.map((item, i) => (i === index ? { ...item, title } : item))
|
||||
})
|
||||
deps.notifyChanged(getRepoIdFromWorktreeId(job.worktreeId))
|
||||
pendingNotify.add(getRepoIdFromWorktreeId(job.worktreeId))
|
||||
}
|
||||
|
||||
const drain = async (): Promise<void> => {
|
||||
@@ -91,11 +108,13 @@ export function installGitHubIssueLinkTitleFill(deps: {
|
||||
if (disposed) {
|
||||
return
|
||||
}
|
||||
const repo = findRepoRowForHostScopedWrite(
|
||||
deps.store.getRepos(),
|
||||
getRepoIdFromWorktreeId(job.worktreeId),
|
||||
job.hostId
|
||||
)
|
||||
const repo = currentTarget(job)
|
||||
? findRepoRowForHostScopedWrite(
|
||||
deps.store.getRepos(),
|
||||
getRepoIdFromWorktreeId(job.worktreeId),
|
||||
job.hostId
|
||||
)
|
||||
: undefined
|
||||
if (!repo) {
|
||||
continue
|
||||
}
|
||||
@@ -103,13 +122,30 @@ export function installGitHubIssueLinkTitleFill(deps: {
|
||||
if (title?.trim() && !disposed) {
|
||||
apply(job, title.trim())
|
||||
}
|
||||
// One client refresh per repo per window during a burst, not one per filled title.
|
||||
if (Date.now() - lastNotifyAt >= NOTIFY_WINDOW_MS) {
|
||||
flushNotify()
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
draining = false
|
||||
if (!disposed) {
|
||||
flushNotify()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unsubscribe = deps.store.onWorktreeMetaWritten(({ worktreeId, hostId, previous, next }) => {
|
||||
// Most writes (stamps, flags, comments) leave links untouched; skip them without normalizing.
|
||||
if (
|
||||
previous &&
|
||||
previous.instanceId === next.instanceId &&
|
||||
previous.linkedItems === next.linkedItems &&
|
||||
previous.linkedIssue === next.linkedIssue &&
|
||||
previous.linkedWorkItem === next.linkedWorkItem
|
||||
) {
|
||||
return
|
||||
}
|
||||
const known = new Set(
|
||||
previous?.instanceId === next.instanceId
|
||||
? untitledGitHubIssues(previous).map(getWorkspaceReferenceIdentity)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getLocalProjectGhExecOptions } from '../workspaces/execution-host/proje
|
||||
import { getIssue } from './issues'
|
||||
import { getWorkItemByOwnerRepo } from './client/fetch/get-work-item'
|
||||
import { installGitHubIssueLinkTitleFill } from './github-issue-link-title-fill'
|
||||
import { readGitHubRepoUnlessWslStopped } from '../ipc/source-control/github-repo-routing'
|
||||
|
||||
const GITHUB_ISSUE_PATH = /^\/([^/]+)\/([^/]+)\/issues\/(\d+)$/
|
||||
|
||||
@@ -58,12 +59,27 @@ async function readGitHubIssueLinkTitle(
|
||||
|
||||
export function wireGitHubIssueLinkTitleFill(
|
||||
store: Store,
|
||||
notifyWorktreesChanged: (repoId: string, options: { invalidateGitScans: false }) => void
|
||||
runtime: {
|
||||
invalidateResolvedWorktreeCache: () => void
|
||||
notifyWorktreesChanged: (repoId: string, options: { invalidateGitScans: false }) => void
|
||||
}
|
||||
): () => void {
|
||||
return installGitHubIssueLinkTitleFill({
|
||||
store,
|
||||
readIssueTitle: (repo, link) => readGitHubIssueLinkTitle(store, repo, link),
|
||||
// Metadata-only change: publish it without forcing Git rescans.
|
||||
notifyChanged: (repoId) => notifyWorktreesChanged(repoId, { invalidateGitScans: false })
|
||||
// Background reads never start a stopped WSL distro; the link just stays untitled.
|
||||
readIssueTitle: (repo, link) =>
|
||||
readGitHubRepoUnlessWslStopped(
|
||||
store,
|
||||
repo,
|
||||
() => readGitHubIssueLinkTitle(store, repo, link),
|
||||
{
|
||||
wake: false
|
||||
}
|
||||
),
|
||||
notifyChanged: (repoId) => {
|
||||
// Metadata-only change: refresh resolved rows for remote clients without forcing Git rescans.
|
||||
runtime.invalidateResolvedWorktreeCache()
|
||||
runtime.notifyWorktreesChanged(repoId, { invalidateGitScans: false })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -227,11 +227,7 @@ async function startOrcadRuntime(
|
||||
|
||||
accountLaunch?.attachToRuntime(runtime)
|
||||
const { wireGitHubIssueLinkTitleFill } = await import('../github/github-issue-link-title-wiring')
|
||||
registerCleanup(
|
||||
wireGitHubIssueLinkTitleFill(profileStore, (repoId, options) =>
|
||||
runtime.notifyWorktreesChanged(repoId, options)
|
||||
)
|
||||
)
|
||||
registerCleanup(wireGitHubIssueLinkTitleFill(profileStore, runtime))
|
||||
const { installOrcadEmulatorBridge } = await import('./orcad-emulator-bridge')
|
||||
installOrcadEmulatorBridge(runtime, registerCleanup)
|
||||
|
||||
|
||||
@@ -267,7 +267,12 @@ export function setWorktreeMetaForHost(
|
||||
}
|
||||
scheduleSave(scheduling, WORKTREE_METADATA_DOMAINS)
|
||||
for (const listener of runtime.worktreeMetaWriteListeners ?? []) {
|
||||
listener({ worktreeId, hostId: executionHostId, previous: existing, next: updated })
|
||||
try {
|
||||
listener({ worktreeId, hostId: executionHostId, previous: existing, next: updated })
|
||||
} catch (error) {
|
||||
// The row is already written; an observer's failure must not report the write as failed.
|
||||
console.error('[worktree-meta] write listener failed:', error)
|
||||
}
|
||||
}
|
||||
return updated
|
||||
}
|
||||
|
||||
@@ -161,9 +161,7 @@ export function initializeMainProcessRuntime(): OrcaRuntimeService {
|
||||
)
|
||||
wireRecipeWorkspaceRemoval(runtime, store, () => app.getPath('userData'))
|
||||
// Each host titles its own workspaces' untitled GitHub issue links once, when they are linked.
|
||||
const disposeIssueLinkTitleFill = wireGitHubIssueLinkTitleFill(store, (repoId, options) =>
|
||||
runtime.notifyWorktreesChanged(repoId, options)
|
||||
)
|
||||
const disposeIssueLinkTitleFill = wireGitHubIssueLinkTitleFill(store, runtime)
|
||||
app.once('will-quit', disposeIssueLinkTitleFill)
|
||||
state.runtime = runtime
|
||||
// Opening a recipe VM's workspace from a client wakes the VM through the runtime's one owner.
|
||||
|
||||
Reference in New Issue
Block a user