Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat(metrics): wire context-overflow warnings to diagnostic links (#3790)

LearningCircuit69e4b0f6d311
diff --git a/changelog.d/+context-overflow-link-wires.feature.md b/changelog.d/+context-overflow-link-wires.feature.md
new file mode 100644
index 0000000000..e010efc286
--- /dev/null
+++ b/changelog.d/+context-overflow-link-wires.feature.md
@@ -0,0 +1 @@
+Context-overflow warnings (front-page banner, result-page banner, completion toast) now show a clickable action that takes you straight to the relevant diagnostics — historical warnings link to the context-overflow metrics page, while per-research warnings link to that research's overflow section on its details page.
diff --git a/src/local_deep_research/web/static/css/styles.css b/src/local_deep_research/web/static/css/styles.css
index 270e27e642..c085e7d7e2 100644
--- a/src/local_deep_research/web/static/css/styles.css
+++ b/src/local_deep_research/web/static/css/styles.css
@@ -2804,6 +2804,79 @@ input[type="number"].ldr-form-control::-webkit-inner-spin-button {
color: var(--accent-tertiary);
}
+.ldr-alert a,
+.ldr-alert .ldr-alert-action {
+ color: var(--text-primary);
+ text-decoration: underline;
+ font-weight: 500;
+ display: inline-block;
+ margin-top: 6px;
+ font-size: 14px;
+}
+
+.ldr-alert a:hover,
+.ldr-alert a:focus-visible,
+.ldr-alert .ldr-alert-action:hover,
+.ldr-alert .ldr-alert-action:focus-visible {
+ color: #ffffff;
+}
+
+.ldr-alert a:focus-visible,
+.ldr-alert .ldr-alert-action:focus-visible {
+ outline: 2px solid #ffffff;
+ outline-offset: 2px;
+ border-radius: 2px;
+}
+
+@media (max-width: 480px) {
+ .ldr-alert { flex-wrap: wrap; }
+ .ldr-alert .ldr-alert-action { display: block; margin-top: 0.5rem; }
+}
+
+/* Metrics button — context-overflow state */
+.ldr-metrics-btn-overflow {
+ border-color: var(--warning-color) !important;
+ color: var(--warning-color) !important;
+ box-shadow: 0 0 0 1px rgba(var(--warning-color-rgb), 0.4);
+}
+.ldr-metrics-btn-overflow:hover {
+ background-color: rgba(var(--warning-color-rgb), 0.12);
+}
+.ldr-metrics-btn-overflow .ldr-badge-overflow {
+ display: inline-block;
+ font-size: 0.65rem;
+ padding: 1px 5px;
+ margin-left: 6px;
+ background: var(--warning-color);
+ color: #000;
+ border-radius: 3px;
+ font-weight: 600;
+ vertical-align: middle;
+ line-height: 1.4;
+}
+
+/* Details page — context-overflow performance warning */
+.ldr-co-performance-warning {
+ display: flex;
+ align-items: flex-start;
+ gap: 0.75rem;
+ padding: 1rem 1.25rem;
+ margin-bottom: 1rem;
+ background: rgba(var(--warning-color-rgb), 0.12);
+ border: 1px solid rgba(var(--warning-color-rgb), 0.35);
+ border-radius: 0.5rem;
+ color: var(--text-primary);
+}
+.ldr-co-performance-warning i {
+ color: var(--warning-color);
+ font-size: 1.25rem;
+ margin-top: 2px;
+ flex-shrink: 0;
+}
+.ldr-co-performance-warning strong {
+ color: var(--warning-color);
+}
+
.ldr-provider-status-unavailable {
color: var(--error-color);
}
diff --git a/src/local_deep_research/web/static/js/components/details.js b/src/local_deep_research/web/static/js/components/details.js
index bbf062b4a5..625e843074 100644
--- a/src/local_deep_research/web/static/js/components/details.js
+++ b/src/local_deep_research/web/static/js/components/details.js
@@ -1118,6 +1118,14 @@
if (requests && requests.length > 0) {
createUsageChart(requests, overview.context_limit);
}
+
+ // Show performance warning if truncation occurred
+ if (overview.truncation_occurred) {
+ const perfWarning = document.getElementById('co-performance-warning');
+ if (perfWarning) {
+ perfWarning.style.display = 'flex';
+ }
+ }
}
// Display phase breakdown
diff --git a/src/local_deep_research/web/static/js/components/progress.js b/src/local_deep_research/web/static/js/components/progress.js
index 16ca02c519..e143daf8b0 100644
--- a/src/local_deep_research/web/static/js/components/progress.js
+++ b/src/local_deep_research/web/static/js/components/progress.js
@@ -675,7 +675,16 @@
}
message += ' Consider increasing context window.';
- showNotification('Context Overflow Warning', message, 'warning', 10000);
+ showNotification(
+ 'Context Overflow Warning',
+ message,
+ 'warning',
+ 12000,
+ {
+ label: 'View overflow details',
+ url: `/details/${currentResearchId}#context-overflow-section`
+ }
+ );
SafeLogger.log('Context overflow toast shown:', overview);
}
} catch (error) {
@@ -751,8 +760,9 @@
* @param {string} message - Notification message
* @param {string} type - Notification type ('info', 'warning', 'error')
* @param {number} duration - Duration in ms to show in-app notification (0 to not auto-hide)
+ * @param {{label: string, url: string}|null} action - Optional action button { label, url } (url must start with "/")
*/
- function showNotification(title, message, type = 'info', duration = 5000) {
+ function showNotification(title, message, type = 'info', duration = 5000, action = null) {
// First attempt browser notification if enabled
if ('Notification' in window) {
// Check if permission is already granted
@@ -841,6 +851,21 @@
notificationEl.appendChild(hr);
notificationEl.appendChild(p);
+ // Optional action button — only render for safe internal paths
+ if (action && typeof action.url === 'string'
+ && action.url.startsWith('/') && !action.url.startsWith('//')) {
+ const actionBtn = document.createElement('button');
+ actionBtn.type = 'button';
+ actionBtn.className = 'btn btn-primary btn-sm';
+ actionBtn.style.marginTop = '8px';
+ actionBtn.textContent = action.label || 'View details';
+ actionBtn.addEventListener('click', (e) => {
+ e.preventDefault();
+ URLValidator.safeAssign(window.location, 'href', action.url);
+ });
+ notificationEl.appendChild(actionBtn);
+ }
+
// Add to container
notificationContainer.appendChild(notificationEl);
diff --git a/src/local_deep_research/web/static/js/components/results.js b/src/local_deep_research/web/static/js/components/results.js
index 771b9144b7..b00be551c4 100644
--- a/src/local_deep_research/web/static/js/components/results.js
+++ b/src/local_deep_research/web/static/js/components/results.js
@@ -927,6 +927,7 @@
const overview = data.data.overview;
const warningBanner = document.getElementById('context-overflow-warning');
const warningMessage = document.getElementById('context-overflow-message');
+ const warningAction = document.getElementById('context-overflow-action');
if (warningBanner && warningMessage) {
const tokensLost = overview.tokens_lost || 0;
@@ -943,7 +944,33 @@
message += ' Consider increasing context window size for better results.';
warningMessage.textContent = message;
+ if (warningAction && researchId) {
+ URLValidator.safeAssign(
+ warningAction,
+ 'href',
+ URLBuilder.detailsPage(researchId) + '#context-overflow-section'
+ );
+ }
warningBanner.style.display = 'flex';
+
+ // Highlight the metrics button
+ const metricsBtn = document.getElementById('view-metrics-btn');
+ if (metricsBtn) {
+ metricsBtn.classList.add('ldr-metrics-btn-overflow');
+ if (!metricsBtn.querySelector('.fa-exclamation-triangle')) {
+ const icon = document.createElement('i');
+ icon.setAttribute('aria-hidden', 'true');
+ icon.className = 'fas fa-exclamation-triangle';
+ metricsBtn.insertBefore(icon, metricsBtn.firstChild);
+ }
+ if (!metricsBtn.querySelector('.ldr-badge-overflow')) {
+ const badge = document.createElement('span');
+ badge.className = 'ldr-badge-overflow';
+ badge.textContent = 'OVERFLOW';
+ metricsBtn.appendChild(badge);
+ }
+ }
+
SafeLogger.log('Context overflow warning displayed:', overview);
}
}
diff --git a/src/local_deep_research/web/static/js/config/urls.js b/src/local_deep_research/web/static/js/config/urls.js
index 15a669863d..b0e076263d 100644
--- a/src/local_deep_research/web/static/js/config/urls.js
+++ b/src/local_deep_research/web/static/js/config/urls.js
@@ -42,6 +42,7 @@ if (typeof URLS !== 'undefined') {
METRICS: '/metrics/',
METRICS_COSTS: '/metrics/costs', // Added metrics subpage
METRICS_STAR_REVIEWS: '/metrics/star-reviews', // Added metrics subpage
+ METRICS_CONTEXT_OVERFLOW: '/metrics/context-overflow', // Context overflow diagnostics
LIBRARY: '/library/',
COLLECTIONS: '/library/collections',
COLLECTION_DETAILS: '/library/collections/{id}',
diff --git a/src/local_deep_research/web/static/js/research_form.js b/src/local_deep_research/web/static/js/research_form.js
index 81b98adcaf..3c87c8a40a 100644
--- a/src/local_deep_research/web/static/js/research_form.js
+++ b/src/local_deep_research/web/static/js/research_form.js
@@ -281,6 +281,18 @@ function displayWarnings(warnings) {
const isInfo = warning.type === 'searxng_recommendation' || warning.type === 'legacy_server_config' || warning.type === 'backup_info';
const alertClass = isInfo ? 'ldr-alert-info' : 'ldr-alert-warning';
+ // Only render an action link for safe internal paths (start with "/" but not "//")
+ const safeActionUrl = (typeof warning.actionUrl === 'string'
+ && warning.actionUrl.startsWith('/')
+ && !warning.actionUrl.startsWith('//'))
+ ? warning.actionUrl
+ : null;
+ const actionHtml = safeActionUrl
+ ? `<a href="${esc(safeActionUrl)}" class="ldr-alert-action">
+ ${esc(warning.actionLabel || 'View details')}
+ <span aria-hidden="true">→</span>
+ </a>`
+ : '';
return `
<div class="ldr-alert ${alertClass} warning-banner warning-${esc(warning.type)}" style="
border-radius: 6px;
@@ -298,6 +310,7 @@ function displayWarnings(warnings) {
<div style="font-size: 14px; line-height: 1.4;">
${esc(warning.message)}
</div>
+ ${actionHtml}
</div>
<button onclick="dismissWarning('${esc(warning.dismissKey)}')" style="
background: none;
diff --git a/src/local_deep_research/web/templates/pages/details.html b/src/local_deep_research/web/templates/pages/details.html
index 0d77bf0f97..d972ad4876 100644
--- a/src/local_deep_research/web/templates/pages/details.html
+++ b/src/local_deep_research/web/templates/pages/details.html
@@ -77,6 +77,13 @@
<!-- Token Usage Over Time (prominent chart at top) -->
<div class="ldr-card" id="token-usage-top-chart" style="display: none;">
<div class="ldr-card-content">
+ <div id="co-performance-warning" class="ldr-co-performance-warning" style="display: none;">
+ <i aria-hidden="true" class="fas fa-exclamation-triangle"></i>
+ <div>
+ <strong>Context overflow detected.</strong>
+ This research exceeded its context window, causing truncation. This can <strong>severely degrade</strong> the quality and completeness of results — information is lost and the model operates on incomplete context. Consider using a model with a larger context window or reducing query complexity.
+ </div>
+ </div>
<h2><i class="fas fa-chart-line"></i> Token Usage Over Time</h2>
<div class="ldr-chart-container" style="height: 300px; margin-top: 1rem;">
<canvas id="co-usage-chart"></canvas>
diff --git a/src/local_deep_research/web/templates/pages/results.html b/src/local_deep_research/web/templates/pages/results.html
index 09065c82e5..ebd26b13ed 100644
--- a/src/local_deep_research/web/templates/pages/results.html
+++ b/src/local_deep_research/web/templates/pages/results.html
@@ -60,11 +60,15 @@
</div>
</div>
<!-- Context Overflow Warning Banner -->
- <div id="context-overflow-warning" class="ldr-alert ldr-alert-warning" role="status" style="display: none;">
+ <div id="context-overflow-warning" class="ldr-alert ldr-alert-warning" role="region" aria-label="Context overflow notice" style="display: none;">
<i aria-hidden="true" class="fas fa-exclamation-triangle"></i>
<div>
<strong>Context Overflow Detected</strong>
<span id="context-overflow-message"></span>
+ <a id="context-overflow-action" class="ldr-alert-action">
+ View overflow details
+ <span aria-hidden="true">→</span>
+ </a>
</div>
</div>
<div class="ldr-results-content" id="results-content">
diff --git a/src/local_deep_research/web/warning_checks/context.py b/src/local_deep_research/web/warning_checks/context.py
index 078391d712..654884123b 100644
--- a/src/local_deep_research/web/warning_checks/context.py
+++ b/src/local_deep_research/web/warning_checks/context.py
@@ -50,6 +50,8 @@ def check_context_below_history(
f"(min safe: {min_safe_context:,}). This may cause truncation."
),
"dismissKey": "app.warnings.dismiss_context_reduced",
+ "actionUrl": "/metrics/context-overflow",
+ "actionLabel": "View context metrics",
}
@@ -76,4 +78,6 @@ def check_context_truncation_history(
f"or higher context. Consider increasing context window."
),
"dismissKey": "app.warnings.dismiss_context_reduced",
+ "actionUrl": "/metrics/context-overflow",
+ "actionLabel": "View context metrics",
}
diff --git a/tests/web/routes/test_context_overflow_coverage.py b/tests/web/routes/test_context_overflow_coverage.py
index dd60919278..13bb85401e 100644
--- a/tests/web/routes/test_context_overflow_coverage.py
+++ b/tests/web/routes/test_context_overflow_coverage.py
@@ -153,7 +153,11 @@ def client(app):
def authed_client(client):
with client.session_transaction() as sess:
sess["username"] = "testuser"
- return client
+ with patch(
+ f"{MODULE}.SettingsManager",
+ return_value=MagicMock(get_setting=MagicMock(return_value=8192)),
+ ):
+ yield client
# ---------------------------------------------------------------------------
diff --git a/tests/web/routes/test_context_overflow_logic.py b/tests/web/routes/test_context_overflow_logic.py
index 3b100de450..bef9c64744 100644
--- a/tests/web/routes/test_context_overflow_logic.py
+++ b/tests/web/routes/test_context_overflow_logic.py
@@ -69,6 +69,10 @@ def _authenticated_client(app):
patches = [
patch("local_deep_research.web.auth.decorators.db_manager", mock_db),
patch(f"{_ROUTES_MOD}.get_user_db_session", side_effect=_fake_session),
+ patch(
+ f"{_ROUTES_MOD}.SettingsManager",
+ return_value=Mock(get_setting=Mock(return_value=8192)),
+ ),
]
started = []
diff --git a/tests/web/warning_checks/test_context.py b/tests/web/warning_checks/test_context.py
index 50fac3e3d1..eeb28153ce 100644
--- a/tests/web/warning_checks/test_context.py
+++ b/tests/web/warning_checks/test_context.py
@@ -151,13 +151,22 @@ class TestCheckContextTruncationHistory:
db = Mock()
db.query.return_value.filter.return_value.filter.return_value.scalar.return_value = 1
result = check_context_truncation_history(db, local_context=4096)
- assert set(result.keys()) == {
+ required = {
"type",
"icon",
"title",
"message",
"dismissKey",
}
+ assert required.issubset(set(result.keys()))
+
+ def test_warning_dict_has_action_link(self):
+ """Truncation warnings carry actionUrl/actionLabel pointing to the diagnostic page."""
+ db = Mock()
+ db.query.return_value.filter.return_value.filter.return_value.scalar.return_value = 1
+ result = check_context_truncation_history(db, local_context=4096)
+ assert result["actionUrl"] == "/metrics/context-overflow"
+ assert result["actionLabel"]
def test_dismiss_key(self):
db = Mock()
diff --git a/tests/web/warning_checks/test_warning_checks_high_value.py b/tests/web/warning_checks/test_warning_checks_high_value.py
index 16fa7a439c..fca20b87ae 100644
--- a/tests/web/warning_checks/test_warning_checks_high_value.py
+++ b/tests/web/warning_checks/test_warning_checks_high_value.py
@@ -187,10 +187,10 @@ class TestCheckContextTruncationHistoryEdgeCases:
assert "50 time(s)" in result["message"]
def test_warning_dict_structure(self):
- """Warning dict has all expected keys."""
+ """Warning dict has all required keys (may carry optional enrichment fields)."""
mock_session = MagicMock()
mock_session.query.return_value.filter.return_value.filter.return_value.scalar.return_value = 5
result = check_context_truncation_history(mock_session, 8192)
- expected_keys = {"type", "icon", "title", "message", "dismissKey"}
- assert set(result.keys()) == expected_keys
+ required_keys = {"type", "icon", "title", "message", "dismissKey"}
+ assert required_keys.issubset(set(result.keys()))