Skip to content

Cut the restart resume line's approval note on a code point boundary - #3240

Merged
Birfy merged 1 commit into
ThinkFlowLab:mainfrom
HugoXK:dev/5-approval-note-codepoint
Nov 20, 2026
Merged

Birfy merged 1 commit into
ThinkFlowLab:mainfrom
HugoXK:dev/5-approval-note-codepoint

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Written-by: FlyBot Dev-5
Fixes #3234
Owner: Dev-5
Reviewer: Reviewer
Bot: Dev-5
Tier: T3
Claim-Id: 7df797cc75b043e0bdf73856848e7b85
Branch: dev/5-approval-note-codepoint
Base: ffe6f3d9b8339922e84f0da3531a0e164790fce1 (where the red was measured)
Rebased onto: c0e3a586bf6fb7f7796662a3f200ec34ad7b4d08

What was wrong

core/src/host/approvals.js:85 stored the note a restart quotes back with a bare entry.reason.slice(0, 200) — 200 UTF-16 units, cut wherever the 200th unit landed. Two lines above, :80 already bounds the same kind of text through cut(String(request.reason ?? ''), 500).text. When the cut landed inside a character outside the BMP ('x'.repeat(199) + '😀' is 200 code points, 201 units), the stored note ended in a lone high surrogate U+D83D; core/src/host/resume.js:25 pastes that value into the resume turn the user reads, and the wire flattens it with toWellFormed, so the user saw U+FFFD in the middle of their own reason.

The fix

One line: reason: cut(entry.reason, 200).text. cut (shared with :80's 500 path) flattens first and then moves the window end back onto a code point boundary (core/src/shared/text-boundary.js), so a note never ends on half a pair.

The budget is unchanged and still counts UTF-16 units, on purpose: cut's max is a stored-field unit budget by its own contract, and the 500 path beside it was already using it. What changes is only the boundary: a 201-unit input keeps its 199 units before the emoji and drops the character whole, and a note that fits 200 units comes back byte for byte. No schema change, no new option, :80 untouched.

Red first

On base ffe6f3d9b8339922e84f0da3531a0e164790fce1, with only the new test added (the fix reverted), in a detached worktree of that base:

cd core && TZ=UTC TMPDIR=/tmp node --import ./test/harness-resolve.mjs --test --test-name-pattern='#3234' test/follow-through.test.js
not ok 1 - \#3234: an approval note cut at 200 keeps an emoji whole and never stores half of one
  error: |-
    Expected values to be strictly equal:
    + actual - expected
    + 'xxxx…x\ud83d'
    - 'xxxx…x'
  code: 'ERR_ASSERTION'
  operator: 'strictEqual'
# tests 1
# pass 0
# fail 1

The two values are 199 x each; the actual one carries the trailing \ud83d. The same case at this tip is # tests 1 / # pass 1 / # fail 0, and the whole file test/follow-through.test.js is # tests 20 / # pass 20 / # fail 0 (the control 'x'.repeat(198) + '😀', 200 units exactly, is unchanged and well formed).

Verification at this tip

  • TZ=UTC npm run verify — exit 0 at this tip ff1f0893141a405fc00482acb267cdae67364b8f (tree fef44300): ten suites, 0 failures in each — 3355, 20, 752, 152, 172, 538, 151, 686, 37, 34 tests; arch-docs: OK (5 changed file(s)); ok 10 patches apply cleanly in order; ok patches/ds-bot/ is what generate writes (generate is a no-op).
  • node scripts/ds-bot-patches.mjs check — ok 10 patches apply cleanly in order, ok core/ equals ds-bot/ + patches/ds-bot/; canonical — ok patches/ds-bot/ is what generate writes; git status --porcelain -- core patches changelog.d is empty after generate.
  • node .github/scripts/changelog.mjs check — changelog: 1 fragment(s) in changelog.d/ are well formed (changelog.d/3234-approval-note-codepoint.fixed.md).

Boundaries

  • 无 UI 面 — host-side text storage only; the change is invisible except that a replacement glyph stops appearing in the quoted reason.
  • patches/ds-bot/0001-core-fixes.patch comes from generate; nothing is hand-edited.
  • docs/subsystems/core-host.md carries one sentence in the approvals paragraph, because arch-docs owns core/src/host/approvals.js there and it was red without it at this base.
  • No core/src/client/**, core/client.js, patches/ds-bot/0008, gate files or .github/** touched.

Checkpoint

{
  "pr": 3240,
  "claim": "Dev-5",
  "issue": 3234,
  "summary": "The approval note a restart quotes back was bounded with a bare slice(0, 200), so a reason whose 200th UTF-16 unit fell inside an emoji kept a lone high surrogate and the resume line showed U+FFFD in the user's own text. The note now goes through the cut helper the 500-unit reason bound two lines above already uses, which ends the prefix on a code point boundary while keeping the unit budget and every note that fits it intact. One source line changes; the schema and the second bound are untouched.",
  "files": ["core/src/host/approvals.js", "core/test/follow-through.test.js", "docs/subsystems/core-host.md", "patches/ds-bot/0001-core-fixes.patch", "changelog.d/3234-approval-note-codepoint.fixed.md"],
  "checks": { "ran": "TZ=UTC npm run verify; cd core && TZ=UTC node --import ./test/harness-resolve.mjs --test test/follow-through.test.js; node scripts/ds-bot-patches.mjs check; node scripts/ds-bot-patches.mjs canonical; node .github/scripts/changelog.mjs check", "result": "green", "at": "ff1f0893141a405fc00482acb267cdae67364b8f" },
  "next": "none — ready for review"
}

The restart resume line quotes back the note of an approval a restart dropped, and
the note was kept with a bare slice(0, 200) in UTF-16 units: a reason whose 200th
unit fell inside an emoji kept the lone high surrogate, and the harness flattens it
on the wire with toWellFormed, so the user read a replacement glyph inside their own
reason. Use the same code-point-safe helper the 500 bound two lines above already
uses. The budget stays UTF-16 units, as the helper documents.

Fixes ThinkFlowLab#3234
@HugoXK

HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Written-by: FlyBot Lead

@Birfy — T3 review request at tip ff1f0893141a405fc00482acb267cdae67364b8f (one request at this tip).

  • Base c0e3a586bf6fb7f7796662a3f200ec34ad7b4d08 (red was measured at ffe6f3d9b8, same code). 5 files, +78/−6, draft: false, maintainer_can_modify: true.
  • Scope: core/src/host/approvals.js:85 bounded the approval note a restart quotes back with slice(0, 200), so a cut inside an astral character stored a lone high surrogate and the user saw U+FFFD inside their own reason; the line now goes through cut(), the helper :80 already uses. Plus one sentence in docs/subsystems/core-host.md, a changelog fragment, and one new case in core/test/follow-through.test.js.
  • No UI face: the change is to how a stored note is cut; no rendered row, copy or layout changes.
  • Red first (base, fix reverted): 1 test / 0 pass / 1 fail — expected: 'x'*199, actual: 'x'*199 + '\ud83d'.
  • Green at this tip: the new case 1/1 twice, follow-through.test.js 20/20 twice; full verify exit 0 (core 3355/3355, social 752, arch-docs: OK (5 changed file(s)), ds-bot-patches check ok, canonical no-op).
  • Independent advisory by FlyBot Test at this tip (no writes on the PR): same shape, and cut() probed directly — 'x'*199+'😀' keeps 199 units and isWellFormed() is true, a note that fits 200 units comes back byte for byte.
  • Checks at this tip: 19 runs = 16 success + 2 skipped + 1 failure, the failure being enqueue-guard "no Verifier report names the tip ff1f089".
  • Body carries Fixes #3234, Owner: Dev-5, Reviewer: Reviewer and the checkpoint block.

@Birfy

Birfy commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Verdict: PASS at ff1f089
Written-by: Reviewer
Attestation: ff1f089 role=Reviewer

Ran at this tip:

$ tar xzf ff1f0893141a405fc00482acb267cdae67364b8f.tar.gz -C tip --strip-components=1
$ cd tip/core && TZ=UTC TMPDIR=/data/flybot-tmp node --test test/follow-through.test.js
# tests 20  # pass 20  # fail 0
$ cp ../base/core/src/host/approvals.js src/host/approvals.js && TZ=UTC TMPDIR=/data/flybot-tmp node --test test/follow-through.test.js
# tests 20  # pass 19  # fail 1
$ cd scratch/repo && TZ=UTC TMPDIR=/data/flybot-tmp node scripts/ds-bot-patches.mjs check
$ cd scratch/repo/core && TZ=UTC TMPDIR=/data/flybot-tmp node scripts/build-client.mjs --check
$ cd scratch/repo && TZ=UTC TMPDIR=/data/flybot-tmp node scripts/ds-bot-patches.mjs canonical

Two scratch trees from tarballs: tip/ is this tip alone (suite), scratch/repo holds this tip's head merged onto main 540a307a7a1f44cb570b408850166fc548a61691 (artifact commands). The DSH peers come from the 0.2.1-rc.2 install core/.npmrc keeps out of node_modules (the same version test.yml installs), linked in for the suite.

  • Red first: with only core/src/host/approvals.js swapped back to the base blob and the new test kept, # tests 20 # pass 19 # fail 1; the one failure is #3234: an approval note cut at 200 keeps an emoji whole and never stores half of one — the stored note came back as 199 x plus a lone \ud83d. With the tip's line restored, the same file is 20/20/0.
  • Route: no replay needed. Merging this tip onto current main still leaves the generators canonical — check: ok ds-bot/ = Fei2411/DeepSeek-Bot@2b10c70 (tree 5834c00, v0.1.5), ok 10 patches apply cleanly in order, ok core/ equals ds-bot/ + patches/ds-bot/; build-client.mjs --check exit 0, tree clean; canonical: ok patches/ds-bot/ is what generate writes (generate is a no-op). The merge auto-merged patches/ds-bot/0001-core-fixes.patch without a conflict, so cut 28's rewrite of it and this tip's +42/−4 regeneration do not collide.
  • Scope, from the compare/pulls/3240/files against base c0e3a586: 5 files, +78/−6, all inside the stated change set — core/src/host/approvals.js +1/−1, core/test/follow-through.test.js +33/−0, docs/subsystems/core-host.md +1/−1, changelog.d/3234-approval-note-codepoint.fixed.md +1/−0, and the generated patches/ds-bot/0001-core-fixes.patch +42/−4 (handwritten part: 4 files, +36/−2). No gate file, .github/**, core/src/client/** or 0008 touched.
  • The fix does what it says: core/src/host/approvals.js:85 now bounds the note with cut(entry.reason, 200).text, the helper the :80 500-unit path beside it already used, so a cut inside an astral character drops that character whole instead of storing half a pair that resume.js pasted into the resume turn as U+FFFD. The unit budget is unchanged; a note that fits 200 units is byte-for-byte unchanged (the new case asserts the 'x'.repeat(198) + '😀' control too).
  • tip check-runs (21): tests-ok success, merge-gate success, policy-sign success, plugins/tree/social/timeline/workflow success, judge success, reviewed tip (report only) success, package success; the only failure is enqueue-guard (do not enqueue #3240: no Verifier report names the tip ff1f0893141a), which this comment is the missing piece of. Two live legs are skipped by design (live · ubuntu · Node 24 · real model, window check).
  • Body: Fixes #3234 and the checkpoint block parse clean (1216 characters, no refusal reason). I add the agent-pr label; Owner:/Reviewer: lines are already there.

@Birfy Birfy added the agent-pr Pull request opened by an agent label Nov 20, 2026
@github-actions github-actions Bot added the pass label Nov 20, 2026
@Birfy
Birfy added this pull request to the merge queue Nov 20, 2026
Merged via the queue into ThinkFlowLab:main with commit ff43e06 Nov 20, 2026
22 checks passed
@Birfy
Birfy deleted the dev/5-approval-note-codepoint branch November 20, 2026 03:39
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restart resume line: the approval note keeps a lone surrogate when the 200-unit cut lands inside an emoji

2 participants