Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ai_usage): stop charging users for chat_rename (#7700)

Will Hutchinsond066029c6a69
diff --git a/crates/ai_billing/src/domain/admission/test.rs b/crates/ai_billing/src/domain/admission/test.rs
index 73a1dc2397..d665bd33ef 100644
--- a/crates/ai_billing/src/domain/admission/test.rs
+++ b/crates/ai_billing/src/domain/admission/test.rs
@@ -133,7 +133,7 @@ async fn enabled_admission_preserves_allowance_decisions() {
for feature in [
AiFeature::Chat,
AiFeature::AiEditing,
- AiFeature::ChatRename,
+ AiFeature::Automation,
AiFeature::AgentRepositoryChoice,
] {
let result = admission.admit(&user(), feature).await;
diff --git a/crates/ai_usage/src/domain/counting.rs b/crates/ai_usage/src/domain/counting.rs
index 909ab5293b..2697dbe88d 100644
--- a/crates/ai_usage/src/domain/counting.rs
+++ b/crates/ai_usage/src/domain/counting.rs
@@ -33,12 +33,14 @@ impl AiUsageEnforcement {
}
/// Features whose provider costs are recorded but never consume allowances,
-/// prepaid credits, or overage. Dictation is the Whispr transcription feature.
-pub const NON_BILLABLE_AI_FEATURES: [AiFeature; 4] = [
+/// prepaid credits, or overage. Dictation is the Whispr transcription feature;
+/// chat rename is the automatic title given to a new chat or agent session.
+pub const NON_BILLABLE_AI_FEATURES: [AiFeature; 5] = [
AiFeature::Memory,
AiFeature::AiProjection,
AiFeature::CallSummary,
AiFeature::Dictation,
+ AiFeature::ChatRename,
];
/// Whether a feature's usage is billable, independent of enforcement or identity.
@@ -48,11 +50,11 @@ pub const fn is_billable_feature(feature: AiFeature) -> bool {
AiFeature::Memory
| AiFeature::AiProjection
| AiFeature::CallSummary
- | AiFeature::Dictation => false,
+ | AiFeature::Dictation
+ | AiFeature::ChatRename => false,
AiFeature::Chat
| AiFeature::Automation
| AiFeature::DynamicCompletionsApi
- | AiFeature::ChatRename
| AiFeature::ChannelBot
| AiFeature::AiEditing
| AiFeature::Import
diff --git a/crates/ai_usage/src/domain/counting/test.rs b/crates/ai_usage/src/domain/counting/test.rs
index 81e86e2abd..c9411ed2a3 100644
--- a/crates/ai_usage/src/domain/counting/test.rs
+++ b/crates/ai_usage/src/domain/counting/test.rs
@@ -5,7 +5,7 @@ const FEATURES: [(AiFeature, bool); 14] = [
(AiFeature::Memory, false),
(AiFeature::Automation, true),
(AiFeature::DynamicCompletionsApi, true),
- (AiFeature::ChatRename, true),
+ (AiFeature::ChatRename, false),
(AiFeature::CallSummary, false),
(AiFeature::ChannelBot, true),
(AiFeature::AiProjection, false),
@@ -30,7 +30,7 @@ fn feature_classification_preserves_billing_policy() {
assert_eq!(is_billable_feature(feature), billable, "{feature:?}");
assert_eq!(NON_BILLABLE_AI_FEATURES.contains(&feature), !billable);
}
- assert_eq!(NON_BILLABLE_AI_FEATURES.len(), 4);
+ assert_eq!(NON_BILLABLE_AI_FEATURES.len(), 5);
}
#[test]
diff --git a/crates/macro_db_client/src/history/upsert_history.rs b/crates/macro_db_client/src/history/upsert_history.rs
index cbf32af633..a0756e4398 100644
--- a/crates/macro_db_client/src/history/upsert_history.rs
+++ b/crates/macro_db_client/src/history/upsert_history.rs
@@ -131,12 +131,15 @@ mod tests {
#[sqlx::test(fixtures(path = "../../fixtures"))]
async fn test_upsert_item_last_accessed(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ // Seed well in the past. The column has millisecond precision, so a row
+ // seeded at NOW() can share its timestamp with the upsert that follows.
let last_accessed = sqlx::query!(
r#"
- INSERT INTO "ItemLastAccessed" ("item_id", "item_type", "last_accessed") VALUES ($1, $2, NOW())
+ INSERT INTO "ItemLastAccessed" ("item_id", "item_type", "last_accessed")
+ VALUES ($1, $2, '2019-10-16 00:00:00')
RETURNING "last_accessed" as last_accessed
- "#,
- "d1",
+ "#,
+ "d1",
"document"
)
.map(|row| row.last_accessed)
@@ -157,7 +160,10 @@ mod tests {
.fetch_one(&pool)
.await?;
- assert_ne!(last_accessed, updated_last_access);
+ assert!(
+ updated_last_access > last_accessed,
+ "upsert must move last_accessed forward: {last_accessed} -> {updated_last_access}"
+ );
Ok(())
}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index 43f1b4d587..72510eaf94 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -599,7 +599,7 @@ protocol error with a stable `code` and `retryable` flag, not an HTTP status.
A direct AI tool/MCP or AI-edit refusal is a failed tool result even if the outer
transport succeeds. No worker/provider edit should happen after refusal. Ordinary
manual editing, deterministic tools/imports, and the exempt Memory, AiProjection,
-CallSummary, and Dictation features are not blocked by quota. Optional naming or
+CallSummary, Dictation, and ChatRename features are not blocked by quota. Optional naming or
trigger inference may be skipped without blocking successful primary work; it
must not make a fallback model call. Managed sessions use their persisted owner
for quota, not a collaborating sender. Externally funded runtimes skip session
diff --git a/docs/AI_QUOTA_ENFORCEMENT.md b/docs/AI_QUOTA_ENFORCEMENT.md
index 60aeea346e..bbe8f34202 100644
--- a/docs/AI_QUOTA_ENFORCEMENT.md
+++ b/docs/AI_QUOTA_ENFORCEMENT.md
@@ -29,9 +29,10 @@ admission and recording:
| Historical rows / inserts omitting column | Never retrospectively classified | `false` |
| Disabled after activation | Stop admission and new counting | Existing booleans unchanged |
-**Exempt:** Memory, AiProjection, CallSummary, Dictation. **Billable:** Chat,
-Automation, DynamicCompletionsApi, ChatRename, ChannelBot, AiEditing, Import,
-AgentSession, AgentRepositoryChoice. In particular, AI editing is not exempt.
+**Exempt:** Memory, AiProjection, CallSummary, Dictation, ChatRename.
+**Billable:** Chat, Automation, DynamicCompletionsApi, ChannelBot, AiEditing,
+Import, AgentSession, AgentRepositoryChoice, ImageGeneration. In particular, AI
+editing is not exempt.
The classification is exhaustive and server-selected, not request-controlled.
Unlimited (enterprise) entitlements are never blocked by this quota policy.
@@ -219,8 +220,9 @@ inspect the content type and code rather than assuming every 503 is billing.
are terminal bookkeeping, not automatic replay. Agent targets delegate funding
decisions to the session/harness service. A 503 describes a retryable cause, not
a promise that a scheduler or broker will redeliver the same run.
-- Optional chat/session naming is independently admitted as ChatRename; refusal
- retains the existing/default title without failing successful primary work.
+- Optional chat/session naming is independently admitted as ChatRename, an exempt
+ feature, so the gate does no quota billing I/O and never charges the user; a
+ refusal retains the existing/default title without failing successful primary work.
Optional bot/trigger inference (including image captions) skips classification
on failure, without AI fallback or implied approval. Explicit mentions still
route deterministically; downstream execution has its own gate and failures.
@@ -270,7 +272,7 @@ admission and R. Admission itself never records usage or calls settlement.
| Repository chooser / AgentRepositoryChoice | [repository choice service](../crates/agent_harness/src/domain/repository_choice.rs) | Harness main → `CursorContainerManager`, independent R | [deterministic bypass / typed model refusal](../crates/agent_harness/src/domain/repository_choice/test.rs) |
| Scheduled manual/cron/event model work / Automation | [shared executor](../services/scheduled_action/src/domain/execution.rs) | [scheduled service](../services/scheduled_action/src/bins/service.rs), common context T | [claims, schedules, terminal events](../services/scheduled_action/src/domain/execution/test.rs), [manual HTTP](../services/scheduled_action/src/inbound/axum_router/test.rs) |
| Scheduled agent targets / session funding policy | [target runner](../services/scheduled_action/src/domain/target_runner.rs) → session/harness admission | Target runtime's recorder, not duplicate scheduler metering | [delegation and typed errors](../services/scheduled_action/src/domain/target_runner/test.rs), [routine error transport](../crates/agent_session/src/inbound/routine_sessions/test.rs) |
-| Memory, projection, call summary, dictation / exempt | [shared admission policy](../crates/ai_billing/src/domain/admission.rs) skips quota; ordinary permissions still apply | DCS/DSS configured recorders; [memory context](../crates/memory/src/context.rs) uses T; DSS independent call-summary/dictation recorders use R | [all exempt features](../crates/ai_usage/src/domain/counting/test.rs), [no billing I/O](../crates/ai_billing/src/domain/admission/test.rs), [configured recording](../crates/ai_billing/src/composition/test.rs) |
+| Memory, projection, call summary, dictation, chat rename / exempt | [shared admission policy](../crates/ai_billing/src/domain/admission.rs) skips quota; ordinary permissions still apply | DCS/DSS configured recorders; [memory context](../crates/memory/src/context.rs) uses T; DSS independent call-summary/dictation recorders use R | [all exempt features](../crates/ai_usage/src/domain/counting/test.rs), [no billing I/O](../crates/ai_billing/src/domain/admission/test.rs), [configured recording](../crates/ai_billing/src/composition/test.rs) |
| Existing system task duplicate judge / Automation | [system attribution](../crates/task_dedup/src/outbound/judge.rs), no user quota gate | DSS main, independent R; system events stay uncounted | [system counting](../crates/ai_usage/src/domain/counting/test.rs), [system recorder behavior](../crates/ai_billing/src/outbound/settling_recorder/test.rs) |
| Billing summary (not execution) | [billing service policy](../crates/ai_billing/src/domain/service.rs) | [authentication main](../services/authentication_service/src/main.rs) configures the same flag plus `ENABLE_AI_USAGE_BILLING`, no usage producer | [settlement policy/free/unlimited/settlement](../crates/ai_billing/src/domain/service/test.rs), [authentication configuration](../services/authentication_service/src/config/test.rs) |