Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

收口启动期创作状态写入

MigenAI734e465e6d89
diff --git a/background.js b/background.js
index e16ed00..2f5753e 100644
--- a/background.js
+++ b/background.js
@@ -491,15 +491,17 @@ const captureRuntime = createCaptureWorkspace({
resolveSourceContext: resolveCaptureSourceContext
});
-chrome.runtime.onInstalled.addListener(async (details) => {
- await extensionUpdateLifecycle.handleInstalled(details);
- await restrictLocalStorageAccess();
- await syncContextMenus();
- await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false });
+chrome.runtime.onInstalled.addListener((details) => {
+ enqueue(async () => {
+ await extensionUpdateLifecycle.handleInstalled(details);
+ await restrictLocalStorageAccess();
+ await syncContextMenus();
+ await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false });
- const state = await readState();
- await commitLocalChanges({ [STORAGE_KEYS.settings]: state.settings }, { markSyncDirty: false });
- await migrateLegacyScreenshots(state.entries);
+ const state = await readState();
+ await commitLocalChanges({ [STORAGE_KEYS.settings]: state.settings }, { markSyncDirty: false });
+ await migrateLegacyScreenshots(state.entries);
+ }).catch((error) => console.error("PromptDirector installation setup failed", error));
});
chrome.runtime.onUpdateAvailable.addListener((details) => {
@@ -7580,19 +7582,29 @@ async function recoverCreativeJobs() {
// Continue to the explicit interrupted state below when the resumable runner cannot restart.
}
}
- const interrupted = interruptActiveCreativeJobs(creativeJobs);
- const sessions = normalizeComposerSessions(stored[STORAGE_KEYS.composerSessions]);
- const sourceSession = sessions.find((item) => item.id === active.sessionId) ?? active.request.session;
- const session = setComposerFailure(sourceSession, {
- userMessageId: active.userMessageId,
- phase: active.phase === "planning" ? "planning" : "streaming",
- kind: "storage",
- message: "浏览器曾在任务完成前退出,结果状态未知,请手动重试",
- retryable: true
- });
- await commitLocalChanges({
- [STORAGE_KEYS.creativeJobs]: interrupted,
- [STORAGE_KEYS.composerSessions]: upsertSessionList(sessions, session)
+ const recoveryJobId = active.id;
+ await enqueue(async () => {
+ const latest = await chrome.storage.local.get([
+ STORAGE_KEYS.creativeJobs,
+ STORAGE_KEYS.composerSessions
+ ]);
+ const creativeJobs = normalizeCreativeJobsState(latest[STORAGE_KEYS.creativeJobs]);
+ const active = activeCreativeJob(creativeJobs);
+ if (!active || active.id !== recoveryJobId) return;
+ const interrupted = interruptActiveCreativeJobs(creativeJobs);
+ const sessions = normalizeComposerSessions(latest[STORAGE_KEYS.composerSessions]);
+ const sourceSession = sessions.find((item) => item.id === active.sessionId) ?? active.request.session;
+ const session = setComposerFailure(sourceSession, {
+ userMessageId: active.userMessageId,
+ phase: active.phase === "planning" ? "planning" : "streaming",
+ kind: "storage",
+ message: "浏览器曾在任务完成前退出,结果状态未知,请手动重试",
+ retryable: true
+ });
+ await commitLocalChanges({
+ [STORAGE_KEYS.creativeJobs]: interrupted,
+ [STORAGE_KEYS.composerSessions]: upsertSessionList(sessions, session)
+ });
});
}
diff --git a/test/creative-jobs.test.js b/test/creative-jobs.test.js
index 6a5e757..5d585c3 100644
--- a/test/creative-jobs.test.js
+++ b/test/creative-jobs.test.js
@@ -89,6 +89,27 @@ test("startup normalization never rewrites an unchanged creative job from a stal
assert.match(normalization, /commitLocalChanges\(creativeNormalizationUpdate/);
});
+test("startup recovery re-reads and commits interrupted jobs inside the shared write queue", () => {
+ const start = background.indexOf("async function recoverCreativeJobs()");
+ const end = background.indexOf("function waitForDownload", start);
+ const recovery = background.slice(start, end);
+
+ assert.match(recovery, /await enqueue\(async \(\) => \{/);
+ assert.match(recovery, /const latest = await chrome\.storage\.local\.get/);
+ assert.match(recovery, /const active = activeCreativeJob\(creativeJobs\)/);
+ assert.match(recovery, /await commitLocalChanges\(\{[\s\S]*creativeJobs[\s\S]*composerSessions/);
+});
+
+test("installation migration shares the write queue with startup recovery", () => {
+ const start = background.indexOf("chrome.runtime.onInstalled.addListener");
+ const end = background.indexOf("chrome.runtime.onUpdateAvailable.addListener", start);
+ const installation = background.slice(start, end);
+
+ assert.match(installation, /enqueue\(async \(\) => \{/);
+ assert.match(installation, /const state = await readState\(\)/);
+ assert.match(installation, /await migrateLegacyScreenshots\(state\.entries\)/);
+});
+
test("an interrupted local edit can be retried explicitly with its retained mask reference", () => {
const created = createCreativeJob(undefined, request({
imageEdit: {
diff --git a/test/creative_job_recovery_e2e.py b/test/creative_job_recovery_e2e.py
index f2826ee..386e6da 100644
--- a/test/creative_job_recovery_e2e.py
+++ b/test/creative_job_recovery_e2e.py
@@ -88,6 +88,27 @@ def main() -> None:
assert jobs and len(jobs["items"]) == 1, jobs
interrupted = jobs["items"][0]
+ if interrupted["status"] != "interrupted":
+ diagnostics = []
+ for _ in range(5):
+ diagnostics.append(composer.evaluate(
+ """async () => {
+ const stored = await chrome.storage.local.get(['creativeJobs', 'composerSessions']);
+ const state = await chrome.runtime.sendMessage({type: 'GET_STATE'});
+ const session = await chrome.runtime.sendMessage({
+ type: 'GET_COMPOSER_SESSION', sessionId: 'recovery-session'
+ });
+ return {
+ storedJob: stored.creativeJobs?.items?.[0],
+ storedFailure: stored.composerSessions?.find(item => item.id === 'recovery-session')?.lastFailure,
+ publicJob: state.creativeJobs?.items?.[0],
+ publicFailure: session.session?.lastFailure,
+ timeline: document.querySelector('#composer-timeline')?.innerText || ''
+ };
+ }"""
+ ))
+ composer.wait_for_timeout(200)
+ raise AssertionError({"interrupted": interrupted, "diagnostics": diagnostics})
assert interrupted["status"] == "interrupted", interrupted
assert interrupted["error"]["retryable"] is True, interrupted
assert not interrupted.get("retryOf"), interrupted