Agent Manager message in a log: "Invalid or nonexistent document" about the just running agent. Why is it happening?

I have the following picture about my scheduled agent in a log:

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document #: 7420

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document #: 7421

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document #: 7422

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document

#: 7423

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document #: 7424

03/14/2008 02:30:26 PM AMgr: Agent (‘Update Thread Maps’ in ‘\mydbname.nsf’) printing: processed document #: 7425

03/14/2008 02:30:31 PM AMgr: Error executing agent ‘Update Thread Maps’ in ‘\mydbname.nsf’: Invalid or nonexistent document

In an agent log I have this message: ERROR: Agent did not complete within the time limit.

MY problem is that the error appears even if I have less then 10 unprocessed documents in a selection for the agent.

What might go wrong here? Should I increase the time frame for the agent run (it is already 30 min.)?

INteresting thing, that the same agent works fine in a bunch of other databases on the same server…

Thanks!

Subject: Agent Manager message in a log: “Invalid or nonexistent document” about the just running agent. Why is it happening?

You didn’t show us any code, but the symptoms give us some hints. First, check to see if you have a valid handle on a NotesDocument before trying to use it. Second, if the agent is only processing 10 documents, then it probably is stuck in an endless loop. Show us the code for the agents and we can tell you more.

if sDoc is nothing then …

Subject: RE: Agent Manager message in a log: “Invalid or nonexistent document” about the just running agent. Why is it happening?

Trying to send a code. Unfortunately it is pretty complex and has several functions. I’m posting the Initialize function and also 2 others that presumably can cause the problem:

Sub Initialize

 'On Error Goto ErrorRoutine

' Set up our basic variables

On Error Resume Next

Set s = New NotesSession

Set db = s.CurrentDatabase



 ' Get the view we'll use for building threads

Set viewThreads = db.GetView( "(Threads)" )



 ' Fill our list of main topics to be processed

Call ProcessDocuments



 ' For each main topic in our list, process it!



Forall topic In topics

	ProcessMainTopic( Listtag(topic) )

End Forall



'NN test:

Print "Job done..."



Exit Sub

ErrorRoutine:

Print "Unexpected condition @ " & Erl & ": " & Err & " - " & Error 

Err = 0

Exit Sub

End Sub

=================

Sub ProcessDocuments

Dim coll As NotesDocumentCollection

Set coll = db.UnprocessedDocuments

'On Error Goto ErrorHndlr

On Error Resume Next

 ' Work through the documents, and for each one, find the main topic.

Dim doc As NotesDocument

Dim i As Integer

'NN TEST

Print "amount of documents to process is: " + Cstr(coll.Count)

For i = 1 To coll.Count

	'NN TEST

	Set doc = coll.GetNthDocument( i )

	'TEST NN

	If doc Is Nothing Then

		Goto EndOfStory

	'TEST NN

		Print "No Docs topics to process"

	End If

	

      ' Is this a discussion topic?

	If (((doc.Form(0) = "MainTopic") Or (doc.Form(0) = "MainNotes") Or (doc.Form(0) = "RespNotes") Or (doc.Form(0) = "Response")) ) Then

		

           ' We find the main topic by walking up the parent hierarchy.

		Dim docMain As NotesDocument

		Set docMain = GetMainTopic( doc )

		

		

		If Not (docMain Is Nothing) Then

				'NN TEST

			Print "processed document #: " + Cstr(i)

                ' If the document has no MainUNID item, it is a hold-over from pre-threaded

                ' days: write the item in.

			If Not (doc.HasItem( "MainUNID" )) Then

				Call doc.ReplaceItemValue( "MainUNID", docMain.UniversalID )

				Call doc.Save( True, False )

			End If

			

                ' docMain is now the main topic. Add it to our list of main topics to process

			topics%( docMain.NoteID ) = 1

		End If

	End If

	

      ' Without this next line, the agent will run on all documents all the time.

	Call s.UpdateProcessedDoc( doc )

	

	

Next

'NN TEST

EndOfStory:

ErrorHndlr:

Dim ErrorMessage As String

Dim unid As String

unid = doc.UniversalID

ErrorMessage = "ProcessDocuments Error #" & Str(Err) & " :" & Error$  & " at line " & Erl() & " " & unid



Print ErrorMessage

Exit Sub	

End Sub

===============

Sub ProcessMainTopic( id As String )

 ' Open the main topic document

Dim docTopic As NotesDocument

Set docTopic = db.GetDocumentByID( id$ )

On Error Resume Next



 ' Look up the main topic in the view of topics. If it doesn't exist, then

 ' this isn't something we should worry about.



Dim docView As NotesDocument

Set docView = viewThreads.GetDocumentByKey( docTopic.UniversalID )



If docView Is Nothing Then

	'TEST NN Exit Sub

	Goto EndOfStory

	'TEST NN

	Print "No Main topics to process"

End If



 ' Clean out any old map in this document

Call docTopic.RemoveItem( "ThreadMap" )



 ' Create the new body of the map

Dim map As NotesItem

Dim mapStr( 0 To 0 ) As String

mapStr( 0 ) = ""

Set map = New NotesItem( docTopic, "ThreadMap", mapStr )



Call map.AppendToTextList( LineForDocument( docTopic ) )



Call AddChildrenToMap( map, docView, 1 )



 ' Save the map document to the database



Call docTopic.Save(True, False)

EndOfStory:

End Sub

============

Thanks!