12 KiB
Native manuscript import and synchronisation correction — 7 November 2026
Application source: e4ce822b0bf5700eed1f043178d7c0a674bd056a, shared branch codex/word-companion-native-phase1-20261104. Safely fast-forwarded the clean Atlas worktree from 1ccb6c4 to Windows commit 25c75ad before editing. Windows version16 association/save fixes and qualified installer metadata are preserved. Application source is now 1.0.0.17; no Windows packages were built or installed on Atlas.
Confirmed causes
Failed scene analysis
The historical fixes 794606f (structural Word paragraph mapping) and 845b42e (trailing boundary normalisation) were inspected first. The established onboarding importer extracts through Office.js (word-companion-host.js); the native intake builds the same ManuscriptScanParagraphMap / ManuscriptScanSourceParagraph contracts and calls the same ManuscriptStructureAnalysisService. There is no separate DOCX-upload parser in the current onboarding controller/service path.
The actual Development failure at 16:19:29 and 16:19:37 was a JSON numeric syntax error at $.sceneBoundaries[3].confidence: the provider returned "confidence": 0. Nine and then 0. nine. Both attempts failed parsing before scene-coordinate validation. An earlier chapter showed the same defect but succeeded on retry.
A private read-only probe of the actual failed chapter's durable capture found 97 contiguous structural paragraphs and 99 source paragraphs, with monotonically increasing Word paragraph identities. It passed the canonical analysis/mapping service with a synthetic response containing the observed malformed confidence token. This probe made no provider call, saved no invented scene, printed no manuscript prose and removed its temporary protected source file. It verifies the actual input mapping, not the narrative quality or complete contents of the original failed AI response. The complete original failed response was not persisted by the previous implementation; the precise parser path/excerpts are recorded in service logs.
Two additional defects were confirmed: successful chapter analyses existed only in a local list and were discarded when a later chapter failed; the native intake inserted leading material as a numbered, included chapter instead of applying the original importer's front-matter behaviour.
Stale book list and disconnected wizard
- The chooser bound a snapshot of the book list when opened and did not request a fresh list or update the open chooser as the catalogue changed.
- Connection checks used an interlocked early return, so callers could finish without waiting for an already running refresh.
- The agent published only documents with
Book > 0; the server rejectedBookId == 0; the wizard filtered live presence to the selected book. A first-time manuscript could therefore be visible locally but invisible to the server/wizard until an association already existed. - The wizard reduced the resulting states to connected/disconnected and could not explain authenticated-without-Word, Word-without-document or an unassociated manuscript.
Corrections
Canonical analysis and retry
StoryIntelligenceJsonRepair.cs now performs a narrowly scoped, reported repair for an unambiguous spelled fractional digit in a Chapter Structure confidence field, such as 0. Nine → 0.9. It scans JSON strings safely; prose strings are untouched. Scene ordinals and paragraph coordinates are never repaired by this new rule. Unknown malformed responses still use the existing single retry and then fail explicitly; the existing validator and boundary normaliser remain authoritative.
OnboardingService.AnalyseApprovedChaptersAsync checkpoints chapter results using a SHA-256 of the full canonical request: preview/book/chapter identity, reviewed title/number, prose, original paragraph mapping and story context. Identical successful chapters are reused; failures are retried; changed requests do not reuse stale results. The same canonical AI service still performs all analysis. Existing location, character, asset, summary and review stages are retained.
Migration 239_ManuscriptAnalysisCheckpoints.sql adds a bounded JSON sidecar column and dbo.OnboardingManuscriptChapterAnalysis to the existing durable capture table. Dapper repository calls enforce user ownership and current project access. Accepted Payload and PayloadHash are never rewritten. Checkpoints are server-owned, not trusted from client preview JSON. No credentials, consent, active jobs or Word sessions are recreated.
Native front matter is preserved separately for review, excluded by default in the canonical preview store, labelled Front matter, and does not shift numbered story chapters. Initial known front-matter headings use the established Office.js vocabulary. Plain documents without chapter headings still retain the existing single-manuscript fallback. Existing explicit author inclusion decisions are not silently changed.
Live connection and book selection
- The chooser awaits a coalesced connection/book check on opening and updates its options when authorised book data changes.
- Book creation/editing through the established
BookServicechanges a bounded, account-specific catalogue nonce in the existing presence store. Existing presence/installation heartbeat responses carry it. The agent refreshes authorised books when it changes; an invalidation during an in-flight check is not lost. No extra polling loop or authentication mechanism was introduced. Background updates arrive on the existing heartbeat cadence; chooser opening requests a fresh check immediately. - Authenticated unassociated documents publish metadata under
BookId = 0. Such leases cannot claim saved chapter/scene data. Word-running/no-document is reported separately from Word unavailable. - The existing wizard's explicit Import manuscript request can select one trustworthy active/unique unassociated capture-capable session. It carries the authorised destination book on the existing exact-session command. The agent refreshes book access and associates locally before requesting extraction. An existing book association takes priority. An inactive unassociated document is never substituted for an active document belonging to another book; ambiguous or stale sessions fail safely.
- Wizard labels distinguish disconnected, authenticated/no Word, Word/no manuscript, unassociated manuscript, wrong book and ready-to-import. An unassociated eligible manuscript can start an explicit first import. Office.js remains a supported fallback.
- No opening, heartbeat, reconnect, catalogue refresh or association automatically uploads prose.
Marker messaging
Native Detect Scenes and build/recovery messages now state that accepted text is processed on the server and Word markers are not rewritten. The original Office.js marker/save instructions remain conditional for that implementation. No marker-write-back subsystem was added. Existing native saved-position mapping remains limited to trustworthy unchanged session/revision data.
Verification
| Check | Result |
|---|---|
| Managed solution build, including Windows-targeted agent | Passed, zero warnings/errors; VSTO host not built |
| Full application executable harness | 416 checks passed |
| Native portable executable harness | 265 checks passed, including lost-invalidation race, new-book refresh, unassociated presence and explicit wizard association |
--native-import-corrections |
13 checks passed: observed confidence defect, strict malformed-coordinate refusal, source mapping/duplicates/manual breaks/blanks/front matter, checkpoint resume/invalidation |
--native-companion-http |
Passed actual loopback authentication, own unassociated presence, cleared foreign scene claims, ownership and existing import/security behaviour |
--native-tray |
Passed durable capture, first-time import, refusal to reassign another book, disconnection/restart and existing saved mapping |
| Guarded synthetic SQL regression | Passed real checkpoint JSON/prose round-trip, immutable source/hash, idempotency, changed request isolation, populated cross-account read/write refusal, revoked membership and rollback cleanup |
| Headless browser connection regression | Passed all wizard states, stale lease handling, explicit-only transfer and Office.js fallback |
| Existing native workspace browser regression | Passed Context/Intent following/disconnection and status clearing |
| Live Development, fresh synthetic author/book | Passed normal browser approval before book creation, catalogue invalidation/new book visibility without restart, unassociated first capture, durable intake, disconnected review, explicit configured AI scene analysis with no connected Word client, saved scene mapping and two reused workspace windows |
| Final Development capture follow-up | Final e4ce822 deployment repeated the normal new-book/unassociated capture, durable source and workspace flow successfully without another AI call |
| Live SQL assertions | Exact accepted synthetic prose and canonical saved scene prose matched; native build Complete/NotRequested; successful chapter checkpoint present |
The live test used a scripted HTTP native client and Linux headless browser, not Microsoft Word or the Windows tray. Its AI request contained only the isolated synthetic test chapter. A database-backed retry test and service-level failure injection establish resume behaviour; no real author's failed import was automatically rerun.
The live synthetic account, project, book, captured source and generated scenes were removed. The existing normal account cleanup hit its pre-existing onboarding-state FK issue; only the explicitly verified fixture's onboarding state was removed, then normal account cleanup succeeded. Private fixture credentials were deleted. This unrelated product deletion defect was not refactored.
Development delivery
- Both databases were backed up with COPY_ONLY/CHECKSUM and passed
RESTORE VERIFYONLY:/var/opt/mssql/backup/PlotDirector_Development_before_native_import_20261107T164506Z.bak/var/opt/mssql/backup/PlotDirector_Synthetic_before_native_import_20261107T164506Z.bak
- Migration239 applied to the guarded synthetic database first, then to PlotDirector_Development, through the verified application principal. No existing numbered migration was edited.
- Active-work guards passed before migration/deployment. Release:
/srv/apps/plotdirector-dev/releases/e4ce822-20261107T172533Z. - Previous deployment preserved:
/srv/apps/plotdirector-dev/current-before-e4ce822-20261107T172533Z. - Published and deployed
PlotLine.dllSHA-256:2c87f960e4efb5445e83423b5a2b5377ab0b53b9ec8a23e95b50283012a9665d. - The live configured-AI run used the initial
a0cee0ddeployment; its analysis implementation is unchanged in the final document-selection safety follow-up. The final deployment repeated capture/workspace tests without a second AI call. - Service active; public Development GET200; authenticated live workflow and SQL evidence passed. Production unchanged.
Boundaries and author recovery
The accepted failed manuscript remains durable and can be reviewed/retried without another Word capture. The previous implementation did not checkpoint its earlier successful chapter analyses, so those pre-fix results cannot be recovered retroactively and may need one reanalysis. New successful results survive a later failure and server restart.
The existing wizard stores review selections in memory. Following this Development restart, an already open pre-update import may require its chapter review to be confirmed again; the captured manuscript is not lost. This correction does not silently recreate author approval or redesign the entire review-persistence system.
The wizard's automatic association does not silently write Word metadata. The existing Remember-in-document option and a normal Word save remain the path for a durable file association when the document has no persistent identity. The qualified version16 metadata/save behaviour is retained.
Actual Windows extraction, chooser behaviour, tray recovery and author-owned manuscript acceptance require the version17 Windows qualification in the handover. Do not test confirmed import against a populated primary book without a disposable copy/destination. No new native scene marker write-back is claimed.