Skip to content

fix(memory): replace episode reprocessing contributions (MEMMY-647) - #815

Open
whqf1123 wants to merge 11 commits into
MemTensor:v1.2.8from
whqf1123:fix/memmy-647-episode-reprocessing-v127
Open

whqf1123 wants to merge 11 commits into
MemTensor:v1.2.8from
whqf1123:fix/memmy-647-episode-reprocessing-v127

Conversation

@whqf1123

@whqf1123 whqf1123 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

问题与修复

同一 Episode 关闭、重开并再次关闭后,应替换该任务之前的派生结果和数值贡献。任务从成功改判失败、再恢复成功时,旧贡献必须撤回并恢复,不能把同一任务当成新来源重复累计,也不能抹掉其他任务、独立反馈或人工修改。

本次统一旧式与 unified 经验处理、直接生成 Skill 与经验派生 Skill 两条路径:

  • 用稳定的任务来源识别贡献,内容和评分变化只用于判断是否重算。统一抽取与奖励改判共用完整、同账号的参考证据;有历史时由统计逻辑统一写入支持数,避免自动 support 被误记为人工检查点。展示置信度与新数值在同一次更新中保持一致。
  • 成功来源失效后,已有经验及直接技能撤回对应贡献;来源恢复后沿用原 ID。保留有效负面教训、其他任务、独立召回反馈、后续试用、正文版本和人工归档/编辑。旧重复事件及自动检查点仅在来源和连续审计证据充分时接续,含混历史不猜测重置。
  • 负经验和片段按来源替换,簇按唯一成员汇总;重开清理关闭原因。奖励和异步生成通过处理代次、完整输入版本及事务检查,拒绝过期结果覆盖新状态。
  • 经验抽取保留严格格式与完整覆盖校验,反馈具体错误并保留最近三条诊断。每轮最多三次模型纠错,持久化预算,避免 Worker 重试放大调用;耗尽后保留候选和失败记录,通过任务详情的正式入口显式恢复。桌面前端、后端转发、Memory HTTP 与 Worker 已贯通。

不改变任务重开条件、两小时规则或合并窗口,不升级依赖或迁移数据库表结构。

v1.2.8 兼容修正

合入目标分支 v1.2.8 的 d6a7888356ede310e44063aad1f2c01007c29072,解决旧 PR 与新版的冲突,并统一历史账号记录与本机记录混合时的证据、统计和恢复逻辑:

  • 任务、原始回合、正文支持关系共同证明来源;奖励、经验抽取和技能维护共用完整任务上下文,不再截取全局最近 1000 条记录作为证据。保留 project/profile 精确范围、删除及脱敏约束。
  • 直接技能与经验派生技能分别保留新版维护规则,支持历史来源撤回及同 ID 恢复;不改写历史 owner,保留其他任务、独立反馈、试用和人工修改。
  • 历史任务新增的本机纠错记录按真实来源进入候选,恢复时逐 owner 入队。保留前端分页、隐藏暂停、取消及迟到响应保护,以及接口凭证与 scope 限制。

本轮验证

已验收并提交的版本:635a8aff75f3cc91d0b0bb0715fd8434c03162d6。该提交包含旧 PR 头 64f0aad5 和上述 v1.2.8 基线。提交前通过远端 refs 确认目标分支仍为 d6a78883。

  • 修复前保留机械合并后的直接技能、经验抽取、状态卡、恢复权限失败,以及真实服务装配中的混合来源遗漏、技能正文内部证据 ID 残留等复现记录。修复和回归覆盖成功→失败→成功、其他任务贡献保护、来源隔离、删除撤回、旧历史、文件数据库重开、恢复队列和完整 HTTP/Worker 链。
  • 最终 Memory 全量:4988 通过、0 失败、2 条件跳过;三端类型检查通过。前端记忆页面及相关 API 回归 418 通过,最终真实 HTTP/Worker 链 10 通过。专项存在覆盖交集,不累加作为独立测试总数。
  • macOS arm64 unsigned DMG 构建退出 0,镜像完整性 VALID;打包保护 153 通过、1 跳过。包内首轮 313 通过、1 项技能名称测试超过原 5 秒时限;同包、同断言、同限制完整复测 314 通过,桌面调用链 5 通过。首轮超时原因尚未查明,保留失败记录。
  • 20 个 Memory 模块、119 个界面文件、259 个后端/契约文件及全部 5469 项应用文件/链接与镜像核对一致。
  • 真实隔离 GUI:同一任务由成功 0.94 重开为进行中,再判失败 -0.55,修正任务样例后成功 1.00;共享直接技能支持数 3→2→3,簇成员数不增加。其他 3 个任务及其 L1 数值、6 条无关经验保持不变;一条旧经验正常吸收新纠错证据并保留旧来源。
  • 18 条经验的增益按保存贡献独立重算一致,派生技能数值与当前证据一致。一次界面重试将 2 条待处理变为 0,26 条候选处理完成;26 项只读核对通过。真实 DeepSeek 进化调用成功,其中一次输出截断经内置重试提高上限后成功,原记录保留。
  • 刷新、切换任务及同包正常退出重启后,任务仍为 16 轮、已完成、评分 1.00、无待处理经验;任务、经验技能、L1 数值、候选、试用、变更记录、链接、簇、成员及目标作业共 10 类业务快照保持一致。旧 generation 4 失败记录未清空,本轮新作业已完成。

DMG SHA256:fda7fba59a6004c87d304f5f0f466102e0312cb9348decd86972a5f13aa48eca。

已知问题与验收边界

  • 消息确认超时后恢复草稿、后台稍后仍执行的问题暂不处理,不纳入本次 647 修复。离线探针在本候选和未修改上游 d6a78883 各验证 3 种场景:无缓存时目录准备 45 秒超过前端 30 秒确认时限,迟到接受仍执行;有缓存对照正常。测试通过表示复现成立,不能当作该问题已修复;真实云端目录失败原因及完整网关/界面恢复未查明。本轮真实 GUI 的 4 次发送分别只执行一次,未通过重复点击重发。
  • DMG 安装背景替换出现临时镜像空间不足警告,较宽 Finder 窗口右侧白边已实测确认;应用与 Applications 入口可见。外观问题未修复。
  • 本轮真实 GUI 未覆盖非空独立技能试用、人工归档修改以及请求进行中的快速连点/隐藏竞争;相关边界依赖自动化覆盖,不宣称已全部手工验收。覆盖安装、Windows/Linux 实机未验收。
  • 不宣称模型输出稳定性、包内首次超时或完整 GUI 的全部问题已经解决。本 PR 供 647 修复复审,未合并、未发布。

关联与来源

云效 MEMMY-647:https://devops.aliyun.com/projex/bug/df818a432a7af099435e39fdd4

接手 #740 的修复用途,旧 PR 保持不动。部分贡献回放组件、片段/分簇逻辑及用例参考 yxyi123 的 #740(660b3b9c),对应文件头保留来源说明;未整体合并旧 PR。本轮按用户要求不修改云效。

@Memtensor-AI

Memtensor-AI commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #815
Task: c26fa9af7c4eb968
Base: v1.2.8
Head: fix/memmy-647-episode-reprocessing-v127
Head SHA: 635a8aff75f3cc91d0b0bb0715fd8434c03162d6

🔍 OpenCodeReview found 61 issue(s) in this PR.

⚠️ Review warnings (25)

  • semantic groups split by file count and complete diff byte size; all selected files remain in coverage
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • comment filed against App/frontend/desktop/src/task-experience-processing.tsx describes code in App/frontend/desktop/src/pages/memory/task-experience-processing.tsx; re-filed
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • bounded analysis finalized with explicit task_done after reviewing all group files
  • tool output exceeded the byte/line budget; use narrower file ranges or paginated searches; omitted output is not reviewed
  • tool result exceeded the byte/line budget; narrow the request or page through results; omitted content is not reviewed
  • … 15 additional warning(s) omitted.

1. App/backend/src/adapters/outbound/memory-client/types.ts (L140-L141)

These two methods are now required on MemoryClient, but the shared test double createMockMemoryClient (declared as : MemoryClient in src/tests/support/mock-memory-client.ts) was not extended with them. Because src/tests/** is excluded from tsc in tsconfig.json, this won't fail npm run typecheck, but the mock will silently drift from the interface and throw TypeError: ... is not a function for any test that drives the new panel routes through createPanelService with the mock client. Please add mock implementations (e.g. returning { episodeId, state: "complete", pendingCount: 0, canRetry: false, serverTime: now() } and the same with accepted: true).


2. App/backend/src/adapters/inbound/local-api/routes/agent-runtime/panel.ts (L72-L73)

Style: the two new route blocks end directly against the compact app.post("/api/v1/panel/logs", ...) line, making the file harder to read. Add a blank line (and consider keeping the new compact-style single-line form consistent with neighbours or the expanded form used for the new routes).


3. App/frontend/desktop/src/api/memory-runtime-client.ts (L357-L359)

This new read bypasses panelQueue, unlike every other panel read in this client (listPanelTasks, listPanelItems, etc.). Since the new drawer card polls this endpoint every 5s and re-mounts on navigation, requests are no longer deduped/throttled by the shared queue (concurrency 2) or aborted through panelQueue.request(..., callerSignal), so concurrent polls can pile up while a panel refresh is in flight.

Also, an older Memory runtime that does not expose this route returns 404 not_found, which will surface as a user-visible polling error every 5s; the rest of this client treats that case via isUnsupportedPanelRoute.

💡 Suggested Change

Before:

    async taskExperienceProcessing(id, signal) {
      return requestJson({ config, path: `/api/v1/panel/tasks/${encodeURIComponent(id)}/experience-processing`, schema: TaskExperienceProcessingSchema, init: { signal } });
    },

After:

    async taskExperienceProcessing(id, signal) {
      const path = `/api/v1/panel/tasks/${encodeURIComponent(id)}/experience-processing`;
      // Older runtimes do not expose experience generation; callers treat it as unsupported.
      return panelQueue.request(path, (sharedSignal) => requestJson({ config, path, schema: TaskExperienceProcessingSchema, init: { signal: sharedSignal } }), signal);
    },

4. App/frontend/desktop/src/api/memory-runtime-client.ts (L360-L363)

The retry mutates server state (queues a new L2 recovery round) but, unlike deletePanelTask right below it, never calls invalidatePanel(). Nothing dispatches memmy-panel-invalidated or clears the browse cache, so other panel views (task summaries / detail) keep showing the stale pre-retry state until an unrelated refresh happens.

💡 Suggested Change

Before:

    async retryTaskExperienceProcessing(id) {
      return requestJson({ config, path: `/api/v1/panel/tasks/${encodeURIComponent(id)}/experience-processing/retry`,
        schema: RetryTaskExperienceProcessingSchema, body: {} });
    },

After:

    async retryTaskExperienceProcessing(id) {
      const result = await requestJson({ config, path: `/api/v1/panel/tasks/${encodeURIComponent(id)}/experience-processing/retry`,
        schema: RetryTaskExperienceProcessingSchema, body: {} });
      if (result.accepted) invalidatePanel();
      return result;
    },

5. Memory/src/server/http.ts (L1280-L1282)

This envelope construction diverges from the established pattern used by the other scoped-mutation routes in this file (evidence.skills.approve / evidence.skills.edit), which pick the strict envelope based on scopedPrincipal.namespace, not on localPanel. Two consequences:

  1. For a cloud/scoped principal, localPanel is false but a namespace may be absent → strictEnvelopeWithPrincipal throws invalid_argument, whereas the sibling routes fall back to envelopeWithPrincipal.
  2. Spreading the raw namespace after strictEnvelopeWithPrincipal(...) overwrites the merged namespace produced inside it (dropping any source-derived fields), which makes the strict conflict validation partly moot; only the cast hides the mismatch.
💡 Suggested Change

Before:

    const request = localPanel ? envelopeWithPrincipal(input, principal) : {
      ...strictEnvelopeWithPrincipal(input, { ...principal, namespace }), namespace
    } as RequestEnvelope;

After:

    const scopedPrincipal = { ...principal, namespace };
    const request = (!localPanel && scopedPrincipal.namespace
      ? strictEnvelopeWithPrincipal(input, scopedPrincipal)
      : envelopeWithPrincipal(input, scopedPrincipal)) as RequestEnvelope;

6. App/frontend/desktop/src/pages/memory/task-experience-processing.tsx (L36)

This re-implements polling that already exists as usePanelPoll in this folder (visibility pause, single-flight active guard, exponential backoff on failures, configurable enabled). The inline version polls forever at a fixed 5s even in terminal states (complete) and retries immediately on every failure, and the interval is a bare magic number. Reusing the hook also removes the need for the manual reading/canRead bookkeeping here.

💡 Suggested Change

Before:

    const timer = window.setInterval(() => void refresh(), 5000);

After:

    const timer = window.setInterval(() => void refresh(), POLL_INTERVAL_MS);

7. App/frontend/desktop/src/pages/memory/task-experience-processing.tsx (L20)

The effect unconditionally clears the submission lock and replaces status on every re-run (visibility toggle or client identity change). An in-flight retry() therefore has submitting.current reset in the middle of the request, so the button can be re-enabled and a second concurrent retry submitted; the first response is then discarded by the current === generation.current check. Only reset state when the identity (episodeId/client) actually changes, not on visibility flips.


8. App/frontend/desktop/src/pages/memory/task-experience-processing.tsx (L52)

submitting/busy are only released when canRead() is still true and the generation is unchanged. If the panel is hidden or the row unmounts while the retry is in flight, the guard is false and the lock is never cleared: the retry button stays disabled and refresh() is permanently skipped by submitting.current until the effect happens to re-run. Always release the local lock, and only gate the state writes on the read guard.

💡 Suggested Change

Before:

      if (canRead() && current === generation.current) { submitting.current = false; setBusy(false); }

After:

      submitting.current = false;
      if (canRead() && current === generation.current) setBusy(false);

9. App/frontend/desktop/src/pages/memory/task-experience-processing.tsx (L60)

Building translation keys from server values couples the i18n catalog names to the wire enum (invalid_model_output, model_or_processing_failed, task_changed), which breaks the camelCase key convention used everywhere else in messages.ts and gives no runtime fallback if the backend later emits a new code (messageCatalogs[language][key] would be undefined and formatMessage would throw). The existing convention in this folder (observed-memory-detail.tsx) maps the code to an explicit MessageKey; please do the same, with a generic fallback for unknown codes.

💡 Suggested Change

Before:

    {status?.errorCode && status.state === "failed" && <p>{t(`memory.tasks.experience.${status.errorCode}`)}</p>}

After:

    {status?.errorCode && status.state === "failed" && <p>{t(experienceErrorKey(status.errorCode))}</p>}

10. App/frontend/desktop/src/pages/memory/tasks-sub-page.tsx (L472)

client is optional in TasksSubPageViewProps, and the existing tasks-sub-page.test.tsx renders TasksSubPageView without it, so the new card is entirely untested (poll/render of each state, retry enabling via canRetry, stale-response handling). Given the sibling observed-memory-detail.interaction.test.tsx covers the equivalent retry button, please add an interaction test that passes a stub client here.


11. App/backend/local-api-contracts/src/memory-runtime.ts (L986-L992)

This shared schema is used to parse real HTTP responses on both the backend client and the renderer, but it uses bare z.string() for episodeId/jobId/serverTime while every neighbouring panel schema uses NonEmptyStringSchema and IsoTimeSchema. Using the existing primitives keeps the contract consistent and preserves meaningful response validation (empty ids / non-ISO timestamps would currently be accepted silently).

💡 Suggested Change

Before:

  episodeId: z.string(),
  state: z.enum(["complete", "pending", "queued", "running", "failed", "blocked"]),
  pendingCount: z.number().int().nonnegative(),
  canRetry: z.boolean(),
  jobId: z.string().optional(),
  errorCode: z.enum(["invalid_model_output", "model_or_processing_failed", "task_changed"]).optional(),
  serverTime: z.string()

After:

  episodeId: NonEmptyStringSchema,
  state: z.enum(["complete", "pending", "queued", "running", "failed", "blocked"]),
  pendingCount: z.number().int().nonnegative(),
  canRetry: z.boolean(),
  jobId: NonEmptyStringSchema.optional(),
  errorCode: z.enum(["invalid_model_output", "model_or_processing_failed", "task_changed"]).optional(),
  serverTime: IsoTimeSchema

12. Memory/src/server/http.ts (L1269-L1271)

The scoped-namespace derivation principal.authenticatedNamespace ?? principal.namespace is duplicated in both new branches, and each branch then builds a different kind of envelope. Neighbouring scoped-mutation routes (e.g. evidence.skills.approve / evidence.skills.edit above) factor this into a single scopedPrincipal and pick the envelope from it. Extracting the same helper here would keep GET/POST consistent and make the later divergence auditable in one place.

💡 Suggested Change

Before:

  if (taskExperience && method === "GET" && !taskExperience[2]) {
    requireMemoryRead(principal);
    const namespace = principal.authenticatedNamespace ?? principal.namespace;

After:

  if (taskExperience && method === "GET" && !taskExperience[2]) {
    requireMemoryRead(principal);
    const scopedPrincipal = { ...principal, namespace: principal.authenticatedNamespace ?? principal.namespace };

13. App/frontend/desktop/src/pages/memory/task-experience-processing.tsx (L58)

When a read fails, refresh() only sets error and leaves status as null, so the status region keeps announcing "loading" (memory.tasks.experience.loading) on every subsequent poll while the request keeps failing. The user sees a permanent "loading" label plus a raw error string, with no way to tell that loading has stopped. Consider rendering a distinct failed/unavailable state when error is set and status is still null.

💡 Suggested Change

Before:

    <div role="status">{status ? t(`memory.tasks.experience.${status.state}`) : t("memory.tasks.experience.loading")}</div>

After:

    <div role="status">{status ? t(`memory.tasks.experience.${status.state}`) : t(error ? "memory.tasks.experience.failed" : "memory.tasks.experience.loading")}</div>

14. Memory/src/service/evolution/policy-evidence.ts (L36-L37)

traceOriginIsCurrent no longer rejects a raw turn that was redacted/deleted. The previous isPolicyEvidenceValid check (raw.deletedAt || raw.redactedAt) was dropped here, and getRawTurn returns rows regardless of those flags (repositories.ts: SELECT * FROM raw_turns WHERE id = ?). On raw-turn redaction the L1 memory itself is not deleted (invalidateMemoryDependencies only invalidates the unified L2 source), so after this change a redacted raw turn keeps its L1 trace "current" and continues contributing support/gain to an active policy — a privacy and validity regression. Please restore the flag check.

💡 Suggested Change

Before:

  const raw = repos.runtime.getRawTurn(source.rawTurnId);
  if (!raw) return false;

After:

  const raw = repos.runtime.getRawTurn(source.rawTurnId);
  if (!raw || raw.deletedAt || raw.redactedAt) return false;

15. Memory/src/service/evolution/policy-evidence.ts (L80)

N+1 query storm: sourceTraces is filtered with the cached links, but validTraces goes through isCurrentPolicyEvidence → isTrustedPolicySource without links, so the default parameter runs listTracePolicyLinks({ l2MemoryId, limit: -1 }) (an unbounded scan of trace_policy_links, repositories.ts:6620) once per candidate trace. policiesDependingOnTrace has the same problem: one full link scan per candidate policy, on every L1 invalidation. Please thread the already-fetched links into isCurrentPolicyEvidence/policiesDependingOnTrace.

💡 Suggested Change

Before:

  const validTraces = sourceTraces.filter(trace => isCurrentPolicyEvidence(repos, trace, policy, successEligible));

After:

  const validTraces = sourceTraces.filter(trace => isCurrentPolicyEvidence(repos, trace, policy, successEligible, links));

16. Memory/src/service/evolution/policy-induction.ts (L253)

Throwing a bare Error here aborts the whole l2_induction job: induceL2 has no try/catch in the signature loop, so every remaining signature in this job is skipped, and processJob (job-handlers.ts:275) lets the error propagate to the worker, which counts it as a failed attempt against maxAttempts and discards the model call already paid for. If episodeRevision keeps moving (other pipelines write traces/episodes during the same round trip), each retry fails again and the bucket never converges. Prefer skipping just this signature (continue, leaving the candidate pool entries pending for a later job) or re-deriving the bucket after generation, and log the decision instead of failing the job.

💡 Suggested Change

Before:

      if (evidenceRevision() !== beforeGeneration) throw new Error("policy evidence changed during generation; retry");

After:

      if (evidenceRevision() !== beforeGeneration) {
        logEvolutionDecision(job, "l2_induction", "evidence_changed", {
          sourceMemoryId: source.id,
          evidenceCount: bucket.length,
          distinctEpisodeCount
        });
        continue;
      }

17. Memory/src/service/evolution/policy-induction.ts (L6)

l2SharesComparisonScope is no longer referenced anywhere in this file (its only remaining use in recomputePolicyStats was moved into policy-evidence.ts), so this import is dead and will trip unused-import lint. Please remove it.


18. Memory/src/service/evolution/policy-induction.ts (L761)

Two problems in this rewritten helper: (1) the _userId parameter is never read — both call sites still pass source.userId/memory.userId, which misleadingly suggests the reference traces are user-scoped; drop the parameter. (2) It now issues one listTracesForEpisodes query per source trace (via traceEpisodeContext), so a policy with N evidence traces performs N queries per recompute. listTracesForEpisodes(userId, episodeIds[]) accepts a batch, so collect the unique episode IDs once and query a single time.

💡 Suggested Change

Before:

  private l2GainReferenceTraces(sourceTraces: TraceMeta[], _userId: string): TraceMeta[] {

After:

  private l2GainReferenceTraces(sourceTraces: TraceMeta[]): TraceMeta[] {

19. Memory/src/service/evolution/l2-extraction-pipeline.ts (L374)

A request_failed attempt is pushed onto attempts before the model call, so it also counts against the attempts.length < 3 correction budget. Three transient LLM/network failures therefore end in L2ExtractionExhaustedError (mapped to dead_letter by worker-runner) with diagnostic === undefined, so the message claims the correction budget was exhausted although no decision was ever rejected, and l2ProcessingState then classifies it as invalid_model_output. Suggest excluding request failures from the correction budget (e.g. count only invalid attempts against the limit).


20. Memory/src/service/evolution/l2-extraction-pipeline.ts (L336-L338)

Re-validating the persisted previous.operations happens outside the try/catch that turns validation failures into a correction attempt. The throw is a plain L2ExtractionValidationError (not L2ExtractionExhaustedError), so the worker retries, every retry recomputes the same snapshot key (hash of the unchanged input) and throws again, and an explicit recovery round re-hits it before any new model call. Suggested fix: catch the failure here and discard the unusable snapshot decision (start a fresh round) instead of letting the error escape.


21. Memory/src/service/evolution/l2-extraction-pipeline.ts (L384)

The lesson schema is now exported as L2_LESSON_FIELDS (and imported in this file), but this unchanged-revision check still hardcodes its own copy of the six field names — as does prepareRevision below. Prompt, validator and these checks can drift apart, silently accepting an unchanged revision or rejecting a changed one. Use L2_LESSON_FIELDS for the check above (and in prepareRevision).


22. Memory/src/service/evolution/l2-extraction-recovery.ts (L82-L83)

errorCode is derived by matching raw lastError text, using a nested ternary. Rewording any thrown message (e.g. the new "task changed during experience recovery") silently reclassifies the failure, and nested ternaries are hard to read. Suggest persisting a structured error code when dead-lettering, or at least extracting a named classifier function using if/else on stable codes.


23. Memory/src/service/evolution/l2-extraction-recovery.ts (L93)

getEpisode can legitimately return undefined (assertL2RecoveryCurrent already treats that as stale). The non-null assertion turns a concurrently deleted episode into a TypeError inside the transaction (surfacing as a 500) instead of a normal non-retryable state. Add an explicit guard.

💡 Suggested Change

Before:

    const current = deps.repos.runtime.getEpisode(episode.id)!;

After:

    const current = deps.repos.runtime.getEpisode(episode.id);
    if (!current) return { episodeId: episode.id, state: "blocked", pendingCount: 0, canRetry: false, accepted: false };

24. Memory/src/service/evolution/l2-extraction-contract.ts (L64)

path is computed per operation (operations[${index}]) but several operation-level errors report the literal "operations" instead (here, invalid L1 IDs, unknown/stale target, duplicate/conflicting operations). Those diagnostics cannot point at the offending array element, weakening the correction feedback sent back to the model. Use path for per-operation failures.

💡 Suggested Change

Before:

    if (!isRecord(raw)) throw new L2ExtractionValidationError("l2 extraction: invalid operation", { code: "invalid_decision", path: "operations" });

After:

    if (!isRecord(raw)) throw new L2ExtractionValidationError("l2 extraction: invalid operation", { code: "invalid_decision", path });

25. Memory/src/service/evolution/negative-experience-pipeline.ts (L123)

A non-actionable LLM draft is a normal outcome (generic guidance / low confidence, see isActionableNegativeExperience), but when a previous contribution exists this is converted into a thrown error. The job then fails and is retried up to maxAttempts (3) and finally marked failed, leaving the stale record untouched and generating failure noise. A malformed/generic draft should be logged and treated as "keep existing record" (or retried with backoff) instead of failing the job deterministically.


26. Memory/src/service/evolution/negative-experience-pipeline.ts (L198)

The merged record's representative fields (title, experience_type, policy_confidence, evidence_strength, salience, source_basis, signature) are taken from the last entry of an object whose key order depends on insertion/deletion history (e.g. delete oldContributions[attributableLegacy[0]]). When the current event already had a contribution, contributions[eventKey] = ... keeps its old position, so last may be a stale, unrelated contribution while the memory key was just derived from the new draft's signature. Pass the contribution being written explicitly (or sort deterministically, e.g. by inputHash/sourceEventIds) instead of relying on rows[rows.length - 1].


27. Memory/src/service/evolution/negative-experience-pipeline.ts (L199)

last.episodeId can come from a synthesized legacy: contribution built out of policy.source_episode_ids[0] (contributionMap), i.e. an episode that may have been purged. The non-null assertion then throws a TypeError inside the caller's transaction, rolling back the memory write after the caller already retired/split records. Handle the missing episode explicitly (fall back to the previous row / skip the write and log) instead of asserting.


28. Memory/src/service/evolution/negative-experience-pipeline.ts (L232)

negative_contributions stores the full prose of every source (title, trigger, antiPattern, preference, procedure, verification, boundary, sourceTraceIds, ...) and is never bounded, unlike the maxSourceIds/maxPreferences/maxAntiPatterns caps applied to the derived arrays. A long-lived policy accumulates unbounded row/payload size (this object is also written into every change record snapshot). Consider capping retained contributions (e.g. keep the N most recent and fold the rest into aggregate fields).

💡 Suggested Change

Before:

        negative_experience_sources: distinct(rows.map(row => row.source)), negative_contributions: contributions },

After:

        negative_experience_sources: distinct(rows.map(row => row.source)),
        negative_contributions: Object.fromEntries(Object.entries(contributions).slice(-config.maxSourceIds)) },

29. Memory/src/service/evolution/negative-experience-pipeline.ts (L226)

The rendered body uses the uncapped antiPatterns.join("\n") while info.policy.decision_guidance.anti_pattern uses the capped slice, so the memory value and the stored metadata diverge (and the value can grow without limit). Use the same capped array for both, and filter(Boolean) so empty contributions do not inject blank lines into trigger/procedure/verification/boundary.

💡 Suggested Change

Before:

      value: renderNegativeExperienceBody({ ...policy, antiPattern: antiPatterns.join("\n"), confidence: last.confidence }),

After:

      value: renderNegativeExperienceBody({ ...policy, antiPattern: policy.decision_guidance.anti_pattern.join("\n"), confidence: last.confidence }),

30. Memory/src/service/evolution/negative-experience-pipeline.ts (L215)

Dead code left behind by the rewrite: the private findExisting() method (only used by the removed code) and the module-level cappedDistinct() helper are no longer referenced anywhere, and deps.upsertEvolutionMemory is no longer used by this pipeline either. Please remove them / narrow the dep interface so the pipeline does not keep an unused injection point.


31. Memory/src/service/evolution/negative-experience-pipeline.ts (L28)

These three imports are declared after the runtime statement const pipelineLogger = createMemoryLogger("pipeline") (plus a stray extra blank line). Import declarations should be hoisted to the top block with the other imports to avoid import/first lint violations and confusing module evaluation order.


32. Memory/src/service/evolution/reward-pipeline.ts (L183)

The skip branch enqueues skill_cluster_assign without a dedupeKey, and the skip path (unlike the scored path) never persists meta.rewardInputRevision, so the guard at the top of applyReward can never short-circuit it. Every redelivered/duplicated reward job for a skipped episode therefore enqueues another cluster-assignment job. Add a dedupe key tied to the episode generation/reward reason (and/or store a skip marker) to keep this idempotent.

💡 Suggested Change

Before:

        if (this.deps.repos.runtime.getSkillClusterForEpisode(savedEpisode.id)) {

After:

        if (this.deps.repos.runtime.getSkillClusterForEpisode(savedEpisode.id)) {
          // dedupeKey keeps redelivered reward jobs from stacking cluster assignments.
          this.deps.enqueueJob({ jobType: "skill_cluster_assign", userId: savedEpisode.userId,
            sessionId: savedEpisode.sessionId, episodeId: savedEpisode.id,
            dedupeKey: `skill_cluster_assign:reward_skipped:${savedEpisode.id}:${savedEpisode.meta.processingGeneration ?? 0}`,
            payload: { reason: "reward.skipped" }, createdAt: savedEpisode.updatedAt });

33. Memory/src/service/feedback/feedback-experience.ts (L1677)

Building the revision event id with JSON.stringify([event.id, feedback.id]) leaks JSON punctuation into a durable identifier that is also prefixed with the content revision inside revisePolicyFeedback (feedback:<id>), and makes the stored history hard to inspect/compare. Prefer the stableHash-based key convention used by the other pipelines (e.g. stableHash(recall-feedback:${event.id}:${feedback.id})).


34. Memory/src/service/evolution/policy-induction.ts (L161-L165)

This reload re-runs, for every signature in the loop, a 2000-row listPendingCandidatePool scan plus getMany hydration plus full eligibility re-validation, and isTraceEligibleForL2 → isAcceptedSuccessEvidence → traceOriginIsCurrent now performs several runtime lookups per trace (resolveL1Source, getRawTurn, getSession, getEpisode). With a restored pool of many signatures this is O(signatures × pool) queries/rows instead of the single pass done above (lines 135-147). Freshness before persisting is already guaranteed by the transaction guard at lines 361-369 (version/updatedAt/episode re-check, throws on drift), so this per-iteration full re-scan is largely redundant. Consider refreshing only the current signature's candidates (or a per-job eligibility cache invalidated for the current bucket).


35. Memory/src/service/evolution/policy-induction.ts (L665-L667)

listChanges(memory.userId, -1, undefined, undefined, memory.id) uses LIMIT -1, i.e. it loads the entire change log of this policy. Each memory_change_log row stores full before/after memory snapshots, and recomputePolicyStats now runs inside repos.transaction(...) (line 637), so this unbounded read + hydration happens while holding the write transaction on every association of a policy that carries a manual checkpoint. Bound the read (e.g. a limit or a change_type IN ('unified_l2_supported','policy_stats_update') filter) and prefer doing it before opening the transaction.


36. Memory/src/service/evolution/policy-evidence.ts (L10-L15)

policyUsesSpecialEvidence moved the "special evidence" decision from per-trace (stringArray(rawPolicy.special_source_trace_ids).includes(trace.id)) to policy level: now any non-empty special_source_trace_ids makes the whole lesson special. For records that mix ordinary and special sources (addSupport only appends non-ordinary routes to special_source_trace_ids, so legacy/schemaVersion<2 rows can hold a partial list), isCurrentPolicyEvidence stops applying isAcceptedSuccessEvidence (i.e. policy_eligible !== false and value >= minTraceValue) to their ordinary sources. Those low-value/rejected traces can then count as valid support/gain evidence. If the intent is only to decide the semantics of the lesson, the per-trace gate should still be preserved (or the special list should be required to cover the trace).


37. Memory/src/service/evolution/policy-evidence.ts (L72-L73)

The non-null assertion on policyMetaFromMemory(memory) will throw a TypeError for a row without an L2 policy payload (e.g. a non-L2 row or partially migrated policy), and this exported helper is mapped over rows by callers (reconcileOrphanedPolicies, previewPolicyEvidenceReconciliation) without re-checking. Since every downstream check already tolerates a missing meta, return an empty snapshot rather than crashing the worker job.

💡 Suggested Change

Before:

  const policy = policyMetaFromMemory(memory)!;
  const links = repos.runtime.listTracePolicyLinks({ l2MemoryId: policy.id, limit: -1 });

After:

  const policy = policyMetaFromMemory(memory);
  if (!policy) return { links: [], linkedTraceIds: new Set<string>(), sourceTraces: [], validTraces: [] };
  const links = repos.runtime.listTracePolicyLinks({ l2MemoryId: policy.id, limit: -1 });

38. Memory/src/service/evolution/l2-extraction-recovery.ts (L112-L113)

before is the pre-retry state, so spreading it into the accepted response carries the previous job's errorCode (e.g. invalid_model_output) into a response that reports state: "queued". Clients using errorCode to show a failure reason will keep showing a stale error while the new job is running. Override/clear errorCode on the accepted path.

💡 Suggested Change

Before:

    if (!jobs.length) return { ...l2ProcessingState(deps.repos, current, deps.enabled), accepted: false };
    return { ...before, state: "queued", canRetry: false, accepted: true, jobId: jobs[0]!.id };

After:

    if (!jobs.length) return { ...l2ProcessingState(deps.repos, current, deps.enabled), accepted: false };
    const { errorCode: _previousError, ...queued } = before;
    return { ...queued, state: "queued", canRetry: false, accepted: true, jobId: jobs[0]!.id };

39. Memory/src/service/evolution/l2-candidate-service.ts (L180-L184)

traceOriginIsCurrent already calls repos.runtime.resolveL1Source(trace.id) internally (plus raw/session/episode lookups), and this line resolves the same L1 again. Since readSource runs for every pending candidate on each listL2Candidates call (including the repeated calls inside extraction and fallback persistence), each candidate now costs two full provenance resolutions. Consider resolving once and passing the origin into the provenance check (or deriving episodeId from the already-validated origin).


40. Memory/src/service/evolution/negative-experience-pipeline.ts (L350)

Inconsistent evidence identity between the two modes. materialize() now explicitly rejects a queue attempt as an evidence identity (if (!sourceEventId) return; // A queue attempt is not an evidence identity.), but the unified path still builds signal.eventId as text(job.payload.sourceEventId) ?? job.id. For jobs enqueued without sourceEventId (e.g. retried/legacy negative jobs) each queue attempt therefore produces a different candidate eventId, so the candidate snapshot and the downstream induction payload are no longer reproducible for the same evidence. Derive the fallback from the evidence itself (episode/feedback/repair id) or skip the job, mirroring materialize().


41. Memory/src/service/evolution/reward-pipeline.ts (L374-L376)

The deferred value-distribution repair is deduped on rewardInputKey, which only covers the episode content revision, the feedback fields and the reward config — it does not include the trace values/alpha that the repair decision actually depends on (maybeCreateValueDistributionRepair compares highValueMemories/lowValueMemories). Because enqueueJob persists the dedupe key, a later reward pass that re-scores the same episode content/feedback but with different back-propagated trace values (e.g. rewardDirty caused by other traces, afterRewardRepair re-runs) will be coalesced into nothing and the divergence check is silently skipped. Include the repaired trace's value/alpha (or a scoring-pass identifier) in the dedupe key.


42. Memory/src/service/worker/job-handlers.ts (L460)

enqueueJob builds the reward dedupe key as ${evolutionJobDedupeKey(input)}:generation:${generation} (with generation read fresh via getEpisode(input.episodeId)?.meta.processingGeneration), but this check reconstructs that string by hand and derives the generation from the caller-supplied episode snapshot. Two risks: (1) if the passed record is stale (e.g. enqueued after a reopen), the lookup targets a non-existent key, so an active reward job is missed and the payload gets merged/duplicated; (2) the key format is duplicated in two places, so any future change to the suffix silently disables this guard. Please factor the key into a shared helper (e.g. rewardDedupeKey(repos, episodeId)) that reads the current generation, and use it in both places.


43. Memory/src/service/worker/job-handlers.ts (L239-L240)

evolutionJobDedupeKey(input) can return undefined (e.g. l2_association/span_big_turn enqueued without targetMemoryId), and revision is truthy for every revisioned job that has an episodeId. In that combination this template produces the literal key "undefined:<hash>", which would make unrelated jobs of the same type collapse onto one row via the dedupe/merge logic in enqueueJobInTransaction. Compute the base key first and only append the revision when it exists.

💡 Suggested Change

Before:

    dedupeKey: dedupeRevision ? `${input.dedupeKey ?? evolutionJobDedupeKey(input)}:${dedupeRevision}`
      : input.dedupeKey ?? evolutionJobDedupeKey(input),

After:

    dedupeKey: (() => {
      const base = input.dedupeKey ?? evolutionJobDedupeKey(input);
      return base && dedupeRevision ? `${base}:${dedupeRevision}` : base;
    })(),

44. Memory/src/service/worker/worker-runner.ts (L1175)

Skipping a stale job here relies on instanceof for a class that lives in evolution/l2-extraction-contract.js. Note that L2ExtractionExhaustedError is thrown from a different module graph path than the worker (l2-extraction-pipeline), so if the runtime ever loads duplicate copies of the contract module (bundled/duplicated package builds), instanceof will be false and the exhausted extraction error will be retried instead of dead-lettered. Consider a stable marker (e.g. error.name/a code field) as an additional check, or verify the bundler guarantees a single module instance.


45. Memory/src/service/evolution/skill-cluster-pipeline.ts (L521-L523)

refreshClusterFeatures runs inside the assignment write transaction and now calls processedFingerprint for every member, and processedFingerprint → packEpisode → listRawTurnsByEpisode(id, -1), i.e. it loads and hashes all raw turns of every member (LIMIT -1 disables the limit). Combined with the episodeInputRevision calls (which also hash all turns per member, several times per job via clusterInputRevision) this turns a single assignment into O(members × turns) work while holding the write transaction, which can block other writers / hit busy timeouts on large clusters. Consider computing the fingerprints from the already-loaded features plus a cheap turn-count/revision marker, or moving the fingerprint recomputation outside the transaction.


46. Memory/src/service/evolution/skill-cluster-pipeline.ts (L240)

Early-returning here skips the skip_unknown_only / skip_no_success_anchor / llm_disabled handling below, so a cluster with no new episodes no longer records its reject reason in the meta-skill nor refreshes processedEpisodeIds. If evidence for a processed episode changes without a re-assignment (which is what clears processedEpisodeIds and clusterProcessedFeatures), the previously produced Skill is never rebuilt and the rejection/rebuild signal is lost. Consider keeping the previous behaviour (still call updateMetaSkill/markProcessed) while only skipping the LLM generation.


47. Memory/src/service/evolution/skill-pipeline.ts (L103)

listSkillsByPolicySource has no owner filter (it only matches source_policy_ids), so replacing the previous userId: source.userId listing plus the row.userId !== ... checks with skillDependencyScopeMatches removes owner isolation: l2ComparisonScope normalizes the owner to DEVICE_MEMORY_OWNER, so a policy owned by a different user with the same project/profile scope can now suspend or rewrite another user's Skill. l2SharesComparisonScope already encodes the intended "same owner or device bridge" rule and would keep the previous guarantee while still allowing device-owned rows.

💡 Suggested Change

Before:

      if (!skill?.sourcePolicyIds.includes(policyId) || !skillDependencyScopeMatches(source, memory) || skill.status === "archived" || isReadOnlySkillMemory(memory)) continue;

After:

      if (!skill?.sourcePolicyIds.includes(policyId) || !l2SharesComparisonScope(source, memory) || skill.status === "archived" || isReadOnlySkillMemory(memory)) continue;

48. Memory/src/service/trials/skill-trial-resolver.ts (L171)

previous is taken from the live row but next is derived from memory, which may be the detached recoveredMemory snapshot. The subsequent this.deps.repos.memories.update(...) is an unversioned blind write, so any concurrent edit/policy revision applied to the skill row after the recovery scan (or a row deleted in the meantime, where the ! assertion yields undefined and appendChange records before: undefined) is lost. Prefer updateIfVersion against the live row's version and abort/retry when it moved.


49. Memory/src/service/evolution/skill-pipeline.ts (L28)

stableStringify is imported but never used anywhere in this file (only stableHash is referenced), which is dead code and will be flagged by lint/noUnusedLocals.

💡 Suggested Change

Before:

import { stableHash, stableStringify } from "../../utils/id.js";

After:

import { stableHash } from "../../utils/id.js";

50. Memory/src/service/worker/job-handlers.ts (L260)

A stale job now returns here without any signal, and runLeasedWorkerJob treats the returned promise as success (completeLeasedWorkerJob), so dropped jobs are recorded as succeeded in job change history, workerLogger.info("job.succeeded") and the succeeded counter. Stale skips therefore look identical to real executions, which makes diagnosing "my reward/span job never ran" very hard. Consider emitting a distinct signal (e.g. a job.stale_skipped log/change and a skipped metric) instead of an unqualified silent return.


51. Memory/src/service/evolution/big-turn-span-pipeline.ts (L150-L151)

retireSourceSpans already rewrites source.properties.internal_info.trace.span_ids to keepIds (and bumps the source version), and then linkSpansToSourceTrace writes the very same span_ids value again and appends another span_links_updated change entry. Every span run therefore does two source updates/version bumps and emits a duplicate changelog row for the same logical write (also in the retire branch at line ~108). Pass the span ids with a single write (or make retireSourceSpans skip the trace write when the caller will link right after).


52. Memory/src/service/evolution/episode-revision.ts (L64-L65)

If any enqueue site ever stamps payload.episodeRevision on a job type that is not in REVISIONED_JOBS (e.g. a legacy/renamed type), jobEpisodeRevision returns undefined, so this comparison is always false and the job is silently skipped forever instead of running or failing loudly. Treat a missing computed revision as "cannot verify" (return true, or throw) instead of "stale".

💡 Suggested Change

Before:

  return typeof job.payload.episodeRevision !== "string"
    || job.payload.episodeRevision === jobEpisodeRevision(repos, job);

After:

  const current = jobEpisodeRevision(repos, job);
  return typeof job.payload.episodeRevision !== "string" || current === undefined
    || job.payload.episodeRevision === current;

53. Memory/src/service/evolution/episode-revision.ts (L6)

episodeInputRevision hashes every raw turn, every trace's internal_info.trace and every feedback row of the episode, and it is invoked up to three times per span job (once in jobRevisionIsCurrent, once to capture inputRevision, once in the commit check) plus once per reward/association/induction job. On long episodes this is an O(turns + traces) JSON+sha256 pass per job. Consider caching the revision per (episode, generation) inside the current transaction/job execution and reusing it for the pre-write and commit checks.


54. Memory/src/service/evolution/revision-stats.ts (L147)

Nested ternary (violates the project rule against nested ternaries, and hard to read): the outer checkpoint/feedback branches already guarantee a SkillStatus, so this can be simplified to a single expression.

💡 Suggested Change

Before:

        currentStatus: state.status === "active" ? "active" : state.status === "archived" ? "archived" : "candidate"

After:

        currentStatus: state.status === "archived" ? "archived" : state.status === "active" ? "active" : "candidate"

55. Memory/src/service/evolution/revision-stats.ts (L531-L533)

This condition mixes && and || without parentheses, so the actual grouping is (isPolicyUpdate && (...)) || (event.type === "policy" && ...) and depends purely on operator precedence. Please parenthesize the two alternatives so the disabled-event rule is explicit and cannot be broken by a later edit.

💡 Suggested Change

Before:

      if (isPolicyUpdate(replacement) && (replacement.input.evidence.length === 0
        || event.type === "policy" && Boolean(replacement.duplicateOf))
        || event.type === "policy" && replacement.type === "checkpoint" && Boolean(replacement.automaticSupport)) event.disabled = true;

After:

      const evidenceGone = isPolicyUpdate(replacement) && (replacement.input.evidence.length === 0
        || (event.type === "policy" && Boolean(replacement.duplicateOf)));
      const automaticCheckpoint = event.type === "policy" && replacement.type === "checkpoint"
        && Boolean(replacement.automaticSupport);
      if (evidenceGone || automaticCheckpoint) event.disabled = true;

56. Memory/src/storage/repositories.ts (L772)

This guard drops the manual-archive marker whenever a persisted Skill row has status !== "archived", but MemoryRepository.archive() only sets properties.status and skill_manually_archived — it never syncs internal_info.skill.status. Any automatic writer that re-derives the status from skillMetaFromMemory() (which reads internal_info.skill.status, still "active") can therefore persist status: "active" for a user-archived skill and this branch silently un-archives it (also flipping history.externallyArchived to false). Consider treating skill_manually_archived (or skillMetaFromMemory().status === "archived") as authoritative here, or keeping internal_info.skill.status in sync inside archive().


57. Memory/src/service/evolution/skill-cluster-pipeline.ts (L519-L520)

The running centroid uses the array index as memberCount for mergeCentroid, but mergeCentroid returns early (if (!incoming?.length) return current;) for rows without a queryVec while the index keeps advancing. Whenever any member has a null vector the denominator is too large, e.g. rows [A, null, B] yield (A*2 + B)/3 instead of (A + B)/2, skewing the centroid used for later cluster-assignment decisions. Track how many vectors have actually been merged.

💡 Suggested Change

Before:

    let centroid: number[] | null = null;
    rows.forEach((row, index) => { centroid = mergeCentroid(centroid, row.queryVec, index); });

After:

    let centroid: number[] | null = null;
    let merged = 0;
    rows.forEach(row => {
      centroid = mergeCentroid(centroid, row.queryVec, merged);
      if (row.queryVec?.length) merged += 1;
    });

58. Memory/src/service/evolution/skill-cluster-pipeline.ts (L411)

clusterInputRevision hashes episodeInputRevision for every member, and episodeInputRevision now loads all raw turns (listRawTurnsByEpisode(id, -1)) plus every L1 trace/feedback per member. A single evolveCluster run calls it four times (line 206, after generation at line 326, and twice inside updateMetaSkill), so the cost is O(4 × members × full raw-turn scans) per job, all of it re-reading and re-hashing unchanged rows. Consider computing the revision once per job and passing it down (or deriving it from stored revision/version markers) instead of recomputing it at every guard point.


59. Memory/src/service/trials/skill-trial-resolver.ts (L238-L242)

When the verdict is unchanged but the attribution differs (typical for an episode-level reward pass, where input.feedbackId is undefined while the trial already has an implicit feedback id), execution falls through and updateSkillTrial rewrites the row with feedbackId: undefined and a fresh resolvedAt. That silently erases the original feedback attribution and settlement timestamp on every reward pass, and it also removes the attribution that the explicit-feedback guard above relies on. Only skip on identical attribution, or preserve the existing feedbackId/resolvedAt when input.feedbackId is absent.


60. Memory/src/service/evolution/episode-revision.ts (L20)

The includeReward branch hashes the whole rewardDetail object, which contains volatile derived values written by every scoring run (scoredAt, traceCount, trigger, phase, axes). The docstring states the revision deliberately excludes derived scores and timestamps. As a result, a redundant/repair reward run that produces identical content but a new scoredAt changes the revision and silently discards in-flight span_big_turn / negative_experience (source episode_reward) / l2_association jobs even though the episode content did not change. Consider hashing only episode.rTask plus the stable reward inputs (e.g. feedback axes/polarity) and excluding timestamp/derived metadata.


61. Memory/src/service/evolution/big-turn-span-pipeline.ts (L424-L427)

Unlike linkSpansToSourceTrace, this final source-trace update (span_ids rewrite) is not followed by runtime.appendChange, so the Trace's span_ids mutation never appears in the change log for callers such as the reward pipeline that invoke retireSourceSpans directly; change-log driven consumers will keep showing stale span links. Also note updatedAt is set to at (the job's createdAt), which can move the trace's updatedAt backwards when a stale job runs. Please either append the corresponding change record here or drop the duplicate write in the caller path.


🧹 Filtered 1 low-confidence OCR finding(s) before posting/fix-loop (duplicate: 1).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

⚠️ Automated Test Results: ENV ISSUE

The test environment encountered an issue that requires manual attention.

Details: Executor error: Configured directory does not exist: AgentSourceCore
Branch: fix/memmy-647-episode-reprocessing-v127

Tested source: e6f180a4028089678089963d12477a732df2d66d
Tested base: 8c13f583f5cf542d1ca429fd85eb7eb641e5b53c
Tested commit: e6f180a4028089678089963d12477a732df2d66d
These results apply only to this immutable source/base snapshot.

|| !rawTurn || rawTurn.toolCalls.length < SPAN_BIG_TURN_MIN_TOOL_CALLS)) {
retireSourceSpans(this.deps.repos, saved.id, [], at, this.deps.namespaceIdFromMemory);
}
if (payload.downstreamScheduled !== true && savedTrace && this.deps.isTraceEligibleForL2(savedTrace)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Episode 重开后被判失败,旧的 Policy 和 Skill 统计贡献没有撤回

问题

一个 Episode 首次关闭时获得正奖励,已经计入某条 Policy(归纳经验)的支持数和关联 Skill 的可信度 η;继续该任务、重开并再次关闭后,如果它被判失败,旧的正向贡献仍然保留。本轮补充测试预置三个来源及其已有关联,再通过 completeTurn、任务选择、自动关闭和真实 worker 执行成功→重开→失败,未手动排入奖励或关联任务。Episode 奖励从 0.9 变为 -0.9,原 Trace(回合记录)的 value 降为约 -0.4385,但 Policy 支持数仍为 3,未降到剩余两个有效来源对应的 2;gain 和 Skill η 也保持原值。目标 base 同样复现,属于本次来源替换的修复遗漏。

原因

奖励写回后,这里只为仍满足 L2 证据门槛的 Trace 排入 l2_association。失败来源已经低于门槛,原来的 Trace–Policy 关联虽然还在,却没有任务重算已保存的统计;仅补排现有任务也不够,关联入口 (line 480)还会因相同资格检查直接返回。此外,统计重算 (line 756)在支持数归零时跳过 Skill 数值回放,最后一份有效证据被撤回的情况也需要一起处理。

建议做法

奖励变化时,根据已有 Trace–Policy 关联重算受影响的经验,使不再合格的来源能撤回旧贡献,并继续保留其他 Episode 的贡献。同步重算关联 Skill 的 η,处理支持数归零后的状态,同时保留后续 trial 和人工检查点。补充正常成功→重开→失败、最后来源失效、失败后恢复成功及仍成功时重复处理的回归,验证支持数、gain、η 与仅按最终有效证据处理一次一致。

Integrate current v1.2.7 while retaining unified extraction and content revision guards. Recompute existing legacy policy consumers on reward changes, replay zero-support and restored contributions, and cover real lifecycle transitions.
.filter((link) => {
const target = this.deps.repos.memories.get(link.l2MemoryId);
return target && link.relation === l2SupportRelation(target);
return target && (this.deps.config.algorithm.l2Induction.mode === "legacy"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

切换到 unified 后,旧关联来源改判失败仍保留成功贡献

问题

说明场景:已有一条由两份成功 Episode 支持的 Policy(可复用经验),第三份 Episode 通过旧版关联流程加入它;随后服务切换到当前默认的 unified 模式。第三份 Episode 被重新打开、补充对话并再次关闭,这次判为失败。预期撤掉第三份 Episode 的贡献,保留另外两份;实际支持数仍为 3,Policy gain 和关联 Skill 的 η 也保持旧值。

本轮用隔离 SQLite、真实关联 worker 和公开的 completeTurn、reloadConfig 入口复现了这个顺序,模型和向量使用替身。第三份来源的关联由产品代码生成,类型为 matches_signature;改判后 Trace value 已为负,支持数仍为 3。保持 legacy 的相邻对照则正确降为 2。准确 base 也存在此问题,因此这是本次修复的兼容性遗漏,不是新引入的回归,也不涉及批量清理历史数据。

原因

旧版 Policy 关联流程 (line 454) 写入 matches_signature 或 similar_pattern。这里在 unified 模式下只接受当前 l2SupportRelation 返回的 supports/supports:rN,把这些仍在贡献的旧关联排除在受影响 Policy 集合之外。新的失败奖励已保存,但该 Policy 没有进入后续重算,所以旧统计和 Skill 贡献保留下来。

建议做法

在本次来源重新评分时,按 Policy 的记录格式和当前有效来源判断需要重算的消费者,兼容仍有效的旧关联类型;同时保留新版内容修订的关联隔离,避免让旧正文的支持重新生效。用“两份原有支持+第三份真实关联 → 切换 unified → 第三份重开后改判失败”验收,检查支持数变为 2、其来源退出统计、gain 和 Skill η 按剩余贡献重算,并覆盖不切换模式和新版 supports:rN 的对照。

const linkedTraces = allTraces.filter((trace) => linkedTraceIds.has(trace.id));
const evidenceTraces = linkedTraces;
if (evidenceTraces.length === 0) {
if (unifiedEvidence && evidenceTraces.length === 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unified 撤掉最后一份支持时,没有撤回 Skill 的 η 贡献

问题

说明场景:unified 模式正在使用一条旧格式的成功经验及其关联 Skill。这条经验最后一份有效成功来源被重新打开、再次关闭并改判失败。预期该来源退出 Policy 统计,同时撤回它此前对 Skill η(可信度数值)的影响;实际 Policy 支持数已从 1 变为 0、状态变为 quarantined,Skill η 却仍为 0.752。

本轮通过公开完成对话、Episode 归属和自动关闭流程、真实 worker 与隔离 SQLite 复现,初始 Policy/Skill/supports 关联由测试夹具准备,模型和向量使用替身。Skill 本轮贡献前的 η 为 0.8,成功处理后为 0.752;失败后 unified 仍为 0.752,legacy 对照已恢复到 0.8。准确 base 同样保留 0.752,属于上轮问题仍未修完的边界。此结论限定于已验证的旧格式成功经验,不要求把新版负经验的有效证据按成功奖励门槛删除。

原因

新的奖励流程已经请求重算这条 Policy,但此处 unified 的零证据分支保存隔离状态后直接返回,没有执行后面的贡献回放和 onSkillRewardDrift。因此 Policy 已明确没有来源,Skill 中本轮记录的对应贡献却仍有效。此次改动让 legacy 的零证据情况继续回放,但 unified 仍走原来的提前返回。

建议做法

零证据状态也应完成可追溯贡献的撤回,再结束事务:同步更新 Policy 与关联 Skill,保留其他 Policy、trial 和人工检查点的独立影响。对缺乏可验证历史的记录继续采用已有保守策略,不做全库回填。回归覆盖最后一份支持撤回、仍有其他支持、同一来源再次恢复成功和重复执行,断言最终 η 与只保留有效贡献的结果一致。

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

⚠️ Automated Test Results: ENV ISSUE

The test environment encountered an issue that requires manual attention.

Details: Executor error: Configured directory does not exist: AgentSourceCore
Branch: fix/memmy-647-episode-reprocessing-v127

Tested source: 64f0aad508408f73ca68e85497d00024f67064bf
Tested base: 13b493472d5df42df7167216e600cae1c849da67
Tested commit: 64f0aad508408f73ca68e85497d00024f67064bf
These results apply only to this immutable source/base snapshot.

import { byokRuntimeConfig, createMemoryServiceFixture } from "../../../../../Memory/tests/fixtures/memory-service-fixture.js";
import { createHttpMemoryRuntimeClient } from "../../../../frontend/desktop/src/api/memory-runtime-client.js";
import { createHttpMemoryClient } from "../../adapters/outbound/memory-client/http-memory-client.js";
import { createLocalApiServer } from "../../adapters/inbound/local-api/server.js";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

两份新增 HTTP 集成测试导致根级 lint 失败

同一问题还在 desktop-support-contribution.integration.test.ts (line 14)。

问题

执行根目录的 npm run lint 失败。预期两份新增的 HTTP 集成测试也能通过现有代码规则;实际每份各报一个 import/no-restricted-paths 错误,命令退出 1,提示 services 层不能反向依赖入站适配器。

原因

测试放在 src/services/tests,却直接导入 adapters/inbound/local-api/server.js 来启动 HTTP 服务器。仓库 ESLint 的依赖方向规则覆盖这个测试目录,禁止 services 层反向依赖入站适配器,所以新增导入被拒绝。

建议做法

将这两份需要跨层启动服务器的集成测试移到既有的 App/backend/src/tests 等集成测试目录,调整相对导入,保留 renderer client→Backend→Memory 的完整链路断言。不要关闭依赖方向规则或删除原断言。用最终提交的根级 npm run lint 和这两份集成测试共同验收。

panelAnalysis(context?: MemoryRequestContext): Promise<PanelAnalysisOutput>;
panelItems(input: PanelItemsInput, context?: MemoryRequestContext): Promise<PanelItemsOutput>;
panelTasks(input: PanelTasksInput, context?: MemoryRequestContext): Promise<PanelTasksOutput>;
taskExperienceProcessing(taskId: string, context?: MemoryRequestContext): Promise<TaskExperienceProcessing>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

公共测试客户端缺少方法导致类型检查失败

问题

运行目标分支工作流要求的 tsc -p App/backend/tsconfig.plugin-tests.json --noEmit。预期现有插件测试使用的公共 Memory 客户端仍符合接口;实际报 TS2739:App/backend/src/tests/support/mock-memory-client.ts:37 返回的测试客户端缺少 taskExperienceProcessing 和 retryTaskExperienceProcessing,即新增的“查询经验生成状态”和“重试经验生成”方法。

原因

这里将两个新方法设为 MemoryClient 的必选成员。真实 HTTP 客户端已经实现,但公共测试客户端工厂仍只返回旧接口。v1.2.8 的 plugin-host/Teach Host 检查通过独立 tsconfig 收集使用该工厂的测试,因而发现缺少方法。

建议做法

同步公共测试客户端工厂及其契约测试,为查询、重试返回符合当前输出格式约定的数据,保留现有插件和账号相关场景的契约。不要为了绕过检查,随意将产品调用所需的方法改为可选。以目标分支的 plugin tests 类型检查、公共 mock 契约测试和新增恢复接口测试共同验收。

for (const id of episodeIds) {
const episode = this.deps.repos.runtime.getEpisode(id);
if (episode) this.deps.repos.runtime.updateEpisodeMeta(id, {
clusterProcessedFeatures: this.processedFingerprint(episode.meta.clusterFeatures as EpisodeSkillFeatures | undefined)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

技能重建草稿被拒绝后仍记为已处理,再次反馈无法重新生成

相关代码:同文件第 238、338–352 行。

问题

说明场景:Memmy 中已有一份汇总 Excel 的技能,也就是一份可复用的操作说明,当前由两次成功任务支持。调用方后来反馈其中一次任务验收失败,系统准备根据新证据重写这份说明。

如果这次生成的草稿未通过内容检查,新正文就不会保存。预期应保留“重建尚未完成,可以重试”的状态;实际却同时把这份任务证据记为已处理、把生成任务记为成功。之后再次提交相同的失败反馈,系统会跳过生成,数据库中仍保留旧正文和“需要重建”的标记。

原因

草稿校验失败后仍调用 markProcessed,把当前任务内容的校验值保存为“已经处理过”。下一次调度发现内容未变,就保留已处理记录,并在 newEpisodeIds.length === 0 时提前返回,没有检查 direct_evidence_rebuild_required 这个“正文仍需重建”的标记。

因此,数据库实际记录的是“旧正文还在、重建没有完成”,调度代码读取到的却是“这份任务证据已经处理”,导致后续相同反馈无法触发重建。

建议做法

对于需要替换技能正文的任务修订,只有有效正文成功提交后,才能一起保存已处理标记。草稿校验失败时保留待重建记录,并按现有策略记录失败、安排有界重试;相同内容的去重判断也应检查是否仍有未完成的重建。继续保护人工修改、归档、其他任务贡献和技能试用结果。

回归沿用同一场景:先拒绝第一次替换草稿,再让模型替身返回有效草稿,重新提交相同失败反馈。应重新请求生成、成功保存新正文并清除待重建标记;成功后的重复反馈应保持幂等,失败尝试不能被提前记为成功。

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants