feat(ai): add source-aware log analysis and configurable log context - #5353
feat(ai): add source-aware log analysis and configurable log context#5353alti3 wants to merge 2 commits into
Conversation
| async read(path, start, length) { | ||
| const handle = await call<Buffer>((done) => sftp.open(path, "r", done)); | ||
| try { | ||
| const stat = await call<Stats>((done) => sftp.fstat(handle, done)); | ||
| if (!stat.isFile()) throw new Error("Only regular files can be read"); |
There was a problem hiding this comment.
Remote source inspection checks that a path is inside the checkout, but later opens that path through SFTP without preventing symlink following. If a deployment replaces the checked checkout entry with a symlink between those operations, the read can access a file outside the checkout and send its contents to the configured AI provider. The local adapter prevents this with O_NOFOLLOW; remote source reads need an equivalent atomic safeguard or must be disabled when one cannot be provided.
How this was verified: Remote reads validate the path before calling sftp.open(path, "r"), while deployment operations can concurrently recreate the same checkout and source tool results are forwarded to the configured model.
| deployment.schedule?.serverId || | ||
| service?.serverId || | ||
| null; | ||
| if (!service && !serverId) throw denied(); |
There was a problem hiding this comment.
Web-server backup deployments have neither a linked service nor a server ID, so this condition rejects their analysis with FORBIDDEN. Authorized owners and admins can view these local backup logs, but the updated UI now sends the deployment ID instead of the loaded log text. As a result, selecting Analyze fails rather than analyzing the backup log. Permit this authorized local deployment case or retain the text-log fallback for targets without a service or server.
What is this PR about?
Allow AI log analysis to investigate relevant application source alongside deployment and runtime logs, with explicit per-provider opt-in. Add a configurable log-line limit in the same AI settings form, and fetch recent logs on the server independently of the log viewer's filters or loaded-line count.
Closes #5352.
AI settings and user experience
Source-aware analysis
listFiles, literalsearchFiles, and line-numberedreadFiletools. Ask the model to correlate source with logs, cite file paths and lines, and distinguish evidence from inference.Access controls and resource limits
.envfiles, Git internals, binary files, dependencies, and generated output.Database and documentation
0192_ai_log_inspection.sqland its Drizzle snapshot/journal entry, regenerated on currentcanaryto avoid migration-number conflicts.Validation
corepack pnpm --filter dokploy test --run __test__/ai __test__/permissions: 108 tests passed across 10 files after updating the branch to currentcanary.corepack pnpm --filter dokploy typecheck: passed after refreshing dependencies for currentcanary.git diff --check.Review note: most added lines are the required generated Drizzle snapshot; its schema diff changes only the
aitable.Testing scope: browser/live-model checks and the screenshots were captured before the final
canaryrefresh, using disposable fixtures and a local mock OpenAI-compatible provider, not a hosted LLM. SSH/SFTP and Swarm task behavior have mocked test coverage; they were not validated against a live remote SSH host or Swarm cluster. The local browser server was run without the log-stream WebSocket server, which explains the background loading indicators in the screenshots; AI independently fetched the logs successfully. A full production build was not run.Checklist
canary(updated to currentcanarybefore submission).Issues related
Closes #5352 — Optional source code inspection and configurable log context for AI log analysis.
Screenshots
Screenshots use local test data and a mock model. Images are hosted on a separate assets branch in the contributor fork and are not included in the application diff.
Per-provider AI settings
Source-inspection opt-in and configurable log context (321 shown as a persisted custom value; the default is 200).
Runtime log analysis
251 lines analyzed independently of the viewer's 100-line setting, with source status, checkout notice, inspected files, and a file/line citation.
Deployment log analysis
Deployment analysis reports its three-line input and source evidence in the same UI.
Greptile Summary
This PR adds provider-configurable AI log context and optional source-aware analysis, moves deployment and runtime log retrieval to authorized server-side target resolution, adds bounded local/remote source-reading tools, and updates the dashboard and database schema.
Confidence Score: 2/5
The PR is not safe to merge until remote source reads cannot escape the checkout during concurrent mutation and local web-server backup logs remain analyzable.
Remote SFTP source inspection can follow a replacement symlink after containment validation and disclose an outside file to the AI provider, while deployment-target resolution unconditionally rejects supported web-server backup deployments that have no service or server ID.
Files Needing Attention: packages/server/src/utils/ai/file-access.ts, packages/server/src/utils/ai/source-reader.ts, packages/server/src/services/ai-log-context.ts
Security Review
Remote SFTP source reads have a check/use race: checkout paths are validated before a separate symlink-following open, allowing concurrent checkout replacement to redirect an opted-in source read outside the checkout and disclose host file contents to the configured AI provider.
Reviews (1): Last reviewed commit: "feat: migrate AI source inspection and l..." | Re-trigger Greptile