Skip to content

feat(tinyhumans): report the credential kind with each auth failure - #137

Merged
M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/tinyhumans-auth-failure-credential-kind
Oct 23, 2026
Merged

M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/tinyhumans-auth-failure-credential-kind

Conversation

@M3gA-Mind

@M3gA-Mind M3gA-Mind commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

TinyHumansModel can now report which credential each failed request was sent with.

  • TinyHumansModel::new_with_credential(base_url, model, default_model, resolver): the resolver returns a TinyHumansCredential { bearer, kind }, where kind is TinyHumansCredentialKind::Session or ApiKey.
  • TinyHumansAuthFailure::credential() -> Option<TinyHumansCredentialKind>: the kind the failing request itself carried. It is None for a model built with plain new, which is otherwise unchanged.

How it works: the bearer is resolved inside the generic OpenAiModel, so a ProviderError can't name the credential behind it. invoke and stream-open now run inside a tokio::task_local! scope. ResolvedBearer::current() records the kind it handed out into that scope, and the failure handler reads it back. Stream items reuse the kind captured when the stream opened. Outside a dispatch scope (the readiness probe), nothing is recorded and credential() is None.

Why

The host (openhuman) must sign the user out only on a 401 for the session credential; an API-key 401 is a rejected key. The host used to record "the credential last resolved" in shared state, which a request in flight across a credential switch can misattribute: a late API-key 401 then looks like a session 401. Context: tinyhumansai/openhuman#8240 (review thread on credential provenance). The host will move to new_with_credential once this lands.

Where the task-local is read

The kind is read inside the task-local scope on both paths. SENT_CREDENTIAL.with(Cell::get) runs inside the async block passed to SENT_CREDENTIAL.scope(...), and the block returns (result, credential) from within the scope:

  • invoke_operation: mod.rs:387-391.
  • stream(): stream-open, mod.rs:480-484. In-band stream items reuse the credential captured there.

ResolvedBearer::current() writes it with SENT_CREDENTIAL.try_with(...) (mod.rs:585). Outside a dispatch scope that's a no-op, so the readiness probe reports None.

The stream-open path is covered by managed_auth_failure_reports_the_credential_its_request_carried. Its third request is model.stream(...), and the test asserts (TinyHumansOperation::Stream, Some(TinyHumansCredentialKind::Session)).

Tests

  • managed_auth_failure_reports_the_credential_its_request_carried: the resolver switches from API key to session between requests. The failures report ApiKey (invoke), then Session (invoke and stream-open).
  • a_plain_bearer_resolver_reports_no_credential_kind: new reports None.
  • The existing managed_auth_callback_reports_typed_provenance_for_each_operation still passes.
  • Local run: cargo test -p tinyinference-llm --lib -- providers::tinyhumans::tests::managed_auth providers::tinyhumans::tests::a_plain_bearer gave 3 passed.
  • CHANGELOG.md has an Unreleased entry. The change is additive: no existing signature changes, and the new field is private.

TinyHumansModel::new_with_credential takes a resolver that says whether
each bearer is the session token or an API key, and
TinyHumansAuthFailure::credential() returns the kind the failing request
itself carried (captured per dispatch through a task-local the bearer
source writes). A host can then tell a rejected API key from an expired
session even when the credential changes with requests in flight,
instead of reading its own 'last resolved' state. new() is unchanged and
reports None.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b1bb9fa-03dc-41d8-acd1-e10f371b0a21
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tinysweeper

tinysweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 4854743e344d162f3907058ed2980e5ab659c67b

Findings

No active actionable findings.

Advisory notes

  • medium: Report in-band stream credential, not open-time credential (crates/tinyinference-llm/src/providers/tinyhumans/mod.rs:480)
    Problem: The credential passed to an in-band `ProviderFailed` stream item is the task-local value read at stream *open*, captured in `credential` and moved into the `map_items` closure. `Ti
    Suggested fix:
    No concrete fix was supplied.

Resolved this pass

  • Read the stream-open credential inside the task-local scope
  • Capture the credential kind inside the stream scope closure

Verdict: Ready for maintainer review · Priority: medium
Coverage: Reviewed 3 of 3 files.

Diagnostics and supporting details

Full summary

Pull request purpose (title): feat(tinyhumans): report the credential kind with each auth failure. Purpose (from the title and description): `feat(tinyhumans): report the credential kind with each auth failure`. The pull request lets `TinyHumansModel` report which credential kind — `Session` or `ApiKey` — a failed managed request was actually sent with, so a host can sign the user out only on a session 401 and treat an API-key 401 as a rejected key, rather than misattributing a late 401 to whatever credential was resolved last. The two findings from the prior cycle (reading the stream-open credential outside the scope, and capturing the kind outside the scope closure) are reported as fixed by the description and tests lanes. One gap remains: in-band stream-item failures still report the credential resolved at stream open rather than the credential the failing in-band request carried, which the tests lane says should be fixed before merge.

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 1 Noted findings 1
Documentation 1 Resolved findings 2
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

Features

  • Added — Kinded credential resolver for the managed model: Hosts can supply a resolver that reports each bearer's kind so an auth failure is attributed to the credential the request actually carried, avoiding misattribution when the credential rotates mid-flight; `new` is unchanged and reports `None`. (crates/tinyinference-llm/src/providers/tinyhumans/mod.rs impl TinyHumansModel {)
  • Added — Credential kind exposed on `TinyHumansAuthFailure`: Auth-failure callbacks and the `TinyHumansAuthFailure` value carry the failing request's credential kind, letting hosts sign out only on a session 401 while treating an API-key 401 as a rejected key. (crates/tinyinference-llm/src/providers/tinyhumans/mod.rs impl TinyHumansAuthFailure {)

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Before merge

None.

Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The critique lane answered for the changelog: the Unreleased entry is documentation-only and accurately describes `new_with_credential`, `TinyHumansCredentialKind`, and `TinyHumansAuthFailure::credential()`, including the `None` behavior of `new`.
  • Lane summary: The CHANGELOG entry is a documentation-only change; it accurately describes `new_with_credential`, `TinyHumansCredentialKind`, and `TinyHumansAuthFailure::credential()` as they exist in the tree, including the `None` behaviour of `new`. No defects found in this file. (2 earlier finding(s) still open) _The code index is behind this pull request (indexed at `32ec67f8bfac`), so retrieved context may be out of date._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The security lane answered with 0 findings across the reviewed files; `CHANGELOG.md` was noted as not security-reviewed because it is prose. This revision threads a credential kind through the resolver into the auth-failure path.
  • Lane summary: Reviewed 0 files; 0 findings. 1 file was not security-reviewed: CHANGELOG.md (prose or tabular data). (2 earlier finding(s) still open) _The code index is behind this pull request (indexed at `32ec67f8bfac`), so retrieved context may be out of date._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The change adds a credential-kind-aware constructor that attributes a managed auth failure to the credential the failing request actually carried, via a task-local read inside the dispatch scope. The prior cycle's two findings — reading the stream-open credential outside the scope and capturing the kind outside the scope closure — are fixed in this revision: both `invoke_operation` and `stream` now read `SENT_CREDENTIAL` inside the `scope` closure, and the new tests exercise exactly those paths (invoke with rotating credential, stream open, and the plain-resolver `None` case). One gap remains: the in-band stream-item failure still reports the credential resolved at stream open rather than the one the failing in-band request carried, which is the documented contract. No repository rule is violated. The behaviour is otherwise sound, but the in-band mismatch should be fixed before merge. (2 earlier finding(s) still open) _The code index is behind this pull request (indexed at `32ec67f8bfac`), so retrieved context may be out of date._

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The commits lane answered and found no sensitive content in committed files.
  • Lane summary: No sensitive content in committed files. (2 earlier finding(s) still open) _The code index is behind this pull request (indexed at `32ec67f8bfac`), so retrieved context may be out of date._

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The change adds a credential-kind channel (`TinyHumansCredentialKind`, `TinyHumansCredential`, `new_with_credential`, `TinyHumansAuthFailure::credential()`) that records the kind each request's bearer carried into a task-local and reads it back inside the dispatch scope on both invoke and stream-open, so an auth failure is attributed to its own request even when the credential rotates mid-flight. The task-local is read inside the scope closure on both paths, so the two earlier findings about reading the credential outside the scope are fixed; the stream-open test also covers the previously-untested path. I found nothing further worth blocking on. _The code index is behind this pull request (indexed at `32ec67f8bfac`), so retrieved context may be out of date._
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.006803
  • Tokens: 146239 input · 4119 output · 33792 cached · 377 embedding
  • Updated: 2026-10-23T08:21:02Z
Head State Pass summary
1f1ddb511249 changes requested 1 active finding(s), 0 resolved finding(s) (at 2026-10-23T00:36:49Z)
4854743e344d ready for maintainer review 0 active finding(s), 2 resolved finding(s) (at 2026-10-23T08:21:02Z)

tinysweeper 0.1.2

@tinysweeper tinysweeper 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.

Requesting changes: 1 lane(s) blocking, worst finding is critical.

Fix or reply to the findings below and push. The next review clears this automatically once they are gone — you should not need to dismiss anything by hand.

Diagnostics

Total spend: $0.0010

…h-failure-credential-kind

# Conflicts:
#	CHANGELOG.md

@tinysweeper tinysweeper 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.

The previously-blocking findings are resolved. Clearing the changes request.

Diagnostics

Total spend: $0.0068

@M3gA-Mind
M3gA-Mind merged commit f5c0e56 into tinyhumansai:main Oct 23, 2026
10 checks passed
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.

1 participant