Context Collection¶
Context collection helps the AI understand your application by gathering relevant information from your codebase, logs, and configuration.
What is Context Collection?¶
When an error is detected, the connector can collect:
- Code files related to the error
- Configuration (for example
config.php,package.json,requirements.txt) - Log files and any custom monitored log paths you set
How It Works¶
- Automatic collection - When an error is detected, the connector gathers context.
- Detection snapshot - When supported, connectors also capture a small sanitized excerpt of the failing source file at detection time (if the file is readable on the host). That snapshot is stored with the error and used when a live refresh from the site is unavailable (for example during a WordPress theme fatal).
- AI analysis - Context is sent with the error. The prompt template uses the site's optional language/framework, connector-reported context, or the error content.
- Improved fixes - More context usually means more accurate patches.
Automatic Context Collection¶
The connector collects from:
- Error location - Code files where the error occurred (live file-content fetch during analysis)
- Related paths (first pass) - Same-directory or one-level parent-relative imports/requires in the primary excerpt (capped at 3 files total with traceback frames)
- Detection snapshot - Small sanitized primary-file excerpt at ingest when readable
- Configuration / logs - Site environment summary and configured log paths
Plan-based context depth¶
Context depth follows advanced_fixes (Core and Pro; Personal uses the narrower window):
- Standard (Personal): narrower line window; single AI pass
- Advanced (Core/Pro): wider windows, richer site environment summary, and optionally one automatic extra-file follow-up when Pass 1 is Not patchable for insufficient context and the model names 1 - 2 project-relative paths
Both tiers use the same safety rules. The difference is depth and that one entitled follow-up.
Line numbers in analysis¶
In Error details → Analysis, source excerpts show absolute line numbers from the original file (L 54| …). The line marked ← ERROR matches the stack trace. Unified diffs use standard @@ hunk headers.
Custom log paths¶
Add extra log files under Sites → expand the site → Customize next to Monitored Logs (Core and Pro - Advanced Error Monitoring). Full path rules: Site paths.
- Paths may be absolute or relative to the app root
- The connector needs read permission
- Very large files may be truncated to the last N lines
- Prefer UTF-8 encoding
Logging tips for better analysis¶
Patcherly analyzes the error text your connector sends from monitored log files. Message-only lines (no stack frames) often leave the AI without enough call-site context. Patcherly does not inject tracing into your app - standalone connectors only see what lands in watched logs.
Prefer one multi-line event with: the error message / exception type, stack frames with file paths and line numbers, and (for PHP) a clear "thrown in" locus when available.
| Stack | Tip |
|---|---|
| WordPress / PHP | Enable WP_DEBUG_LOG (display off in production). Prefer full Stack trace: / #N frames over a path-only fatal line. Confirm debug.log (or your custom path) is monitored. |
| Laravel | Prefer report($e) / Log::error(..., ['exception' => $e]) so the stack is written. Monitor storage/logs/laravel.log. |
| Python | Use logger.exception("…") or exc_info=True. Point Patcherly at the framework/stderr log file. |
| Node.js | Log err.stack (or a serializer that includes stack), not only err.message. |
Ignored - no source file path means the log had no extractable path. Not patchable after analysis often means a missing stack or thin FILE CONTEXT - see Auto-analysis.
Configure which files are watched under Site paths.
Context Refresh¶
- Go to your site's page in the dashboard.
- Click Refresh Context.
- Wait for collection to complete.
Viewing Collected Context¶
Open an error → scroll to Context → view collected files and logs.
Best Practices¶
- Include log paths that contain useful debugging information
- Avoid logs with passwords, API keys, or personal information
- Update paths when your app structure changes
- Watch very large log files (rotation helps)
- Add descriptions on custom log paths so you remember them later
Troubleshooting¶
Context Not Collected¶
- Check connector read permissions and that paths exist
- Confirm your plan includes Advanced Error Monitoring for custom logs
- Review connector logs for collection errors
Context Too Large¶
- Disable unnecessary log paths; the system truncates very large files
Context Outdated¶
- Trigger a manual refresh; context also refreshes when new errors occur
Related Features¶
- Site paths - Monitoring / patch exclusions and monitored logs
- Understanding Errors
- Approving Fixes
- Auto-analysis