Skip to content

feat: productize durable Deep Research workflow - #1227

Merged
likun666661 merged 3 commits into
apache:mainfrom
ACMerJuyu:feat/deep-research-fs-workspace
Jul 21, 2026
Merged

likun666661 merged 3 commits into
apache:mainfrom
ACMerJuyu:feat/deep-research-fs-workspace

Conversation

@ACMerJuyu

Copy link
Copy Markdown
Contributor

Summary

  • add a durable, append-only Deep Research run model with resumable checklist, evidence, checkpoint, report, and handoff state
  • add eight source-grounded runtime tools backed by a session-scoped JSONL ledger and semantic idempotency checks
  • expose inspectable progress in Desktop, including inspected refs, workers, blockers, report sections, and an explicit read-only-to-implementation handoff
  • document the workflow and add deterministic component, contract, persistence, runtime, and visual-smoke coverage

Why

Deep Research already existed as a read-only session profile and empty-state prompt surface, but it had no durable authority for long-running state. A resumed session could not reliably inspect prior evidence, checkpoints, or report progress, and implementation handoff semantics were implicit.

This change productizes the workflow requested in #566 while keeping research visibly read-only and source-grounded. The filesystem-backed design is informed by FS-Researcher: research state is persisted as inspectable artifacts and append-only events rather than hidden model context.

What changed

Durable research workspace

  • defines the run projection, source/evidence traceability rules, bounded exploration steps, checklist, report sections, checkpoints, and completion gates
  • persists events under the session workspace and reconstructs runs after store recreation
  • accepts exact tool-call replay while rejecting the same toolCallId with conflicting semantic input
  • fails closed for corrupt ledgers and untraceable derived artifacts

Runtime and Desktop integration

  • registers eight Maka-owned Deep Research tools only for labeled root research sessions
  • wires the durable read model through main/preload IPC into the renderer
  • renders checklist progress, report state, inspected files/symbols/tests, workers, blockers, and completion status
  • keeps the completed research session read-only; the implementation CTA creates a normal task with a bounded handoff prompt and does not auto-send

Reviewability

  • adds a deterministic deep-research-progress visual-smoke scenario
  • fixes Windows screenshot cleanup by terminating the Electron process tree
  • documents storage authority, resume behavior, permission boundaries, and implementation handoff

User/developer impact

Users can inspect and resume long-running research without silently switching into write mode. Developers get a stable storage/runtime/UI contract with explicit evidence provenance and focused tests for replay, recovery, completion, and permission boundaries.

Validation

  • npm run lint — 1,806 files checked
  • npm --workspace @maka/desktop run typecheck
  • npm --workspace @maka/desktop run build
  • 98 focused Core, Storage, Runtime, UI, Desktop contract, and visual-fixture tests
  • npm --workspace @maka/desktop run test:checks
  • git diff --check
  • visual capture: light-1280-motion and dark-990-reduced-motion

Closes #566

@likun666661

Copy link
Copy Markdown
Member

Deep Research architecture walkthrough

Bottom line: This PR upgrades Deep Research from a read-only mode prompt and an empty-state UI into a durable, resumable, auditable workflow with an explicit handoff to implementation.

1. What problem does it solve?

Before this PR, Deep Research already had:

  • a dedicated session mode;
  • mode-specific prompting;
  • a renderer entry point and empty state;
  • user-facing visibility for Deep Research artifacts.

However, it did not have a durable runtime protocol for executing and recovering a research run. In particular:

Gap What this PR adds
No authoritative persisted run state A ledger-backed DeepResearchRun state model stored in the Artifact Store
No reliable resume/recovery path Checkpoints, current-step state, and projection from the append-only ledger
No structured evidence workflow Source artifacts with locator, summary, content hash, and citation metadata
No deterministic report assembly Five report sections plus a generated final report artifact
No explicit implementation handoff A handoff artifact and handoff_ready terminal state
No semantic retry protection Tool-call IDs and replay/conflict checks for mutating operations
No clear completion contract Completion gates that validate required steps, sections, sources, and handoff state

Conceptually, the PR introduces a two-stage state machine:

stateDiagram-v2
    [*] --> active
    active --> completed: deep_research_complete
    completed --> handoff_ready: deep_research_handoff
    handoff_ready --> [*]
Loading

A run cannot be completed until its required research steps and report sections are satisfied. The implementation handoff is a separate transition, so research completed and ready for downstream implementation are no longer conflated.

2. Related modules

The design has two authorities:

  • The Artifact Store owns durable artifact bodies.
  • The Deep Research ledger owns run state, ordering, references, hashes, replay metadata, and lifecycle transitions.
flowchart LR
    AI["AI model"] --> RT["Runtime Deep Research tools"]
    RT --> CORE["Core run state machine"]
    RT --> STORE["Artifact Store"]

    CORE --> LEDGER["Deep Research ledger artifact"]
    STORE --> SRC["Source artifacts"]
    STORE --> SEC["Report section artifacts"]
    STORE --> FINAL["Final report artifact"]
    STORE --> HANDOFF["Implementation handoff artifact"]

    LEDGER --> HOOK["useDeepResearchRun"]
    SRC --> PANE["Artifact Pane"]
    SEC --> PANE
    FINAL --> PANE
    HANDOFF --> PANE
    HOOK --> VIEW["Deep Research workspace UI"]
    PANE --> VIEW
Loading

The main responsibilities are split as follows:

Area Responsibility
packages/core/src/deep-research-run.ts Domain model, ledger projection, lifecycle transitions, validation, and replay semantics
packages/runtime/src/deep-research-tools.ts Tool definitions and orchestration between the model, core state machine, and Artifact Store
packages/runtime/src/deep-research-prompt.ts Runtime protocol exposed to the model in Deep Research mode
packages/storage/... Durable Artifact Store persistence and change notifications
apps/desktop/src/main/... IPC bridge and desktop integration
apps/desktop/src/renderer/hooks/use-deep-research-run.ts Loads and subscribes to the current run projection
apps/desktop/src/renderer/deep-research-view.tsx Displays progress, sources, report sections, and handoff state
apps/desktop/src/renderer/artifact-visibility.ts Makes Deep Research artifacts visible in the normal artifact experience

The runtime exposes eight workflow tools to the model:

  1. deep_research_start
  2. deep_research_step
  3. deep_research_save_artifact
  4. deep_research_update_report
  5. deep_research_checkpoint
  6. deep_research_status
  7. deep_research_complete
  8. deep_research_handoff

Under normal Deep Research operation, these tools are visible to the AI. The prompt explicitly tells the model to use the durable workflow, and the runtime registers the tools for Deep Research sessions. The user-facing Artifact Store tools remain a separate concern from the model-facing workflow tools.

3. Main sequence

sequenceDiagram
    participant AI as AI model
    participant RT as Runtime tools
    participant Core as Core state machine
    participant Store as Artifact Store
    participant UI as Desktop UI

    AI->>RT: deep_research_start(plan)
    RT->>Core: create run and initial ledger
    RT->>Store: persist ledger
    Store-->>UI: artifact/deep-research change

    loop Research steps
        AI->>RT: deep_research_step(...)
        RT->>Core: update active step
        AI->>RT: deep_research_save_artifact(source)
        RT->>Store: persist source body
        RT->>Core: append source reference and hash
        AI->>RT: deep_research_update_report(section)
        RT->>Store: persist section body
        RT->>Core: update section reference
        AI->>RT: deep_research_checkpoint(...)
        RT->>Core: append checkpoint
        RT->>Store: persist updated ledger
        Store-->>UI: refresh projected run
    end

    AI->>RT: deep_research_complete(...)
    RT->>Core: validate completion gates
    RT->>Store: persist final report and completed ledger
    Store-->>UI: show completed state

    AI->>RT: deep_research_handoff(...)
    RT->>Store: persist handoff artifact
    RT->>Core: transition to handoff_ready
    RT->>Store: persist final ledger
    Store-->>UI: show implementation handoff
Loading

4. Scope and review focus

This PR is primarily the durable orchestration layer. It does not attempt to redesign the general Artifact Store or turn Deep Research into an independent execution engine.

The most important review areas are:

  • whether the ledger and Artifact Store remain consistent under deletion or corruption;
  • whether semantic idempotency is complete for every mutating input and terminal-state retry;
  • whether untrusted artifact content can forge protocol envelope tags;
  • whether the UI observes every state change that can invalidate a run.

At the time of review, the PR is still a draft, contains 2 commits and 33 changed files (+4463 / -9), and GitHub reports it as not currently mergeable. I have posted the concrete blocking findings separately so they can be discussed independently.

@likun666661

Copy link
Copy Markdown
Member

Blocking review findings

I would block merge on the first two issues below.

1. Completion can seal a run whose authoritative artifacts are missing or corrupt

deep_research_complete validates the references recorded in the ledger, but it does not re-read and validate the referenced artifact bodies before transitioning the run to completed.

Relevant code:

This creates a split-brain state between the ledger and the Artifact Store. A source, report section, final report, or handoff artifact can be deleted or modified after its reference and hash have been recorded. The completion gate can still succeed because it trusts the ledger metadata. The UI can then show a completed run even though a later artifact read fails integrity or liveness checks.

There is also a UI invalidation gap: useDeepResearchRun reacts to Deep Research state changes, but deletion through the generic Artifact Pane is an artifact change. The projected run can therefore remain visibly stale after a referenced artifact is deleted.

Suggested fix: before completion and handoff, re-read every required current artifact and validate:

  • artifact exists and is not soft-deleted;
  • artifact belongs to the same session/run;
  • artifact type and role match the ledger reference;
  • SHA-256 matches the hash recorded in the ledger.

At minimum this should cover all referenced sources, all five current report sections, the final report, and the handoff artifact. The UI should also subscribe to artifact changes that can invalidate the run, or Deep Research-owned artifacts should not be deletable without updating the ledger.

2. Semantic tool-call idempotency is incomplete

The replay comparison for saved artifacts checks role, locator, content hash, source IDs, and section metadata, but it does not compare name or summary:

As a result, the same toolCallId can be retried with a different name or summary and still be accepted as an exact replay. That breaks the documented semantic-idempotency contract, where a reused tool-call ID with different inputs should be rejected as a conflict.

Terminal-state retry handling is also inconsistent. Several mutating tools call requireActiveRun() before checking whether the toolCallId is an exact replay. Once the run is completed, an exact retry is rejected even though the protocol describes completed runs as terminal except for exact replay.

Suggested fix:

  • compare every semantic input, including name and summary, or compare a canonical hash of the complete normalized request;
  • perform replay lookup before active/terminal-state rejection;
  • ensure a toolCallId cannot be reused across different event/tool types;
  • add negative tests for changed name, changed summary, cross-tool ID reuse, and exact retry after completion.

Additional safety issue: forged workspace envelopes are not fully stripped

The sanitization helper removes <deep-research-artifact> tags, but not <deep-research-workspace> tags:

An untrusted source artifact can therefore inject a forged <deep-research-workspace status="completed"> envelope into model-visible content. The parser may not treat it as authoritative state today, but this contradicts the documented trust boundary and is a prompt-injection footgun.

Suggested fix: strip or escape both workspace and artifact envelope tags at every untrusted-content boundary, and add adversarial tests for opening source artifacts containing forged envelopes.

Merge state

GitHub currently reports this draft PR as mergeable: false, so the branch also needs to be synchronized and conflicts resolved before merge.

The focused Core, Storage, UI, Runtime Deep Research, and Desktop test suites passed locally, but the negative paths above are not covered by those tests.

@ACMerJuyu
ACMerJuyu force-pushed the feat/deep-research-fs-workspace branch from 32a9c93 to 2a733f9 Compare July 21, 2026 09:56
@ACMerJuyu
ACMerJuyu force-pushed the feat/deep-research-fs-workspace branch from 2a733f9 to 717c000 Compare July 21, 2026 10:16
@ACMerJuyu

Copy link
Copy Markdown
Contributor Author

Addressed the blocking findings in 717c0004 (the branch is also rebased onto current main).

1. Completion integrity / deletion safety

  • deep_research_complete now re-reads every referenced source, current report section, final report, and handoff artifact before sealing the run.
  • Each record must still exist, be live, belong to the same session, have the expected persisted Markdown type and Deep Research role, and match the ledger SHA-256.
  • Deep Research-owned artifacts are now protected from generic Artifact Pane deletion in both the renderer and main-process IPC guard, preventing the ledger/store split-brain path.

2. Semantic idempotency

  • Artifact replay comparison now includes normalized name and summary as well as the other semantic inputs.
  • Replay lookup happens before the active/terminal-state guard, so exact retries remain valid after completion.
  • Tool-call IDs are checked across event/tool types and conflicting reuse is rejected.
  • Negative coverage was added for changed name, changed summary, cross-tool ID reuse, and exact terminal replay.

3. Workspace-envelope sanitization

  • Both <deep-research-workspace> and <deep-research-artifact> envelopes are stripped at persisted and model-visible untrusted-content boundaries.
  • Adversarial coverage verifies forged workspace/artifact tags cannot survive artifact reads.

Architecture clarification: the current protocol has one terminal completed transition. deep_research_complete requires both the final report and structured handoff; there is no separate handoff_ready state or deep_research_handoff tool in the current head.

Verification

  • Core + Runtime Deep Research focused tests: 21 passed
  • Storage Artifact/Deep Research tests: 20 passed, 3 Windows symlink cases skipped as designed
  • Desktop contract/visual fixture tests: 76 passed
  • UI progress tests: 2 passed
  • Core, Storage, and UI builds passed
  • Desktop preload and renderer typechecks passed
  • Full Biome lint: 1,960 files checked, no errors
  • git diff --check passed

The full Runtime build and Desktop main typecheck still hit pre-existing errors in untouched AI SDK and MCP files (MockLanguageModelV4/provider-version skew and missing McpClientManager.cancelConnect respectively); none of those failing paths are part of this PR diff.

@ACMerJuyu
ACMerJuyu marked this pull request as ready for review July 21, 2026 10:17
@ACMerJuyu

Copy link
Copy Markdown
Contributor Author

@likun666661 The blocking findings have been addressed and the PR is ready for review. Could you please take another look when convenient? The detailed fix and verification summary is in the comment immediately above.

@likun666661
likun666661 merged commit bc5b781 into apache:main Jul 21, 2026
1 of 3 checks passed
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.

roadmap: productize Deep Research workflow

2 participants