CodeForPhilly / CodeForPhilly/codeforphilly-ng

boot: reconcile fast-forward does not re-open the store snapshot, so in-memory state is built from the pre-reconcile tree

未关闭
#160 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
1
派生
1
平均合并
5 天 3 小时
30 天内合并 PR
9

描述

## What

`buildApp` registers the plugins in this order: `store` (opens the gitsheets public store; each Sheet caches a `dataTree` snapshot at open time) → `reconcile` (fetch + fast-forward/rebase against `origin/`) → `services` (builds `InMemoryState` + FTS from `fastify.store.public`).

When the local bare clone is behind origin at boot, `reconcile` fast-forwards the branch, but nothing calls `Store.swapPublic` afterwards. `services` then builds the in-memory state from the Sheet snapshots captured before the fast-forward. Records that arrived in the fast-forward are invisible until the next hot-reload webhook or a restart.

The hot-reload path (`reloadInMemoryStateAndFts`) already handles this correctly by re-opening the public store after reconcile. The boot path skips that step.

## Why it hasn't bitten

Production pods bare-clone the data repo on every boot (`emptyDir` volume), so the clone is in sync with origin by the time `reconcile` runs and the outcome is `in-sync`. The gap only shows when a clone is reused across boots: local dev, and tests that seed the remote after creating the rig (see the re-import test in `apps/api/tests/internal-reload.test.ts`, which works around it with an explicit `git fetch origin main:main` before boot).

## Fix sketch

In the `reconcile` plugin (or a small step between it and `services`), when the outcome is anything other than `in-sync`/`fetch-failed`, re-open the public store and `fastify.store.swapPublic(freshPublic)` before `services` reads it. Or reorder so the store opens after reconcile; `reconcile` only needs the repo path and the lock, not the Sheet handles.

Found while working on the hot-reload stale-indices fix (`fix/hot-reload-stale-indices`); out of scope there.

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 buildApp 的 store → reconcile → services 注册开始,并将其与 reloadInMemoryStateAndFts 进行比较。阅读 apps/api/tests/internal-reload.test.ts,尤其是重新导入测试及其启动前的 fetch workaround。当复用的 clone 生成的内存状态和 FTS 中包含 reconcile 在 services 初始化前引入的记录时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, typescript
领域
api, backend, search
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。