Skip to content

feat(ai-providers): export the shared history-entry renderer - #1758

Open
smart-ssh-coder[bot] wants to merge 4 commits into
developfrom
issue-1757-ai-providers-export-the-shared-history
Open

smart-ssh-coder[bot] wants to merge 4 commits into
developfrom
issue-1757-ai-providers-export-the-shared-history

Conversation

@smart-ssh-coder

@smart-ssh-coder smart-ssh-coder Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1757

Summary

ai_providers::history_entry_text and ai_providers::role_label are public. The built-in providers' own functions now carry these names (no aliases), so rustdoc, the codemap checker and callers see one name. Logic is unchanged; the doc comment states the text contains fenced untrusted content and must reach a model unmodified. Codemap entry is in §4 "Extension points".

Acceptance Criteria

  • Public and documented: met (lib.rs pub use, doc on both functions)
  • Every variant incl. fence and security_notice, outside the crate: met (crates/ai-providers/tests/history_rendering.rs:test_history_entry_text_renders_every_variant_as_the_providers_do, :test_history_entry_text_keeps_fence_and_notice_for_command_output, :test_role_label_maps_every_role; fixed expected texts, fail to compile if the export is pub(crate))
  • Built-in provider output unchanged: met (existing provider tests pass)
  • Request bodies identical: met (crates/ai-providers/tests/history_request_bodies.rs:test_anthropic_history_body_is_pinned, :test_openai_chat_history_body_is_pinned, :test_openai_responses_history_body_is_pinned; fixtures were checked against a clean checkout of develop and pass there too)
  • Relevant tests pass: met (cargo test -p ai-providers)

Tests

Counter-proof: the rendering test does not compile without the public exports; the body tests pass unchanged on the base, proving no change on that path.

Assumptions

Open question decided: two functions, as recommended.

Spec: none (no behaviour change)
Threat model: no change – only exposes the existing renderer, no new data flow.
Manual test steps: none.
Follow-ups: None.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@smart-ssh-coder smart-ssh-coder Bot linked an issue Dec 5, 2026 that may be closed by this pull request
5 tasks
smart-ssh-coder Bot and others added 2 commits December 5, 2026 06:50
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@smart-ssh-reviewer smart-ssh-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review

Verdict: changes requested
Review level: elevated (issue label security; no path from security-paths.txt touched)

Blocking

  • docs/codemap.md:144 — The issue's Technical Notes ask for an update to the extension points list (§4 "Extension points"). The entry went into §6 "Large files (more than 2,000 lines)" instead, and prompt_format.rs has 428 lines. §4, the list embedders read, still does not mention the new public functions. The entry also says "the one place … untrusted output is fenced". That claims too much: this file fences only remote command output. Web, extension and sealed content are fenced in core (WebActivity::to_model_text, unavailable_model_text, SealedContent::text_for_model), and the module header correctly says "Remote output". Fix: remove the §6 line and add a §4 entry, e.g. "crates/ai-providers/src/lib.rs — history_entry_text, role_label: render history entries (remote command output fenced) for text-only providers wrapped in TextActionFallback; implemented in crates/ai-providers/src/common/prompt_format.rs." Keep the symbols backticked so check-codemap checks them (see the next point).

  • crates/ai-providers/src/lib.rs:27-29, prompt_format.rs:9,22-23 — The pub use … as … alias gives one function two names: message_content_text/role_str inside the crate and history_entry_text/role_label outside it. Three things follow from that:

    • rustdoc puts the original doc on the re-export, so the public page of ai_providers::role_label says it is "Re-exported as ai_providers::role_label".
    • check-codemap cannot resolve the aliases. That is why the last commit removed the backticks, and the public names are no longer checked.
    • The test compares a function with itself (next point).

    Clean shape: rename the two functions in prompt_format.rs to history_entry_text / role_label. Update the use lines in anthropic.rs, openai_compatible.rs and openai_responses.rs, the see message_content_text comment and the existing test names. Then re-export with a plain pub use common::prompt_format::{history_entry_text, role_label}; and drop the "Re-exported as …" sentences. Also update the stale reference to ai_providers::role_str in crates/app-logic/src/compaction.rs:826. This stays within the issue's "thin public re-export" and adds no logic.

  • prompt_format.rs:294 (test_public_history_entry_text_matches_internal_for_every_variant) — For AC1/AC2 the test says almost nothing:

    • assert_eq!(crate::history_entry_text(c), message_content_text(c)) compares the same function with itself.
    • The test runs inside the crate, so it stays green when the re-export is made pub(crate). The functional review checked this: the test stays green, while an external caller fails with E0603.
    • Only the CommandResult variant is pinned to a fixed expected text.

    Fix: move the test to the integration tests (crates/ai-providers/tests/, so the names must be public). For every MessageContent variant, assert the output against a fixed expected string, or for the core-rendered variants against the public core function (WebActivity::to_model_text, ExtensionPart::unavailable_model_text, SealedContent::text_for_model, ask_user_model_text). Keep the fence and <security_notice> check for CommandResult and the role mapping for all three roles.

  • AC4 ("test covering the default path: the Anthropic/OpenAI request bodies stay byte-identical") — The PR adds no such test. test_anthropic_and_openai_bodies_render_the_same_command_result pins one variant's text inside the bodies, not the bodies. The rename above touches the call sites in all three providers, so the criterion now needs real coverage. Add a test that builds the Anthropic and OpenAI (Chat Completions and Responses) request bodies for a history with every variant and role and compares them to the bodies from the base (golden fixture or fixed expected JSON).

Non-blocking

  • Commits 2baf4c86 and a7486bc5 share the message "docs(codemap): reference real symbols for the history renderer". The second one actually removes the symbol markup. Reword them or squash.
  • Open PRs #1733 and #1743 also touch docs/codemap.md. There is no conflict now, but one may appear in the same section.

Verified

  • AC1 public and documented: the public rustdoc pages for both names exist and carry the "fenced untrusted content … unmodified" text (executed: cargo doc). An external crate calling both compiles (executed: temporary integration test, removed).
  • AC2: all 7 variants are covered (read: crates/core/src/ai/types.rs), but the comparison is tautological. See Blocking.
  • AC3: no existing test edited, and the crate suite passes (executed).
  • requirement "no logic duplicated or changed": the diff only changes visibility and doc comments. All internal call sites use the one implementation (read).
  • counter-proof: not a bug fix. A visibility counter-proof was run instead: with pub(crate) use the PR test stays green and an external caller fails with E0603 (executed, reverted).
  • edge cases: binary sealed block → marker only, fail-closed (read). Unsealed extension → fenced placeholder (read). Stdout containing </stdout> → escaped by the unchanged format_command_result (executed: existing test).
  • callers checked: message_content_text (5 call sites) → ok. role_str (4) → ok. crates/app-logic/src/compaction.rs:826 comment names the never-public ai_providers::role_str (see Blocking, rename).
  • tests run locally: cargo test -q -p ai-providers --locked → 290 + 27 + 37 + 21 passed. cargo clippy -p ai-providers --all-targets --locked -- -D warnings → clean. cargo fmt --all --check → ok. node scripts/check-codemap.mjs, node scripts/check-doc-paths.mjs → ok (all executed).
  • UI: not a UI change
  • data: not touched
  • CI: all checks green on a7486bc5.

Timing analysis

  • 1 test file analysed: no timing dependency found (synchronous, deterministic, no I/O).

Coherence

  • comments: 3 checked. The codemap entry is misplaced and overclaims, and the "Re-exported as …" doc sentences refer to themselves on the public page. Both are blocking (see above).
  • fit: the alias gives one function two names → blocking (in-scope). Clean shape: rename plus plain re-export (see above).

Spec and boundary

  • visible behaviour changed: none (library API only, model-facing output unchanged)
  • spec searched (fenc, security_notice, untrusted, history), spec covering it: 0039. It describes what is fenced, not where, and is unaffected.
  • verdict: not needed. No ADR needed (option A as recommended in the issue). No changelog fragment needed (not user-visible).
  • boundary, CI changes, vendor: ok. Public texts are English and edition-neutral. No .github/ changes. The threat-model note "no change – only exposes the existing renderer, no new data flow" holds.

Security checks

  • fencing still happens in exactly one place (Spec 0039, invariant 8). format_command_result / fence_untrusted / format_action_rejected are unchanged and stay pub(crate). No filter, risk or confirmation code is touched. Nothing was loosened against the base.
  • security review (subagent): 6 bypass attempts (forged closing tags in stdout/stderr, a forged cancel notice, an injected web result tag, an unsealed extension part, ActionResult role spoofing), all blocked by the unchanged renderer → no findings.

UI review

  • not a UI change

Follow-ups

  • None.

…eir real names, add black-box tests (#1757)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@smart-ssh-coder

Copy link
Copy Markdown
Contributor Author

Review points: 1. codemap entry moved to §4, symbols backticked, says 'remote command output' — fixed in 6c75e08. 2. aliases removed, functions renamed, plain pub use, comments/compaction.rs/ADR 0048 reference updated — fixed in 6c75e08. 3. in-crate test replaced by tests/history_rendering.rs with fixed expected text — fixed in 6c75e08. 4. body pinning tests added in tests/history_request_bodies.rs — fixed in 6c75e08.

@smart-ssh-reviewer smart-ssh-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review

Verdict: approved
Review level: elevated (issue label security; no path from security-paths.txt touched)

Blocking

  • None.

Non-blocking

  • crates/ai-providers/src/common/prompt_format.rs:295 — the in-crate test is still named test_role_str_maps_action_result_to_user, but it now calls role_label. Last round asked to rename the existing tests too. This is cosmetic: rename it to test_role_label_maps_action_result_to_user the next time the file is touched.
  • prompt_format.rs:9, :22-23 — "Exported as ai_providers::…" is true but repeats the item's own name on its public docs page. It could read "Re-exported at the crate root."
  • crates/ai-providers/tests/support/history_fixture.rs:23 — the Sealed fixture has no content, so the tests pin only the "[content no longer available]" placeholder. That rendering lives in core and this PR does not touch it, so the acceptance criteria do not need more coverage.
  • crates/ai-providers/tests/history_request_bodies.rs — the tests use a wiremock port and a 10 s timeout. A runner with HTTP_PROXY set and no NO_PROXY for 127.0.0.1 could bypass wiremock. Low risk, and nothing to change on hosted runners.
  • No changelog fragment: correct. An app user does not notice the change (changelog.d/README.md), and #1637 shipped without one too.

Verified

  • AC1 public and documented: plain pub use common::prompt_format::{history_entry_text, role_label};, no aliases. The doc comment states the fenced untrusted-content contract (read: crates/ai-providers/src/lib.rs, prompt_format.rs).
  • AC2: tests/history_rendering.rs checks all 7 MessageContent variants against fixed expected strings, the full fence and <security_notice> for a command result, and all 3 roles (read; variant list cross-checked against crates/core/src/ai/types.rs). Making the export pub(crate) breaks compilation with E0603 (executed, reverted).
  • AC3: existing provider tests changed only by the rename this review requested. No assertion changed (read).
  • AC4: tests/history_request_bodies.rs sends through the real AnthropicProvider, OpenAiCompatibleProvider and OpenAiResponsesProvider against wiremock and compares messages/input with JSON fixtures. On a clean origin/develop the same tests pass, 3 passed (executed: temporary worktree, removed).
  • counter-proof: with a temporary change to format_action_rejected, the every-variant test and all 3 body tests fail. With Role::ActionResult → "assistant", the role test and all 3 body tests fail. Both changes were reverted and everything is green again (executed).
  • edge cases: same-role grouping (Anthropic/Chat) vs. no grouping (Responses) → pinned, ok. Anthropic cache_control on the last message → pinned, ok. Sealed entry with content → not covered (non-blocking).
  • callers checked: history_entry_text / role_label (7 uses in 3 providers) → ok. rg 'message_content_text|role_str\b' → no leftovers in code or docs (executed).
  • tests run locally: cargo test -p ai-providers --locked -q → 289 + 27 + 3 + 3 + 37 + 21 passed. cargo clippy -p ai-providers --all-targets --locked -- -D warnings → clean. cargo fmt --all --check → ok. node scripts/check-codemap.mjs, node scripts/check-doc-paths.mjs → ok (all executed).
  • UI: not a UI change
  • data: not touched
  • CI: all checks green on 6c75e08d.

Timing analysis

  • 3 test files analysed: no timing dependency in practice. history_request_bodies.rs uses a 10 s timeout and an ephemeral localhost port; with an empty SSE response there is no retry path → possible, non-blocking. JSON is compared as Value, so key order does not matter.

Coherence

  • comments: 4 checked (two doc comments, the history_entry_text reference in role_label, compaction.rs:827) → all match the code. The "Exported as …" sentences are true; wording is non-blocking.
  • fit: the alias is gone, the functions carry their public names and the re-export is plain → the change fits. Stale test name → non-blocking (above).

Spec and boundary

  • visible behaviour changed: none (public crate API only; model-facing output pinned unchanged)
  • spec searched (history, fenc, untrusted, TextActionFallback, provider), spec covering it: 0039 §3. It describes what is fenced, not where, so it is unaffected.
  • verdict: not needed, because behaviour does not change. The ADR 0048 edit only updates a symbol name.
  • boundary, CI changes, vendor: ok. Codemap entry now in §4 "Extension points", names the symbols in backticks and says "remote command output fenced". No .github/ changes. "Threat model: no change – only exposes the existing renderer, no new data flow" holds.

Security checks

  • Fencing in exactly one place (Spec 0039, invariant 8): fence_untrusted is still called only in prompt_format.rs. format_command_result / format_action_rejected stay pub(crate), mod common stays private. The function bodies are unchanged against the base. No filter, risk, confirmation or credential code is touched, and nothing is loosened.
  • security review (subagent): 5 bypass attempts (fence-like text in stdout/stderr through the public path, rebuilding a command result without the renderer, direct access to internal formatters, body drift from the rename, public vs. internal variant divergence) → all blocked, no findings.

UI review

  • not a UI change

Previous findings

  • codemap entry in §6 and overclaiming → fixed in 6c75e08d (§4, backticked symbols, "remote command output")
  • alias pub use … as … → fixed in 6c75e08d (functions renamed, plain re-export, compaction.rs and ADR 0048 references updated). One test name left over (non-blocking).
  • AC2 test tautological / in-crate → fixed in 6c75e08d (black-box tests in tests/ with fixed expected text)
  • AC4 missing request-body test → fixed in 6c75e08d (pinned bodies for Anthropic, Chat Completions, Responses; pass on the base)

Follow-ups

  • None.

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.

ai-providers: export the shared history-entry renderer for text-only providers

0 participants