Skip to content

feat(ai): add source-aware log analysis and configurable log context - #5353

Open
alti3 wants to merge 2 commits into
Dokploy:canaryfrom
alti3:feat/ai-log-source-inspection
Open

feat(ai): add source-aware log analysis and configurable log context#5353
alti3 wants to merge 2 commits into
Dokploy:canaryfrom
alti3:feat/ai-log-source-inspection

Conversation

@alti3

@alti3 alti3 commented Sep 4, 2026

Copy link
Copy Markdown

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

  • Add Inspect source code when analyzing logs, disabled by default for both existing and new providers.
  • Add Log lines sent to AI, defaulting to 200, with integer validation from 1 to 10,000.
  • Persist both settings per provider; preserve them on partial provider updates.
  • Pass deployment/container/service identifiers from log viewers so analysis retrieves the selected target's recent logs directly.
  • Show the actual analyzed line count, source-inspection status, inspected file paths, and investigation/truncation/fallback notices.
  • Reset analysis when the target or provider changes and ignore stale responses.

Source-aware analysis

  • Add bounded, read-only listFiles, literal searchFiles, and line-numbered readFile tools. Ask the model to correlate source with logs, cite file paths and lines, and distinguish evidence from inference.
  • Resolve available application, Compose, and preview checkouts, including remote build/deployment servers through SSH/SFTP.
  • Support deployment logs and native Docker / Swarm runtime logs, including Swarm task IDs returned by the existing selectors.
  • Clearly disclose that the available checkout may differ from the revision that produced the logs. This does not clone historical revisions, modify files, execute model-requested commands, or redeploy services.
  • Fall back to log-only analysis with an explanation when source is unavailable or the model does not support tools. Legacy text-only callers remain supported without source access.

Access controls and resource limits

  • Validate provider organization ownership and target/service/server permissions before retrieving logs or source; verify Docker target association with the selected service.
  • Confine source reads to the resolved checkout; reject traversal and symlinks, and exclude credential files, .env files, Git internals, binary files, dependencies, and generated output.
  • Bound log payloads to 1 MiB and source investigation to eight tool rounds, 40 tool calls, 20 file reads, 64 KiB per file, and 256 KiB of source reads/output, with timeouts and limitation notices.
  • Treat logs and source as untrusted evidence. Source opt-in sends relevant code to the selected provider; exclusions cannot prevent secrets embedded in ordinary source or log text from being sent.

Database and documentation

Validation

  • corepack pnpm --filter dokploy test --run __test__/ai __test__/permissions: 108 tests passed across 10 files after updating the branch to current canary.
  • corepack pnpm --filter dokploy typecheck: passed after refreshing dependencies for current canary.
  • Biome checked all 19 changed TypeScript files: no errors; three warnings in unchanged code.
  • Applied the migration chain to a disposable PostgreSQL 17 database; verified default values, persistence, partial updates, and cross-organization denial against the database.
  • Local browser checks verified provider creation/edit persistence and analysis in both runtime and deployment log dialogs, without page errors.
  • Live checks used real Docker stdout/stderr and deployment log files with a local mock AI provider: runtime analysis fetched more lines than the viewer's configured limit, source tools read a fixture file and returned a path/line citation, and disabling inspection restored log-only behavior.
  • git diff --check.

Review note: most added lines are the required generated Drizzle snapshot; its schema diff changes only the ai table.

Testing scope: browser/live-model checks and the screenshots were captured before the final canary refresh, 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

  • Created a dedicated branch based on canary (updated to current canary before submission).
  • Read and followed the contribution guide.
  • Tested the feature in a local instance; validation details and limitations are listed above.
  • Added focused automated tests and a companion documentation PR.

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).

AI provider settings with source inspection and configurable log lines

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.

Runtime analysis with independent log count and source evidence

Deployment log analysis

Deployment analysis reports its three-line input and source evidence in the same UI.

Deployment log analysis with inspected source files

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.

  • Adds per-provider source-inspection and log-line settings with migration defaults.
  • Adds deployment, native Docker, and Swarm log target resolution with permission checks.
  • Adds bounded source listing, literal search, and line-numbered file reads.
  • Updates log-analysis UI state, notices, and inspected-file reporting.
  • Adds focused tests for analysis behavior, permissions, log windows, remote access, and source exclusions.

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

Greptile also left 2 inline comments on this PR.

Comment on lines +124 to +128
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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Remote Reads Follow Symlinks

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Backup Analysis Is Denied

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Optional source code inspection and configurable log context for AI log analysis

1 participant