Skip to content

fix: wait for metadata before archive cascade - #577

Open
Dante-dan wants to merge 2 commits into
LodyAI:mainfrom
Dante-dan:fix/574-archive-hydration
Open

fix: wait for metadata before archive cascade#577
Dante-dan wants to merge 2 commits into
LodyAI:mainfrom
Dante-dan:fix/574-archive-hydration

Conversation

@Dante-dan

Copy link
Copy Markdown

Related issue

Closes #574

Problem / pressure

Session Detail can expose a bootstrapped root Session before the initial workspace metadata scan has discovered its child Tabs. Archiving during that window derived lifecycle targets from a partial cache, so the root could be archived while a direct parentSessionId child stayed active.

Summary

  • Wait for the captured workspace runtime's metadata cache to be fully hydrated before deriving archive targets or writing archive state.
  • Cancel a pending archive if the active workspace runtime changes, and recheck cache ownership after the asynchronous root metadata read.
  • Add deterministic coverage for delayed child hydration, workspace switching, and the existing post-hydration rendered-meta fallback.
  • Document the archive-readiness invariant and its implementation decision.

Visual explanation

flowchart LR
  A[Archive requested for root] --> B{Captured runtime cache ready?}
  B -->|No| C[Wait for ready scope]
  C -->|Runtime changed| D[Reject without writes]
  C -->|Root + child hydrated| E[Derive lifecycle targets]
  B -->|Yes| E
  E --> F[Archive root and child Tab]
Loading

Before / after

Before After
A visible bootstrap root could be archived from a partial lifecycle cache. Archive waits until the captured runtime owns a complete initial metadata projection.
A workspace switch during the wait could mix an old action with newer global cache state. The pending action rejects and releases its subscriptions when the runtime changes.
Existing hydrated actions preferred repo metadata and fell back to rendered metadata. That post-hydration fallback remains unchanged.

Test plan

  • pnpm --filter @lody/components exec vitest run tests/use-session-actions.test.ts — passed, 30/30 tests.
  • pnpm --filter @lody/components typecheck — passed.
  • pnpm format — passed.
  • pnpm run docs check — passed with no errors.
  • node .github/scripts/check-pr-body.mjs --body-file <this body> --changed-lines 230 — passed.

Context handoff

Instructions for reviewing agents

  • Review focus: Verify waitForDocMetaCacheReady cannot author archive writes before the captured runtime owns a ready cache and that both hydration and runtime-switch tests exercise observable state.
  • Decisions to challenge: Confirm waiting on the existing metadata readiness/scope signals is preferable to issuing a second full metadata scan for each archive action.
  • Plausible failures / evidence gaps: Metadata scan failure handling remains owned by the existing workspace bootstrap path; this change does not add a separate timeout or retry policy.

Authoring context

  • User goal / directives: Prevent cold-start archive from leaving a direct child Tab active when its root Session is already visible.
  • Constraints / non-goals: Preserve already-hydrated behavior and do not change which relationship fields define lifecycle targets, restore/delete semantics, or workspace metadata hydration.
  • Risk-bearing decisions: A pending archive is bound to its captured runtime and fails closed on a workspace switch instead of continuing against global cache state.
  • Destructive or irreversible behavior: No delete behavior changes; archive writes remain the existing reversible isArchived state transition and machine queue updates.
  • Deliberately not done or tested: No real-time sleep or device-specific test was added because the race is covered deterministically through explicit atom transitions.
  • Unknowns / confidence: Confidence is high for the cache-ordering boundary; broader metadata scan failure UX is unchanged and outside this issue.

Model: gpt-5.6-sol
Signed-off-by: Dante <duanjl.china@gmail.com>
@Dante-dan
Dante-dan marked this pull request as ready for review September 10, 2026 06:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T07:46:11.033639Z 2128112 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f8fbe28d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/components/src/hooks/use-session-actions.ts
Model: gpt-5.6-sol

Signed-off-by: Dante <duanjl.china@gmail.com>
@github-actions github-actions Bot added the status:needs-pr-attention External PR needs contributor attention before review label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@Dante-dan, this pull request needs updates before review.

It is marked status:needs-pr-attention. Address the findings below by 2026-09-18 08:18:13 UTC. The label and this comment are removed automatically after the PR passes validation.

If the PR remains invalid for 7 days, it will be closed and marked status:pr-policy-expired. Continue afterward by opening a new pull request with the current template.

Policy findings
PR does not meet Lody contribution requirements:

- Context handoff must include ### Original user prompt.

See `CONTRIBUTING.md` and `.github/PULL_REQUEST_TEMPLATE.md`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: components status:needs-pr-attention External PR needs contributor attention before review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Archive can miss child Tabs before metadata cache hydration

1 participant