Skip to content

fix(lark): preserve image replies in adopted and unified sessions - #1703

Closed
LeonYuanYao wants to merge 4 commits into
masterfrom
fix/adopted-reply-images
Closed

LeonYuanYao wants to merge 4 commits into
masterfrom
fix/adopted-reply-images

Conversation

@LeonYuanYao

@LeonYuanYao LeonYuanYao commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

An adopted Codex final containing a local Markdown screenshot could be visible in the terminal while Feishu rejected the entire reply card with 230099 / 200570: card contains invalid image keys. This change uploads eligible workspace images before rendering and preserves the answer when an image cannot be displayed.

  • Reuse the existing Feishu image upload API for local, non-isolated adopted replies and adopt preambles. Resolve absolute, relative, and file-URL paths within the session workspace; validate the inspected bytes and bound automatic uploads to 8 images of at most 8 MiB each. Cache upload results across delivery retries.
  • Convert unsupported image references into readable descriptions at the shared rendering boundary. Preserve valid image keys, the existing --images / img:N flow, and image syntax inside code examples.
  • Retry only the specific invalid-image-key rejection with an image-free card, including Markdown table cells. Keep the reply body, controls, ownership checks, and delivery identity.
  • Handle unified-card POST and PATCH fallback in the durable publisher. Persist the downgraded final and pending POST before retrying, so recovery and later terminal updates cannot restore rejected images. Unknown POST results retain the same body and UUID.

The shared renderer covers ordinary finals, adopted local turns, and adopt preambles. Existing native image uploads remain supported. Remote, sandbox/read-isolated, API-only, and managed VC sessions do not gain host-file uploads; managed VC retains its audited delivery contract. Tests cover Codex and Claude paths. Local validation ran on macOS; Linux was not exercised.

Validation

The new table and unified-card regression tests failed before the fixes and passed afterward. The following suite passed 14 files / 526 tests:

bun run test -- \
  test/reply-images.test.ts test/lark-image-buffer-upload.test.ts \
  test/md-card-images.test.ts test/md-card.test.ts test/md-card-vega-lite.test.ts \
  test/bridge-final-output-retry.test.ts test/cli-send-image-mode.test.ts \
  test/turn-reply-card.test.ts test/turn-reply-card-runtime.test.ts \
  test/lark-transport-boundary.test.ts test/turn-reply-ask.test.ts \
  test/cli-send-reply-card.test.ts test/daemon-turn-reply-sender-wiring.test.ts \
  test/vc-meeting-im-reply.test.ts
bun run build
git diff --check
  • Full build, type checks, and distribution/asset audits passed.
  • The original failing transcript was rechecked offline against the rebuilt distribution; both the original reply and text-only control produced no unsupported card-image sources.
  • A synthetic JPEG was uploaded through the deployed resolver/upload/render/send path using an absolute workspace path. Feishu accepted the card; message readback contained the real image key, and the downloaded image matched the original bytes.
  • The local daemons were restarted with the repaired build. Both health endpoints returned HTTP 200, and all 8 existing adopted Codex sessions recovered with their original session IDs and CLI processes.

The live check did not trigger a new Codex turn. Invalid-image-key rejection, fallback, and crash recovery were verified offline using simulated provider errors; deliberate rejection/fallback has not been exercised against Feishu.

Visual example

This local illustration is rendered from the current card JSON using fixture keys. It is not a Feishu client screenshot.

Workspace image display and image-free fallback, including table cells

Review follow-up

The filesystem mock in test/reply-images.test.ts now uses a synchronous, typed require('memfs') factory. This removes the Bun await import() mock deadlock that caused the sole native-Bun CI timeout. The file passes 25/25 under Vitest and 25/25 under local Bun 1.3.14; the pinned Bun 1.4.2 also passes 25/25 locally in 429 ms. Production code is unchanged by this follow-up. The optional image-placeholder localization suggestion remains a separate UI follow-up.

yaoyuan.leon added 3 commits October 5, 2026 22:22
Upload bounded workspace images in adopted replies through the existing Lark image API. Preserve code examples and explicit image placeholders, and degrade unresolved images without losing the reply body.

Retry only confirmed invalid-image-key rejections with an image-free card while retaining delivery ownership and UUID semantics. Cover final output, local turns, adopt preambles, and existing image flows with regression tests.
Remove rejected images from native Markdown table cells while preserving text columns and code examples. Apply image fallback at the durable reply-card publisher so POST, PATCH, and later terminal updates share the delivered image-free state.

Persist downgraded pending content before retrying with the same provider UUID, retain ownership and withdrawal checks, and leave managed VC delivery unchanged. Add regression coverage for table fallback, recovery after unknown send results, and Codex and Claude bridge delivery.
@deepcoldy

Copy link
Copy Markdown
Owner

Thanks for the thorough PR — the layered design is solid: the shared render boundary, the heavily guarded workspace upload (lexical + realpath containment, nlink === 1, O_NOFOLLOW, the before/after fstat pinning, bounded 8 MiB × 8), and the narrow three-part rejection predicate with same-UUID replay all check out. We independently verified the production code under both the Node/vitest leg and the Bun leg, ran the full build/audits, and exercised the symlink/directory-symlink/hardlink/../ escapes against a real filesystem — all correctly produce zero uploads while legitimate workspace images upload.

There is one blocking issue, test-only, which is also why the bun-test CI check is currently red:

test/reply-images.test.ts — async vi.mock factory deadlocks under bun test

The file mocks node:fs with an async factory that does await import('memfs'):

vi.mock('node:fs', async () => {
  const { fs } = await import('memfs');
  return { ...fs, default: fs };
});

Under bun test, an await import() inside a mock factory deadlocks: the file prints only the test banner, collects nothing, and is eventually killed. In CI (bun 1.4.2) this is exactly the single failure on the bun-test leg — 1340/1341 files green, this one killed by SIGKILL at the 720 000 ms per-file wall:
https://github.com/deepcoldy/botmux/actions/runs/37328813371/job/111826307824

We reproduced the same hang locally on both bun 1.4.0 and 1.4.2. This repo already documents this trap — see the comment above the node:fs mock in test/write-input.test.ts ("An await import() inside a mock factory HANGS under bun test… require resolves at the same moment for both runners and does not deadlock"). Note the bun-leg static selector cannot detect this shape, so the file is classified as runnable and the hang only surfaces at runtime.

Fix — make the factory synchronous with require, matching the existing convention:

vi.mock('node:fs', () => {
  const { fs } = require('memfs');
  return { ...fs, default: fs };
});

With that change the file passes 25/25 on both legs (vitest and bun test, ~0.4 s). No src/ change is needed — this is purely a test-harness fix.

Non-blocking suggestions (P3)

  • [Image omitted] is a hardcoded English string at src/im/lark/md-card.ts (the two normalizeCardImages/omitReplyCardImages sites). All other user-facing card copy goes through the t() i18n helper (src/i18n/); adding a key would keep Chinese-localized cards consistent. Optional for this PR.

Everything else LGTM — the unified-card persistence-before-retry ordering, ownership re-checks, and the untouched managed-VC path all behave as described.

This is preliminary feedback from an automated review; the maintainer's review remains final.

@deepcoldy deepcoldy closed this in cec5d0f Oct 7, 2026
deepcoldy added a commit that referenced this pull request Oct 7, 2026
#1703 的图片上传回归测试把夹具与工作目录写死为 /tmp/test-sessions;
主干 #1615 将 config.session.dataDir 改为每例独立的 mkdtemp 后,
beforeEach 不再创建该共享目录,干净 CI 上 writeFileSync 夹具 ENOENT,
test(3/3) 上 12 个图片用例红(本机因目录残留而假绿)。

把这些用例的夹具路径、getSessionWorkingDir、ds.workingDir 统一迁到
config.session.dataDir(beforeEach 已按例创建并清理),恢复隔离、
消除对共享残留目录的依赖。纯测试改动,无生产代码影响。

Co-Authored-By: Claude Code <[email protected]>
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.

2 participants