Skip to content

fix(branch-name): strip leading harness envelopes from naming prompts - #34782

Open
kaluli123123 wants to merge 6 commits into
stablyai:mainfrom
kaluli123123:fix/omp-20261028-branch-hook-envelopes
Open

kaluli123123 wants to merge 6 commits into
stablyai:mainfrom
kaluli123123:fix/omp-20261028-branch-hook-envelopes

Conversation

@kaluli123123

@kaluli123123 kaluli123123 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Generated branch names should describe the task the person typed, not hook or system metadata saved before it. Ordinary user XML stays part of the request.

What Changed

Strip complete leading allowlisted harness envelopes at the downstream branch-naming prompt boundary, including nested and mixed-case hook_result wrappers. Recognize attributed source-channel envelopes without stripping bare <channel> user content. Bound channel-prefix classification rather than lowercasing the full remaining prompt.

This is the focused naming-boundary contribution split from #14838 following the maintainer request. Existing #14791 and #14807 concern hook ingestion/classification; this branch handles already-recorded mixed transcript envelopes at the naming boundary and does not replace or close those contributions.

Why

Filtering at prompt construction prevents persisted harness metadata from becoming a branch name without changing transcript ingestion or deleting unknown user tags. A depth-aware tag scan handles nested known wrappers; no new dependency or broad XML parser is introduced.

Linked Issue

#14789

This addresses the downstream naming portion of the reported harness-message problem. It is not a claim that every ingestion or display path is fixed.

Visual Proof

N/A — prompt construction only; no layout or interaction flow changes. The production-module differential smoke reproduces hook metadata in the generated prompt on pinned main and verifies its removal while preserving ordinary XML with this change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Agent-executed macOS arm64 validation at fixed base ee09f979fac61fc5b1db4a528c9e3a20667b796f:

  • Production-module differential smoke: baseline fails on metadata leakage; the fixed source passes and preserves ordinary channel XML.
  • ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --base=ee09f979fac61fc5b1db4a528c9e3a20667b796f --maxWorkers=1 completed: 18 of 19 checks passed. Format, lint, typechecks and ratchets passed. The affected unit-test gate is not green: 22,930 passed, 10 failed, 8 expected failures, 91 skipped.
  • Each of those ten failing assertions was also reproduced with pinned-base production: eight specific PTY admission/materialization assertions, the WSL relay fixture delivery assertion, and the queued-close SQLite indexer assertion. This is exact-assertion baseline evidence, not a claim that the aggregate or all upstream tests passed. No unrelated PTY/SQLite/WSL production code or assertions were weakened.
  • The GitHub-created commit has a Verified/valid signature and tree 7c7b011efd2fdccbd7a702c8ea669a8c69fa2448, exactly matching the local validated tree at 365c946106266a3101b044c3c45f548868164c57. No existing branch history was rewritten.

Full repository tests, packaged builds, real SSH/WSL and Linux/Windows/mobile matrices were not completed. Current-head upstream CI and maintainer review remain gates; local evidence does not establish merge readiness. This PR stays Draft.

Risk

Level: Medium

Incorrect envelope recognition could remove task text or leave metadata in generated branch names for local or remote conversations. Unknown user tags must remain intact. Revert the prompt-boundary change to restore prior naming; already-created branches are not renamed by a revert.

AI Disclosure

AI-assisted implementation and review through OMP. Parent model: openai-codex/gpt-6.1-sol. Jev was unavailable; no model approval is claimed. Agent execution does not substitute for contributor-personal verification.

Review

Shared TypeScript only; no OS-specific command/path, transport payload, permission, or provider API changes. Unknown tags and custom naming guidance remain intact. Prefix recognition is bounded and nested known wrappers are scanned linearly. No new network or filesystem boundary is introduced. GUI quality is N/A; cross-platform and remote execution remain unverified.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Author

GitHub: @kaluli123123. X (Twitter) handle: not provided.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance (agent review above; no personal attestation)
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Current-main integration evidence

Published 9137ac6e7cde410a0840034d68dc903caf5ca029 with normal merge parents 7a122d5e341a0e69965709b4f16cd0d58561e9a8 and frozen main 2195eae58947313781a90ee6aa299a8c31f18d98; force: false. Exact remote tree 7b2100e1c6c82bb2372bbcd34c294212f70da63d and both parents were read back; the PR head matches. Git Database commits are unsigned; no Verified signature is claimed.

Moved harness-envelope stripping into the canonical shared injected-user-turn parser and branch-name prompt owner. Retained bounded handling of leading harness wrappers, literal user content and ownership-layer regressions without restoring obsolete naming-module paths.

The aggregate is not green: 22/23 gates pass; affected units retain 48 observed baseline failures. All 22 static gates passed. After storage recovery, the complete selected affected-unit invocation finished with 10,007 passed, 48 failed and 67 pending tests; all 48 failed file/full-test IDs and normalized first error reasons exactly match the independently run frozen-main persistence-control failure map. The two owning harness/naming suites pass all nine tests. The baseline comparison selects the same previously failing suites, not an identical full affected inventory. Earlier ENOSPC/localization and interrupted-unit records are retained as setup failures, not relabeled green. Persistent local transform caching was disabled through the existing supported runner environment flag; no tests, assertions or retries were changed.

Final ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --base=2195eae58947313781a90ee6aa299a8c31f18d98 --maxWorkers=2 --timeout=30:

check:changed: 5 changed file(s) since 2195eae58947313781a90ee6aa299a8c31f18d98 (2195eae589); running 23 check(s).

This is the selected changed-file contribution gate, not an independent full-repository/native release build. Earlier local results are historical evidence for their named trees, not current-main integration proof. No source conflict was hidden by an obsolete transport/shim or forced ref update.

Exact-head required PR checks passed and applicable real-host/platform/interaction evidence remain separate gates. Upstream permissions are pull-only; only maintainers can approve gated workflows or merge. No real SSH/WSL/phone verification, human manual-testing attestation, or new rendered before/after screenshots are claimed by this integration. No configured SSH hosts are available; no arbitrary or paid hosts were used. The PR remains open and preserves its draft status, if any, pending the actual gates.

Preserve ordinary user XML while removing complete leading known harness wrappers at the downstream branch naming boundary.

Focused split of stablyai#14838; source tree matches the locally reviewed and validated tree.
@kaluli123123

Copy link
Copy Markdown
Contributor Author

Current-main integration evidence

Published 9137ac6e7cde410a0840034d68dc903caf5ca029 with normal merge parents 7a122d5e341a0e69965709b4f16cd0d58561e9a8 and frozen main 2195eae58947313781a90ee6aa299a8c31f18d98; force: false. Exact remote tree 7b2100e1c6c82bb2372bbcd34c294212f70da63d and both parents were read back; the PR head matches. Git Database commits are unsigned; no Verified signature is claimed.

Moved harness-envelope stripping into the canonical shared injected-user-turn parser and branch-name prompt owner. Retained bounded handling of leading harness wrappers, literal user content and ownership-layer regressions without restoring obsolete naming-module paths.

The aggregate is not green: 22/23 gates pass; affected units retain 48 observed baseline failures. All 22 static gates passed. After storage recovery, the complete selected affected-unit invocation finished with 10,007 passed, 48 failed and 67 pending tests; all 48 failed file/full-test IDs and normalized first error reasons exactly match the independently run frozen-main persistence-control failure map. The two owning harness/naming suites pass all nine tests. The baseline comparison selects the same previously failing suites, not an identical full affected inventory. Earlier ENOSPC/localization and interrupted-unit records are retained as setup failures, not relabeled green. Persistent local transform caching was disabled through the existing supported runner environment flag; no tests, assertions or retries were changed.

Final ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --base=2195eae58947313781a90ee6aa299a8c31f18d98 --maxWorkers=2 --timeout=30:

check:changed: 5 changed file(s) since 2195eae58947313781a90ee6aa299a8c31f18d98 (2195eae589); running 23 check(s).

This is the selected changed-file contribution gate, not an independent full-repository/native release build. Earlier local results are historical evidence for their named trees, not current-main integration proof. No source conflict was hidden by an obsolete transport/shim or forced ref update.

Exact-head required PR checks passed and applicable real-host/platform/interaction evidence remain separate gates. Upstream permissions are pull-only; only maintainers can approve gated workflows or merge. No real SSH/WSL/phone verification, human manual-testing attestation, or new rendered before/after screenshots are claimed by this integration. No configured SSH hosts are available; no arbitrary or paid hosts were used. The PR remains open and preserves its draft status, if any, pending the actual gates.

# Conflicts:
#	src/shared/source-control/ai/naming/branch-name-from-work.ts
@kaluli123123

Copy link
Copy Markdown
Contributor Author

Merged current main (075b631fd9d80df5c289118c3c18acc4f3247524) in f3e140b. Main moved harness-injected-user-turns to agent-session/journal/ and added change-based naming (fromChanges). The resolution strips envelopes only from real user prompts; change summaries are only trimmed. Validation: naming and harness tests passed, tc:node/tc:web passed, and the changed-code quality gate passed.

@kaluli123123
kaluli123123 marked this pull request as ready for review November 21, 2026 11:45
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds helpers to strip leading known harness envelopes and extract task text. Hook prompt resolution and explicit-prompt routing use the extracted text. Branch-name prompt generation and command templates use context-selected source text. Tests cover nested, self-closing, mixed-case, attributed, and incomplete wrappers, plus preservation of ordinary user XML. The settings documentation describes envelope removal for branch naming.

Merge Risk: Moderate · up to 1dadb

Branch-name and prompt handling now strip leading harness envelopes. Compact self-closing envelopes, envelopes with odd attribute content, and other consumers of the harness classifier may still mishandle or drop the real task. These are narrow edge cases, so the change should be reviewed and tightened before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: branch-name naming prompts now strip leading harness envelopes. The changeset matches this: stripKnownHarnessEnvelope and branchNameSourceText are added and wired into…
Description check Passed The description follows the template well. It covers ELI5, What Changed, Why, Linked Issue (#14789), Visual Proof (N/A with reason), Testing, Performance, Risk (Medium, with a revert path), AI Disclos…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: branch-name naming prompts now strip leading harness envelopes. The changeset matches this: stripKnownHarnessEnvelope and branchNameSourceText are added and wired into buildBranchNamePrompt, and prompt-fields and provider routing use the new helper. The title is specific and concise, and it follows the conventional commit style.

Full details: Description check

Explanation

The description follows the template well. It covers ELI5, What Changed, Why, Linked Issue (#14789), Visual Proof (N/A with reason), Testing, Performance, Risk (Medium, with a revert path), AI Disclosure, Review, the upstream boundary checkbox, and the checklist. The Performance section is filled in with a substantive statement about bounded prefix classification and linear nested scanning. Two gaps: the Performance line does not finish the template's 'None, because' sentence in a clear way, and the description includes long, status-heavy integration notes that make the Testing section hard to scan. Neither gap makes the description largely incomplete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6fdeeae2-5076-4372-b6e2-236617d84988
Commits

Reviewing files that changed from the base of the PR and between eae932b and 1dadb47.

Files selected for processing: 1

  • src/shared/agent-session/journal/harness-injected-user-turns.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7cdc058b-d6d8-423f-bfa0-64b68b0f1c83
Commits

Reviewing files that changed from the base of the PR and between 075b631 and f3e140b.

Files selected for processing: 5

  • docs/site/content/docs/settings.mdx
  • src/shared/agent-session/journal/harness-injected-user-turns.test.ts
  • src/shared/agent-session/journal/harness-injected-user-turns.ts
  • src/shared/source-control/ai/naming/branch-name-from-work.test.ts
  • src/shared/source-control/ai/naming/branch-name-from-work.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Treat a submitted prompt as harness-only only when nothing but envelope content remains, and store/route the stripped task instead. Also ignore self-closing nested tags when matching envelopes and fill the {{firstPrompt}} branch-name template with the stripped task.
…anch-hook-envelopes

# Conflicts:
#	src/main/text-generation/requests/commit-message-text-generation-regression.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

Major · Keep the trailing task when a turn starts with a harness… · harness-injected-user-turns.ts:15

src/shared/agent-session/journal/harness-injected-user-turns.ts:15
Major · Data Integrity & Integration · Heavy lift

Keep the trailing task when a turn starts with a harness envelope.

Adding hook_result to the known harness tags makes isKnownHarnessInjectedUserTurnText return true for the whole turn. For example, <hook_result>{}</hook_result>\nFix CI config is classified as harness content. Several consumers then discard the whole turn, including the task:

  • native-chat-noise.ts drops the whole message, so the task is removed from native chat.
  • claude-transcript-decoder.ts omits the text of the turn.
  • session-scanner-primary-parsers.ts and session-scanner-codebuddy-parser.ts do not seed the first user prompt from the turn.
  • session-scanner-first-user-prompt.ts returns null for the turn.
  • native-chat-tool-fold.ts and claude-helper-transcript-evidence.ts also treat the whole text as harness content.

Update these consumers to use the task that remains after the envelope, as returned by userTaskTextAfterHarnessEnvelope. A turn that has a trailing task must keep that task visible or available. Classify a turn as harness-only only when no task remains after the envelope.

Minor · Recognize compact self-closing envelopes. · harness-injected-user-turns.ts:3

src/shared/agent-session/journal/harness-injected-user-turns.ts:3
Minor · Functional Correctness · Quick win

Recognize compact self-closing envelopes.

For <hook_result/>\nFix CI config, this matcher rejects / after the tag name. The new task helper returns the raw prompt, and the naming stripper also leaves the envelope intact.

Accept / as a tag-name terminator. Keep the allowlist check so unknown XML remains unchanged.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a2be4ea2-6500-42a2-ac0a-7bb1f19f723f
Commits

Reviewing files that changed from the base of the PR and between f3e140b and 659d213.

Files selected for processing: 8

  • src/main/text-generation/requests/commit-message-text-generation-regression.test.ts
  • src/main/text-generation/requests/source-control-text-generation-requests.ts
  • src/shared/agent-hook-listener/prompt-fields.test.ts
  • src/shared/agent-hook-listener/prompt-fields.ts
  • src/shared/agent-hook-listener/provider-event-routing.ts
  • src/shared/agent-session/journal/harness-injected-user-turns.test.ts
  • src/shared/agent-session/journal/harness-injected-user-turns.ts
  • src/shared/source-control/ai/naming/branch-name-from-work.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

Major · Keep the trailing task when a turn starts with a harness… · harness-injected-user-turns.ts:15

src/shared/agent-session/journal/harness-injected-user-turns.ts:15
Major · Data Integrity & Integration · Heavy lift

Keep the trailing task when a turn starts with a harness envelope.

Adding hook_result to the known harness tags makes isKnownHarnessInjectedUserTurnText return true for the whole turn. For example, <hook_result>{}</hook_result>\nFix CI config is classified as harness content. Several consumers then discard the whole turn, including the task:

  • native-chat-noise.ts drops the whole message, so the task is removed from native chat.
  • claude-transcript-decoder.ts omits the text of the turn.
  • session-scanner-primary-parsers.ts and session-scanner-codebuddy-parser.ts do not seed the first user prompt from the turn.
  • session-scanner-first-user-prompt.ts returns null for the turn.
  • native-chat-tool-fold.ts and claude-helper-transcript-evidence.ts also treat the whole text as harness content.

Update these consumers to use the task that remains after the envelope, as returned by userTaskTextAfterHarnessEnvelope. A turn that has a trailing task must keep that task visible or available. Classify a turn as harness-only only when no task remains after the envelope.

Minor · Recognize compact self-closing envelopes. · harness-injected-user-turns.ts:3

src/shared/agent-session/journal/harness-injected-user-turns.ts:3
Minor · Functional Correctness · Quick win

Recognize compact self-closing envelopes.

For <hook_result/>\nFix CI config, this matcher rejects / after the tag name. The new task helper returns the raw prompt, and the naming stripper also leaves the envelope intact.

Accept / as a tag-name terminator. Keep the allowlist check so unknown XML remains unchanged.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a2be4ea2-6500-42a2-ac0a-7bb1f19f723f
Commits

Reviewing files that changed from the base of the PR and between f3e140b and 659d213.

Files selected for processing: 8

  • src/main/text-generation/requests/commit-message-text-generation-regression.test.ts
  • src/main/text-generation/requests/source-control-text-generation-requests.ts
  • src/shared/agent-hook-listener/prompt-fields.test.ts
  • src/shared/agent-hook-listener/prompt-fields.ts
  • src/shared/agent-hook-listener/provider-event-routing.ts
  • src/shared/agent-session/journal/harness-injected-user-turns.test.ts
  • src/shared/agent-session/journal/harness-injected-user-turns.ts
  • src/shared/source-control/ai/naming/branch-name-from-work.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comments failed to post: 1

src/shared/agent-session/journal/harness-injected-user-turns.ts: 1

59-59: Minor · Functional Correctness · Quick win

Ignore tag terminators inside quoted attributes.

For <hook_result note="a/>b">metadata</hook_result>\nFix CI config, this regex treats /> inside the attribute as the element terminator. The scanner returns early. Task storage and naming then receive b">metadata</hook_result>\nFix CI config.

Scan quoted attribute values before identifying the opening tag's end and self-closing marker. Preserve paired nesting and actual self-closing tags.

Tools

ast-grep (0.51.1)

[warning] 59-59: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(<(?:(/)${tagName}>|${tagName}(?=[\\s/>]|$)(?:[^<>]*(/)>)?), 'gi')
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

Upstream 2cffded ("test: cut the suite to the tests that guard real
invariants") deleted both test files this branch had modified. Accept the
deletion of the commit-message generation regression suite (template
wiring) and keep only the stripKnownHarnessEnvelope parser cases, which
the rewritten AGENTS.md testing rule still sanctions. The production fix
is unchanged.
@kaluli123123

Copy link
Copy Markdown
Contributor Author

Refreshed against current main (c354ab30ce7d615add5cbcbaae6b6ff8f3b51bdc); new head is 1dadb47f0fb.

Conflicts and how they were resolved

Both conflicts were modify/delete against 2cffdeda72c ("test: cut the suite to the tests that guard real invariants", #46786), which deleted ~93% of the suite and rewrote the AGENTS.md testing rule:

  • src/main/text-generation/requests/commit-message-text-generation-regression.test.ts — accepted the upstream deletion. The case this branch added there asserted template wiring ({{firstPrompt}} substitution), which the new rule explicitly does not want committed.
  • src/shared/agent-session/journal/harness-injected-user-turns.test.ts — kept the file, reduced to the stripKnownHarnessEnvelope cases this branch added (nested same-name tags, self-closing tags, mixed case, attributed <channel source=…>). That function is a parser with depth tracking, which the rewritten rule still lists as worth a test. The pre-existing isKnownHarnessInjectedUserTurnText block was dropped as upstream deleted it.

No production code was changed by the merge; the fix itself is unchanged.

Validation on the merge commit

  • pnpm tc — clean (all projects).
  • pnpm test src/shared/agent-session/journal/harness-injected-user-turns.test.ts src/shared/agent-hook-listener/prompt-fields.test.ts — 2 files, 7 tests passed.
  • npx oxlint and npx oxfmt --check on the files this branch changes — no findings.

State after the push

mergeable: MERGEABLE. clean check passed; CodeRabbit was still in progress at the time of writing, which is why mergeStateStatus reads UNSTABLE.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant